1 /* Configure box module for the Midnight Commander
2 Copyright (C) 1994 Radek Doulik
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 /* Needed for the extern declarations of integer parameters */
23 #include <sys/types.h>
35 #include "setup.h" /* For save_setup() */
36 #include "dialog.h" /* For do_refresh() */
38 #include "profile.h" /* For sync_profiles */
40 #include "panel.h" /* Needed for the externs */
41 #include "file.h" /* safe_delete */
42 #include "layout.h" /* For nice_rotating_dash */
44 static Dlg_head
*conf_dlg
;
48 #define TOGGLE_VARIABLE 0
50 static int first_width
, second_width
;
51 static char *title1
, *title2
, *title3
;
56 void (*toggle_function
)(void);
59 } check_options
[] = {
61 {N_("safe de&Lete"), &safe_delete
, TOGGLE_VARIABLE
, 0, "safe-del" },
62 {N_("cd follows lin&Ks"), &cd_symlinks
, TOGGLE_VARIABLE
, 0, "cd-follow" },
63 {N_("L&ynx-like motion"), &navigate_with_arrows
,TOGGLE_VARIABLE
, 0, "lynx" },
64 {N_("rotatin&G dash"), &nice_rotating_dash
,TOGGLE_VARIABLE
, 0, "rotating" },
65 {N_("co&Mplete: show all"),&show_all_if_ambiguous
,TOGGLE_VARIABLE
, 0, "completion" },
66 {N_("&Use internal view"), &use_internal_view
, TOGGLE_VARIABLE
, 0, "view-int" },
67 {N_("use internal ed&It"), &use_internal_edit
, TOGGLE_VARIABLE
, 0, "edit-int" },
68 {N_("auto m&Enus"), &auto_menu
, TOGGLE_VARIABLE
, 0, "auto-menus" },
69 {N_("&Auto save setup"), &auto_save_setup
, TOGGLE_VARIABLE
, 0, "auto-save" },
70 {N_("shell &Patterns"), &easy_patterns
, TOGGLE_VARIABLE
, 0, "shell-patt" },
71 {N_("Compute &Totals"), &file_op_compute_totals
, TOGGLE_VARIABLE
, 0, "compute-totals" },
72 {N_("&Verbose operation"), &verbose
, TOGGLE_VARIABLE
, 0, "verbose" },
74 {N_("&Fast dir reload"), &fast_reload
, toggle_fast_reload
, 0, "fast-reload" },
75 {N_("mi&X all files"), &mix_all_files
, toggle_mix_all_files
, 0, "mix-files" },
76 {N_("&Drop down menus"), &drop_menus
, TOGGLE_VARIABLE
, 0, "drop-menus" },
77 {N_("ma&Rk moves down"), &mark_moves_down
, TOGGLE_VARIABLE
, 0, "mark-moves" },
78 {N_("show &Hidden files"), &show_dot_files
, toggle_show_hidden
, 0, "show-hidden" },
79 {N_("show &Backup files"), &show_backups
, toggle_show_backup
, 0, "show-backup" },
83 /* Make sure this corresponds to the check_options structure */
84 #define OTHER_OPTIONS 12
85 #define PANEL_OPTIONS 6
87 static WRadio
*pause_radio
;
89 static char *pause_options
[3] = {
91 N_("on dumb &Terminals"),
94 #define PAUSE_OPTIONS (sizeof(pause_options) / sizeof(char *))
96 /* Heights of the panes */
99 /* Align bottoms of "pause after run" and "other options" */
100 #define RY (OTHER_OPTIONS - PAUSE_OPTIONS + OY)
101 #define DLG_Y (OTHER_OPTIONS + 9)
102 #define BY (DLG_Y - 3)
104 /* Horizontal dimensions */
109 #define OX (first_width + X_MARGIN + X_PANE_GAP)
111 static int configure_callback (struct Dlg_head
*h
, int Id
, int Msg
)
115 common_dialog_repaint (h
);
117 attrset (COLOR_NORMAL
);
118 draw_box (h
, PY
, PX
, PANEL_OPTIONS
+ 2, first_width
);
119 draw_box (h
, RY
, RX
, PAUSE_OPTIONS
+ 2, first_width
);
120 draw_box (h
, OY
, OX
, OTHER_OPTIONS
+ 2, second_width
);
122 attrset (COLOR_HOT_NORMAL
);
123 dlg_move (h
, OY
, OX
+1);
125 dlg_move (h
, RY
, RX
+1);
127 dlg_move (h
, PY
, PX
+1);
138 /* Create the "Configure options" dialog */
140 init_configure (void)
143 static int i18n_config_flag
= 0;
144 static int b1
, b2
, b3
;
145 char *ok_button
= _("&OK");
146 char *cancel_button
= _("&Cancel");
147 char *save_button
= _("&Save");
149 if (!i18n_config_flag
) {
152 /* Similar code is in layout.c (init_layout()) */
154 title1
= _(" Panel options ");
155 title2
= _(" Pause after run... ");
156 title3
= _(" Other options ");
158 first_width
= strlen (title1
) + 1;
159 second_width
= strlen (title3
) + 1;
161 for (i
= 0; check_options
[i
].text
; i
++) {
162 check_options
[i
].text
= _(check_options
[i
].text
);
163 l1
= strlen (check_options
[i
].text
) + 7;
164 if (i
>= OTHER_OPTIONS
) {
165 if (l1
> first_width
)
168 if (l1
> second_width
)
173 i
= sizeof (pause_options
) / sizeof (char *);
175 pause_options
[i
] = _(pause_options
[i
]);
176 l1
= strlen (pause_options
[i
]) + 7;
177 if (l1
> first_width
)
181 l1
= strlen (title2
) + 1;
182 if (l1
> first_width
)
185 l1
= 11 + strlen (ok_button
)
186 + strlen (save_button
)
187 + strlen (cancel_button
);
189 i
= (first_width
+ second_width
- l1
) / 4;
191 b2
= b1
+ strlen (ok_button
) + i
+ 6;
192 b3
= b2
+ strlen (save_button
) + i
+ 4;
194 i18n_config_flag
= 1;
198 create_dlg (0, 0, DLG_Y
,
199 first_width
+ second_width
+ 2 * X_MARGIN
+ X_PANE_GAP
,
200 dialog_colors
, configure_callback
, "[Configuration]",
201 _("Configure options"), DLG_CENTER
);
203 add_widget (conf_dlg
,
204 button_new (BY
, b3
, B_CANCEL
, NORMAL_BUTTON
,
205 cancel_button
, 0, 0, "button-cancel"));
207 add_widget (conf_dlg
,
208 button_new (BY
, b2
, B_EXIT
, NORMAL_BUTTON
,
209 save_button
, 0, 0, "button-save"));
211 add_widget (conf_dlg
,
212 button_new (BY
, b1
, B_ENTER
, DEFPUSH_BUTTON
,
213 ok_button
, 0, 0, "button-ok"));
215 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options [i].tk
217 /* Add checkboxes for "other options" */
218 for (i
= 0; i
< OTHER_OPTIONS
; i
++) {
219 check_options
[i
].widget
=
220 check_new (OY
+ (OTHER_OPTIONS
- i
), OX
+ 2, XTRACT (i
));
221 add_widget (conf_dlg
, check_options
[i
].widget
);
225 radio_new (RY
+ 1, RX
+ 2, 3, pause_options
, 1, "pause-radio");
226 pause_radio
->sel
= pause_after_run
;
227 add_widget (conf_dlg
, pause_radio
);
229 /* Add checkboxes for "panel options" */
230 for (i
= 0; i
< PANEL_OPTIONS
; i
++) {
231 check_options
[i
+ OTHER_OPTIONS
].widget
=
232 check_new (PY
+ (PANEL_OPTIONS
- i
), PX
+ 2,
233 XTRACT (i
+ OTHER_OPTIONS
));
234 add_widget (conf_dlg
, check_options
[i
+ OTHER_OPTIONS
].widget
);
239 void configure_box (void)
246 result
= conf_dlg
->ret_value
;
247 if (result
== B_ENTER
|| result
== B_EXIT
){
248 for (i
= 0; check_options
[i
].text
; i
++)
249 if (check_options
[i
].widget
->state
& C_CHANGE
){
250 if (check_options
[i
].toggle_function
)
251 (*check_options
[i
].toggle_function
)();
253 *check_options
[i
].variable
=
254 !(*check_options
[i
].variable
);
256 pause_after_run
= pause_radio
->sel
;
259 /* If they pressed the save button */
260 if (result
== B_EXIT
){
265 destroy_dlg (conf_dlg
);