2 Directory panel listing format editor -- for the Midnight Commander
4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2005,
6 The Free Software Foundation, Inc.
10 Janne Kukonlehto, 1995
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 * \brief Source: directory panel listing format editor
34 #ifdef LISTMODE_EDITOR
39 #include <sys/types.h>
43 #include "lib/global.h"
44 #include "lib/widget.h"
46 #include "lib/tty/tty.h"
47 #include "lib/tty/key.h"
48 #include "lib/skin/skin.h"
50 /* Needed for the extern declarations of integer parameters */
52 #include "panel.h" /* Needed for the externs */
56 /*** global variables ****************************************************************************/
58 /*** file scope macro definitions ****************************************************************/
67 #define B_REMOVE (B_USER + 1)
70 #define B_MINUS (B_USER+1)
72 /*** file scope type declarations ****************************************************************/
74 struct listmode_button
76 int ret_cmd
, flags
, y
, x
;
87 /*** file scope variables ************************************************************************/
89 static WListbox
*l_listmode
;
93 static char *listmode_section
= "[Listing format edit]";
95 static char *s_genwidth
[2] = { "Half width", "Full width" };
97 static WRadio
*radio_genwidth
;
98 static char *s_columns
[2] = { "One column", "Two columns" };
100 static WRadio
*radio_columns
;
101 static char *s_justify
[3] = { "Left justified", "Default justification", "Right justified" };
103 static WRadio
*radio_justify
;
104 static char *s_itemwidth
[3] = { "Free width", "Fixed width", "Growable width" };
106 static WRadio
*radio_itemwidth
;
108 /*** file scope functions ************************************************************************/
109 /* --------------------------------------------------------------------------------------------- */
112 select_new_item (void)
114 char **possible_items
;
119 possible_items
= panel_get_user_possible_fields (NULL
);
121 mylistbox
= create_listbox_window (20, 12, "Add listing format item", listmode_section
);
122 for (i
= 0; possible_items
[i
]; i
++)
124 listbox_add_item (mylistbox
->list
, LISTBOX_APPEND_AT_END
, 0, possible_items
[i
], NULL
);
127 i
= run_listbox (mylistbox
);
129 ret
= g_strdup (possible_items
[i
]);
131 g_strfreev (possible_items
);
135 /* --------------------------------------------------------------------------------------------- */
138 bplus_cback (int action
)
143 /* --------------------------------------------------------------------------------------------- */
146 bminus_cback (int action
)
151 /* --------------------------------------------------------------------------------------------- */
154 badd_cback (int action
)
156 char *s
= select_new_item ();
159 listbox_add_item (l_listmode
, LISTBOX_APPEND_AT_END
, 0, s
, NULL
);
165 /* --------------------------------------------------------------------------------------------- */
168 bremove_cback (int action
)
170 listbox_remove_current (l_listmode
);
174 /* --------------------------------------------------------------------------------------------- */
177 init_listmode (char *oldlistformat
)
181 int format_width
= 0;
182 int format_columns
= 0;
183 WDialog
*listmode_dlg
;
185 static struct listmode_label listmode_labels
[] = {
186 {UY
+ 13, UX
+ 22, "Item width:"}
189 static struct listmode_button listmode_but
[] = {
190 {B_CANCEL
, NORMAL_BUTTON
, BY
, BX
+ 53, "&Cancel", NULL
},
191 {B_ADD
, NORMAL_BUTTON
, BY
, BX
+ 22, "&Add item", badd_cback
},
192 {B_REMOVE
, NORMAL_BUTTON
, BY
, BX
+ 10, "&Remove", bremove_cback
},
193 {B_ENTER
, DEFPUSH_BUTTON
, BY
, BX
, "&OK", NULL
},
194 {B_PLUS
, NARROW_BUTTON
, UY
+ 13, UX
+ 37, "&+", bplus_cback
},
195 {B_MINUS
, NARROW_BUTTON
, UY
+ 13, UX
+ 34, "&-", bminus_cback
},
201 create_dlg (TRUE
, 0, 0, 22, 74, dialog_colors
, NULL
, NULL
, listmode_section
,
202 "Listing format edit", DLG_CENTER
| DLG_REVERSE
);
204 add_widget (listmode_dlg
, groupbox_new (UY
, UX
, 4, 63, "General options"));
205 add_widget (listmode_dlg
, groupbox_new (UY
+ 4, UX
, 11, 18, "Items"));
206 add_widget (listmode_dlg
, groupbox_new (UY
+ 4, UX
+ 20, 11, 43, "Item options"));
208 for (i
= 0; i
< sizeof (listmode_but
) / sizeof (struct listmode_button
); i
++)
209 add_widget (listmode_dlg
,
210 button_new (listmode_but
[i
].y
, listmode_but
[i
].x
,
211 listmode_but
[i
].ret_cmd
,
212 listmode_but
[i
].flags
,
213 listmode_but
[i
].text
, listmode_but
[i
].callback
));
215 /* We add the labels. */
216 for (i
= 0; i
< sizeof (listmode_labels
) / sizeof (struct listmode_label
); i
++)
218 pname
= label_new (listmode_labels
[i
].y
, listmode_labels
[i
].x
, listmode_labels
[i
].text
);
219 add_widget (listmode_dlg
, pname
);
222 radio_itemwidth
= radio_new (UY
+ 9, UX
+ 22, 3, s_itemwidth
);
223 add_widget (listmode_dlg
, radio_itemwidth
);
225 radio_justify
= radio_new (UY
+ 5, UX
+ 22, 3, s_justify
);
226 add_widget (listmode_dlg
, radio_justify
);
227 radio_justify
->sel
= 1;
229 /* get new listbox */
230 l_listmode
= listbox_new (UY
+ 5, UX
+ 1, 9, 16, FALSE
, NULL
);
232 if (strncmp (oldlistformat
, "full ", 5) == 0)
237 if (strncmp (oldlistformat
, "half ", 5) == 0)
241 if (strncmp (oldlistformat
, "2 ", 2) == 0)
246 if (strncmp (oldlistformat
, "1 ", 2) == 0)
250 s
= strtok (oldlistformat
, ",");
254 listbox_add_item (l_listmode
, LISTBOX_APPEND_AT_END
, 0, s
, NULL
);
255 s
= strtok (NULL
, ",");
258 /* add listbox to the dialogs */
259 add_widget (listmode_dlg
, l_listmode
);
261 radio_columns
= radio_new (UY
+ 1, UX
+ 32, 2, s_columns
);
262 add_widget (listmode_dlg
, radio_columns
);
263 radio_columns
->sel
= format_columns
;
264 radio_genwidth
= radio_new (UY
+ 1, UX
+ 2, 2, s_genwidth
);
265 add_widget (listmode_dlg
, radio_genwidth
);
266 radio_genwidth
->sel
= format_width
;
271 /* --------------------------------------------------------------------------------------------- */
274 listmode_done (WDialog
* h
)
278 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
282 /* --------------------------------------------------------------------------------------------- */
285 collect_new_format (void)
292 newformat
= g_malloc (1024);
293 if (radio_genwidth
->sel
)
294 strcpy (newformat
, "full ");
296 strcpy (newformat
, "half ");
297 if (radio_columns
->sel
)
298 strcat (newformat
, "2 ");
302 listbox_select_entry (l_listmode
, i
);
303 listbox_get_current (l_listmode
, &text
, &extra
);
307 strcat (newformat
, ",");
308 strcat (newformat
, text
);
314 /* --------------------------------------------------------------------------------------------- */
315 /*** public functions ****************************************************************************/
316 /* --------------------------------------------------------------------------------------------- */
318 /** Return new format or NULL if the user cancelled the dialog */
320 listmode_edit (char *oldlistformat
)
322 char *newformat
= NULL
;
324 WDialog
*listmode_dlg
;
326 s
= g_strdup (oldlistformat
);
327 listmode_dlg
= init_listmode (s
);
330 if (run_dlg (listmode_dlg
) == B_ENTER
)
332 newformat
= collect_new_format ();
335 listmode_done (listmode_dlg
);
339 /* --------------------------------------------------------------------------------------------- */
341 #endif /* LISTMODE_EDITOR */