"Configure options" dialog window: remove "Save" button
[midnight-commander.git] / src / filemanager / option.c
blobf7dd67e2e87469fea97d1b1d60fe2a01efd37033
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 (26, dlg_width, dlg_height - 3, dlg_height, N_("&Save"), B_EXIT, NULL),
298 QUICK_BUTTON (14, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
299 /* quick search */
300 QUICK_RADIO (dlg_width / 2 + 2, dlg_width, 12, dlg_height, QSEARCH_NUM, qsearch_options,
301 (int *) &panels_options.qsearch_mode),
302 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 11, dlg_height, dlg_width / 2 - 4,
303 QSEARCH_NUM + 2,
304 N_("Quick search")),
305 /* file highlighting */
306 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("&Permissions"),
307 &panels_options.permission_mode),
308 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 8, dlg_height, N_("File &types"),
309 &panels_options.filetype_mode),
310 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 7, dlg_height, dlg_width / 2 - 4, 4,
311 N_("File highlight")),
312 /* navigation */
313 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 5, dlg_height, N_("&Mouse page scrolling"),
314 &panels_options.mouse_move_pages),
315 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 4, dlg_height, N_("Pa&ge scrolling"),
316 &panels_options.scroll_pages),
317 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 3, dlg_height, N_("L&ynx-like motion"),
318 &panels_options.navigate_with_arrows),
319 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 5,
320 N_("Navigation")),
321 /* main panel options */
322 QUICK_CHECKBOX (5, dlg_width, 11, dlg_height, N_("A&uto save panels setup"),
323 &panels_options.auto_save_setup),
324 QUICK_CHECKBOX (5, dlg_width, 10, dlg_height, N_("Simple s&wap"),
325 &simple_swap),
326 QUICK_CHECKBOX (5, dlg_width, 9, dlg_height, N_("Re&verse files only"),
327 &panels_options.reverse_files_only),
328 QUICK_CHECKBOX (5, dlg_width, 8, dlg_height, N_("Ma&rk moves down"),
329 &panels_options.mark_moves_down),
330 QUICK_CHECKBOX (5, dlg_width, 7, dlg_height, N_("&Fast dir reload"),
331 &panels_options.fast_reload),
332 QUICK_CHECKBOX (5, dlg_width, 6, dlg_height, N_("Show &hidden files"),
333 &panels_options.show_dot_files),
334 QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Show &backup files"),
335 &panels_options.show_backups),
336 QUICK_CHECKBOX (5, dlg_width, 4, dlg_height, N_("Mi&x all files"),
337 &panels_options.mix_all_files),
338 QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("Use SI si&ze units"),
339 &panels_options.kilobyte_si),
340 QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 14,
341 N_("Main panel options")),
342 QUICK_END
345 const size_t qw_num = G_N_ELEMENTS (quick_widgets) - 1;
347 QuickDialog Quick_input = {
348 dlg_width, dlg_height, -1, -1,
349 N_("Panel options"), "[Panel options]",
350 quick_widgets, NULL, TRUE
353 int qd_result;
355 int b0_len, b1_len, b2_len;
356 int b_len, c_len, g_len;
357 size_t i;
359 #ifdef ENABLE_NLS
361 for (i = 0; i < qw_num; i++)
362 if (i < 3)
363 /* buttons */
364 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
365 else if (i == 3)
367 /* radio button */
368 size_t j;
369 for (j = 0; j < QSEARCH_NUM; j++)
370 qsearch_options[j] = _(qsearch_options[j]);
372 else if ((i == 4) || (i == 7) || (i == 11) || (i == 21))
373 /* groupboxes */
374 quick_widgets[i].u.groupbox.title = _(quick_widgets[i].u.groupbox.title);
375 else
376 /* checkboxes */
377 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
379 Quick_input.title = _(Quick_input.title);
381 #endif /* ENABLE_NLS */
383 /* calculate widget and dialog widths */
384 /* dialog title */
385 dlg_width = max (dlg_width, str_term_width1 (Quick_input.title) + 4);
386 /* buttons */
387 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
388 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
389 b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5;
390 b_len = b0_len + b1_len + b2_len + 2;
392 /* checkboxes within groupboxes */
393 c_len = 0;
394 for (i = 5; i < 21; i++)
395 if ((i != 7) && (i != 11))
396 c_len = max (c_len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
398 /* radiobuttons */
399 for (i = 0; i < QSEARCH_NUM; i++)
400 c_len = max (c_len, str_term_width1 (qsearch_options[i]) + 3);
401 /* groupboxes */
402 g_len = max (c_len + 2, str_term_width1 (quick_widgets[4].u.groupbox.title) + 4);
403 g_len = max (g_len, str_term_width1 (quick_widgets[7].u.groupbox.title) + 4);
404 g_len = max (g_len, str_term_width1 (quick_widgets[11].u.groupbox.title) + 4);
405 g_len = max (g_len, str_term_width1 (quick_widgets[21].u.groupbox.title) + 4);
406 /* dialog width */
407 Quick_input.xlen = max (dlg_width, g_len * 2 + 9);
408 Quick_input.xlen = max (Quick_input.xlen, b_len + 2);
409 if ((Quick_input.xlen & 1) != 0)
410 Quick_input.xlen++;
412 /* fix widget parameters */
413 for (i = 0; i < qw_num; i++)
414 quick_widgets[i].x_divisions = Quick_input.xlen;
416 /* groupboxes */
417 quick_widgets[4].u.groupbox.width =
418 quick_widgets[7].u.groupbox.width =
419 quick_widgets[11].u.groupbox.width = Quick_input.xlen / 2 - 3;
420 quick_widgets[21].u.groupbox.width = Quick_input.xlen / 2 - 4;
422 /* right column */
423 quick_widgets[4].relative_x =
424 quick_widgets[7].relative_x = quick_widgets[11].relative_x = Quick_input.xlen / 2;
425 for (i = 3; i < 11; i++)
426 if ((i != 4) && (i != 7))
427 quick_widgets[i].relative_x = quick_widgets[4].relative_x + 2;
429 /* buttons */
430 quick_widgets[2].relative_x = (Quick_input.xlen - b_len) / 2;
431 quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + 1;
432 quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + 1;
434 qd_result = quick_dialog (&Quick_input);
436 if ((qd_result == B_ENTER) || (qd_result == B_EXIT))
438 mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION,
439 "simple_swap", (gboolean) (simple_swap & C_BOOL));
441 if (!panels_options.fast_reload_msg_shown && panels_options.fast_reload)
443 message (D_NORMAL, _("Information"),
444 _("Using the fast reload option may not reflect the exact\n"
445 "directory contents. In this case you'll need to do a\n"
446 "manual reload of the directory. See the man page for\n" "the details."));
447 panels_options.fast_reload_msg_shown = TRUE;
449 update_panels (UP_RELOAD, UP_KEEPSEL);
452 if (qd_result == B_EXIT)
454 /* save panel options */
455 panels_save_options ();
456 mc_config_save_file (mc_main_config, NULL);
460 /* --------------------------------------------------------------------------------------------- */