2 Configure box module for the Midnight Commander
4 Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
6 The Free Software Foundation, Inc.
8 This file is part of the Midnight Commander.
10 The Midnight Commander is free software: you can redistribute it
11 and/or modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation, either version 3 of the License,
13 or (at your option) any later version.
15 The Midnight Commander is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * \brief Source: configure boxes module
30 #include <stdlib.h> /* atoi() */
32 #include <sys/types.h>
35 #include "lib/global.h"
36 #include "lib/mcconfig.h"
37 #include "lib/strutil.h" /* str_term_width1() */
38 #include "lib/tty/key.h" /* old_esc_mode_timeout */
39 #include "lib/widget.h"
41 #include "src/setup.h" /* variables */
42 #include "src/history.h" /* MC_HISTORY_ESC_TIMEOUT */
43 #include "src/execute.h" /* pause_after_run */
45 #include "layout.h" /* nice_rotating_dash */
46 #include "panel.h" /* update_panels() */
50 /*** global variables ****************************************************************************/
52 /*** file scope macro definitions ****************************************************************/
54 /*** file scope type declarations ****************************************************************/
56 /*** file scope variables ************************************************************************/
58 /*** file scope functions ************************************************************************/
59 /* --------------------------------------------------------------------------------------------- */
61 /* don't use max() macro to avoid double call of str_term_width1() in widget width calculation */
70 /* --------------------------------------------------------------------------------------------- */
73 configure_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
78 /* message from "Single press" checkbutton */
79 if (sender
!= NULL
&& sender
->id
== 17)
81 const gboolean not_single
= !(((WCheck
*) sender
)->state
& C_BOOL
);
85 w
= dlg_find_by_id (h
, sender
->id
- 1);
86 widget_disable (*w
, not_single
);
87 send_message (w
, WIDGET_DRAW
, 0);
89 w
= dlg_find_by_id (h
, sender
->id
- 2);
90 widget_disable (*w
, not_single
);
91 send_message (w
, WIDGET_DRAW
, 0);
95 return MSG_NOT_HANDLED
;
98 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
102 /* --------------------------------------------------------------------------------------------- */
103 /*** public functions ****************************************************************************/
104 /* --------------------------------------------------------------------------------------------- */
112 char time_out
[BUF_TINY
] = "";
115 const char *pause_options
[] = {
117 N_("On dum&b terminals"),
121 int pause_options_num
= G_N_ELEMENTS (pause_options
);
123 QuickWidget quick_widgets
[] = {
125 QUICK_BUTTON (38, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Cancel"), B_CANCEL
, NULL
),
126 QUICK_BUTTON (14, dlg_width
, dlg_height
- 3, dlg_height
, N_("&OK"), B_ENTER
, NULL
),
128 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 12, dlg_height
, N_("A&uto save setup"),
130 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 11, dlg_height
, N_("Sa&fe delete"),
132 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 10, dlg_height
, N_("Cd follows lin&ks"),
133 &mc_global
.vfs
.cd_symlinks
),
134 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 9, dlg_height
, N_("Rotating d&ash"),
135 &nice_rotating_dash
),
136 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 8, dlg_height
, N_("Co&mplete: show all"),
137 &mc_global
.widget
.show_all_if_ambiguous
),
138 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 7, dlg_height
, N_("Shell &patterns"),
140 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 6, dlg_height
, N_("&Drop down menus"),
142 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 5, dlg_height
, N_("Auto m&enus"), &auto_menu
),
143 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 4, dlg_height
, N_("Use internal vie&w"),
145 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 3, dlg_height
, N_("Use internal edi&t"),
147 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 16,
148 N_("Other options")),
150 QUICK_RADIO (5, dlg_width
, 14, dlg_height
, pause_options_num
, pause_options
,
152 QUICK_GROUPBOX (3, dlg_width
, 13, dlg_height
, dlg_width
/ 2 - 4, 5, N_("Pause after run")),
155 QUICK_INPUT (10, dlg_width
, 11, dlg_height
, (const char *) time_out
, 8, 0,
156 MC_HISTORY_ESC_TIMEOUT
, &time_out_new
),
157 QUICK_LABEL (5, dlg_width
, 11, dlg_height
, N_("Timeout:")),
158 QUICK_CHECKBOX (5, dlg_width
, 10, dlg_height
, N_("S&ingle press"), &old_esc_mode
),
159 QUICK_GROUPBOX (3, dlg_width
, 9, dlg_height
, dlg_width
/ 2 - 4, 4, N_("Esc key mode")),
161 /* file operation options */
162 QUICK_CHECKBOX (5, dlg_width
, 7, dlg_height
, N_("Preallocate &space"),
163 &mc_global
.vfs
.preallocate_space
),
164 QUICK_CHECKBOX (5, dlg_width
, 6, dlg_height
, N_("Mkdi&r autoname"), &auto_fill_mkdir_name
),
165 QUICK_CHECKBOX (5, dlg_width
, 5, dlg_height
, N_("Classic pro&gressbar"),
166 &classic_progressbar
),
167 QUICK_CHECKBOX (5, dlg_width
, 4, dlg_height
, N_("Compute tota&ls"),
168 &file_op_compute_totals
),
169 QUICK_CHECKBOX (5, dlg_width
, 3, dlg_height
, N_("&Verbose operation"), &verbose
),
170 QUICK_GROUPBOX (3, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 7,
171 N_("File operation options")),
175 const size_t qw_num
= G_N_ELEMENTS (quick_widgets
) - 1;
177 QuickDialog Quick_input
= {
178 dlg_width
, dlg_height
, -1, -1,
179 N_("Configure options"), "[Configuration]",
180 quick_widgets
, configure_callback
, TRUE
184 int b_len
, c_len
, g_len
, l_len
;
188 for (i
= 0; i
< qw_num
; i
++)
194 quick_widgets
[i
].u
.button
.text
= _(quick_widgets
[i
].u
.button
.text
);
201 quick_widgets
[i
].u
.groupbox
.title
= _(quick_widgets
[i
].u
.groupbox
.title
);
207 for (j
= 0; j
< (size_t) pause_options_num
; j
++)
208 pause_options
[j
] = _(pause_options
[j
]);
216 quick_widgets
[i
].u
.label
.text
= _(quick_widgets
[i
].u
.label
.text
);
220 quick_widgets
[i
].u
.checkbox
.text
= _(quick_widgets
[i
].u
.checkbox
.text
);
224 Quick_input
.title
= _(Quick_input
.title
);
225 #endif /* ENABLE_NLS */
227 /* calculate widget and dialog widths */
229 dlg_width
= max (dlg_width
, str_term_width1 (Quick_input
.title
) + 4);
231 b0_len
= str_term_width1 (quick_widgets
[0].u
.button
.text
) + 3;
232 b1_len
= str_term_width1 (quick_widgets
[1].u
.button
.text
) + 5;
233 b_len
= b0_len
+ b1_len
+ 1;
235 /* checkboxes within groupboxes */
237 for (i
= 2; i
< 24; i
++)
238 if ((i
< 12) || (i
== 17) || (i
> 18))
239 c_len
= max (c_len
, str_term_width1 (quick_widgets
[i
].u
.checkbox
.text
) + 3);
241 for (i
= 0; i
< (size_t) pause_options_num
; i
++)
242 c_len
= max (c_len
, str_term_width1 (pause_options
[i
]) + 3);
244 l_len
= str_term_width1 (quick_widgets
[16].u
.label
.text
);
245 c_len
= max (c_len
, l_len
+ 1 + 8);
247 g_len
= max (c_len
+ 2, str_term_width1 (quick_widgets
[24].u
.groupbox
.title
) + 4);
248 g_len
= max (g_len
, str_term_width1 (quick_widgets
[18].u
.groupbox
.title
) + 4);
249 g_len
= max (g_len
, str_term_width1 (quick_widgets
[14].u
.groupbox
.title
) + 4);
250 g_len
= max (g_len
, str_term_width1 (quick_widgets
[12].u
.groupbox
.title
) + 4);
252 Quick_input
.xlen
= max (dlg_width
, g_len
* 2 + 9);
253 Quick_input
.xlen
= max (Quick_input
.xlen
, b_len
+ 2);
254 if ((Quick_input
.xlen
& 1) != 0)
257 /* fix widget parameters */
258 for (i
= 0; i
< qw_num
; i
++)
259 quick_widgets
[i
].x_divisions
= Quick_input
.xlen
;
262 quick_widgets
[14].u
.groupbox
.width
=
263 quick_widgets
[18].u
.groupbox
.width
=
264 quick_widgets
[24].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 4;
265 quick_widgets
[12].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 3;
268 quick_widgets
[15].relative_x
= quick_widgets
[16].relative_x
+ l_len
+ 1;
269 quick_widgets
[15].u
.input
.len
= quick_widgets
[18].u
.groupbox
.width
- l_len
- 4;
272 quick_widgets
[12].relative_x
= Quick_input
.xlen
/ 2;
273 for (i
= 2; i
< 12; i
++)
274 quick_widgets
[i
].relative_x
= quick_widgets
[12].relative_x
+ 2;
277 quick_widgets
[1].relative_x
= (Quick_input
.xlen
- b_len
) / 3;
278 quick_widgets
[0].relative_x
= 2 * quick_widgets
[1].relative_x
+ b1_len
+ 1;
280 g_snprintf (time_out
, sizeof (time_out
), "%d", old_esc_mode_timeout
);
283 quick_widgets
[15].options
= quick_widgets
[16].options
= W_DISABLED
;
285 #ifndef HAVE_POSIX_FALLOCATE
286 mc_global
.vfs
.preallocate_space
= FALSE
;
287 quick_widgets
[19].options
= W_DISABLED
;
290 if (quick_dialog (&Quick_input
) == B_ENTER
)
291 old_esc_mode_timeout
= atoi (time_out_new
);
293 g_free (time_out_new
);
296 /* --------------------------------------------------------------------------------------------- */
299 panel_options_box (void)
304 int simple_swap
= mc_config_get_bool (mc_main_config
, CONFIG_PANELS_SECTION
,
305 "simple_swap", FALSE
) ? 1 : 0;
307 const char *qsearch_options
[] = {
308 N_("Case &insensitive"),
309 N_("Case s&ensitive"),
310 N_("Use panel sort mo&de")
313 QuickWidget quick_widgets
[] = {
315 QUICK_BUTTON (38, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Cancel"), B_CANCEL
, NULL
),
316 QUICK_BUTTON (14, dlg_width
, dlg_height
- 3, dlg_height
, N_("&OK"), B_ENTER
, NULL
),
318 QUICK_RADIO (dlg_width
/ 2 + 2, dlg_width
, 12, dlg_height
, QSEARCH_NUM
, qsearch_options
,
319 (int *) &panels_options
.qsearch_mode
),
320 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 11, dlg_height
, dlg_width
/ 2 - 4,
323 /* file highlighting */
324 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 9, dlg_height
, N_("&Permissions"),
325 &panels_options
.permission_mode
),
326 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 8, dlg_height
, N_("File &types"),
327 &panels_options
.filetype_mode
),
328 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 7, dlg_height
, dlg_width
/ 2 - 4, 4,
329 N_("File highlight")),
331 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 5, dlg_height
, N_("&Mouse page scrolling"),
332 &panels_options
.mouse_move_pages
),
333 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 4, dlg_height
, N_("Pa&ge scrolling"),
334 &panels_options
.scroll_pages
),
335 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 3, dlg_height
, N_("L&ynx-like motion"),
336 &panels_options
.navigate_with_arrows
),
337 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 5,
339 /* main panel options */
340 QUICK_CHECKBOX (5, dlg_width
, 12, dlg_height
, N_("A&uto save panels setup"),
341 &panels_options
.auto_save_setup
),
342 QUICK_CHECKBOX (5, dlg_width
, 11, dlg_height
, N_("Simple s&wap"),
344 QUICK_CHECKBOX (5, dlg_width
, 10, dlg_height
, N_("Re&verse files only"),
345 &panels_options
.reverse_files_only
),
346 QUICK_CHECKBOX (5, dlg_width
, 9, dlg_height
, N_("Ma&rk moves down"),
347 &panels_options
.mark_moves_down
),
348 QUICK_CHECKBOX (5, dlg_width
, 8, dlg_height
, N_("&Fast dir reload"),
349 &panels_options
.fast_reload
),
350 QUICK_CHECKBOX (5, dlg_width
, 7, dlg_height
, N_("Show &hidden files"),
351 &panels_options
.show_dot_files
),
352 QUICK_CHECKBOX (5, dlg_width
, 6, dlg_height
, N_("Show &backup files"),
353 &panels_options
.show_backups
),
354 QUICK_CHECKBOX (5, dlg_width
, 5, dlg_height
, N_("Mi&x all files"),
355 &panels_options
.mix_all_files
),
356 QUICK_CHECKBOX (5, dlg_width
, 4, dlg_height
, N_("Use SI si&ze units"),
357 &panels_options
.kilobyte_si
),
358 QUICK_CHECKBOX (5, dlg_width
, 3, dlg_height
, N_("Show mi&ni-status"),
359 &panels_options
.show_mini_info
),
360 QUICK_GROUPBOX (3, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 14,
365 const size_t qw_num
= G_N_ELEMENTS (quick_widgets
) - 1;
367 QuickDialog Quick_input
= {
368 dlg_width
, dlg_height
, -1, -1,
369 N_("Panel options"), "[Panel options]",
370 quick_widgets
, NULL
, TRUE
374 int b_len
, c_len
, g_len
;
378 for (i
= 0; i
< qw_num
; i
++)
384 quick_widgets
[i
].u
.button
.text
= _(quick_widgets
[i
].u
.button
.text
);
390 for (j
= 0; j
< QSEARCH_NUM
; j
++)
391 qsearch_options
[j
] = _(qsearch_options
[j
]);
399 quick_widgets
[i
].u
.groupbox
.title
= _(quick_widgets
[i
].u
.groupbox
.title
);
403 quick_widgets
[i
].u
.checkbox
.text
= _(quick_widgets
[i
].u
.checkbox
.text
);
407 Quick_input
.title
= _(Quick_input
.title
);
408 #endif /* ENABLE_NLS */
410 /* calculate widget and dialog widths */
412 dlg_width
= max (dlg_width
, str_term_width1 (Quick_input
.title
) + 4);
414 b0_len
= str_term_width1 (quick_widgets
[0].u
.button
.text
) + 3;
415 b1_len
= str_term_width1 (quick_widgets
[1].u
.button
.text
) + 5;
416 b_len
= b0_len
+ b1_len
+ 1;
418 /* checkboxes within groupboxes */
420 for (i
= 4; i
< 21; i
++)
421 if ((i
!= 6) && (i
!= 10))
422 c_len
= max (c_len
, str_term_width1 (quick_widgets
[i
].u
.checkbox
.text
) + 4);
425 for (i
= 0; i
< QSEARCH_NUM
; i
++)
426 c_len
= max (c_len
, str_term_width1 (qsearch_options
[i
]) + 3);
428 g_len
= max (c_len
+ 2, str_term_width1 (quick_widgets
[3].u
.groupbox
.title
) + 4);
429 g_len
= max (g_len
, str_term_width1 (quick_widgets
[6].u
.groupbox
.title
) + 4);
430 g_len
= max (g_len
, str_term_width1 (quick_widgets
[10].u
.groupbox
.title
) + 4);
431 g_len
= max (g_len
, str_term_width1 (quick_widgets
[21].u
.groupbox
.title
) + 4);
433 Quick_input
.xlen
= max (dlg_width
, g_len
* 2 + 9);
434 Quick_input
.xlen
= max (Quick_input
.xlen
, b_len
+ 2);
435 if ((Quick_input
.xlen
& 1) != 0)
438 /* fix widget parameters */
439 for (i
= 0; i
< qw_num
; i
++)
440 quick_widgets
[i
].x_divisions
= Quick_input
.xlen
;
443 quick_widgets
[3].u
.groupbox
.width
=
444 quick_widgets
[6].u
.groupbox
.width
=
445 quick_widgets
[10].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 3;
446 quick_widgets
[21].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 4;
449 quick_widgets
[3].relative_x
=
450 quick_widgets
[6].relative_x
= quick_widgets
[10].relative_x
= Quick_input
.xlen
/ 2;
451 for (i
= 2; i
< 10; i
++)
452 if ((i
!= 3) && (i
!= 6))
453 quick_widgets
[i
].relative_x
= quick_widgets
[3].relative_x
+ 2;
456 quick_widgets
[1].relative_x
= (Quick_input
.xlen
- b_len
) / 3;
457 quick_widgets
[0].relative_x
= 2 * quick_widgets
[1].relative_x
+ b1_len
+ 1;
459 if (quick_dialog (&Quick_input
) != B_ENTER
)
462 mc_config_set_bool (mc_main_config
, CONFIG_PANELS_SECTION
,
463 "simple_swap", (gboolean
) (simple_swap
& C_BOOL
));
465 if (!panels_options
.fast_reload_msg_shown
&& panels_options
.fast_reload
)
467 message (D_NORMAL
, _("Information"),
468 _("Using the fast reload option may not reflect the exact\n"
469 "directory contents. In this case you'll need to do a\n"
470 "manual reload of the directory. See the man page for\n" "the details."));
471 panels_options
.fast_reload_msg_shown
= TRUE
;
474 update_panels (UP_RELOAD
, UP_KEEPSEL
);
477 /* --------------------------------------------------------------------------------------------- */