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.
21 * \brief Source: configure boxes module
26 #include <stdlib.h> /* atoi() */
30 #include <sys/types.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 */
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 */
55 char time_out
[BUF_TINY
] = "";
58 const char *pause_options
[] = {
60 N_("On dum&b terminals"),
64 int pause_options_num
= sizeof (pause_options
) / sizeof (pause_options
[0]);
66 QuickWidget quick_widgets
[] = {
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
),
72 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 12, dlg_height
, N_("A&uto save setup"),
74 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 11, dlg_height
, N_("Sa&fe delete"),
76 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 10, dlg_height
, N_("Cd follows lin&ks"),
78 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 9, dlg_height
, N_("Rotating d&ash"),
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"),
84 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 6, dlg_height
, N_("&Drop down 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"),
89 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 3, dlg_height
, N_("Use internal edi&t"),
91 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 15,
94 QUICK_RADIO (5, dlg_width
, 13, dlg_height
, pause_options_num
, pause_options
,
96 QUICK_GROUPBOX (3, dlg_width
, 12, dlg_height
, dlg_width
/ 2 - 4, 5, N_("Pause after run")),
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")),
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]",
126 int b0_len
, b1_len
, b2_len
;
127 int b_len
, c_len
, g_len
, l_len
;
132 for (i
= 0; i
< qw_num
; i
++)
135 quick_widgets
[i
].u
.button
.text
= _(quick_widgets
[i
].u
.button
.text
);
136 else if ((i
== 13) || (i
== 15) || (i
== 19) || (i
== 24))
138 quick_widgets
[i
].u
.groupbox
.title
= _(quick_widgets
[i
].u
.groupbox
.title
);
143 for (j
= 0; j
< (size_t) pause_options_num
; j
++)
144 pause_options
[j
] = _(pause_options
[j
]);
148 quick_widgets
[i
].u
.label
.text
= _(quick_widgets
[i
].u
.label
.text
);
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 */
159 dlg_width
= max (dlg_width
, str_term_width1 (Quick_input
.title
) + 4);
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 */
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);
172 for (i
= 0; i
< (size_t) pause_options_num
; i
++)
173 c_len
= max (c_len
, str_term_width1 (pause_options
[i
]) + 3);
175 l_len
= str_term_width1 (quick_widgets
[17].u
.label
.text
);
176 c_len
= max (c_len
, l_len
+ 1 + 8);
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);
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)
188 /* fix widget parameters */
189 for (i
= 0; i
< qw_num
; i
++)
190 quick_widgets
[i
].x_divisions
= Quick_input
.xlen
;
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;
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;
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;
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
);
222 if (qd_result
== B_EXIT
)
225 mc_config_save_file (mc_main_config
, NULL
);
230 panel_options_box (void)
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
[] = {
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
),
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,
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")),
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,
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")),
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]",
298 int b0_len
, b1_len
, b2_len
;
299 int b_len
, c_len
, g_len
;
304 for (i
= 0; i
< qw_num
; i
++)
307 quick_widgets
[i
].u
.button
.text
= _(quick_widgets
[i
].u
.button
.text
);
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))
317 quick_widgets
[i
].u
.groupbox
.title
= _(quick_widgets
[i
].u
.groupbox
.title
);
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 */
328 dlg_width
= max (dlg_width
, str_term_width1 (Quick_input
.title
) + 4);
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 */
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);
342 for (i
= 0; i
< QSEARCH_NUM
; i
++)
343 c_len
= max (c_len
, str_term_width1 (qsearch_options
[i
]) + 3);
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);
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)
355 /* fix widget parameters */
356 for (i
= 0; i
< qw_num
; i
++)
357 quick_widgets
[i
].x_divisions
= Quick_input
.xlen
;
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;
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;
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"
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
);