1 /* Directory panel listing format editor -- for the Midnight Commander
2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2005,
3 2006, 2007 Free Software Foundation, Inc.
5 Written by: 1994 Radek Doulik
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * \brief Source: directory panel listing format editor
29 #ifdef LISTMODE_EDITOR
34 #include <sys/types.h>
38 #include "lib/global.h"
39 #include "lib/widget.h"
41 #include "lib/tty/tty.h"
42 #include "lib/tty/key.h"
43 #include "lib/skin/skin.h"
45 /* Needed for the extern declarations of integer parameters */
47 #include "panel.h" /* Needed for the externs */
49 #include "layout.h" /* repaint_screen() */
52 /*** global variables ****************************************************************************/
54 /*** file scope macro definitions ****************************************************************/
63 #define B_REMOVE (B_USER + 1)
66 #define B_MINUS (B_USER+1)
68 /*** file scope type declarations ****************************************************************/
70 struct listmode_button
72 int ret_cmd
, flags
, y
, x
;
83 /*** file scope variables ************************************************************************/
85 static WListbox
*l_listmode
;
89 static char *listmode_section
= "[Listing format edit]";
91 static char *s_genwidth
[2] = { "Half width", "Full width" };
93 static WRadio
*radio_genwidth
;
94 static char *s_columns
[2] = { "One column", "Two columns" };
96 static WRadio
*radio_columns
;
97 static char *s_justify
[3] = { "Left justified", "Default justification", "Right justified" };
99 static WRadio
*radio_justify
;
100 static char *s_itemwidth
[3] = { "Free width", "Fixed width", "Growable width" };
102 static WRadio
*radio_itemwidth
;
104 /*** file scope functions ************************************************************************/
105 /* --------------------------------------------------------------------------------------------- */
108 select_new_item (void)
110 char **possible_items
;
115 possible_items
= panel_get_user_possible_fields (NULL
);
117 mylistbox
= create_listbox_window (20, 12, "Add listing format item", listmode_section
);
118 for (i
= 0; possible_items
[i
]; i
++)
120 listbox_add_item (mylistbox
->list
, LISTBOX_APPEND_AT_END
, 0, possible_items
[i
], NULL
);
123 i
= run_listbox (mylistbox
);
125 ret
= g_strdup (possible_items
[i
]);
127 g_strfreev (possible_items
);
131 /* --------------------------------------------------------------------------------------------- */
134 bplus_cback (int action
)
139 /* --------------------------------------------------------------------------------------------- */
142 bminus_cback (int action
)
147 /* --------------------------------------------------------------------------------------------- */
150 badd_cback (int action
)
152 char *s
= select_new_item ();
155 listbox_add_item (l_listmode
, LISTBOX_APPEND_AT_END
, 0, s
, NULL
);
161 /* --------------------------------------------------------------------------------------------- */
164 bremove_cback (int action
)
166 listbox_remove_current (l_listmode
);
170 /* --------------------------------------------------------------------------------------------- */
173 init_listmode (char *oldlistformat
)
177 int format_width
= 0;
178 int format_columns
= 0;
179 Dlg_head
*listmode_dlg
;
181 static struct listmode_label listmode_labels
[] = {
182 {UY
+ 13, UX
+ 22, "Item width:"}
185 static struct listmode_button listmode_but
[] = {
186 {B_CANCEL
, NORMAL_BUTTON
, BY
, BX
+ 53, "&Cancel", NULL
},
187 {B_ADD
, NORMAL_BUTTON
, BY
, BX
+ 22, "&Add item", badd_cback
},
188 {B_REMOVE
, NORMAL_BUTTON
, BY
, BX
+ 10, "&Remove", bremove_cback
},
189 {B_ENTER
, DEFPUSH_BUTTON
, BY
, BX
, "&OK", NULL
},
190 {B_PLUS
, NARROW_BUTTON
, UY
+ 13, UX
+ 37, "&+", bplus_cback
},
191 {B_MINUS
, NARROW_BUTTON
, UY
+ 13, UX
+ 34, "&-", bminus_cback
},
197 create_dlg (TRUE
, 0, 0, 22, 74, dialog_colors
, NULL
, listmode_section
,
198 "Listing format edit", DLG_CENTER
| DLG_REVERSE
);
200 add_widget (listmode_dlg
, groupbox_new (UY
, UX
, 4, 63, "General options"));
201 add_widget (listmode_dlg
, groupbox_new (UY
+ 4, UX
, 11, 18, "Items"));
202 add_widget (listmode_dlg
, groupbox_new (UY
+ 4, UX
+ 20, 11, 43, "Item options"));
204 for (i
= 0; i
< sizeof (listmode_but
) / sizeof (struct listmode_button
); i
++)
205 add_widget (listmode_dlg
,
206 button_new (listmode_but
[i
].y
, listmode_but
[i
].x
,
207 listmode_but
[i
].ret_cmd
,
208 listmode_but
[i
].flags
,
209 listmode_but
[i
].text
, listmode_but
[i
].callback
));
211 /* We add the labels. */
212 for (i
= 0; i
< sizeof (listmode_labels
) / sizeof (struct listmode_label
); i
++)
214 pname
= label_new (listmode_labels
[i
].y
, listmode_labels
[i
].x
, listmode_labels
[i
].text
);
215 add_widget (listmode_dlg
, pname
);
218 radio_itemwidth
= radio_new (UY
+ 9, UX
+ 22, 3, s_itemwidth
);
219 add_widget (listmode_dlg
, radio_itemwidth
);
221 radio_justify
= radio_new (UY
+ 5, UX
+ 22, 3, s_justify
);
222 add_widget (listmode_dlg
, radio_justify
);
223 radio_justify
->sel
= 1;
225 /* get new listbox */
226 l_listmode
= listbox_new (UY
+ 5, UX
+ 1, 9, 16, FALSE
, NULL
);
228 if (strncmp (oldlistformat
, "full ", 5) == 0)
233 if (strncmp (oldlistformat
, "half ", 5) == 0)
237 if (strncmp (oldlistformat
, "2 ", 2) == 0)
242 if (strncmp (oldlistformat
, "1 ", 2) == 0)
246 s
= strtok (oldlistformat
, ",");
250 listbox_add_item (l_listmode
, LISTBOX_APPEND_AT_END
, 0, s
, NULL
);
251 s
= strtok (NULL
, ",");
254 /* add listbox to the dialogs */
255 add_widget (listmode_dlg
, l_listmode
);
257 radio_columns
= radio_new (UY
+ 1, UX
+ 32, 2, s_columns
);
258 add_widget (listmode_dlg
, radio_columns
);
259 radio_columns
->sel
= format_columns
;
260 radio_genwidth
= radio_new (UY
+ 1, UX
+ 2, 2, s_genwidth
);
261 add_widget (listmode_dlg
, radio_genwidth
);
262 radio_genwidth
->sel
= format_width
;
267 /* --------------------------------------------------------------------------------------------- */
270 listmode_done (Dlg_head
* h
)
274 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
278 /* --------------------------------------------------------------------------------------------- */
281 collect_new_format (void)
288 newformat
= g_malloc (1024);
289 if (radio_genwidth
->sel
)
290 strcpy (newformat
, "full ");
292 strcpy (newformat
, "half ");
293 if (radio_columns
->sel
)
294 strcat (newformat
, "2 ");
298 listbox_select_entry (l_listmode
, i
);
299 listbox_get_current (l_listmode
, &text
, &extra
);
303 strcat (newformat
, ",");
304 strcat (newformat
, text
);
310 /* --------------------------------------------------------------------------------------------- */
311 /*** public functions ****************************************************************************/
312 /* --------------------------------------------------------------------------------------------- */
314 /** Return new format or NULL if the user cancelled the dialog */
316 listmode_edit (char *oldlistformat
)
318 char *newformat
= NULL
;
320 Dlg_head
*listmode_dlg
;
322 s
= g_strdup (oldlistformat
);
323 listmode_dlg
= init_listmode (s
);
326 if (run_dlg (listmode_dlg
) == B_ENTER
)
328 newformat
= collect_new_format ();
331 listmode_done (listmode_dlg
);
335 /* --------------------------------------------------------------------------------------------- */
337 #endif /* LISTMODE_EDITOR */