Split file src/keybind.[ch] to lib/keybind.[ch] and src/keybind-defaults.[ch].
[midnight-commander.git] / src / option.c
blob6057c15a0eb7bbc619c731be9026982eaf1d32ea
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" /* mc_config_save_file() */
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 "setup.h" /* panels_options */
41 #include "main.h"
42 #include "file.h" /* file_op_compute_totals */
43 #include "layout.h" /* nice_rotating_dash */
44 #include "history.h" /* MC_HISTORY_ESC_TIMEOUT */
46 #include "option.h"
48 /*** global variables ****************************************************************************/
50 /*** file scope macro definitions ****************************************************************/
52 /*** file scope type declarations ****************************************************************/
54 /*** file scope variables ************************************************************************/
56 /*** file scope functions ************************************************************************/
57 /* --------------------------------------------------------------------------------------------- */
59 static cb_ret_t
60 configure_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
62 switch (msg)
64 case DLG_ACTION:
65 if (sender->id == 18)
67 /* message from "Single press" checkbutton */
68 const gboolean not_single = !(((WCheck *) sender)->state & C_BOOL);
69 Widget *w;
71 /* label */
72 w = dlg_find_by_id (h, sender->id - 1);
73 widget_disable (*w, not_single);
74 send_message (w, WIDGET_DRAW, 0);
75 /* input */
76 w = dlg_find_by_id (h, sender->id - 2);
77 widget_disable (*w, not_single);
78 send_message (w, WIDGET_DRAW, 0);
80 return MSG_HANDLED;
82 return MSG_NOT_HANDLED;
84 default:
85 return default_dlg_callback (h, sender, msg, parm, data);
89 /* --------------------------------------------------------------------------------------------- */
90 /*** public functions ****************************************************************************/
91 /* --------------------------------------------------------------------------------------------- */
93 void
94 configure_box (void)
96 int dlg_width = 60;
97 int dlg_height = 20;
99 char time_out[BUF_TINY] = "";
100 char *time_out_new;
102 const char *pause_options[] = {
103 N_("&Never"),
104 N_("On dum&b terminals"),
105 N_("Alwa&ys")
108 int pause_options_num = sizeof (pause_options) / sizeof (pause_options[0]);
110 QuickWidget quick_widgets[] = {
111 /* buttons */
112 QUICK_BUTTON (38, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
113 QUICK_BUTTON (26, dlg_width, dlg_height - 3, dlg_height, N_("&Save"), B_EXIT, 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 = sizeof (quick_widgets) / sizeof (quick_widgets[0]) - 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 qd_result;
171 int b0_len, b1_len, b2_len;
172 int b_len, c_len, g_len, l_len;
173 size_t i;
175 #ifdef ENABLE_NLS
177 for (i = 0; i < qw_num; i++)
178 if (i < 3)
179 /* buttons */
180 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
181 else if ((i == 13) || (i == 15) || (i == 19) || (i == 24))
182 /* groupboxes */
183 quick_widgets[i].u.groupbox.title = _(quick_widgets[i].u.groupbox.title);
184 else if (i == 14)
186 /* radio button */
187 size_t j;
188 for (j = 0; j < (size_t) pause_options_num; j++)
189 pause_options[j] = _(pause_options[j]);
191 else if (i == 17)
192 /* label */
193 quick_widgets[i].u.label.text = _(quick_widgets[i].u.label.text);
194 else if (i != 16)
195 /* checkboxes */
196 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
198 Quick_input.title = _(Quick_input.title);
200 #endif /* ENABLE_NLS */
202 /* calculate widget and dialog widths */
203 /* dialog title */
204 dlg_width = max (dlg_width, str_term_width1 (Quick_input.title) + 4);
205 /* buttons */
206 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
207 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
208 b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5;
209 b_len = b0_len + b1_len + b2_len + 2;
211 /* checkboxes within groupboxes */
212 c_len = 0;
213 for (i = 3; i < 24; i++)
214 if ((i < 13) || (i == 18) || (i > 19))
215 c_len = max (c_len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 3);
216 /* radiobuttons */
217 for (i = 0; i < (size_t) pause_options_num; i++)
218 c_len = max (c_len, str_term_width1 (pause_options[i]) + 3);
219 /* label + input */
220 l_len = str_term_width1 (quick_widgets[17].u.label.text);
221 c_len = max (c_len, l_len + 1 + 8);
222 /* groupboxes */
223 g_len = max (c_len + 2, str_term_width1 (quick_widgets[24].u.groupbox.title) + 4);
224 g_len = max (g_len, str_term_width1 (quick_widgets[19].u.groupbox.title) + 4);
225 g_len = max (g_len, str_term_width1 (quick_widgets[15].u.groupbox.title) + 4);
226 g_len = max (g_len, str_term_width1 (quick_widgets[13].u.groupbox.title) + 4);
227 /* dialog width */
228 Quick_input.xlen = max (dlg_width, g_len * 2 + 9);
229 Quick_input.xlen = max (Quick_input.xlen, b_len + 2);
230 if ((Quick_input.xlen & 1) != 0)
231 Quick_input.xlen++;
233 /* fix widget parameters */
234 for (i = 0; i < qw_num; i++)
235 quick_widgets[i].x_divisions = Quick_input.xlen;
237 /* groupboxes */
238 quick_widgets[15].u.groupbox.width =
239 quick_widgets[19].u.groupbox.width =
240 quick_widgets[24].u.groupbox.width = Quick_input.xlen / 2 - 4;
241 quick_widgets[13].u.groupbox.width = Quick_input.xlen / 2 - 3;
243 /* input */
244 quick_widgets[16].relative_x = quick_widgets[17].relative_x + l_len + 1;
245 quick_widgets[16].u.input.len = quick_widgets[19].u.groupbox.width - l_len - 4;
247 /* right column */
248 quick_widgets[13].relative_x = Quick_input.xlen / 2;
249 for (i = 3; i < 13; i++)
250 quick_widgets[i].relative_x = quick_widgets[13].relative_x + 2;
252 /* buttons */
253 quick_widgets[2].relative_x = (Quick_input.xlen - b_len) / 2;
254 quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + 1;
255 quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + 1;
257 g_snprintf (time_out, sizeof (time_out), "%d", old_esc_mode_timeout);
259 if (!old_esc_mode)
260 quick_widgets[16].options = quick_widgets[17].options = W_DISABLED;
262 qd_result = quick_dialog (&Quick_input);
264 if ((qd_result == B_ENTER) || (qd_result == B_EXIT))
265 old_esc_mode_timeout = atoi (time_out_new);
267 g_free (time_out_new);
269 /* Save button */
270 if (qd_result == B_EXIT)
272 save_config ();
273 mc_config_save_file (mc_main_config, NULL);
277 /* --------------------------------------------------------------------------------------------- */
279 void
280 panel_options_box (void)
282 int dlg_width = 60;
283 int dlg_height = 19;
285 const char *qsearch_options[] = {
286 N_("Case &insensitive"),
287 N_("Case s&ensitive"),
288 N_("Use panel sort mo&de")
291 QuickWidget quick_widgets[] = {
292 /* buttons */
293 QUICK_BUTTON (38, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
294 QUICK_BUTTON (26, dlg_width, dlg_height - 3, dlg_height, N_("&Save"), B_EXIT, NULL),
295 QUICK_BUTTON (14, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
296 /* quick search */
297 QUICK_RADIO (dlg_width / 2 + 2, dlg_width, 12, dlg_height, QSEARCH_NUM, qsearch_options,
298 (int *) &panels_options.qsearch_mode),
299 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 11, dlg_height, dlg_width / 2 - 4,
300 QSEARCH_NUM + 2,
301 N_("Quick search")),
302 /* file highlighting */
303 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("&Permissions"),
304 &panels_options.permission_mode),
305 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 8, dlg_height, N_("File &types"),
306 &panels_options.filetype_mode),
307 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 7, dlg_height, dlg_width / 2 - 4, 4,
308 N_("File highlight")),
309 /* navigation */
310 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 5, dlg_height, N_("&Mouse page scrolling"),
311 &panels_options.mouse_move_pages),
312 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 4, dlg_height, N_("Pa&ge scrolling"),
313 &panels_options.scroll_pages),
314 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 3, dlg_height, N_("L&ynx-like motion"),
315 &panels_options.navigate_with_arrows),
316 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 5,
317 N_("Navigation")),
318 /* main panel options */
319 QUICK_CHECKBOX (5, dlg_width, 10, dlg_height, N_("A&uto save panels setup"),
320 &panels_options.auto_save_setup),
321 QUICK_CHECKBOX (5, dlg_width, 9, dlg_height, N_("Re&verse files only"),
322 &panels_options.reverse_files_only),
323 QUICK_CHECKBOX (5, dlg_width, 8, dlg_height, N_("Ma&rk moves down"),
324 &panels_options.mark_moves_down),
325 QUICK_CHECKBOX (5, dlg_width, 7, dlg_height, N_("&Fast dir reload"),
326 &panels_options.fast_reload),
327 QUICK_CHECKBOX (5, dlg_width, 6, dlg_height, N_("Show &hidden files"),
328 &panels_options.show_dot_files),
329 QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Show &backup files"),
330 &panels_options.show_backups),
331 QUICK_CHECKBOX (5, dlg_width, 4, dlg_height, N_("Mi&x all files"),
332 &panels_options.mix_all_files),
333 QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("Use SI si&ze units"),
334 &panels_options.kilobyte_si),
335 QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 14,
336 N_("Main panel options")),
337 QUICK_END
340 const size_t qw_num = sizeof (quick_widgets) / sizeof (quick_widgets[0]) - 1;
342 QuickDialog Quick_input = {
343 dlg_width, dlg_height, -1, -1,
344 N_("Panel options"), "[Panel options]",
345 quick_widgets, NULL, TRUE
348 int qd_result;
350 int b0_len, b1_len, b2_len;
351 int b_len, c_len, g_len;
352 size_t i;
354 #ifdef ENABLE_NLS
356 for (i = 0; i < qw_num; i++)
357 if (i < 3)
358 /* buttons */
359 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
360 else if (i == 3)
362 /* radio button */
363 size_t j;
364 for (j = 0; j < QSEARCH_NUM; j++)
365 qsearch_options[j] = _(qsearch_options[j]);
367 else if ((i == 4) || (i == 7) || (i == 11) || (i == 20))
368 /* groupboxes */
369 quick_widgets[i].u.groupbox.title = _(quick_widgets[i].u.groupbox.title);
370 else
371 /* checkboxes */
372 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
374 Quick_input.title = _(Quick_input.title);
376 #endif /* ENABLE_NLS */
378 /* calculate widget and dialog widths */
379 /* dialog title */
380 dlg_width = max (dlg_width, str_term_width1 (Quick_input.title) + 4);
381 /* buttons */
382 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
383 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
384 b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5;
385 b_len = b0_len + b1_len + b2_len + 2;
387 /* checkboxes within groupboxes */
388 c_len = 0;
389 for (i = 5; i < 20; i++)
390 if ((i != 7) && (i != 11))
391 c_len = max (c_len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
393 /* radiobuttons */
394 for (i = 0; i < QSEARCH_NUM; i++)
395 c_len = max (c_len, str_term_width1 (qsearch_options[i]) + 3);
396 /* groupboxes */
397 g_len = max (c_len + 2, str_term_width1 (quick_widgets[4].u.groupbox.title) + 4);
398 g_len = max (g_len, str_term_width1 (quick_widgets[7].u.groupbox.title) + 4);
399 g_len = max (g_len, str_term_width1 (quick_widgets[11].u.groupbox.title) + 4);
400 g_len = max (g_len, str_term_width1 (quick_widgets[20].u.groupbox.title) + 4);
401 /* dialog width */
402 Quick_input.xlen = max (dlg_width, g_len * 2 + 9);
403 Quick_input.xlen = max (Quick_input.xlen, b_len + 2);
404 if ((Quick_input.xlen & 1) != 0)
405 Quick_input.xlen++;
407 /* fix widget parameters */
408 for (i = 0; i < qw_num; i++)
409 quick_widgets[i].x_divisions = Quick_input.xlen;
411 /* groupboxes */
412 quick_widgets[4].u.groupbox.width =
413 quick_widgets[7].u.groupbox.width =
414 quick_widgets[11].u.groupbox.width = Quick_input.xlen / 2 - 3;
415 quick_widgets[20].u.groupbox.width = Quick_input.xlen / 2 - 4;
417 /* right column */
418 quick_widgets[4].relative_x =
419 quick_widgets[7].relative_x = quick_widgets[11].relative_x = Quick_input.xlen / 2;
420 for (i = 3; i < 11; i++)
421 if ((i != 4) && (i != 7))
422 quick_widgets[i].relative_x = quick_widgets[4].relative_x + 2;
424 /* buttons */
425 quick_widgets[2].relative_x = (Quick_input.xlen - b_len) / 2;
426 quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + 1;
427 quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + 1;
429 qd_result = quick_dialog (&Quick_input);
431 if ((qd_result == B_ENTER) || (qd_result == B_EXIT))
433 if (!panels_options.fast_reload_msg_shown && panels_options.fast_reload)
435 message (D_NORMAL, _("Information"),
436 _("Using the fast reload option may not reflect the exact\n"
437 "directory contents. In this case you'll need to do a\n"
438 "manual reload of the directory. See the man page for\n" "the details."));
439 panels_options.fast_reload_msg_shown = TRUE;
441 update_panels (UP_RELOAD, UP_KEEPSEL);
444 if (qd_result == B_EXIT)
446 /* save panel options */
447 panels_save_options ();
448 mc_config_save_file (mc_main_config, NULL);
452 /* --------------------------------------------------------------------------------------------- */