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"
36 #include "lib/strutil.h" /* str_term_width1() */
37 #include "lib/tty/key.h" /* old_esc_mode_timeout */
38 #include "lib/widget.h"
40 #include "src/setup.h" /* variables */
41 #include "src/history.h" /* MC_HISTORY_ESC_TIMEOUT */
42 #include "src/execute.h" /* pause_after_run */
44 #include "layout.h" /* nice_rotating_dash */
45 #include "panel.h" /* update_panels() */
49 /*** global variables ****************************************************************************/
51 /*** file scope macro definitions ****************************************************************/
53 /*** file scope type declarations ****************************************************************/
55 /*** file scope variables ************************************************************************/
57 /*** file scope functions ************************************************************************/
58 /* --------------------------------------------------------------------------------------------- */
61 configure_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
66 /* message from "Single press" checkbutton */
67 if (sender
!= NULL
&& sender
->id
== 17)
69 const gboolean not_single
= !(((WCheck
*) sender
)->state
& C_BOOL
);
73 w
= dlg_find_by_id (h
, sender
->id
- 1);
74 widget_disable (*w
, not_single
);
75 send_message (w
, WIDGET_DRAW
, 0);
77 w
= dlg_find_by_id (h
, sender
->id
- 2);
78 widget_disable (*w
, not_single
);
79 send_message (w
, WIDGET_DRAW
, 0);
83 return MSG_NOT_HANDLED
;
86 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
90 /* --------------------------------------------------------------------------------------------- */
91 /*** public functions ****************************************************************************/
92 /* --------------------------------------------------------------------------------------------- */
100 char time_out
[BUF_TINY
] = "";
103 const char *pause_options
[] = {
105 N_("On dum&b terminals"),
109 int pause_options_num
= G_N_ELEMENTS (pause_options
);
111 QuickWidget quick_widgets
[] = {
113 QUICK_BUTTON (38, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Cancel"), B_CANCEL
, NULL
),
114 QUICK_BUTTON (14, dlg_width
, dlg_height
- 3, dlg_height
, N_("&OK"), B_ENTER
, NULL
),
116 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 12, dlg_height
, N_("A&uto save setup"),
118 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 11, dlg_height
, N_("Sa&fe delete"),
120 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 10, dlg_height
, N_("Cd follows lin&ks"),
122 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 9, dlg_height
, N_("Rotating d&ash"),
123 &nice_rotating_dash
),
124 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 8, dlg_height
, N_("Co&mplete: show all"),
125 &show_all_if_ambiguous
),
126 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 7, dlg_height
, N_("Shell &patterns"),
128 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 6, dlg_height
, N_("&Drop down menus"),
130 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 5, dlg_height
, N_("Auto m&enus"), &auto_menu
),
131 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 4, dlg_height
, N_("Use internal vie&w"),
133 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 3, dlg_height
, N_("Use internal edi&t"),
135 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 15,
136 N_("Other options")),
138 QUICK_RADIO (5, dlg_width
, 13, dlg_height
, pause_options_num
, pause_options
,
140 QUICK_GROUPBOX (3, dlg_width
, 12, dlg_height
, dlg_width
/ 2 - 4, 5, N_("Pause after run")),
143 QUICK_INPUT (10, dlg_width
, 10, dlg_height
, (const char *) time_out
, 8, 0,
144 MC_HISTORY_ESC_TIMEOUT
, &time_out_new
),
145 QUICK_LABEL (5, dlg_width
, 10, dlg_height
, N_("Timeout:")),
146 QUICK_CHECKBOX (5, dlg_width
, 9, dlg_height
, N_("S&ingle press"), &old_esc_mode
),
147 QUICK_GROUPBOX (3, dlg_width
, 8, dlg_height
, dlg_width
/ 2 - 4, 4, N_("Esc key mode")),
149 /* file operation options */
150 QUICK_CHECKBOX (5, dlg_width
, 6, dlg_height
, N_("Mkdi&r autoname"), &auto_fill_mkdir_name
),
151 QUICK_CHECKBOX (5, dlg_width
, 5, dlg_height
, N_("Classic pro&gressbar"),
152 &classic_progressbar
),
153 QUICK_CHECKBOX (5, dlg_width
, 4, dlg_height
, N_("Compute tota&ls"),
154 &file_op_compute_totals
),
155 QUICK_CHECKBOX (5, dlg_width
, 3, dlg_height
, N_("&Verbose operation"), &verbose
),
156 QUICK_GROUPBOX (3, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 6,
157 N_("File operation options")),
161 const size_t qw_num
= G_N_ELEMENTS (quick_widgets
) - 1;
163 QuickDialog Quick_input
= {
164 dlg_width
, dlg_height
, -1, -1,
165 N_("Configure options"), "[Configuration]",
166 quick_widgets
, configure_callback
, TRUE
170 int b_len
, c_len
, g_len
, l_len
;
174 for (i
= 0; i
< qw_num
; i
++)
180 quick_widgets
[i
].u
.button
.text
= _(quick_widgets
[i
].u
.button
.text
);
187 quick_widgets
[i
].u
.groupbox
.title
= _(quick_widgets
[i
].u
.groupbox
.title
);
193 for (j
= 0; j
< (size_t) pause_options_num
; j
++)
194 pause_options
[j
] = _(pause_options
[j
]);
202 quick_widgets
[i
].u
.label
.text
= _(quick_widgets
[i
].u
.label
.text
);
206 quick_widgets
[i
].u
.checkbox
.text
= _(quick_widgets
[i
].u
.checkbox
.text
);
210 Quick_input
.title
= _(Quick_input
.title
);
211 #endif /* ENABLE_NLS */
213 /* calculate widget and dialog widths */
215 dlg_width
= max (dlg_width
, str_term_width1 (Quick_input
.title
) + 4);
217 b0_len
= str_term_width1 (quick_widgets
[0].u
.button
.text
) + 3;
218 b1_len
= str_term_width1 (quick_widgets
[1].u
.button
.text
) + 5;
219 b_len
= b0_len
+ b1_len
+ 1;
221 /* checkboxes within groupboxes */
223 for (i
= 2; i
< 23; i
++)
224 if ((i
< 12) || (i
== 17) || (i
> 18))
225 c_len
= max (c_len
, str_term_width1 (quick_widgets
[i
].u
.checkbox
.text
) + 3);
227 for (i
= 0; i
< (size_t) pause_options_num
; i
++)
228 c_len
= max (c_len
, str_term_width1 (pause_options
[i
]) + 3);
230 l_len
= str_term_width1 (quick_widgets
[16].u
.label
.text
);
231 c_len
= max (c_len
, l_len
+ 1 + 8);
233 g_len
= max (c_len
+ 2, str_term_width1 (quick_widgets
[23].u
.groupbox
.title
) + 4);
234 g_len
= max (g_len
, str_term_width1 (quick_widgets
[18].u
.groupbox
.title
) + 4);
235 g_len
= max (g_len
, str_term_width1 (quick_widgets
[14].u
.groupbox
.title
) + 4);
236 g_len
= max (g_len
, str_term_width1 (quick_widgets
[12].u
.groupbox
.title
) + 4);
238 Quick_input
.xlen
= max (dlg_width
, g_len
* 2 + 9);
239 Quick_input
.xlen
= max (Quick_input
.xlen
, b_len
+ 2);
240 if ((Quick_input
.xlen
& 1) != 0)
243 /* fix widget parameters */
244 for (i
= 0; i
< qw_num
; i
++)
245 quick_widgets
[i
].x_divisions
= Quick_input
.xlen
;
248 quick_widgets
[14].u
.groupbox
.width
=
249 quick_widgets
[18].u
.groupbox
.width
=
250 quick_widgets
[23].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 4;
251 quick_widgets
[12].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 3;
254 quick_widgets
[15].relative_x
= quick_widgets
[16].relative_x
+ l_len
+ 1;
255 quick_widgets
[15].u
.input
.len
= quick_widgets
[18].u
.groupbox
.width
- l_len
- 4;
258 quick_widgets
[12].relative_x
= Quick_input
.xlen
/ 2;
259 for (i
= 2; i
< 12; i
++)
260 quick_widgets
[i
].relative_x
= quick_widgets
[12].relative_x
+ 2;
263 quick_widgets
[1].relative_x
= (Quick_input
.xlen
- b_len
) / 3;
264 quick_widgets
[0].relative_x
= 2 * quick_widgets
[1].relative_x
+ b1_len
+ 1;
266 g_snprintf (time_out
, sizeof (time_out
), "%d", old_esc_mode_timeout
);
269 quick_widgets
[15].options
= quick_widgets
[16].options
= W_DISABLED
;
271 if (quick_dialog (&Quick_input
) == B_ENTER
)
272 old_esc_mode_timeout
= atoi (time_out_new
);
274 g_free (time_out_new
);
277 /* --------------------------------------------------------------------------------------------- */
280 panel_options_box (void)
285 int simple_swap
= mc_config_get_bool (mc_main_config
, CONFIG_PANELS_SECTION
,
286 "simple_swap", FALSE
) ? 1 : 0;
288 const char *qsearch_options
[] = {
289 N_("Case &insensitive"),
290 N_("Case s&ensitive"),
291 N_("Use panel sort mo&de")
294 QuickWidget quick_widgets
[] = {
296 QUICK_BUTTON (38, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Cancel"), B_CANCEL
, NULL
),
297 QUICK_BUTTON (14, dlg_width
, dlg_height
- 3, dlg_height
, N_("&OK"), B_ENTER
, NULL
),
299 QUICK_RADIO (dlg_width
/ 2 + 2, dlg_width
, 12, dlg_height
, QSEARCH_NUM
, qsearch_options
,
300 (int *) &panels_options
.qsearch_mode
),
301 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 11, dlg_height
, dlg_width
/ 2 - 4,
304 /* file highlighting */
305 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 9, dlg_height
, N_("&Permissions"),
306 &panels_options
.permission_mode
),
307 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 8, dlg_height
, N_("File &types"),
308 &panels_options
.filetype_mode
),
309 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 7, dlg_height
, dlg_width
/ 2 - 4, 4,
310 N_("File highlight")),
312 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 5, dlg_height
, N_("&Mouse page scrolling"),
313 &panels_options
.mouse_move_pages
),
314 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 4, dlg_height
, N_("Pa&ge scrolling"),
315 &panels_options
.scroll_pages
),
316 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 3, dlg_height
, N_("L&ynx-like motion"),
317 &panels_options
.navigate_with_arrows
),
318 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 5,
320 /* main panel options */
321 QUICK_CHECKBOX (5, dlg_width
, 11, dlg_height
, N_("A&uto save panels setup"),
322 &panels_options
.auto_save_setup
),
323 QUICK_CHECKBOX (5, dlg_width
, 10, dlg_height
, N_("Simple s&wap"),
325 QUICK_CHECKBOX (5, dlg_width
, 9, dlg_height
, N_("Re&verse files only"),
326 &panels_options
.reverse_files_only
),
327 QUICK_CHECKBOX (5, dlg_width
, 8, dlg_height
, N_("Ma&rk moves down"),
328 &panels_options
.mark_moves_down
),
329 QUICK_CHECKBOX (5, dlg_width
, 7, dlg_height
, N_("&Fast dir reload"),
330 &panels_options
.fast_reload
),
331 QUICK_CHECKBOX (5, dlg_width
, 6, dlg_height
, N_("Show &hidden files"),
332 &panels_options
.show_dot_files
),
333 QUICK_CHECKBOX (5, dlg_width
, 5, dlg_height
, N_("Show &backup files"),
334 &panels_options
.show_backups
),
335 QUICK_CHECKBOX (5, dlg_width
, 4, dlg_height
, N_("Mi&x all files"),
336 &panels_options
.mix_all_files
),
337 QUICK_CHECKBOX (5, dlg_width
, 3, dlg_height
, N_("Use SI si&ze units"),
338 &panels_options
.kilobyte_si
),
339 QUICK_GROUPBOX (3, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 14,
340 N_("Main panel options")),
344 const size_t qw_num
= G_N_ELEMENTS (quick_widgets
) - 1;
346 QuickDialog Quick_input
= {
347 dlg_width
, dlg_height
, -1, -1,
348 N_("Panel options"), "[Panel options]",
349 quick_widgets
, NULL
, TRUE
353 int b_len
, c_len
, g_len
;
357 for (i
= 0; i
< qw_num
; i
++)
363 quick_widgets
[i
].u
.button
.text
= _(quick_widgets
[i
].u
.button
.text
);
369 for (j
= 0; j
< QSEARCH_NUM
; j
++)
370 qsearch_options
[j
] = _(qsearch_options
[j
]);
378 quick_widgets
[i
].u
.groupbox
.title
= _(quick_widgets
[i
].u
.groupbox
.title
);
382 quick_widgets
[i
].u
.checkbox
.text
= _(quick_widgets
[i
].u
.checkbox
.text
);
386 Quick_input
.title
= _(Quick_input
.title
);
387 #endif /* ENABLE_NLS */
389 /* calculate widget and dialog widths */
391 dlg_width
= max (dlg_width
, str_term_width1 (Quick_input
.title
) + 4);
393 b0_len
= str_term_width1 (quick_widgets
[0].u
.button
.text
) + 3;
394 b1_len
= str_term_width1 (quick_widgets
[1].u
.button
.text
) + 5;
395 b_len
= b0_len
+ b1_len
+ 1;
397 /* checkboxes within groupboxes */
399 for (i
= 4; i
< 20; i
++)
400 if ((i
!= 6) && (i
!= 10))
401 c_len
= max (c_len
, str_term_width1 (quick_widgets
[i
].u
.checkbox
.text
) + 4);
404 for (i
= 0; i
< QSEARCH_NUM
; i
++)
405 c_len
= max (c_len
, str_term_width1 (qsearch_options
[i
]) + 3);
407 g_len
= max (c_len
+ 2, str_term_width1 (quick_widgets
[3].u
.groupbox
.title
) + 4);
408 g_len
= max (g_len
, str_term_width1 (quick_widgets
[6].u
.groupbox
.title
) + 4);
409 g_len
= max (g_len
, str_term_width1 (quick_widgets
[10].u
.groupbox
.title
) + 4);
410 g_len
= max (g_len
, str_term_width1 (quick_widgets
[20].u
.groupbox
.title
) + 4);
412 Quick_input
.xlen
= max (dlg_width
, g_len
* 2 + 9);
413 Quick_input
.xlen
= max (Quick_input
.xlen
, b_len
+ 2);
414 if ((Quick_input
.xlen
& 1) != 0)
417 /* fix widget parameters */
418 for (i
= 0; i
< qw_num
; i
++)
419 quick_widgets
[i
].x_divisions
= Quick_input
.xlen
;
422 quick_widgets
[3].u
.groupbox
.width
=
423 quick_widgets
[6].u
.groupbox
.width
=
424 quick_widgets
[10].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 3;
425 quick_widgets
[20].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 4;
428 quick_widgets
[3].relative_x
=
429 quick_widgets
[6].relative_x
= quick_widgets
[10].relative_x
= Quick_input
.xlen
/ 2;
430 for (i
= 2; i
< 10; i
++)
431 if ((i
!= 3) && (i
!= 6))
432 quick_widgets
[i
].relative_x
= quick_widgets
[3].relative_x
+ 2;
435 quick_widgets
[1].relative_x
= (Quick_input
.xlen
- b_len
) / 3;
436 quick_widgets
[0].relative_x
= 2 * quick_widgets
[1].relative_x
+ b1_len
+ 1;
438 if (quick_dialog (&Quick_input
) != B_ENTER
)
441 mc_config_set_bool (mc_main_config
, CONFIG_PANELS_SECTION
,
442 "simple_swap", (gboolean
) (simple_swap
& C_BOOL
));
444 if (!panels_options
.fast_reload_msg_shown
&& panels_options
.fast_reload
)
446 message (D_NORMAL
, _("Information"),
447 _("Using the fast reload option may not reflect the exact\n"
448 "directory contents. In this case you'll need to do a\n"
449 "manual reload of the directory. See the man page for\n" "the details."));
450 panels_options
.fast_reload_msg_shown
= TRUE
;
453 update_panels (UP_RELOAD
, UP_KEEPSEL
);
456 /* --------------------------------------------------------------------------------------------- */