Merge branch '2153_wrong_selection_fix'
[midnight-commander/osp/pkrayzel.git] / src / option.c
blob8636bc6a3bbf30f6b62a9d455ab4d2477829ecb2
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 */
39 #include "dialog.h" /* B_ constants */
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 "wtools.h" /* QuickDialog */
45 #include "history.h" /* MC_HISTORY_ESC_TIMEOUT */
47 #include "option.h"
49 void
50 configure_box (void)
52 int dlg_width = 60;
53 int dlg_height = 20;
55 char time_out[BUF_TINY] = "";
56 char *time_out_new;
58 const char *pause_options[] = {
59 N_("&Never"),
60 N_("On dum&b terminals"),
61 N_("Alwa&ys")
64 int pause_options_num = sizeof (pause_options) / sizeof (pause_options[0]);
66 QuickWidget quick_widgets[] = {
67 /* buttons */
68 QUICK_BUTTON (38, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
69 QUICK_BUTTON (26, dlg_width, dlg_height - 3, dlg_height, N_("&Save"), B_EXIT, NULL),
70 QUICK_BUTTON (14, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
71 /* other options */
72 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 12, dlg_height, N_("A&uto save setup"),
73 &auto_save_setup),
74 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 11, dlg_height, N_("Sa&fe delete"),
75 &safe_delete),
76 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 10, dlg_height, N_("Cd follows lin&ks"),
77 &cd_symlinks),
78 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("Rotating d&ash"),
79 &nice_rotating_dash),
80 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 8, dlg_height, N_("Co&mplete: show all"),
81 &show_all_if_ambiguous),
82 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 7, dlg_height, N_("Shell &patterns"),
83 &easy_patterns),
84 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 6, dlg_height, N_("&Drop down menus"),
85 &drop_menus),
86 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 5, dlg_height, N_("Auto m&enus"), &auto_menu),
87 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 4, dlg_height, N_("Use internal vie&w"),
88 &use_internal_view),
89 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 3, dlg_height, N_("Use internal edi&t"),
90 &use_internal_edit),
91 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 15,
92 N_("Other options")),
93 /* pause options */
94 QUICK_RADIO (5, dlg_width, 13, dlg_height, pause_options_num, pause_options,
95 &pause_after_run),
96 QUICK_GROUPBOX (3, dlg_width, 12, dlg_height, dlg_width / 2 - 4, 5, N_("Pause after run")),
98 /* Esc key mode */
99 QUICK_INPUT (10, dlg_width, 10, dlg_height, (const char *) time_out, 8, 0,
100 MC_HISTORY_ESC_TIMEOUT, &time_out_new),
101 QUICK_LABEL (5, dlg_width, 10, dlg_height, N_("Timeout:")),
102 QUICK_CHECKBOX (5, dlg_width, 9, dlg_height, N_("S&ingle press"), &old_esc_mode),
103 QUICK_GROUPBOX (3, dlg_width, 8, dlg_height, dlg_width / 2 - 4, 4, N_("Esc key mode")),
105 /* file operation options */
106 QUICK_CHECKBOX (5, dlg_width, 6, dlg_height, N_("Mkdi&r autoname"), &auto_fill_mkdir_name),
107 QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Classic pro&gressbar"), &classic_progressbar),
108 QUICK_CHECKBOX (5, dlg_width, 4, dlg_height, N_("Compute tota&ls"),
109 &file_op_compute_totals),
110 QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("&Verbose operation"), &verbose),
111 QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 6,
112 N_("File operation options")),
113 QUICK_END
116 const size_t qw_num = sizeof (quick_widgets) / sizeof (quick_widgets[0]) - 1;
118 QuickDialog Quick_input = {
119 dlg_width, dlg_height, -1, -1,
120 N_("Configure options"), "[Configuration]",
121 quick_widgets, TRUE
124 int qd_result;
126 int b0_len, b1_len, b2_len;
127 int b_len, c_len, g_len, l_len;
128 size_t i;
130 #ifdef ENABLE_NLS
132 for (i = 0; i < qw_num; i++)
133 if (i < 3)
134 /* buttons */
135 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
136 else if ((i == 13) || (i == 15) || (i == 19) || (i == 24))
137 /* groupboxes */
138 quick_widgets[i].u.groupbox.title = _(quick_widgets[i].u.groupbox.title);
139 else if (i == 14)
141 /* radio button */
142 size_t j;
143 for (j = 0; j < (size_t) pause_options_num; j++)
144 pause_options[j] = _(pause_options[j]);
146 else if (i == 17)
147 /* label */
148 quick_widgets[i].u.label.text = _(quick_widgets[i].u.label.text);
149 else if (i != 16)
150 /* checkboxes */
151 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
153 Quick_input.title = _(Quick_input.title);
155 #endif /* ENABLE_NLS */
157 /* calculate widget and dialog widths */
158 /* dialog title */
159 dlg_width = max (dlg_width, str_term_width1 (Quick_input.title) + 4);
160 /* buttons */
161 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
162 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
163 b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5;
164 b_len = b0_len + b1_len + b2_len + 2;
166 /* checkboxes within groupboxes */
167 c_len = 0;
168 for (i = 3; i < 24; i++)
169 if ((i < 13) || (i == 18) || (i > 19))
170 c_len = max (c_len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 3);
171 /* radiobuttons */
172 for (i = 0; i < (size_t) pause_options_num; i++)
173 c_len = max (c_len, str_term_width1 (pause_options[i]) + 3);
174 /* label + input */
175 l_len = str_term_width1 (quick_widgets[17].u.label.text);
176 c_len = max (c_len, l_len + 1 + 8);
177 /* groupboxes */
178 g_len = max (c_len + 2, str_term_width1 (quick_widgets[24].u.groupbox.title) + 4);
179 g_len = max (g_len, str_term_width1 (quick_widgets[19].u.groupbox.title) + 4);
180 g_len = max (g_len, str_term_width1 (quick_widgets[15].u.groupbox.title) + 4);
181 g_len = max (g_len, str_term_width1 (quick_widgets[13].u.groupbox.title) + 4);
182 /* dialog width */
183 Quick_input.xlen = max (dlg_width, g_len * 2 + 9);
184 Quick_input.xlen = max (Quick_input.xlen, b_len + 2);
185 if ((Quick_input.xlen & 1) != 0)
186 Quick_input.xlen++;
188 /* fix widget parameters */
189 for (i = 0; i < qw_num; i++)
190 quick_widgets[i].x_divisions = Quick_input.xlen;
192 /* groupboxes */
193 quick_widgets[15].u.groupbox.width =
194 quick_widgets[19].u.groupbox.width =
195 quick_widgets[24].u.groupbox.width = Quick_input.xlen / 2 - 4;
196 quick_widgets[13].u.groupbox.width = Quick_input.xlen / 2 - 3;
198 /* input */
199 quick_widgets[16].relative_x = quick_widgets[17].relative_x + l_len + 1;
200 quick_widgets[16].u.input.len = quick_widgets[19].u.groupbox.width - l_len - 4;
202 /* right column */
203 quick_widgets[13].relative_x = Quick_input.xlen / 2;
204 for (i = 3; i < 13; i++)
205 quick_widgets[i].relative_x = quick_widgets[13].relative_x + 2;
207 /* buttons */
208 quick_widgets[2].relative_x = (Quick_input.xlen - b_len) / 2;
209 quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + 1;
210 quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + 1;
212 g_snprintf (time_out, sizeof (time_out), "%d", old_esc_mode_timeout);
214 qd_result = quick_dialog (&Quick_input);
216 if ((qd_result == B_ENTER) || (qd_result == B_EXIT))
217 old_esc_mode_timeout = atoi (time_out_new);
219 g_free (time_out_new);
221 /* Save button */
222 if (qd_result == B_EXIT)
224 save_config ();
225 mc_config_save_file (mc_main_config, NULL);
229 void
230 panel_options_box (void)
232 int dlg_width = 60;
233 int dlg_height = 19;
235 const char *qsearch_options[] = {
236 N_("Case &insensitive"),
237 N_("Case s&ensitive"),
238 N_("Use panel sort mo&de")
241 QuickWidget quick_widgets[] = {
242 /* buttons */
243 QUICK_BUTTON (38, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
244 QUICK_BUTTON (26, dlg_width, dlg_height - 3, dlg_height, N_("&Save"), B_EXIT, NULL),
245 QUICK_BUTTON (14, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
246 /* quick search */
247 QUICK_RADIO (dlg_width / 2 + 2, dlg_width, 12, dlg_height, QSEARCH_NUM, qsearch_options,
248 (int *) &panels_options.qsearch_mode),
249 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 11, dlg_height, dlg_width / 2 - 4, QSEARCH_NUM + 2,
250 N_("Quick search")),
251 /* file highlighting */
252 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("&Permissions"),
253 &panels_options.permission_mode),
254 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 8, dlg_height, N_("File &types"),
255 &panels_options.filetype_mode),
256 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 7, dlg_height, dlg_width / 2 - 4, 4,
257 N_("File highlight")),
258 /* navigation */
259 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 5, dlg_height, N_("&Mouse page scrolling"),
260 &panels_options.mouse_move_pages),
261 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 4, dlg_height, N_("Pa&ge scrolling"),
262 &panels_options.scroll_pages),
263 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 3, dlg_height, N_("L&ynx-like motion"),
264 &panels_options.navigate_with_arrows),
265 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 5,
266 N_("Navigation")),
267 /* main panel options */
268 QUICK_CHECKBOX (5, dlg_width, 10, dlg_height, N_("A&uto save panels setup"),
269 &panels_options.auto_save_setup),
270 QUICK_CHECKBOX (5, dlg_width, 9, dlg_height, N_("Re&verse files only"),
271 &panels_options.reverse_files_only),
272 QUICK_CHECKBOX (5, dlg_width, 8, dlg_height, N_("Ma&rk moves down"),
273 &panels_options.mark_moves_down),
274 QUICK_CHECKBOX (5, dlg_width, 7, dlg_height, N_("&Fast dir reload"),
275 &panels_options.fast_reload),
276 QUICK_CHECKBOX (5, dlg_width, 6, dlg_height, N_("Show &hidden files"),
277 &panels_options.show_dot_files),
278 QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Show &backup files"),
279 &panels_options.show_backups),
280 QUICK_CHECKBOX (5, dlg_width, 4, dlg_height, N_("Mi&x all files"),
281 &panels_options.mix_all_files),
282 QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("Use SI si&ze units"),
283 &panels_options.kilobyte_si),
284 QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 14, N_("Main panel options")),
285 QUICK_END
288 const size_t qw_num = sizeof (quick_widgets) / sizeof (quick_widgets[0]) - 1;
290 QuickDialog Quick_input = {
291 dlg_width, dlg_height, -1, -1,
292 N_("Panel options"), "[Panel options]",
293 quick_widgets, TRUE
296 int qd_result;
298 int b0_len, b1_len, b2_len;
299 int b_len, c_len, g_len;
300 size_t i;
302 #ifdef ENABLE_NLS
304 for (i = 0; i < qw_num; i++)
305 if (i < 3)
306 /* buttons */
307 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
308 else if (i == 3)
310 /* radio button */
311 size_t j;
312 for (j = 0; j < QSEARCH_NUM; j++)
313 qsearch_options[j] = _(qsearch_options[j]);
315 else if ((i == 4) || (i == 7) || (i == 11) || (i == 20))
316 /* groupboxes */
317 quick_widgets[i].u.groupbox.title = _(quick_widgets[i].u.groupbox.title);
318 else
319 /* checkboxes */
320 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
322 Quick_input.title = _(Quick_input.title);
324 #endif /* ENABLE_NLS */
326 /* calculate widget and dialog widths */
327 /* dialog title */
328 dlg_width = max (dlg_width, str_term_width1 (Quick_input.title) + 4);
329 /* buttons */
330 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
331 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
332 b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5;
333 b_len = b0_len + b1_len + b2_len + 2;
335 /* checkboxes within groupboxes */
336 c_len = 0;
337 for (i = 5; i < 20; i++)
338 if ((i != 7) && (i != 11))
339 c_len = max (c_len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
341 /* radiobuttons */
342 for (i = 0; i < QSEARCH_NUM; i++)
343 c_len = max (c_len, str_term_width1 (qsearch_options[i]) + 3);
344 /* groupboxes */
345 g_len = max (c_len + 2, str_term_width1 (quick_widgets[4].u.groupbox.title) + 4);
346 g_len = max (g_len, str_term_width1 (quick_widgets[ 7].u.groupbox.title) + 4);
347 g_len = max (g_len, str_term_width1 (quick_widgets[11].u.groupbox.title) + 4);
348 g_len = max (g_len, str_term_width1 (quick_widgets[20].u.groupbox.title) + 4);
349 /* dialog width */
350 Quick_input.xlen = max (dlg_width, g_len * 2 + 9);
351 Quick_input.xlen = max (Quick_input.xlen, b_len + 2);
352 if ((Quick_input.xlen & 1) != 0)
353 Quick_input.xlen++;
355 /* fix widget parameters */
356 for (i = 0; i < qw_num; i++)
357 quick_widgets[i].x_divisions = Quick_input.xlen;
359 /* groupboxes */
360 quick_widgets[4].u.groupbox.width =
361 quick_widgets[ 7].u.groupbox.width =
362 quick_widgets[11].u.groupbox.width = Quick_input.xlen / 2 - 3;
363 quick_widgets[20].u.groupbox.width = Quick_input.xlen / 2 - 4;
365 /* right column */
366 quick_widgets[4].relative_x =
367 quick_widgets[ 7].relative_x =
368 quick_widgets[11].relative_x = Quick_input.xlen / 2;
369 for (i = 3; i < 11; i++)
370 if ((i != 4) && (i != 7))
371 quick_widgets[i].relative_x = quick_widgets[4].relative_x + 2;
373 /* buttons */
374 quick_widgets[2].relative_x = (Quick_input.xlen - b_len) / 2;
375 quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + 1;
376 quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + 1;
378 qd_result = quick_dialog (&Quick_input);
380 if ((qd_result == B_ENTER) || (qd_result == B_EXIT))
382 if (!panels_options.fast_reload_msg_shown && panels_options.fast_reload)
384 message (D_NORMAL, _("Information"),
385 _("Using the fast reload option may not reflect the exact\n"
386 "directory contents. In this case you'll need to do a\n"
387 "manual reload of the directory. See the man page for\n"
388 "the details."));
389 panels_options.fast_reload_msg_shown = TRUE;
391 update_panels (UP_RELOAD, UP_KEEPSEL);
394 if (qd_result == B_EXIT)
396 /* save panel options */
397 panels_save_options ();
398 mc_config_save_file (mc_main_config, NULL);