This source file includes following definitions.
- select_new_item
- bplus_cback
- bminus_cback
- badd_cback
- bremove_cback
- init_listmode
- listmode_done
- collect_new_format
- listmode_edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 #include <config.h>
32
33 #ifdef LISTMODE_EDITOR
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <unistd.h>
41
42 #include "lib/global.h"
43 #include "lib/widget.h"
44
45 #include "lib/tty/tty.h"
46 #include "lib/tty/key.h"
47 #include "lib/skin/skin.h"
48
49
50 #include "dir.h"
51 #include "panel.h"
52 #include "file.h"
53 #include "listmode.h"
54
55
56
57
58
59 #define UX 5
60 #define UY 2
61
62 #define BX 5
63 #define BY 18
64
65 #define B_ADD B_USER
66 #define B_REMOVE (B_USER + 1)
67
68 #define B_PLUS B_USER
69 #define B_MINUS (B_USER+1)
70
71
72
73 struct listmode_button
74 {
75 int ret_cmd, flags, y, x;
76 char *text;
77 bcback callback;
78 };
79
80 struct listmode_label
81 {
82 int y, x;
83 char *text;
84 };
85
86
87
88 static WListbox *l_listmode;
89
90 static WLabel *pname;
91
92 static char *listmode_section = "[Listing format edit]";
93
94 static char *s_genwidth[2] = { "Half width", "Full width" };
95
96 static WRadio *radio_genwidth;
97 static char *s_columns[2] = { "One column", "Two columns" };
98
99 static WRadio *radio_columns;
100 static char *s_justify[3] = { "Left justified", "Default justification", "Right justified" };
101
102 static WRadio *radio_justify;
103 static char *s_itemwidth[3] = { "Free width", "Fixed width", "Growable width" };
104
105 static WRadio *radio_itemwidth;
106
107
108
109
110 static char *
111 select_new_item (void)
112 {
113 char **possible_items;
114 char *ret = NULL;
115 int i;
116 Listbox *mylistbox;
117
118 possible_items = panel_get_user_possible_fields (NULL);
119
120 mylistbox = create_listbox_window (20, 12, "Add listing format item", listmode_section);
121 for (i = 0; possible_items[i]; i++)
122 {
123 listbox_add_item (mylistbox->list, LISTBOX_APPEND_AT_END, 0, possible_items[i], NULL,
124 FALSE);
125 }
126
127 i = run_listbox (mylistbox);
128 if (i >= 0)
129 ret = g_strdup (possible_items[i]);
130
131 g_strfreev (possible_items);
132 return ret;
133 }
134
135
136
137 static int
138 bplus_cback (int action)
139 {
140 return 0;
141 }
142
143
144
145 static int
146 bminus_cback (int action)
147 {
148 return 0;
149 }
150
151
152
153 static int
154 badd_cback (int action)
155 {
156 char *s = select_new_item ();
157 if (s)
158 {
159 listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL, FALSE);
160 g_free (s);
161 }
162 return 0;
163 }
164
165
166
167 static int
168 bremove_cback (int action)
169 {
170 listbox_remove_current (l_listmode);
171 return 0;
172 }
173
174
175
176 static WDialog *
177 init_listmode (char *oldlistformat)
178 {
179 int i;
180 char *s;
181 int format_width = 0;
182 int format_columns = 0;
183 WDialog *listmode_dlg;
184
185 static struct listmode_label listmode_labels[] = {
186 {UY + 13, UX + 22, "Item width:"}
187 };
188
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},
196 };
197
198 do_refresh ();
199
200 listmode_dlg =
201 dlg_create (TRUE, 0, 0, 22, 74, WPOS_CENTER, FALSE, dialog_colors, NULL, NULL,
202 listmode_section, "Listing format edit");
203
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"));
207
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));
214
215
216 for (i = 0; i < sizeof (listmode_labels) / sizeof (struct listmode_label); i++)
217 {
218 pname = label_new (listmode_labels[i].y, listmode_labels[i].x, listmode_labels[i].text);
219 add_widget (listmode_dlg, pname);
220 }
221
222 radio_itemwidth = radio_new (UY + 9, UX + 22, 3, s_itemwidth);
223 add_widget (listmode_dlg, radio_itemwidth);
224 radio_itemwidth = 0;
225 radio_justify = radio_new (UY + 5, UX + 22, 3, s_justify);
226 add_widget (listmode_dlg, radio_justify);
227 radio_justify->sel = 1;
228
229
230 l_listmode = listbox_new (UY + 5, UX + 1, 9, 16, FALSE, NULL);
231
232 if (strncmp (oldlistformat, "full ", 5) == 0)
233 {
234 format_width = 1;
235 oldlistformat += 5;
236 }
237 if (strncmp (oldlistformat, "half ", 5) == 0)
238 {
239 oldlistformat += 5;
240 }
241 if (strncmp (oldlistformat, "2 ", 2) == 0)
242 {
243 format_columns = 1;
244 oldlistformat += 2;
245 }
246 if (strncmp (oldlistformat, "1 ", 2) == 0)
247 {
248 oldlistformat += 2;
249 }
250 s = strtok (oldlistformat, ",");
251
252 while (s)
253 {
254 listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL, FALSE);
255 s = strtok (NULL, ",");
256 }
257
258
259 add_widget (listmode_dlg, l_listmode);
260
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;
267
268 return listmode_dlg;
269 }
270
271
272
273 static void
274 listmode_done (WDialog * h)
275 {
276 widget_destroy (WIDGET (h));
277 if (0)
278 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
279 repaint_screen ();
280 }
281
282
283
284 static char *
285 collect_new_format (void)
286 {
287 char *newformat;
288 int i;
289 char *last;
290 char *text, *extra;
291
292 newformat = g_malloc (1024);
293 if (radio_genwidth->sel)
294 strcpy (newformat, "full ");
295 else
296 strcpy (newformat, "half ");
297 if (radio_columns->sel)
298 strcat (newformat, "2 ");
299 last = NULL;
300 for (i = 0;; i++)
301 {
302 listbox_select_entry (l_listmode, i);
303 listbox_get_current (l_listmode, &text, &extra);
304 if (text == last)
305 break;
306 if (last != NULL)
307 strcat (newformat, ",");
308 strcat (newformat, text);
309 last = text;
310 }
311 return newformat;
312 }
313
314
315
316
317
318
319 char *
320 listmode_edit (char *oldlistformat)
321 {
322 char *newformat = NULL;
323 char *s;
324 WDialog *listmode_dlg;
325
326 s = g_strdup (oldlistformat);
327 listmode_dlg = init_listmode (s);
328 g_free (s);
329
330 if (dlg_run (listmode_dlg) == B_ENTER)
331 {
332 newformat = collect_new_format ();
333 }
334
335 listmode_done (listmode_dlg);
336 return newformat;
337 }
338
339
340
341 #endif