1 /* Directory panel listing format editor -- for the Midnight Commander
2 Copyright (C) 1994, 1995 The Free Software Foundation
4 Written by: 1994 Radek Doulik
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifdef LISTMODE_EDITOR
31 #include <sys/types.h>
40 #include "dialog.h" /* For do_refresh() */
43 /* Needed for the extern declarations of integer parameters */
45 #include "panel.h" /* Needed for the externs */
59 #define B_REMOVE B_USER + 1
61 static WListbox
*l_listmode
;
65 static char *listmode_section
= "[Listing format edit]";
67 static char *s_genwidth
[2] = { "Half width", "Full width" };
68 static WRadio
*radio_genwidth
;
69 static char *s_columns
[2] = { "One column", "Two columns" };
70 static WRadio
*radio_columns
;
71 static char *s_justify
[3] =
72 { "Left justified", "Default justification", "Right justified" };
73 static WRadio
*radio_justify
;
74 static char *s_itemwidth
[3] =
75 { "Free width", "Fixed width", "Growable width" };
76 static WRadio
*radio_itemwidth
;
78 struct listmode_button
{
79 int ret_cmd
, flags
, y
, x
;
83 static struct listmode_button listmode_but
[BUTTONS
] = {
84 {B_CANCEL
, NORMAL_BUTTON
, 0, 53, "&Cancel"},
85 {B_ADD
, NORMAL_BUTTON
, 0, 22, "&Add item"},
86 {B_REMOVE
, NORMAL_BUTTON
, 0, 10, "&Remove"},
87 {B_ENTER
, DEFPUSH_BUTTON
, 0, 0, "&Ok"},
91 #define B_MINUS B_USER+1
93 struct listmode_label
{
98 static struct listmode_label listmode_labels
[LABELS
] = {
99 {UY
, UX
+ 1, " General options "},
100 {UY
+ 4, UX
+ 1, " Items "},
101 {UY
+ 4, UX
+ 21, " Item options"},
102 {UY
+ 13, UX
+ 22, "Item width:"}
106 listmode_refresh (Dlg_head
* h
)
108 common_dialog_repaint (h
);
110 attrset (COLOR_NORMAL
);
111 draw_box (h
, UY
, UX
, 4, 63);
112 draw_box (h
, UY
+ 4, UX
, 11, 18);
113 draw_box (h
, UY
+ 4, UX
+ 20, 11, 43);
117 bplus_cback (int action
, void *data
)
123 bminus_cback (int action
, void *data
)
129 listmode_callback (Dlg_head
* h
, int Par
, int Msg
)
134 listmode_refresh (h
);
141 attrset (COLOR_NORMAL
);
142 dlg_move (h
, UY
+ 13, UX
+ 35);
144 attrset (MENU_ENTRY_COLOR
);
157 init_listmode (char *oldlistformat
)
161 int format_width
= 0;
162 int format_columns
= 0;
163 Dlg_head
*listmode_dlg
;
168 create_dlg (0, 0, 22, 74, dialog_colors
, listmode_callback
,
169 listmode_section
, "Listing format edit", DLG_CENTER
);
171 #define XTRACT(i) BY+listmode_but[i].y, BX+listmode_but[i].x, listmode_but[i].ret_cmd, listmode_but[i].flags, listmode_but[i].text, 0, 0, NULL
173 for (i
= 0; i
< BUTTONS
; i
++)
174 add_widget (listmode_dlg
, button_new (XTRACT (i
)));
176 /* We add the labels. */
177 for (i
= 0; i
< LABELS
; i
++) {
179 label_new (listmode_labels
[i
].y
, listmode_labels
[i
].x
,
180 listmode_labels
[i
].text
, NULL
);
181 add_widget (listmode_dlg
, pname
);
184 add_widget (listmode_dlg
,
185 button_new (UY
+ 13, UX
+ 37, B_MINUS
, NORMAL_BUTTON
, "&-",
186 bminus_cback
, 0, NULL
));
187 add_widget (listmode_dlg
,
188 button_new (UY
+ 13, UX
+ 34, B_PLUS
, NORMAL_BUTTON
, "&+",
189 bplus_cback
, 0, NULL
));
190 radio_itemwidth
= radio_new (UY
+ 9, UX
+ 22, 3, s_itemwidth
, 1, NULL
);
191 add_widget (listmode_dlg
, radio_itemwidth
);
193 radio_justify
= radio_new (UY
+ 5, UX
+ 22, 3, s_justify
, 1, NULL
);
194 add_widget (listmode_dlg
, radio_justify
);
195 radio_justify
->sel
= 1;
197 /* get new listbox */
198 l_listmode
= listbox_new (UY
+ 5, UX
+ 1, 16, 9, 0, l_call
, NULL
);
200 if (strncmp (oldlistformat
, "full ", 5) == 0) {
204 if (strncmp (oldlistformat
, "half ", 5) == 0) {
207 if (strncmp (oldlistformat
, "2 ", 2) == 0) {
211 if (strncmp (oldlistformat
, "1 ", 2) == 0) {
214 s
= strtok (oldlistformat
, ",");
217 listbox_add_item (l_listmode
, 0, 0, s
, NULL
);
218 s
= strtok (NULL
, ",");
221 /* add listbox to the dialogs */
222 add_widget (listmode_dlg
, l_listmode
);
224 radio_columns
= radio_new (UY
+ 1, UX
+ 32, 2, s_columns
, 1, NULL
);
225 add_widget (listmode_dlg
, radio_columns
);
226 radio_columns
->sel
= format_columns
;
227 radio_genwidth
= radio_new (UY
+ 1, UX
+ 2, 2, s_genwidth
, 1, NULL
);
228 add_widget (listmode_dlg
, radio_genwidth
);
229 radio_genwidth
->sel
= format_width
;
235 listmode_done (Dlg_head
* h
)
239 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
244 select_new_item (void)
246 /* NOTE: The following array of possible items must match the
247 formats array in screen.c. Better approach might be to make the
248 formats array global */
249 char *possible_items
[] =
250 { "name", "size", "type", "mtime", "perm", "mode", "|", "nlink",
251 "owner", "group", "atime", "ctime", "space", "mark",
259 create_listbox_window (12, 20, " Add listing format item ",
261 for (i
= 0; possible_items
[i
]; i
++) {
262 listbox_add_item (mylistbox
->list
, 0, 0, possible_items
[i
], NULL
);
265 i
= run_listbox (mylistbox
);
267 return possible_items
[i
];
273 collect_new_format (void)
280 newformat
= g_malloc (1024);
281 if (radio_genwidth
->sel
)
282 strcpy (newformat
, "full ");
284 strcpy (newformat
, "half ");
285 if (radio_columns
->sel
)
286 strcat (newformat
, "2 ");
289 listbox_select_by_number (l_listmode
, i
);
290 listbox_get_current (l_listmode
, &text
, &extra
);
294 strcat (newformat
, ",");
295 strcat (newformat
, text
);
302 listmode_edit (char *oldlistformat
)
304 char *newformat
= NULL
;
306 Dlg_head
*listmode_dlg
;
308 s
= g_strdup (oldlistformat
);
309 listmode_dlg
= init_listmode (s
);
312 while (newformat
== NULL
) {
313 /* display file info */
314 attrset (SELECTED_COLOR
);
317 * FIXME: Calling run_dlg() more than once doesn't work.
318 * This code is broken.
320 run_dlg (listmode_dlg
);
322 switch (listmode_dlg
->ret_value
) {
324 newformat
= g_strdup (oldlistformat
);
328 s
= select_new_item ();
330 listbox_add_item (l_listmode
, 0, 0, s
, NULL
);
334 listbox_remove_current (l_listmode
, 0);
338 newformat
= collect_new_format ();
343 listmode_done (listmode_dlg
);
347 #endif /* LISTMODE_EDITOR */