"Panel options" dialog window: remove "Save" button
[midnight-commander.git] / src / filemanager / option.c
blobc9e78f54dbf1caaa0d10bce58bdde09e0a945360
1 /* Configure box module for the Midnight Commander
2 Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007, 2009, 2010 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 /** \file option.c
21 * \brief Source: configure boxes module
24 #include <config.h>
26 #include <stdlib.h> /* atoi() */
27 #include <stdio.h>
28 #include <string.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <unistd.h>
34 #include "lib/global.h"
35 #include "lib/mcconfig.h"
36 #include "lib/strutil.h" /* str_term_width1() */
37 #include "lib/tty/key.h" /* old_esc_mode_timeout */
38 #include "lib/widget.h"
40 #include "src/setup.h" /* variables */
41 #include "src/history.h" /* MC_HISTORY_ESC_TIMEOUT */
42 #include "src/execute.h" /* pause_after_run */
44 #include "layout.h" /* nice_rotating_dash */
45 #include "panel.h" /* update_panels() */
47 #include "option.h"
49 /*** global variables ****************************************************************************/
51 /*** file scope macro definitions ****************************************************************/
53 /*** file scope type declarations ****************************************************************/
55 /*** file scope variables ************************************************************************/
57 /*** file scope functions ************************************************************************/
58 /* --------------------------------------------------------------------------------------------- */
60 static cb_ret_t
61 configure_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
63 switch (msg)
65 case DLG_ACTION:
66 /* message from "Single press" checkbutton */
67 if (sender != NULL && sender->id == 17)
69 const gboolean not_single = !(((WCheck *) sender)->state & C_BOOL);
70 Widget *w;
72 /* label */
73 w = dlg_find_by_id (h, sender->id - 1);
74 widget_disable (*w, not_single);
75 send_message (w, WIDGET_DRAW, 0);
76 /* input */
77 w = dlg_find_by_id (h, sender->id - 2);
78 widget_disable (*w, not_single);
79 send_message (w, WIDGET_DRAW, 0);
81 return MSG_HANDLED;
83 return MSG_NOT_HANDLED;
85 default:
86 return default_dlg_callback (h, sender, msg, parm, data);
90 /* --------------------------------------------------------------------------------------------- */
91 /*** public functions ****************************************************************************/
92 /* --------------------------------------------------------------------------------------------- */
94 void
95 configure_box (void)
97 int dlg_width = 60;
98 int dlg_height = 20;
100 char time_out[BUF_TINY] = "";
101 char *time_out_new;
103 const char *pause_options[] = {
104 N_("&Never"),
105 N_("On dum&b terminals"),
106 N_("Alwa&ys")
109 int pause_options_num = G_N_ELEMENTS (pause_options);
111 QuickWidget quick_widgets[] = {
112 /* buttons */
113 QUICK_BUTTON (38, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
114 QUICK_BUTTON (14, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
115 /* other options */
116 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 12, dlg_height, N_("A&uto save setup"),
117 &auto_save_setup),
118 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 11, dlg_height, N_("Sa&fe delete"),
119 &safe_delete),
120 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 10, dlg_height, N_("Cd follows lin&ks"),
121 &cd_symlinks),
122 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("Rotating d&ash"),
123 &nice_rotating_dash),
124 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 8, dlg_height, N_("Co&mplete: show all"),
125 &show_all_if_ambiguous),
126 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 7, dlg_height, N_("Shell &patterns"),
127 &easy_patterns),
128 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 6, dlg_height, N_("&Drop down menus"),
129 &drop_menus),
130 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 5, dlg_height, N_("Auto m&enus"), &auto_menu),
131 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 4, dlg_height, N_("Use internal vie&w"),
132 &use_internal_view),
133 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 3, dlg_height, N_("Use internal edi&t"),
134 &use_internal_edit),
135 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 15,
136 N_("Other options")),
137 /* pause options */
138 QUICK_RADIO (5, dlg_width, 13, dlg_height, pause_options_num, pause_options,
139 &pause_after_run),
140 QUICK_GROUPBOX (3, dlg_width, 12, dlg_height, dlg_width / 2 - 4, 5, N_("Pause after run")),
142 /* Esc key mode */
143 QUICK_INPUT (10, dlg_width, 10, dlg_height, (const char *) time_out, 8, 0,
144 MC_HISTORY_ESC_TIMEOUT, &time_out_new),
145 QUICK_LABEL (5, dlg_width, 10, dlg_height, N_("Timeout:")),
146 QUICK_CHECKBOX (5, dlg_width, 9, dlg_height, N_("S&ingle press"), &old_esc_mode),
147 QUICK_GROUPBOX (3, dlg_width, 8, dlg_height, dlg_width / 2 - 4, 4, N_("Esc key mode")),
149 /* file operation options */
150 QUICK_CHECKBOX (5, dlg_width, 6, dlg_height, N_("Mkdi&r autoname"), &auto_fill_mkdir_name),
151 QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Classic pro&gressbar"),
152 &classic_progressbar),
153 QUICK_CHECKBOX (5, dlg_width, 4, dlg_height, N_("Compute tota&ls"),
154 &file_op_compute_totals),
155 QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("&Verbose operation"), &verbose),
156 QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 6,
157 N_("File operation options")),
158 QUICK_END
161 const size_t qw_num = G_N_ELEMENTS (quick_widgets) - 1;
163 QuickDialog Quick_input = {
164 dlg_width, dlg_height, -1, -1,
165 N_("Configure options"), "[Configuration]",
166 quick_widgets, configure_callback, TRUE
169 int b0_len, b1_len;
170 int b_len, c_len, g_len, l_len;
171 size_t i;
173 #ifdef ENABLE_NLS
174 for (i = 0; i < qw_num; i++)
175 switch (i)
177 case 0:
178 case 1:
179 /* buttons */
180 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
181 break;
182 case 12:
183 case 14:
184 case 18:
185 case 23:
186 /* groupboxes */
187 quick_widgets[i].u.groupbox.title = _(quick_widgets[i].u.groupbox.title);
188 break;
189 case 13:
191 /* radio button */
192 size_t j;
193 for (j = 0; j < (size_t) pause_options_num; j++)
194 pause_options[j] = _(pause_options[j]);
196 break;
197 case 15:
198 /* input line */
199 break;
200 case 16:
201 /* label */
202 quick_widgets[i].u.label.text = _(quick_widgets[i].u.label.text);
203 break;
204 default:
205 /* checkboxes */
206 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
207 break;
210 Quick_input.title = _(Quick_input.title);
211 #endif /* ENABLE_NLS */
213 /* calculate widget and dialog widths */
214 /* dialog title */
215 dlg_width = max (dlg_width, str_term_width1 (Quick_input.title) + 4);
216 /* buttons */
217 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
218 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5;
219 b_len = b0_len + b1_len + 1;
221 /* checkboxes within groupboxes */
222 c_len = 0;
223 for (i = 2; i < 23; i++)
224 if ((i < 12) || (i == 17) || (i > 18))
225 c_len = max (c_len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 3);
226 /* radiobuttons */
227 for (i = 0; i < (size_t) pause_options_num; i++)
228 c_len = max (c_len, str_term_width1 (pause_options[i]) + 3);
229 /* label + input */
230 l_len = str_term_width1 (quick_widgets[16].u.label.text);
231 c_len = max (c_len, l_len + 1 + 8);
232 /* groupboxes */
233 g_len = max (c_len + 2, str_term_width1 (quick_widgets[23].u.groupbox.title) + 4);
234 g_len = max (g_len, str_term_width1 (quick_widgets[18].u.groupbox.title) + 4);
235 g_len = max (g_len, str_term_width1 (quick_widgets[14].u.groupbox.title) + 4);
236 g_len = max (g_len, str_term_width1 (quick_widgets[12].u.groupbox.title) + 4);
237 /* dialog width */
238 Quick_input.xlen = max (dlg_width, g_len * 2 + 9);
239 Quick_input.xlen = max (Quick_input.xlen, b_len + 2);
240 if ((Quick_input.xlen & 1) != 0)
241 Quick_input.xlen++;
243 /* fix widget parameters */
244 for (i = 0; i < qw_num; i++)
245 quick_widgets[i].x_divisions = Quick_input.xlen;
247 /* groupboxes */
248 quick_widgets[14].u.groupbox.width =
249 quick_widgets[18].u.groupbox.width =
250 quick_widgets[23].u.groupbox.width = Quick_input.xlen / 2 - 4;
251 quick_widgets[12].u.groupbox.width = Quick_input.xlen / 2 - 3;
253 /* input */
254 quick_widgets[15].relative_x = quick_widgets[16].relative_x + l_len + 1;
255 quick_widgets[15].u.input.len = quick_widgets[18].u.groupbox.width - l_len - 4;
257 /* right column */
258 quick_widgets[12].relative_x = Quick_input.xlen / 2;
259 for (i = 2; i < 12; i++)
260 quick_widgets[i].relative_x = quick_widgets[12].relative_x + 2;
262 /* buttons */
263 quick_widgets[1].relative_x = (Quick_input.xlen - b_len) / 3;
264 quick_widgets[0].relative_x = 2 * quick_widgets[1].relative_x + b1_len + 1;
266 g_snprintf (time_out, sizeof (time_out), "%d", old_esc_mode_timeout);
268 if (!old_esc_mode)
269 quick_widgets[15].options = quick_widgets[16].options = W_DISABLED;
271 if (quick_dialog (&Quick_input) == B_ENTER)
272 old_esc_mode_timeout = atoi (time_out_new);
274 g_free (time_out_new);
277 /* --------------------------------------------------------------------------------------------- */
279 void
280 panel_options_box (void)
282 int dlg_width = 60;
283 int dlg_height = 19;
285 int simple_swap = mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION,
286 "simple_swap", FALSE) ? 1 : 0;
288 const char *qsearch_options[] = {
289 N_("Case &insensitive"),
290 N_("Case s&ensitive"),
291 N_("Use panel sort mo&de")
294 QuickWidget quick_widgets[] = {
295 /* buttons */
296 QUICK_BUTTON (38, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
297 QUICK_BUTTON (14, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
298 /* quick search */
299 QUICK_RADIO (dlg_width / 2 + 2, dlg_width, 12, dlg_height, QSEARCH_NUM, qsearch_options,
300 (int *) &panels_options.qsearch_mode),
301 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 11, dlg_height, dlg_width / 2 - 4,
302 QSEARCH_NUM + 2,
303 N_("Quick search")),
304 /* file highlighting */
305 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("&Permissions"),
306 &panels_options.permission_mode),
307 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 8, dlg_height, N_("File &types"),
308 &panels_options.filetype_mode),
309 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 7, dlg_height, dlg_width / 2 - 4, 4,
310 N_("File highlight")),
311 /* navigation */
312 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 5, dlg_height, N_("&Mouse page scrolling"),
313 &panels_options.mouse_move_pages),
314 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 4, dlg_height, N_("Pa&ge scrolling"),
315 &panels_options.scroll_pages),
316 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 3, dlg_height, N_("L&ynx-like motion"),
317 &panels_options.navigate_with_arrows),
318 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 5,
319 N_("Navigation")),
320 /* main panel options */
321 QUICK_CHECKBOX (5, dlg_width, 11, dlg_height, N_("A&uto save panels setup"),
322 &panels_options.auto_save_setup),
323 QUICK_CHECKBOX (5, dlg_width, 10, dlg_height, N_("Simple s&wap"),
324 &simple_swap),
325 QUICK_CHECKBOX (5, dlg_width, 9, dlg_height, N_("Re&verse files only"),
326 &panels_options.reverse_files_only),
327 QUICK_CHECKBOX (5, dlg_width, 8, dlg_height, N_("Ma&rk moves down"),
328 &panels_options.mark_moves_down),
329 QUICK_CHECKBOX (5, dlg_width, 7, dlg_height, N_("&Fast dir reload"),
330 &panels_options.fast_reload),
331 QUICK_CHECKBOX (5, dlg_width, 6, dlg_height, N_("Show &hidden files"),
332 &panels_options.show_dot_files),
333 QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Show &backup files"),
334 &panels_options.show_backups),
335 QUICK_CHECKBOX (5, dlg_width, 4, dlg_height, N_("Mi&x all files"),
336 &panels_options.mix_all_files),
337 QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("Use SI si&ze units"),
338 &panels_options.kilobyte_si),
339 QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 14,
340 N_("Main panel options")),
341 QUICK_END
344 const size_t qw_num = G_N_ELEMENTS (quick_widgets) - 1;
346 QuickDialog Quick_input = {
347 dlg_width, dlg_height, -1, -1,
348 N_("Panel options"), "[Panel options]",
349 quick_widgets, NULL, TRUE
352 int b0_len, b1_len;
353 int b_len, c_len, g_len;
354 size_t i;
356 #ifdef ENABLE_NLS
357 for (i = 0; i < qw_num; i++)
358 switch (i)
360 case 0:
361 case 1:
362 /* buttons */
363 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
364 break;
365 case 2:
367 /* radio button */
368 size_t j;
369 for (j = 0; j < QSEARCH_NUM; j++)
370 qsearch_options[j] = _(qsearch_options[j]);
372 break;
373 case 3:
374 case 6:
375 case 10:
376 case 20:
377 /* groupboxes */
378 quick_widgets[i].u.groupbox.title = _(quick_widgets[i].u.groupbox.title);
379 break;
380 default:
381 /* checkboxes */
382 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
383 break;
386 Quick_input.title = _(Quick_input.title);
387 #endif /* ENABLE_NLS */
389 /* calculate widget and dialog widths */
390 /* dialog title */
391 dlg_width = max (dlg_width, str_term_width1 (Quick_input.title) + 4);
392 /* buttons */
393 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
394 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5;
395 b_len = b0_len + b1_len + 1;
397 /* checkboxes within groupboxes */
398 c_len = 0;
399 for (i = 4; i < 20; i++)
400 if ((i != 6) && (i != 10))
401 c_len = max (c_len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
403 /* radiobuttons */
404 for (i = 0; i < QSEARCH_NUM; i++)
405 c_len = max (c_len, str_term_width1 (qsearch_options[i]) + 3);
406 /* groupboxes */
407 g_len = max (c_len + 2, str_term_width1 (quick_widgets[3].u.groupbox.title) + 4);
408 g_len = max (g_len, str_term_width1 (quick_widgets[6].u.groupbox.title) + 4);
409 g_len = max (g_len, str_term_width1 (quick_widgets[10].u.groupbox.title) + 4);
410 g_len = max (g_len, str_term_width1 (quick_widgets[20].u.groupbox.title) + 4);
411 /* dialog width */
412 Quick_input.xlen = max (dlg_width, g_len * 2 + 9);
413 Quick_input.xlen = max (Quick_input.xlen, b_len + 2);
414 if ((Quick_input.xlen & 1) != 0)
415 Quick_input.xlen++;
417 /* fix widget parameters */
418 for (i = 0; i < qw_num; i++)
419 quick_widgets[i].x_divisions = Quick_input.xlen;
421 /* groupboxes */
422 quick_widgets[3].u.groupbox.width =
423 quick_widgets[6].u.groupbox.width =
424 quick_widgets[10].u.groupbox.width = Quick_input.xlen / 2 - 3;
425 quick_widgets[20].u.groupbox.width = Quick_input.xlen / 2 - 4;
427 /* right column */
428 quick_widgets[3].relative_x =
429 quick_widgets[6].relative_x = quick_widgets[10].relative_x = Quick_input.xlen / 2;
430 for (i = 2; i < 10; i++)
431 if ((i != 3) && (i != 6))
432 quick_widgets[i].relative_x = quick_widgets[3].relative_x + 2;
434 /* buttons */
435 quick_widgets[1].relative_x = (Quick_input.xlen - b_len) / 3;
436 quick_widgets[0].relative_x = 2 * quick_widgets[1].relative_x + b1_len + 1;
438 if (quick_dialog (&Quick_input) != B_ENTER)
439 return
441 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
442 "simple_swap", (gboolean) (simple_swap & C_BOOL));
444 if (!panels_options.fast_reload_msg_shown && panels_options.fast_reload)
446 message (D_NORMAL, _("Information"),
447 _("Using the fast reload option may not reflect the exact\n"
448 "directory contents. In this case you'll need to do a\n"
449 "manual reload of the directory. See the man page for\n" "the details."));
450 panels_options.fast_reload_msg_shown = TRUE;
453 update_panels (UP_RELOAD, UP_KEEPSEL);
456 /* --------------------------------------------------------------------------------------------- */