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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #ifdef LISTMODE_EDITOR
29 #include <sys/types.h>
41 /* Needed for the extern declarations of integer parameters */
43 #include "panel.h" /* Needed for the externs */
55 #define B_REMOVE (B_USER + 1)
57 static WListbox
*l_listmode
;
61 static char *listmode_section
= "[Listing format edit]";
63 static char *s_genwidth
[2] = { "Half width", "Full width" };
64 static WRadio
*radio_genwidth
;
65 static char *s_columns
[2] = { "One column", "Two columns" };
66 static WRadio
*radio_columns
;
67 static char *s_justify
[3] =
68 { "Left justified", "Default justification", "Right justified" };
69 static WRadio
*radio_justify
;
70 static char *s_itemwidth
[3] =
71 { "Free width", "Fixed width", "Growable width" };
72 static WRadio
*radio_itemwidth
;
74 struct listmode_button
{
75 int ret_cmd
, flags
, y
, x
;
81 #define B_MINUS (B_USER+1)
83 struct listmode_label
{
89 select_new_item (void)
91 /* NOTE: The following array of possible items must match the
92 formats array in screen.c. Better approach might be to make the
93 formats array global */
94 char *possible_items
[] =
95 { "name", "size", "type", "mtime", "perm", "mode", "|", "nlink",
96 "owner", "group", "atime", "ctime", "space", "mark",
104 create_listbox_window (12, 20, " Add listing format item ",
106 for (i
= 0; possible_items
[i
]; i
++) {
107 listbox_add_item (mylistbox
->list
, 0, 0, possible_items
[i
], NULL
);
110 i
= run_listbox (mylistbox
);
112 return possible_items
[i
];
118 bplus_cback (int action
)
124 bminus_cback (int action
)
130 badd_cback (int action
)
132 char *s
= select_new_item ();
134 listbox_add_item (l_listmode
, 0, 0, s
, NULL
);
140 bremove_cback (int action
)
142 listbox_remove_current (l_listmode
, 0);
147 init_listmode (char *oldlistformat
)
151 int format_width
= 0;
152 int format_columns
= 0;
153 Dlg_head
*listmode_dlg
;
155 static struct listmode_label listmode_labels
[] = {
156 {UY
+ 13, UX
+ 22, "Item width:"}
159 static struct listmode_button listmode_but
[] = {
160 {B_CANCEL
, NORMAL_BUTTON
, BY
, BX
+ 53, "&Cancel", NULL
},
161 {B_ADD
, NORMAL_BUTTON
, BY
, BX
+ 22, "&Add item", badd_cback
},
162 {B_REMOVE
, NORMAL_BUTTON
, BY
, BX
+ 10, "&Remove", bremove_cback
},
163 {B_ENTER
, DEFPUSH_BUTTON
, BY
, BX
, "&OK", NULL
},
164 {B_PLUS
, NARROW_BUTTON
, UY
+ 13, UX
+ 37, "&+", bplus_cback
},
165 {B_MINUS
, NARROW_BUTTON
, UY
+ 13, UX
+ 34, "&-", bminus_cback
},
171 create_dlg (0, 0, 22, 74, dialog_colors
, NULL
, listmode_section
,
172 "Listing format edit", DLG_CENTER
| DLG_REVERSE
);
174 add_widget (listmode_dlg
,
175 groupbox_new (UX
, UY
, 63, 4, "General options"));
176 add_widget (listmode_dlg
, groupbox_new (UX
, UY
+ 4, 18, 11, "Items"));
177 add_widget (listmode_dlg
,
178 groupbox_new (UX
+ 20, UY
+ 4, 43, 11, "Item options"));
181 i
< sizeof (listmode_but
) / sizeof (struct listmode_button
); i
++)
182 add_widget (listmode_dlg
,
183 button_new (listmode_but
[i
].y
, listmode_but
[i
].x
,
184 listmode_but
[i
].ret_cmd
,
185 listmode_but
[i
].flags
,
186 listmode_but
[i
].text
,
187 listmode_but
[i
].callback
));
189 /* We add the labels. */
191 i
< sizeof (listmode_labels
) / sizeof (struct listmode_label
);
194 label_new (listmode_labels
[i
].y
, listmode_labels
[i
].x
,
195 listmode_labels
[i
].text
);
196 add_widget (listmode_dlg
, pname
);
199 radio_itemwidth
= radio_new (UY
+ 9, UX
+ 22, 3, s_itemwidth
, 1);
200 add_widget (listmode_dlg
, radio_itemwidth
);
202 radio_justify
= radio_new (UY
+ 5, UX
+ 22, 3, s_justify
, 1);
203 add_widget (listmode_dlg
, radio_justify
);
204 radio_justify
->sel
= 1;
206 /* get new listbox */
207 l_listmode
= listbox_new (UY
+ 5, UX
+ 1, 16, 9, NULL
);
209 if (strncmp (oldlistformat
, "full ", 5) == 0) {
213 if (strncmp (oldlistformat
, "half ", 5) == 0) {
216 if (strncmp (oldlistformat
, "2 ", 2) == 0) {
220 if (strncmp (oldlistformat
, "1 ", 2) == 0) {
223 s
= strtok (oldlistformat
, ",");
226 listbox_add_item (l_listmode
, 0, 0, s
, NULL
);
227 s
= strtok (NULL
, ",");
230 /* add listbox to the dialogs */
231 add_widget (listmode_dlg
, l_listmode
);
233 radio_columns
= radio_new (UY
+ 1, UX
+ 32, 2, s_columns
, 1);
234 add_widget (listmode_dlg
, radio_columns
);
235 radio_columns
->sel
= format_columns
;
236 radio_genwidth
= radio_new (UY
+ 1, UX
+ 2, 2, s_genwidth
, 1);
237 add_widget (listmode_dlg
, radio_genwidth
);
238 radio_genwidth
->sel
= format_width
;
244 listmode_done (Dlg_head
*h
)
248 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
253 collect_new_format (void)
260 newformat
= g_malloc (1024);
261 if (radio_genwidth
->sel
)
262 strcpy (newformat
, "full ");
264 strcpy (newformat
, "half ");
265 if (radio_columns
->sel
)
266 strcat (newformat
, "2 ");
269 listbox_select_by_number (l_listmode
, i
);
270 listbox_get_current (l_listmode
, &text
, &extra
);
274 strcat (newformat
, ",");
275 strcat (newformat
, text
);
281 /* Return new format or NULL if the user cancelled the dialog */
283 listmode_edit (char *oldlistformat
)
285 char *newformat
= NULL
;
287 Dlg_head
*listmode_dlg
;
289 s
= g_strdup (oldlistformat
);
290 listmode_dlg
= init_listmode (s
);
293 if (run_dlg (listmode_dlg
) == B_ENTER
) {
294 newformat
= collect_new_format ();
297 listmode_done (listmode_dlg
);
301 #endif /* LISTMODE_EDITOR */