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 "widget.h" /* WCheck */
41 #include "setup.h" /* panels_options */
43 #include "file.h" /* file_op_compute_totals */
44 #include "layout.h" /* nice_rotating_dash */
45 #include "wtools.h" /* QuickDialog */
46 #include "history.h" /* MC_HISTORY_ESC_TIMEOUT */
51 configure_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
58 /* message from "Single press" checkbutton */
59 const gboolean not_single
= !(((WCheck
*) sender
)->state
& C_BOOL
);
63 w
= dlg_find_by_id (h
, sender
->id
- 1);
64 widget_disable (*w
, not_single
);
65 send_message (w
, WIDGET_DRAW
, 0);
67 w
= dlg_find_by_id (h
, sender
->id
- 2);
68 widget_disable (*w
, not_single
);
69 send_message (w
, WIDGET_DRAW
, 0);
73 return MSG_NOT_HANDLED
;
76 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
86 char time_out
[BUF_TINY
] = "";
89 const char *pause_options
[] = {
91 N_("On dum&b terminals"),
95 int pause_options_num
= sizeof (pause_options
) / sizeof (pause_options
[0]);
97 QuickWidget quick_widgets
[] = {
99 QUICK_BUTTON (38, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Cancel"), B_CANCEL
, NULL
),
100 QUICK_BUTTON (26, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Save"), B_EXIT
, NULL
),
101 QUICK_BUTTON (14, dlg_width
, dlg_height
- 3, dlg_height
, N_("&OK"), B_ENTER
, NULL
),
103 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 12, dlg_height
, N_("A&uto save setup"),
105 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 11, dlg_height
, N_("Sa&fe delete"),
107 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 10, dlg_height
, N_("Cd follows lin&ks"),
109 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 9, dlg_height
, N_("Rotating d&ash"),
110 &nice_rotating_dash
),
111 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 8, dlg_height
, N_("Co&mplete: show all"),
112 &show_all_if_ambiguous
),
113 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 7, dlg_height
, N_("Shell &patterns"),
115 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 6, dlg_height
, N_("&Drop down menus"),
117 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 5, dlg_height
, N_("Auto m&enus"), &auto_menu
),
118 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 4, dlg_height
, N_("Use internal vie&w"),
120 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 3, dlg_height
, N_("Use internal edi&t"),
122 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 15,
123 N_("Other options")),
125 QUICK_RADIO (5, dlg_width
, 13, dlg_height
, pause_options_num
, pause_options
,
127 QUICK_GROUPBOX (3, dlg_width
, 12, dlg_height
, dlg_width
/ 2 - 4, 5, N_("Pause after run")),
130 QUICK_INPUT (10, dlg_width
, 10, dlg_height
, (const char *) time_out
, 8, 0,
131 MC_HISTORY_ESC_TIMEOUT
, &time_out_new
),
132 QUICK_LABEL (5, dlg_width
, 10, dlg_height
, N_("Timeout:")),
133 QUICK_CHECKBOX (5, dlg_width
, 9, dlg_height
, N_("S&ingle press"), &old_esc_mode
),
134 QUICK_GROUPBOX (3, dlg_width
, 8, dlg_height
, dlg_width
/ 2 - 4, 4, N_("Esc key mode")),
136 /* file operation options */
137 QUICK_CHECKBOX (5, dlg_width
, 6, dlg_height
, N_("Mkdi&r autoname"), &auto_fill_mkdir_name
),
138 QUICK_CHECKBOX (5, dlg_width
, 5, dlg_height
, N_("Classic pro&gressbar"), &classic_progressbar
),
139 QUICK_CHECKBOX (5, dlg_width
, 4, dlg_height
, N_("Compute tota&ls"),
140 &file_op_compute_totals
),
141 QUICK_CHECKBOX (5, dlg_width
, 3, dlg_height
, N_("&Verbose operation"), &verbose
),
142 QUICK_GROUPBOX (3, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 6,
143 N_("File operation options")),
147 const size_t qw_num
= sizeof (quick_widgets
) / sizeof (quick_widgets
[0]) - 1;
149 QuickDialog Quick_input
= {
150 dlg_width
, dlg_height
, -1, -1,
151 N_("Configure options"), "[Configuration]",
152 quick_widgets
, configure_callback
, TRUE
157 int b0_len
, b1_len
, b2_len
;
158 int b_len
, c_len
, g_len
, l_len
;
163 for (i
= 0; i
< qw_num
; i
++)
166 quick_widgets
[i
].u
.button
.text
= _(quick_widgets
[i
].u
.button
.text
);
167 else if ((i
== 13) || (i
== 15) || (i
== 19) || (i
== 24))
169 quick_widgets
[i
].u
.groupbox
.title
= _(quick_widgets
[i
].u
.groupbox
.title
);
174 for (j
= 0; j
< (size_t) pause_options_num
; j
++)
175 pause_options
[j
] = _(pause_options
[j
]);
179 quick_widgets
[i
].u
.label
.text
= _(quick_widgets
[i
].u
.label
.text
);
182 quick_widgets
[i
].u
.checkbox
.text
= _(quick_widgets
[i
].u
.checkbox
.text
);
184 Quick_input
.title
= _(Quick_input
.title
);
186 #endif /* ENABLE_NLS */
188 /* calculate widget and dialog widths */
190 dlg_width
= max (dlg_width
, str_term_width1 (Quick_input
.title
) + 4);
192 b0_len
= str_term_width1 (quick_widgets
[0].u
.button
.text
) + 3;
193 b1_len
= str_term_width1 (quick_widgets
[1].u
.button
.text
) + 3;
194 b2_len
= str_term_width1 (quick_widgets
[2].u
.button
.text
) + 5;
195 b_len
= b0_len
+ b1_len
+ b2_len
+ 2;
197 /* checkboxes within groupboxes */
199 for (i
= 3; i
< 24; i
++)
200 if ((i
< 13) || (i
== 18) || (i
> 19))
201 c_len
= max (c_len
, str_term_width1 (quick_widgets
[i
].u
.checkbox
.text
) + 3);
203 for (i
= 0; i
< (size_t) pause_options_num
; i
++)
204 c_len
= max (c_len
, str_term_width1 (pause_options
[i
]) + 3);
206 l_len
= str_term_width1 (quick_widgets
[17].u
.label
.text
);
207 c_len
= max (c_len
, l_len
+ 1 + 8);
209 g_len
= max (c_len
+ 2, str_term_width1 (quick_widgets
[24].u
.groupbox
.title
) + 4);
210 g_len
= max (g_len
, str_term_width1 (quick_widgets
[19].u
.groupbox
.title
) + 4);
211 g_len
= max (g_len
, str_term_width1 (quick_widgets
[15].u
.groupbox
.title
) + 4);
212 g_len
= max (g_len
, str_term_width1 (quick_widgets
[13].u
.groupbox
.title
) + 4);
214 Quick_input
.xlen
= max (dlg_width
, g_len
* 2 + 9);
215 Quick_input
.xlen
= max (Quick_input
.xlen
, b_len
+ 2);
216 if ((Quick_input
.xlen
& 1) != 0)
219 /* fix widget parameters */
220 for (i
= 0; i
< qw_num
; i
++)
221 quick_widgets
[i
].x_divisions
= Quick_input
.xlen
;
224 quick_widgets
[15].u
.groupbox
.width
=
225 quick_widgets
[19].u
.groupbox
.width
=
226 quick_widgets
[24].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 4;
227 quick_widgets
[13].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 3;
230 quick_widgets
[16].relative_x
= quick_widgets
[17].relative_x
+ l_len
+ 1;
231 quick_widgets
[16].u
.input
.len
= quick_widgets
[19].u
.groupbox
.width
- l_len
- 4;
234 quick_widgets
[13].relative_x
= Quick_input
.xlen
/ 2;
235 for (i
= 3; i
< 13; i
++)
236 quick_widgets
[i
].relative_x
= quick_widgets
[13].relative_x
+ 2;
239 quick_widgets
[2].relative_x
= (Quick_input
.xlen
- b_len
) / 2;
240 quick_widgets
[1].relative_x
= quick_widgets
[2].relative_x
+ b2_len
+ 1;
241 quick_widgets
[0].relative_x
= quick_widgets
[1].relative_x
+ b1_len
+ 1;
243 g_snprintf (time_out
, sizeof (time_out
), "%d", old_esc_mode_timeout
);
246 quick_widgets
[16].options
= quick_widgets
[17].options
= W_DISABLED
;
248 qd_result
= quick_dialog (&Quick_input
);
250 if ((qd_result
== B_ENTER
) || (qd_result
== B_EXIT
))
251 old_esc_mode_timeout
= atoi (time_out_new
);
253 g_free (time_out_new
);
256 if (qd_result
== B_EXIT
)
259 mc_config_save_file (mc_main_config
, NULL
);
264 panel_options_box (void)
269 const char *qsearch_options
[] = {
270 N_("Case &insensitive"),
271 N_("Case s&ensitive"),
272 N_("Use panel sort mo&de")
275 QuickWidget quick_widgets
[] = {
277 QUICK_BUTTON (38, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Cancel"), B_CANCEL
, NULL
),
278 QUICK_BUTTON (26, dlg_width
, dlg_height
- 3, dlg_height
, N_("&Save"), B_EXIT
, NULL
),
279 QUICK_BUTTON (14, dlg_width
, dlg_height
- 3, dlg_height
, N_("&OK"), B_ENTER
, NULL
),
281 QUICK_RADIO (dlg_width
/ 2 + 2, dlg_width
, 12, dlg_height
, QSEARCH_NUM
, qsearch_options
,
282 (int *) &panels_options
.qsearch_mode
),
283 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 11, dlg_height
, dlg_width
/ 2 - 4, QSEARCH_NUM
+ 2,
285 /* file highlighting */
286 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 9, dlg_height
, N_("&Permissions"),
287 &panels_options
.permission_mode
),
288 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 8, dlg_height
, N_("File &types"),
289 &panels_options
.filetype_mode
),
290 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 7, dlg_height
, dlg_width
/ 2 - 4, 4,
291 N_("File highlight")),
293 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 5, dlg_height
, N_("&Mouse page scrolling"),
294 &panels_options
.mouse_move_pages
),
295 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 4, dlg_height
, N_("Pa&ge scrolling"),
296 &panels_options
.scroll_pages
),
297 QUICK_CHECKBOX (dlg_width
/ 2 + 2, dlg_width
, 3, dlg_height
, N_("L&ynx-like motion"),
298 &panels_options
.navigate_with_arrows
),
299 QUICK_GROUPBOX (dlg_width
/ 2, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 5,
301 /* main panel options */
302 QUICK_CHECKBOX (5, dlg_width
, 10, dlg_height
, N_("A&uto save panels setup"),
303 &panels_options
.auto_save_setup
),
304 QUICK_CHECKBOX (5, dlg_width
, 9, dlg_height
, N_("Re&verse files only"),
305 &panels_options
.reverse_files_only
),
306 QUICK_CHECKBOX (5, dlg_width
, 8, dlg_height
, N_("Ma&rk moves down"),
307 &panels_options
.mark_moves_down
),
308 QUICK_CHECKBOX (5, dlg_width
, 7, dlg_height
, N_("&Fast dir reload"),
309 &panels_options
.fast_reload
),
310 QUICK_CHECKBOX (5, dlg_width
, 6, dlg_height
, N_("Show &hidden files"),
311 &panels_options
.show_dot_files
),
312 QUICK_CHECKBOX (5, dlg_width
, 5, dlg_height
, N_("Show &backup files"),
313 &panels_options
.show_backups
),
314 QUICK_CHECKBOX (5, dlg_width
, 4, dlg_height
, N_("Mi&x all files"),
315 &panels_options
.mix_all_files
),
316 QUICK_CHECKBOX (5, dlg_width
, 3, dlg_height
, N_("Use SI si&ze units"),
317 &panels_options
.kilobyte_si
),
318 QUICK_GROUPBOX (3, dlg_width
, 2, dlg_height
, dlg_width
/ 2 - 4, 14, N_("Main panel options")),
322 const size_t qw_num
= sizeof (quick_widgets
) / sizeof (quick_widgets
[0]) - 1;
324 QuickDialog Quick_input
= {
325 dlg_width
, dlg_height
, -1, -1,
326 N_("Panel options"), "[Panel options]",
327 quick_widgets
, NULL
, TRUE
332 int b0_len
, b1_len
, b2_len
;
333 int b_len
, c_len
, g_len
;
338 for (i
= 0; i
< qw_num
; i
++)
341 quick_widgets
[i
].u
.button
.text
= _(quick_widgets
[i
].u
.button
.text
);
346 for (j
= 0; j
< QSEARCH_NUM
; j
++)
347 qsearch_options
[j
] = _(qsearch_options
[j
]);
349 else if ((i
== 4) || (i
== 7) || (i
== 11) || (i
== 20))
351 quick_widgets
[i
].u
.groupbox
.title
= _(quick_widgets
[i
].u
.groupbox
.title
);
354 quick_widgets
[i
].u
.checkbox
.text
= _(quick_widgets
[i
].u
.checkbox
.text
);
356 Quick_input
.title
= _(Quick_input
.title
);
358 #endif /* ENABLE_NLS */
360 /* calculate widget and dialog widths */
362 dlg_width
= max (dlg_width
, str_term_width1 (Quick_input
.title
) + 4);
364 b0_len
= str_term_width1 (quick_widgets
[0].u
.button
.text
) + 3;
365 b1_len
= str_term_width1 (quick_widgets
[1].u
.button
.text
) + 3;
366 b2_len
= str_term_width1 (quick_widgets
[2].u
.button
.text
) + 5;
367 b_len
= b0_len
+ b1_len
+ b2_len
+ 2;
369 /* checkboxes within groupboxes */
371 for (i
= 5; i
< 20; i
++)
372 if ((i
!= 7) && (i
!= 11))
373 c_len
= max (c_len
, str_term_width1 (quick_widgets
[i
].u
.checkbox
.text
) + 4);
376 for (i
= 0; i
< QSEARCH_NUM
; i
++)
377 c_len
= max (c_len
, str_term_width1 (qsearch_options
[i
]) + 3);
379 g_len
= max (c_len
+ 2, str_term_width1 (quick_widgets
[4].u
.groupbox
.title
) + 4);
380 g_len
= max (g_len
, str_term_width1 (quick_widgets
[ 7].u
.groupbox
.title
) + 4);
381 g_len
= max (g_len
, str_term_width1 (quick_widgets
[11].u
.groupbox
.title
) + 4);
382 g_len
= max (g_len
, str_term_width1 (quick_widgets
[20].u
.groupbox
.title
) + 4);
384 Quick_input
.xlen
= max (dlg_width
, g_len
* 2 + 9);
385 Quick_input
.xlen
= max (Quick_input
.xlen
, b_len
+ 2);
386 if ((Quick_input
.xlen
& 1) != 0)
389 /* fix widget parameters */
390 for (i
= 0; i
< qw_num
; i
++)
391 quick_widgets
[i
].x_divisions
= Quick_input
.xlen
;
394 quick_widgets
[4].u
.groupbox
.width
=
395 quick_widgets
[ 7].u
.groupbox
.width
=
396 quick_widgets
[11].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 3;
397 quick_widgets
[20].u
.groupbox
.width
= Quick_input
.xlen
/ 2 - 4;
400 quick_widgets
[4].relative_x
=
401 quick_widgets
[ 7].relative_x
=
402 quick_widgets
[11].relative_x
= Quick_input
.xlen
/ 2;
403 for (i
= 3; i
< 11; i
++)
404 if ((i
!= 4) && (i
!= 7))
405 quick_widgets
[i
].relative_x
= quick_widgets
[4].relative_x
+ 2;
408 quick_widgets
[2].relative_x
= (Quick_input
.xlen
- b_len
) / 2;
409 quick_widgets
[1].relative_x
= quick_widgets
[2].relative_x
+ b2_len
+ 1;
410 quick_widgets
[0].relative_x
= quick_widgets
[1].relative_x
+ b1_len
+ 1;
412 qd_result
= quick_dialog (&Quick_input
);
414 if ((qd_result
== B_ENTER
) || (qd_result
== B_EXIT
))
416 if (!panels_options
.fast_reload_msg_shown
&& panels_options
.fast_reload
)
418 message (D_NORMAL
, _("Information"),
419 _("Using the fast reload option may not reflect the exact\n"
420 "directory contents. In this case you'll need to do a\n"
421 "manual reload of the directory. See the man page for\n"
423 panels_options
.fast_reload_msg_shown
= TRUE
;
425 update_panels (UP_RELOAD
, UP_KEEPSEL
);
428 if (qd_result
== B_EXIT
)
430 /* save panel options */
431 panels_save_options ();
432 mc_config_save_file (mc_main_config
, NULL
);