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 (26, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Save"), B_EXIT
, NULL
),
298 QUICK_BUTTON (14, dlg_width
, dlg_height
- 3, dlg_height
, N_("&OK"), B_ENTER
, NULL
),
300 QUICK_RADIO (dlg_width
/ 2 + 2, dlg_width
, 12, dlg_height
, QSEARCH_NUM
, qsearch_options
,
301 (int *) &panels_options
.qsearch_mode
),
302 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 11, dlg_height
, dlg_width
/ 2 - 4,
305 /* file highlighting */
306 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 9, dlg_height
, N_("&Permissions"),
307 &panels_options
.permission_mode
),
308 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 8, dlg_height
, N_("File &types"),
309 &panels_options
.filetype_mode
),
310 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 7, dlg_height
, dlg_width
/ 2 - 4, 4,
311 N_("File highlight")),
313 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 5, dlg_height
, N_("&Mouse page scrolling"),
314 &panels_options
.mouse_move_pages
),
315 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 4, dlg_height
, N_("Pa&ge scrolling"),
316 &panels_options
.scroll_pages
),
317 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 3, dlg_height
, N_("L&ynx-like motion"),
318 &panels_options
.navigate_with_arrows
),
319 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 5,
321 /* main panel options */
322 QUICK_CHECKBOX (5, dlg_width
, 11, dlg_height
, N_("A&uto save panels setup"),
323 &panels_options
.auto_save_setup
),
324 QUICK_CHECKBOX (5, dlg_width
, 10, dlg_height
, N_("Simple s&wap"),
326 QUICK_CHECKBOX (5, dlg_width
, 9, dlg_height
, N_("Re&verse files only"),
327 &panels_options
.reverse_files_only
),
328 QUICK_CHECKBOX (5, dlg_width
, 8, dlg_height
, N_("Ma&rk moves down"),
329 &panels_options
.mark_moves_down
),
330 QUICK_CHECKBOX (5, dlg_width
, 7, dlg_height
, N_("&Fast dir reload"),
331 &panels_options
.fast_reload
),
332 QUICK_CHECKBOX (5, dlg_width
, 6, dlg_height
, N_("Show &hidden files"),
333 &panels_options
.show_dot_files
),
334 QUICK_CHECKBOX (5, dlg_width
, 5, dlg_height
, N_("Show &backup files"),
335 &panels_options
.show_backups
),
336 QUICK_CHECKBOX (5, dlg_width
, 4, dlg_height
, N_("Mi&x all files"),
337 &panels_options
.mix_all_files
),
338 QUICK_CHECKBOX (5, dlg_width
, 3, dlg_height
, N_("Use SI si&ze units"),
339 &panels_options
.kilobyte_si
),
340 QUICK_GROUPBOX (3, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 14,
341 N_("Main panel options")),
345 const size_t qw_num
= G_N_ELEMENTS (quick_widgets
) - 1;
347 QuickDialog Quick_input
= {
348 dlg_width
, dlg_height
, -1, -1,
349 N_("Panel options"), "[Panel options]",
350 quick_widgets
, NULL
, TRUE
355 int b0_len
, b1_len
, b2_len
;
356 int b_len
, c_len
, g_len
;
361 for (i
= 0; i
< qw_num
; i
++)
364 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
]);
372 else if ((i
== 4) || (i
== 7) || (i
== 11) || (i
== 21))
374 quick_widgets
[i
].u
.groupbox
.title
= _(quick_widgets
[i
].u
.groupbox
.title
);
377 quick_widgets
[i
].u
.checkbox
.text
= _(quick_widgets
[i
].u
.checkbox
.text
);
379 Quick_input
.title
= _(Quick_input
.title
);
381 #endif /* ENABLE_NLS */
383 /* calculate widget and dialog widths */
385 dlg_width
= max (dlg_width
, str_term_width1 (Quick_input
.title
) + 4);
387 b0_len
= str_term_width1 (quick_widgets
[0].u
.button
.text
) + 3;
388 b1_len
= str_term_width1 (quick_widgets
[1].u
.button
.text
) + 3;
389 b2_len
= str_term_width1 (quick_widgets
[2].u
.button
.text
) + 5;
390 b_len
= b0_len
+ b1_len
+ b2_len
+ 2;
392 /* checkboxes within groupboxes */
394 for (i
= 5; i
< 21; i
++)
395 if ((i
!= 7) && (i
!= 11))
396 c_len
= max (c_len
, str_term_width1 (quick_widgets
[i
].u
.checkbox
.text
) + 4);
399 for (i
= 0; i
< QSEARCH_NUM
; i
++)
400 c_len
= max (c_len
, str_term_width1 (qsearch_options
[i
]) + 3);
402 g_len
= max (c_len
+ 2, str_term_width1 (quick_widgets
[4].u
.groupbox
.title
) + 4);
403 g_len
= max (g_len
, str_term_width1 (quick_widgets
[7].u
.groupbox
.title
) + 4);
404 g_len
= max (g_len
, str_term_width1 (quick_widgets
[11].u
.groupbox
.title
) + 4);
405 g_len
= max (g_len
, str_term_width1 (quick_widgets
[21].u
.groupbox
.title
) + 4);
407 Quick_input
.xlen
= max (dlg_width
, g_len
* 2 + 9);
408 Quick_input
.xlen
= max (Quick_input
.xlen
, b_len
+ 2);
409 if ((Quick_input
.xlen
& 1) != 0)
412 /* fix widget parameters */
413 for (i
= 0; i
< qw_num
; i
++)
414 quick_widgets
[i
].x_divisions
= Quick_input
.xlen
;
417 quick_widgets
[4].u
.groupbox
.width
=
418 quick_widgets
[7].u
.groupbox
.width
=
419 quick_widgets
[11].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 3;
420 quick_widgets
[21].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 4;
423 quick_widgets
[4].relative_x
=
424 quick_widgets
[7].relative_x
= quick_widgets
[11].relative_x
= Quick_input
.xlen
/ 2;
425 for (i
= 3; i
< 11; i
++)
426 if ((i
!= 4) && (i
!= 7))
427 quick_widgets
[i
].relative_x
= quick_widgets
[4].relative_x
+ 2;
430 quick_widgets
[2].relative_x
= (Quick_input
.xlen
- b_len
) / 2;
431 quick_widgets
[1].relative_x
= quick_widgets
[2].relative_x
+ b2_len
+ 1;
432 quick_widgets
[0].relative_x
= quick_widgets
[1].relative_x
+ b1_len
+ 1;
434 qd_result
= quick_dialog (&Quick_input
);
436 if ((qd_result
== B_ENTER
) || (qd_result
== B_EXIT
))
438 mc_config_set_bool (mc_main_config
, CONFIG_PANELS_SECTION
,
439 "simple_swap", (gboolean
) (simple_swap
& C_BOOL
));
441 if (!panels_options
.fast_reload_msg_shown
&& panels_options
.fast_reload
)
443 message (D_NORMAL
, _("Information"),
444 _("Using the fast reload option may not reflect the exact\n"
445 "directory contents. In this case you'll need to do a\n"
446 "manual reload of the directory. See the man page for\n" "the details."));
447 panels_options
.fast_reload_msg_shown
= TRUE
;
449 update_panels (UP_RELOAD
, UP_KEEPSEL
);
452 if (qd_result
== B_EXIT
)
454 /* save panel options */
455 panels_save_options ();
456 mc_config_save_file (mc_main_config
, NULL
);
460 /* --------------------------------------------------------------------------------------------- */