Ticket #2344: Fix line jump when started as editor
[midnight-commander.git] / src / option.c
blob64ccfab23d1db851d842c4cafa581d8e7d7d8429
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 "widget.h" /* WCheck */
41 #include "setup.h" /* panels_options */
42 #include "main.h"
43 #include "file.h" /* file_op_compute_totals */
44 #include "layout.h" /* nice_rotating_dash */
45 #include "wtools.h" /* QuickDialog */
46 #include "history.h" /* MC_HISTORY_ESC_TIMEOUT */
48 #include "option.h"
50 static cb_ret_t
51 configure_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
53 switch (msg)
55 case DLG_ACTION:
56 if (sender->id == 18)
58 /* message from "Single press" checkbutton */
59 const gboolean not_single = !(((WCheck *) sender)->state & C_BOOL);
60 Widget *w;
62 /* label */
63 w = dlg_find_by_id (h, sender->id - 1);
64 widget_disable (*w, not_single);
65 send_message (w, WIDGET_DRAW, 0);
66 /* input */
67 w = dlg_find_by_id (h, sender->id - 2);
68 widget_disable (*w, not_single);
69 send_message (w, WIDGET_DRAW, 0);
71 return MSG_HANDLED;
73 return MSG_NOT_HANDLED;
75 default:
76 return default_dlg_callback (h, sender, msg, parm, data);
80 void
81 configure_box (void)
83 int dlg_width = 60;
84 int dlg_height = 20;
86 char time_out[BUF_TINY] = "";
87 char *time_out_new;
89 const char *pause_options[] = {
90 N_("&Never"),
91 N_("On dum&b terminals"),
92 N_("Alwa&ys")
95 int pause_options_num = sizeof (pause_options) / sizeof (pause_options[0]);
97 QuickWidget quick_widgets[] = {
98 /* buttons */
99 QUICK_BUTTON (38, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
100 QUICK_BUTTON (26, dlg_width, dlg_height - 3, dlg_height, N_("&Save"), B_EXIT, NULL),
101 QUICK_BUTTON (14, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
102 /* other options */
103 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 12, dlg_height, N_("A&uto save setup"),
104 &auto_save_setup),
105 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 11, dlg_height, N_("Sa&fe delete"),
106 &safe_delete),
107 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 10, dlg_height, N_("Cd follows lin&ks"),
108 &cd_symlinks),
109 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("Rotating d&ash"),
110 &nice_rotating_dash),
111 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 8, dlg_height, N_("Co&mplete: show all"),
112 &show_all_if_ambiguous),
113 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 7, dlg_height, N_("Shell &patterns"),
114 &easy_patterns),
115 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 6, dlg_height, N_("&Drop down menus"),
116 &drop_menus),
117 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 5, dlg_height, N_("Auto m&enus"), &auto_menu),
118 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 4, dlg_height, N_("Use internal vie&w"),
119 &use_internal_view),
120 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 3, dlg_height, N_("Use internal edi&t"),
121 &use_internal_edit),
122 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 15,
123 N_("Other options")),
124 /* pause options */
125 QUICK_RADIO (5, dlg_width, 13, dlg_height, pause_options_num, pause_options,
126 &pause_after_run),
127 QUICK_GROUPBOX (3, dlg_width, 12, dlg_height, dlg_width / 2 - 4, 5, N_("Pause after run")),
129 /* Esc key mode */
130 QUICK_INPUT (10, dlg_width, 10, dlg_height, (const char *) time_out, 8, 0,
131 MC_HISTORY_ESC_TIMEOUT, &time_out_new),
132 QUICK_LABEL (5, dlg_width, 10, dlg_height, N_("Timeout:")),
133 QUICK_CHECKBOX (5, dlg_width, 9, dlg_height, N_("S&ingle press"), &old_esc_mode),
134 QUICK_GROUPBOX (3, dlg_width, 8, dlg_height, dlg_width / 2 - 4, 4, N_("Esc key mode")),
136 /* file operation options */
137 QUICK_CHECKBOX (5, dlg_width, 6, dlg_height, N_("Mkdi&r autoname"), &auto_fill_mkdir_name),
138 QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Classic pro&gressbar"), &classic_progressbar),
139 QUICK_CHECKBOX (5, dlg_width, 4, dlg_height, N_("Compute tota&ls"),
140 &file_op_compute_totals),
141 QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("&Verbose operation"), &verbose),
142 QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 6,
143 N_("File operation options")),
144 QUICK_END
147 const size_t qw_num = sizeof (quick_widgets) / sizeof (quick_widgets[0]) - 1;
149 QuickDialog Quick_input = {
150 dlg_width, dlg_height, -1, -1,
151 N_("Configure options"), "[Configuration]",
152 quick_widgets, configure_callback, TRUE
155 int qd_result;
157 int b0_len, b1_len, b2_len;
158 int b_len, c_len, g_len, l_len;
159 size_t i;
161 #ifdef ENABLE_NLS
163 for (i = 0; i < qw_num; i++)
164 if (i < 3)
165 /* buttons */
166 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
167 else if ((i == 13) || (i == 15) || (i == 19) || (i == 24))
168 /* groupboxes */
169 quick_widgets[i].u.groupbox.title = _(quick_widgets[i].u.groupbox.title);
170 else if (i == 14)
172 /* radio button */
173 size_t j;
174 for (j = 0; j < (size_t) pause_options_num; j++)
175 pause_options[j] = _(pause_options[j]);
177 else if (i == 17)
178 /* label */
179 quick_widgets[i].u.label.text = _(quick_widgets[i].u.label.text);
180 else if (i != 16)
181 /* checkboxes */
182 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
184 Quick_input.title = _(Quick_input.title);
186 #endif /* ENABLE_NLS */
188 /* calculate widget and dialog widths */
189 /* dialog title */
190 dlg_width = max (dlg_width, str_term_width1 (Quick_input.title) + 4);
191 /* buttons */
192 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
193 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
194 b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5;
195 b_len = b0_len + b1_len + b2_len + 2;
197 /* checkboxes within groupboxes */
198 c_len = 0;
199 for (i = 3; i < 24; i++)
200 if ((i < 13) || (i == 18) || (i > 19))
201 c_len = max (c_len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 3);
202 /* radiobuttons */
203 for (i = 0; i < (size_t) pause_options_num; i++)
204 c_len = max (c_len, str_term_width1 (pause_options[i]) + 3);
205 /* label + input */
206 l_len = str_term_width1 (quick_widgets[17].u.label.text);
207 c_len = max (c_len, l_len + 1 + 8);
208 /* groupboxes */
209 g_len = max (c_len + 2, str_term_width1 (quick_widgets[24].u.groupbox.title) + 4);
210 g_len = max (g_len, str_term_width1 (quick_widgets[19].u.groupbox.title) + 4);
211 g_len = max (g_len, str_term_width1 (quick_widgets[15].u.groupbox.title) + 4);
212 g_len = max (g_len, str_term_width1 (quick_widgets[13].u.groupbox.title) + 4);
213 /* dialog width */
214 Quick_input.xlen = max (dlg_width, g_len * 2 + 9);
215 Quick_input.xlen = max (Quick_input.xlen, b_len + 2);
216 if ((Quick_input.xlen & 1) != 0)
217 Quick_input.xlen++;
219 /* fix widget parameters */
220 for (i = 0; i < qw_num; i++)
221 quick_widgets[i].x_divisions = Quick_input.xlen;
223 /* groupboxes */
224 quick_widgets[15].u.groupbox.width =
225 quick_widgets[19].u.groupbox.width =
226 quick_widgets[24].u.groupbox.width = Quick_input.xlen / 2 - 4;
227 quick_widgets[13].u.groupbox.width = Quick_input.xlen / 2 - 3;
229 /* input */
230 quick_widgets[16].relative_x = quick_widgets[17].relative_x + l_len + 1;
231 quick_widgets[16].u.input.len = quick_widgets[19].u.groupbox.width - l_len - 4;
233 /* right column */
234 quick_widgets[13].relative_x = Quick_input.xlen / 2;
235 for (i = 3; i < 13; i++)
236 quick_widgets[i].relative_x = quick_widgets[13].relative_x + 2;
238 /* buttons */
239 quick_widgets[2].relative_x = (Quick_input.xlen - b_len) / 2;
240 quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + 1;
241 quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + 1;
243 g_snprintf (time_out, sizeof (time_out), "%d", old_esc_mode_timeout);
245 if (!old_esc_mode)
246 quick_widgets[16].options = quick_widgets[17].options = W_DISABLED;
248 qd_result = quick_dialog (&Quick_input);
250 if ((qd_result == B_ENTER) || (qd_result == B_EXIT))
251 old_esc_mode_timeout = atoi (time_out_new);
253 g_free (time_out_new);
255 /* Save button */
256 if (qd_result == B_EXIT)
258 save_config ();
259 mc_config_save_file (mc_main_config, NULL);
263 void
264 panel_options_box (void)
266 int dlg_width = 60;
267 int dlg_height = 19;
269 const char *qsearch_options[] = {
270 N_("Case &insensitive"),
271 N_("Case s&ensitive"),
272 N_("Use panel sort mo&de")
275 QuickWidget quick_widgets[] = {
276 /* buttons */
277 QUICK_BUTTON (38, dlg_width, dlg_height - 3, dlg_height, N_("&Cancel"), B_CANCEL, NULL),
278 QUICK_BUTTON (26, dlg_width, dlg_height - 3, dlg_height, N_("&Save"), B_EXIT, NULL),
279 QUICK_BUTTON (14, dlg_width, dlg_height - 3, dlg_height, N_("&OK"), B_ENTER, NULL),
280 /* quick search */
281 QUICK_RADIO (dlg_width / 2 + 2, dlg_width, 12, dlg_height, QSEARCH_NUM, qsearch_options,
282 (int *) &panels_options.qsearch_mode),
283 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 11, dlg_height, dlg_width / 2 - 4, QSEARCH_NUM + 2,
284 N_("Quick search")),
285 /* file highlighting */
286 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("&Permissions"),
287 &panels_options.permission_mode),
288 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 8, dlg_height, N_("File &types"),
289 &panels_options.filetype_mode),
290 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 7, dlg_height, dlg_width / 2 - 4, 4,
291 N_("File highlight")),
292 /* navigation */
293 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 5, dlg_height, N_("&Mouse page scrolling"),
294 &panels_options.mouse_move_pages),
295 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 4, dlg_height, N_("Pa&ge scrolling"),
296 &panels_options.scroll_pages),
297 QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 3, dlg_height, N_("L&ynx-like motion"),
298 &panels_options.navigate_with_arrows),
299 QUICK_GROUPBOX (dlg_width / 2, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 5,
300 N_("Navigation")),
301 /* main panel options */
302 QUICK_CHECKBOX (5, dlg_width, 10, dlg_height, N_("A&uto save panels setup"),
303 &panels_options.auto_save_setup),
304 QUICK_CHECKBOX (5, dlg_width, 9, dlg_height, N_("Re&verse files only"),
305 &panels_options.reverse_files_only),
306 QUICK_CHECKBOX (5, dlg_width, 8, dlg_height, N_("Ma&rk moves down"),
307 &panels_options.mark_moves_down),
308 QUICK_CHECKBOX (5, dlg_width, 7, dlg_height, N_("&Fast dir reload"),
309 &panels_options.fast_reload),
310 QUICK_CHECKBOX (5, dlg_width, 6, dlg_height, N_("Show &hidden files"),
311 &panels_options.show_dot_files),
312 QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Show &backup files"),
313 &panels_options.show_backups),
314 QUICK_CHECKBOX (5, dlg_width, 4, dlg_height, N_("Mi&x all files"),
315 &panels_options.mix_all_files),
316 QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("Use SI si&ze units"),
317 &panels_options.kilobyte_si),
318 QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 14, N_("Main panel options")),
319 QUICK_END
322 const size_t qw_num = sizeof (quick_widgets) / sizeof (quick_widgets[0]) - 1;
324 QuickDialog Quick_input = {
325 dlg_width, dlg_height, -1, -1,
326 N_("Panel options"), "[Panel options]",
327 quick_widgets, NULL, TRUE
330 int qd_result;
332 int b0_len, b1_len, b2_len;
333 int b_len, c_len, g_len;
334 size_t i;
336 #ifdef ENABLE_NLS
338 for (i = 0; i < qw_num; i++)
339 if (i < 3)
340 /* buttons */
341 quick_widgets[i].u.button.text = _(quick_widgets[i].u.button.text);
342 else if (i == 3)
344 /* radio button */
345 size_t j;
346 for (j = 0; j < QSEARCH_NUM; j++)
347 qsearch_options[j] = _(qsearch_options[j]);
349 else if ((i == 4) || (i == 7) || (i == 11) || (i == 20))
350 /* groupboxes */
351 quick_widgets[i].u.groupbox.title = _(quick_widgets[i].u.groupbox.title);
352 else
353 /* checkboxes */
354 quick_widgets[i].u.checkbox.text = _(quick_widgets[i].u.checkbox.text);
356 Quick_input.title = _(Quick_input.title);
358 #endif /* ENABLE_NLS */
360 /* calculate widget and dialog widths */
361 /* dialog title */
362 dlg_width = max (dlg_width, str_term_width1 (Quick_input.title) + 4);
363 /* buttons */
364 b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
365 b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 3;
366 b2_len = str_term_width1 (quick_widgets[2].u.button.text) + 5;
367 b_len = b0_len + b1_len + b2_len + 2;
369 /* checkboxes within groupboxes */
370 c_len = 0;
371 for (i = 5; i < 20; i++)
372 if ((i != 7) && (i != 11))
373 c_len = max (c_len, str_term_width1 (quick_widgets[i].u.checkbox.text) + 4);
375 /* radiobuttons */
376 for (i = 0; i < QSEARCH_NUM; i++)
377 c_len = max (c_len, str_term_width1 (qsearch_options[i]) + 3);
378 /* groupboxes */
379 g_len = max (c_len + 2, str_term_width1 (quick_widgets[4].u.groupbox.title) + 4);
380 g_len = max (g_len, str_term_width1 (quick_widgets[ 7].u.groupbox.title) + 4);
381 g_len = max (g_len, str_term_width1 (quick_widgets[11].u.groupbox.title) + 4);
382 g_len = max (g_len, str_term_width1 (quick_widgets[20].u.groupbox.title) + 4);
383 /* dialog width */
384 Quick_input.xlen = max (dlg_width, g_len * 2 + 9);
385 Quick_input.xlen = max (Quick_input.xlen, b_len + 2);
386 if ((Quick_input.xlen & 1) != 0)
387 Quick_input.xlen++;
389 /* fix widget parameters */
390 for (i = 0; i < qw_num; i++)
391 quick_widgets[i].x_divisions = Quick_input.xlen;
393 /* groupboxes */
394 quick_widgets[4].u.groupbox.width =
395 quick_widgets[ 7].u.groupbox.width =
396 quick_widgets[11].u.groupbox.width = Quick_input.xlen / 2 - 3;
397 quick_widgets[20].u.groupbox.width = Quick_input.xlen / 2 - 4;
399 /* right column */
400 quick_widgets[4].relative_x =
401 quick_widgets[ 7].relative_x =
402 quick_widgets[11].relative_x = Quick_input.xlen / 2;
403 for (i = 3; i < 11; i++)
404 if ((i != 4) && (i != 7))
405 quick_widgets[i].relative_x = quick_widgets[4].relative_x + 2;
407 /* buttons */
408 quick_widgets[2].relative_x = (Quick_input.xlen - b_len) / 2;
409 quick_widgets[1].relative_x = quick_widgets[2].relative_x + b2_len + 1;
410 quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + 1;
412 qd_result = quick_dialog (&Quick_input);
414 if ((qd_result == B_ENTER) || (qd_result == B_EXIT))
416 if (!panels_options.fast_reload_msg_shown && panels_options.fast_reload)
418 message (D_NORMAL, _("Information"),
419 _("Using the fast reload option may not reflect the exact\n"
420 "directory contents. In this case you'll need to do a\n"
421 "manual reload of the directory. See the man page for\n"
422 "the details."));
423 panels_options.fast_reload_msg_shown = TRUE;
425 update_panels (UP_RELOAD, UP_KEEPSEL);
428 if (qd_result == B_EXIT)
430 /* save panel options */
431 panels_save_options ();
432 mc_config_save_file (mc_main_config, NULL);