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 */
56 char time_out
[BUF_TINY
] = "";
59 const char *pause_options
[] = {
61 N_("On dum&b terminals"),
65 int pause_options_num
= sizeof (pause_options
) / sizeof (pause_options
[0]);
67 QuickWidget quick_widgets
[] = {
69 QUICK_BUTTON (38, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Cancel"), B_CANCEL
, NULL
),
70 QUICK_BUTTON (26, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Save"), B_EXIT
, NULL
),
71 QUICK_BUTTON (14, dlg_width
, dlg_height
- 3, dlg_height
, N_("&OK"), B_ENTER
, NULL
),
73 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 12, dlg_height
, N_("A&uto save setup"),
75 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 11, dlg_height
, N_("Sa&fe delete"),
77 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 10, dlg_height
, N_("Cd follows lin&ks"),
79 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 9, dlg_height
, N_("Rotating d&ash"),
81 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 8, dlg_height
, N_("Co&mplete: show all"),
82 &show_all_if_ambiguous
),
83 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 7, dlg_height
, N_("Shell &patterns"),
85 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 6, dlg_height
, N_("&Drop down menus"),
87 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 5, dlg_height
, N_("Auto m&enus"), &auto_menu
),
88 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 4, dlg_height
, N_("Use internal vie&w"),
90 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 3, dlg_height
, N_("Use internal edi&t"),
92 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 15,
95 QUICK_RADIO (5, dlg_width
, 13, dlg_height
, pause_options_num
, pause_options
,
97 QUICK_GROUPBOX (3, dlg_width
, 12, dlg_height
, dlg_width
/ 2 - 4, 5, N_("Pause after run")),
100 QUICK_INPUT (10, dlg_width
, 10, dlg_height
, (const char *) time_out
, 8, 0,
101 MC_HISTORY_ESC_TIMEOUT
, &time_out_new
),
102 QUICK_LABEL (5, dlg_width
, 10, dlg_height
, N_("Timeout:")),
103 QUICK_CHECKBOX (5, dlg_width
, 9, dlg_height
, N_("S&ingle press"), &old_esc_mode
),
104 QUICK_GROUPBOX (3, dlg_width
, 8, dlg_height
, dlg_width
/ 2 - 4, 4, N_("Esc key mode")),
106 /* file operation options */
107 QUICK_CHECKBOX (5, dlg_width
, 6, dlg_height
, N_("Mkdi&r autoname"), &auto_fill_mkdir_name
),
108 QUICK_CHECKBOX (5, dlg_width
, 5, dlg_height
, N_("Classic pro&gressbar"), &classic_progressbar
),
109 QUICK_CHECKBOX (5, dlg_width
, 4, dlg_height
, N_("Compute tota&ls"),
110 &file_op_compute_totals
),
111 QUICK_CHECKBOX (5, dlg_width
, 3, dlg_height
, N_("&Verbose operation"), &verbose
),
112 QUICK_GROUPBOX (3, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 6,
113 N_("File operation options")),
117 const size_t qw_num
= sizeof (quick_widgets
) / sizeof (quick_widgets
[0]) - 1;
119 QuickDialog Quick_input
= {
120 dlg_width
, dlg_height
, -1, -1,
121 N_("Configure options"), "[Configuration]",
127 int b0_len
, b1_len
, b2_len
;
128 int b_len
, c_len
, g_len
, l_len
;
133 for (i
= 0; i
< qw_num
; i
++)
136 quick_widgets
[i
].u
.button
.text
= _(quick_widgets
[i
].u
.button
.text
);
137 else if ((i
== 13) || (i
== 15) || (i
== 19) || (i
== 24))
139 quick_widgets
[i
].u
.groupbox
.title
= _(quick_widgets
[i
].u
.groupbox
.title
);
144 for (j
= 0; j
< (size_t) pause_options_num
; j
++)
145 pause_options
[j
] = _(pause_options
[j
]);
149 quick_widgets
[i
].u
.label
.text
= _(quick_widgets
[i
].u
.label
.text
);
152 quick_widgets
[i
].u
.checkbox
.text
= _(quick_widgets
[i
].u
.checkbox
.text
);
154 Quick_input
.title
= _(Quick_input
.title
);
156 #endif /* ENABLE_NLS */
158 /* calculate widget and dialog widths */
160 dlg_width
= max (dlg_width
, str_term_width1 (Quick_input
.title
) + 4);
162 b0_len
= str_term_width1 (quick_widgets
[0].u
.button
.text
) + 3;
163 b1_len
= str_term_width1 (quick_widgets
[1].u
.button
.text
) + 3;
164 b2_len
= str_term_width1 (quick_widgets
[2].u
.button
.text
) + 5;
165 b_len
= b0_len
+ b1_len
+ b2_len
+ 2;
167 /* checkboxes within groupboxes */
169 for (i
= 3; i
< 24; i
++)
170 if ((i
< 13) || (i
== 18) || (i
> 19))
171 c_len
= max (c_len
, str_term_width1 (quick_widgets
[i
].u
.checkbox
.text
) + 3);
173 for (i
= 0; i
< (size_t) pause_options_num
; i
++)
174 c_len
= max (c_len
, str_term_width1 (pause_options
[i
]) + 3);
176 l_len
= str_term_width1 (quick_widgets
[17].u
.label
.text
);
177 c_len
= max (c_len
, l_len
+ 1 + 8);
179 g_len
= max (c_len
+ 2, str_term_width1 (quick_widgets
[24].u
.groupbox
.title
) + 4);
180 g_len
= max (g_len
, str_term_width1 (quick_widgets
[19].u
.groupbox
.title
) + 4);
181 g_len
= max (g_len
, str_term_width1 (quick_widgets
[15].u
.groupbox
.title
) + 4);
182 g_len
= max (g_len
, str_term_width1 (quick_widgets
[13].u
.groupbox
.title
) + 4);
184 Quick_input
.xlen
= max (dlg_width
, g_len
* 2 + 9);
185 Quick_input
.xlen
= max (Quick_input
.xlen
, b_len
+ 2);
186 if ((Quick_input
.xlen
& 1) != 0)
189 /* fix widget parameters */
190 for (i
= 0; i
< qw_num
; i
++)
191 quick_widgets
[i
].x_divisions
= Quick_input
.xlen
;
194 quick_widgets
[15].u
.groupbox
.width
=
195 quick_widgets
[19].u
.groupbox
.width
=
196 quick_widgets
[24].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 4;
197 quick_widgets
[13].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 3;
200 quick_widgets
[16].relative_x
= quick_widgets
[17].relative_x
+ l_len
+ 1;
201 quick_widgets
[16].u
.input
.len
= quick_widgets
[19].u
.groupbox
.width
- l_len
- 4;
204 quick_widgets
[13].relative_x
= Quick_input
.xlen
/ 2;
205 for (i
= 3; i
< 13; i
++)
206 quick_widgets
[i
].relative_x
= quick_widgets
[13].relative_x
+ 2;
209 quick_widgets
[2].relative_x
= (Quick_input
.xlen
- b_len
) / 2;
210 quick_widgets
[1].relative_x
= quick_widgets
[2].relative_x
+ b2_len
+ 1;
211 quick_widgets
[0].relative_x
= quick_widgets
[1].relative_x
+ b1_len
+ 1;
213 g_snprintf (time_out
, sizeof (time_out
), "%d", old_esc_mode_timeout
);
215 qd_result
= quick_dialog (&Quick_input
);
217 if ((qd_result
== B_ENTER
) || (qd_result
== B_EXIT
))
218 old_esc_mode_timeout
= atoi (time_out_new
);
220 g_free (time_out_new
);
223 if (qd_result
== B_EXIT
)
226 mc_config_save_file (mc_main_config
, NULL
);
231 panel_options_box (void)
236 const char *qsearch_options
[] = {
237 N_("Case &insensitive"),
238 N_("Case s&ensitive"),
239 N_("Use panel sort mo&de")
242 QuickWidget quick_widgets
[] = {
244 QUICK_BUTTON (38, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Cancel"), B_CANCEL
, NULL
),
245 QUICK_BUTTON (26, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Save"), B_EXIT
, NULL
),
246 QUICK_BUTTON (14, dlg_width
, dlg_height
- 3, dlg_height
, N_("&OK"), B_ENTER
, NULL
),
248 QUICK_RADIO (dlg_width
/ 2 + 2, dlg_width
, 12, dlg_height
, QSEARCH_NUM
, qsearch_options
,
249 (int *) &panels_options
.qsearch_mode
),
250 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 11, dlg_height
, dlg_width
/ 2 - 4, QSEARCH_NUM
+ 2,
252 /* file highlighting */
253 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 9, dlg_height
, N_("&Permissions"),
254 &panels_options
.permission_mode
),
255 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 8, dlg_height
, N_("File &types"),
256 &panels_options
.filetype_mode
),
257 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 7, dlg_height
, dlg_width
/ 2 - 4, 4,
258 N_("File highlight")),
260 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 5, dlg_height
, N_("&Mouse page scrolling"),
261 &panels_options
.mouse_move_pages
),
262 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 4, dlg_height
, N_("Pa&ge scrolling"),
263 &panels_options
.scroll_pages
),
264 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 3, dlg_height
, N_("L&ynx-like motion"),
265 &panels_options
.navigate_with_arrows
),
266 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 5,
268 /* main panel options */
269 QUICK_CHECKBOX (5, dlg_width
, 10, dlg_height
, N_("A&uto save panels setup"),
270 &panels_options
.auto_save_setup
),
271 QUICK_CHECKBOX (5, dlg_width
, 9, dlg_height
, N_("Re&verse files only"),
272 &panels_options
.reverse_files_only
),
273 QUICK_CHECKBOX (5, dlg_width
, 8, dlg_height
, N_("Ma&rk moves down"),
274 &panels_options
.mark_moves_down
),
275 QUICK_CHECKBOX (5, dlg_width
, 7, dlg_height
, N_("&Fast dir reload"),
276 &panels_options
.fast_reload
),
277 QUICK_CHECKBOX (5, dlg_width
, 6, dlg_height
, N_("Show &hidden files"),
278 &panels_options
.show_dot_files
),
279 QUICK_CHECKBOX (5, dlg_width
, 5, dlg_height
, N_("Show &backup files"),
280 &panels_options
.show_backups
),
281 QUICK_CHECKBOX (5, dlg_width
, 4, dlg_height
, N_("Mi&x all files"),
282 &panels_options
.mix_all_files
),
283 QUICK_CHECKBOX (5, dlg_width
, 3, dlg_height
, N_("Use SI si&ze units"),
284 &panels_options
.kilobyte_si
),
285 QUICK_GROUPBOX (3, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 14, N_("Main panel options")),
289 const size_t qw_num
= sizeof (quick_widgets
) / sizeof (quick_widgets
[0]) - 1;
291 QuickDialog Quick_input
= {
292 dlg_width
, dlg_height
, -1, -1,
293 N_("Panel options"), "[Panel options]",
299 int b0_len
, b1_len
, b2_len
;
300 int b_len
, c_len
, g_len
;
305 for (i
= 0; i
< qw_num
; i
++)
308 quick_widgets
[i
].u
.button
.text
= _(quick_widgets
[i
].u
.button
.text
);
313 for (j
= 0; j
< QSEARCH_NUM
; j
++)
314 qsearch_options
[j
] = _(qsearch_options
[j
]);
316 else if ((i
== 4) || (i
== 7) || (i
== 11) || (i
== 20))
318 quick_widgets
[i
].u
.groupbox
.title
= _(quick_widgets
[i
].u
.groupbox
.title
);
321 quick_widgets
[i
].u
.checkbox
.text
= _(quick_widgets
[i
].u
.checkbox
.text
);
323 Quick_input
.title
= _(Quick_input
.title
);
325 #endif /* ENABLE_NLS */
327 /* calculate widget and dialog widths */
329 dlg_width
= max (dlg_width
, str_term_width1 (Quick_input
.title
) + 4);
331 b0_len
= str_term_width1 (quick_widgets
[0].u
.button
.text
) + 3;
332 b1_len
= str_term_width1 (quick_widgets
[1].u
.button
.text
) + 3;
333 b2_len
= str_term_width1 (quick_widgets
[2].u
.button
.text
) + 5;
334 b_len
= b0_len
+ b1_len
+ b2_len
+ 2;
336 /* checkboxes within groupboxes */
338 for (i
= 5; i
< 20; i
++)
339 if ((i
!= 7) && (i
!= 11))
340 c_len
= max (c_len
, str_term_width1 (quick_widgets
[i
].u
.checkbox
.text
) + 4);
343 for (i
= 0; i
< QSEARCH_NUM
; i
++)
344 c_len
= max (c_len
, str_term_width1 (qsearch_options
[i
]) + 3);
346 g_len
= max (c_len
+ 2, str_term_width1 (quick_widgets
[4].u
.groupbox
.title
) + 4);
347 g_len
= max (g_len
, str_term_width1 (quick_widgets
[ 7].u
.groupbox
.title
) + 4);
348 g_len
= max (g_len
, str_term_width1 (quick_widgets
[11].u
.groupbox
.title
) + 4);
349 g_len
= max (g_len
, str_term_width1 (quick_widgets
[20].u
.groupbox
.title
) + 4);
351 Quick_input
.xlen
= max (dlg_width
, g_len
* 2 + 9);
352 Quick_input
.xlen
= max (Quick_input
.xlen
, b_len
+ 2);
353 if ((Quick_input
.xlen
& 1) != 0)
356 /* fix widget parameters */
357 for (i
= 0; i
< qw_num
; i
++)
358 quick_widgets
[i
].x_divisions
= Quick_input
.xlen
;
361 quick_widgets
[4].u
.groupbox
.width
=
362 quick_widgets
[ 7].u
.groupbox
.width
=
363 quick_widgets
[11].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 3;
364 quick_widgets
[20].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 4;
367 quick_widgets
[4].relative_x
=
368 quick_widgets
[ 7].relative_x
=
369 quick_widgets
[11].relative_x
= Quick_input
.xlen
/ 2;
370 for (i
= 3; i
< 11; i
++)
371 if ((i
!= 4) && (i
!= 7))
372 quick_widgets
[i
].relative_x
= quick_widgets
[4].relative_x
+ 2;
375 quick_widgets
[2].relative_x
= (Quick_input
.xlen
- b_len
) / 2;
376 quick_widgets
[1].relative_x
= quick_widgets
[2].relative_x
+ b2_len
+ 1;
377 quick_widgets
[0].relative_x
= quick_widgets
[1].relative_x
+ b1_len
+ 1;
379 qd_result
= quick_dialog (&Quick_input
);
381 if ((qd_result
== B_ENTER
) || (qd_result
== B_EXIT
))
383 if (!panels_options
.fast_reload_msg_shown
&& panels_options
.fast_reload
)
385 message (D_NORMAL
, _("Information"),
386 _(" Using the fast reload option may not reflect the exact \n"
387 " directory contents. In this case you'll need to do a \n"
388 " manual reload of the directory. See the man page for \n"
390 panels_options
.fast_reload_msg_shown
= TRUE
;
392 update_panels (UP_RELOAD
, UP_KEEPSEL
);
395 if (qd_result
== B_EXIT
)
397 /* save panel options */
398 panels_save_options ();
399 mc_config_save_file (mc_main_config
, NULL
);