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>
46 /* Needed for the extern declarations of integer parameters */
48 #include "panel.h" /* Needed for the externs */
50 #include "layout.h" /* repaint_screen() */
61 #define B_REMOVE (B_USER + 1)
63 static WListbox
*l_listmode
;
67 static char *listmode_section
= "[Listing format edit]";
69 static char *s_genwidth
[2] = { "Half width", "Full width" };
70 static WRadio
*radio_genwidth
;
71 static char *s_columns
[2] = { "One column", "Two columns" };
72 static WRadio
*radio_columns
;
73 static char *s_justify
[3] =
74 { "Left justified", "Default justification", "Right justified" };
75 static WRadio
*radio_justify
;
76 static char *s_itemwidth
[3] =
77 { "Free width", "Fixed width", "Growable width" };
78 static WRadio
*radio_itemwidth
;
80 struct listmode_button
{
81 int ret_cmd
, flags
, y
, x
;
87 #define B_MINUS (B_USER+1)
89 struct listmode_label
{
95 select_new_item (void)
97 char **possible_items
;
102 possible_items
= panel_get_user_possible_fields(NULL
);
105 create_listbox_window (20, 12, " Add listing format item ",
107 for (i
= 0; possible_items
[i
]; i
++) {
108 listbox_add_item (mylistbox
->list
, 0, 0, possible_items
[i
], NULL
);
111 i
= run_listbox (mylistbox
);
113 ret
= g_strdup(possible_items
[i
]);
115 g_strfreev (possible_items
);
120 bplus_cback (int action
)
126 bminus_cback (int action
)
132 badd_cback (int action
)
134 char *s
= select_new_item ();
136 listbox_add_item (l_listmode
, 0, 0, s
, NULL
);
143 bremove_cback (int action
)
145 listbox_remove_current (l_listmode
, 0);
150 init_listmode (char *oldlistformat
)
154 int format_width
= 0;
155 int format_columns
= 0;
156 Dlg_head
*listmode_dlg
;
158 static struct listmode_label listmode_labels
[] = {
159 {UY
+ 13, UX
+ 22, "Item width:"}
162 static struct listmode_button listmode_but
[] = {
163 {B_CANCEL
, NORMAL_BUTTON
, BY
, BX
+ 53, "&Cancel", NULL
},
164 {B_ADD
, NORMAL_BUTTON
, BY
, BX
+ 22, "&Add item", badd_cback
},
165 {B_REMOVE
, NORMAL_BUTTON
, BY
, BX
+ 10, "&Remove", bremove_cback
},
166 {B_ENTER
, DEFPUSH_BUTTON
, BY
, BX
, "&OK", NULL
},
167 {B_PLUS
, NARROW_BUTTON
, UY
+ 13, UX
+ 37, "&+", bplus_cback
},
168 {B_MINUS
, NARROW_BUTTON
, UY
+ 13, UX
+ 34, "&-", bminus_cback
},
174 create_dlg (0, 0, 22, 74, dialog_colors
, NULL
, listmode_section
,
175 "Listing format edit", DLG_CENTER
| DLG_REVERSE
);
177 add_widget (listmode_dlg
,
178 groupbox_new (UY
, UX
, 4, 63, "General options"));
179 add_widget (listmode_dlg
, groupbox_new (UY
+ 4, UX
, 11, 18, "Items"));
180 add_widget (listmode_dlg
,
181 groupbox_new (UY
+ 4, UX
+ 20, 11, 43, "Item options"));
184 i
< sizeof (listmode_but
) / sizeof (struct listmode_button
); i
++)
185 add_widget (listmode_dlg
,
186 button_new (listmode_but
[i
].y
, listmode_but
[i
].x
,
187 listmode_but
[i
].ret_cmd
,
188 listmode_but
[i
].flags
,
189 listmode_but
[i
].text
,
190 listmode_but
[i
].callback
));
192 /* We add the labels. */
194 i
< sizeof (listmode_labels
) / sizeof (struct listmode_label
);
197 label_new (listmode_labels
[i
].y
, listmode_labels
[i
].x
,
198 listmode_labels
[i
].text
);
199 add_widget (listmode_dlg
, pname
);
202 radio_itemwidth
= radio_new (UY
+ 9, UX
+ 22, 3, s_itemwidth
);
203 add_widget (listmode_dlg
, radio_itemwidth
);
205 radio_justify
= radio_new (UY
+ 5, UX
+ 22, 3, s_justify
);
206 add_widget (listmode_dlg
, radio_justify
);
207 radio_justify
->sel
= 1;
209 /* get new listbox */
210 l_listmode
= listbox_new (UY
+ 5, UX
+ 1, 9, 16, NULL
);
212 if (strncmp (oldlistformat
, "full ", 5) == 0) {
216 if (strncmp (oldlistformat
, "half ", 5) == 0) {
219 if (strncmp (oldlistformat
, "2 ", 2) == 0) {
223 if (strncmp (oldlistformat
, "1 ", 2) == 0) {
226 s
= strtok (oldlistformat
, ",");
229 listbox_add_item (l_listmode
, 0, 0, s
, NULL
);
230 s
= strtok (NULL
, ",");
233 /* add listbox to the dialogs */
234 add_widget (listmode_dlg
, l_listmode
);
236 radio_columns
= radio_new (UY
+ 1, UX
+ 32, 2, s_columns
);
237 add_widget (listmode_dlg
, radio_columns
);
238 radio_columns
->sel
= format_columns
;
239 radio_genwidth
= radio_new (UY
+ 1, UX
+ 2, 2, s_genwidth
);
240 add_widget (listmode_dlg
, radio_genwidth
);
241 radio_genwidth
->sel
= format_width
;
247 listmode_done (Dlg_head
*h
)
251 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
256 collect_new_format (void)
263 newformat
= g_malloc (1024);
264 if (radio_genwidth
->sel
)
265 strcpy (newformat
, "full ");
267 strcpy (newformat
, "half ");
268 if (radio_columns
->sel
)
269 strcat (newformat
, "2 ");
272 listbox_select_by_number (l_listmode
, i
);
273 listbox_get_current (l_listmode
, &text
, &extra
);
277 strcat (newformat
, ",");
278 strcat (newformat
, text
);
284 /* Return new format or NULL if the user cancelled the dialog */
286 listmode_edit (char *oldlistformat
)
288 char *newformat
= NULL
;
290 Dlg_head
*listmode_dlg
;
292 s
= g_strdup (oldlistformat
);
293 listmode_dlg
= init_listmode (s
);
296 if (run_dlg (listmode_dlg
) == B_ENTER
) {
297 newformat
= collect_new_format ();
300 listmode_done (listmode_dlg
);
303 #endif /* LISTMODE_EDITOR */