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 */
41 #include "panel.h" /* Needed for the externs */
43 #include "layout.h" /* For nice_rotating_dash */
45 static Dlg_head
*conf_dlg
;
49 #define TOGGLE_VARIABLE 0
51 extern int use_internal_edit
;
53 static int first_width
, second_width
;
54 static char *title1
, *title2
, *title3
;
59 void (*toggle_function
)(void);
62 } check_options
[] = {
64 {N_("safe de&Lete"), &know_not_what_am_i_doing
, TOGGLE_VARIABLE
,0, "safe-del" },
65 {N_("cd follows lin&Ks"), &cd_symlinks
, TOGGLE_VARIABLE
, 0, "cd-follow" },
66 {N_("l&Ynx-like motion"), &navigate_with_arrows
,TOGGLE_VARIABLE
, 0, "lynx" },
67 {N_("rotatin&G dash"), &nice_rotating_dash
,TOGGLE_VARIABLE
, 0, "rotating" },
68 {N_("co&Mplete: show all"),&show_all_if_ambiguous
,TOGGLE_VARIABLE
, 0, "completion" },
69 {N_("&Use internal view"), &use_internal_view
, TOGGLE_VARIABLE
, 0, "view-int" },
70 {N_("use internal ed&It"), &use_internal_edit
, TOGGLE_VARIABLE
, 0, "edit-int" },
71 {N_("auto m&Enus"), &auto_menu
, TOGGLE_VARIABLE
, 0, "auto-menus" },
72 {N_("&Auto save setup"), &auto_save_setup
, TOGGLE_VARIABLE
, 0, "auto-save" },
73 {N_("shell &Patterns"), &easy_patterns
, TOGGLE_VARIABLE
, 0, "shell-patt" },
74 {N_("Compute &Totals"), &file_op_compute_totals
, TOGGLE_VARIABLE
, 0, "compute-totals" },
75 {N_("&Verbose operation"), &verbose
, TOGGLE_VARIABLE
, 0, "verbose" },
77 {N_("&Fast dir reload"), &fast_reload
, toggle_fast_reload
, 0, "fast-reload" },
78 {N_("mi&X all files"), &mix_all_files
, toggle_mix_all_files
, 0, "mix-files" },
79 {N_("&Drop down menus"), &drop_menus
, TOGGLE_VARIABLE
, 0, "drop-menus" },
80 {N_("ma&Rk moves down"), &mark_moves_down
, TOGGLE_VARIABLE
, 0, "mark-moves" },
81 {N_("show &Hidden files"), &show_dot_files
, toggle_show_hidden
, 0, "show-hidden" },
82 {N_("show &Backup files"), &show_backups
, toggle_show_backup
, 0, "show-backup" },
86 /* Make sure this corresponds to the check_options structure */
87 #define OTHER_OPTIONS 12
88 #define PANEL_OPTIONS 6
90 static WRadio
*pause_radio
;
92 static char *pause_options
[3] = {
94 N_("on dumb &Terminals"),
97 #define PAUSE_OPTIONS (sizeof(pause_options) / sizeof(char *))
99 /* Heights of the panes */
102 /* Align bottoms of "pause after run" and "other options" */
103 #define RY (OTHER_OPTIONS - PAUSE_OPTIONS + OY)
104 #define DLG_Y (OTHER_OPTIONS + 9)
105 #define BY (DLG_Y - 3)
107 /* Horizontal dimensions */
112 #define OX (first_width + X_MARGIN + X_PANE_GAP)
114 static int configure_callback (struct Dlg_head
*h
, int Id
, int Msg
)
118 common_dialog_repaint (h
);
120 attrset (COLOR_NORMAL
);
121 draw_box (h
, PY
, PX
, PANEL_OPTIONS
+ 2, first_width
);
122 draw_box (h
, RY
, RX
, PAUSE_OPTIONS
+ 2, first_width
);
123 draw_box (h
, OY
, OX
, OTHER_OPTIONS
+ 2, second_width
);
125 attrset (COLOR_HOT_NORMAL
);
126 dlg_move (h
, OY
, OX
+1);
128 dlg_move (h
, RY
, RX
+1);
130 dlg_move (h
, PY
, PX
+1);
141 /* Create the "Configure options" dialog */
143 init_configure (void)
146 static int i18n_config_flag
= 0;
147 static int b1
, b2
, b3
;
148 char *ok_button
= _("&Ok");
149 char *cancel_button
= _("&Cancel");
150 char *save_button
= _("&Save");
152 if (!i18n_config_flag
) {
155 /* Similar code is in layout.c (init_layout()) */
157 title1
= _(" Panel options ");
158 title2
= _(" Pause after run... ");
159 title3
= _(" Other options ");
161 first_width
= strlen (title1
) + 1;
162 second_width
= strlen (title3
) + 1;
164 for (i
= 0; check_options
[i
].text
; i
++) {
165 check_options
[i
].text
= _(check_options
[i
].text
);
166 l1
= strlen (check_options
[i
].text
) + 7;
167 if (i
>= OTHER_OPTIONS
) {
168 if (l1
> first_width
)
171 if (l1
> second_width
)
176 i
= sizeof (pause_options
) / sizeof (char *);
178 pause_options
[i
] = _(pause_options
[i
]);
179 l1
= strlen (pause_options
[i
]) + 7;
180 if (l1
> first_width
)
184 l1
= strlen (title2
) + 1;
185 if (l1
> first_width
)
188 l1
= 11 + strlen (ok_button
)
189 + strlen (save_button
)
190 + strlen (cancel_button
);
192 i
= (first_width
+ second_width
- l1
) / 4;
194 b2
= b1
+ strlen (ok_button
) + i
+ 6;
195 b3
= b2
+ strlen (save_button
) + i
+ 4;
197 i18n_config_flag
= 1;
201 create_dlg (0, 0, DLG_Y
,
202 first_width
+ second_width
+ 2 * X_MARGIN
+ X_PANE_GAP
,
203 dialog_colors
, configure_callback
, "[Configuration]",
204 _("Configure options"), DLG_CENTER
);
206 add_widget (conf_dlg
,
207 button_new (BY
, b3
, B_CANCEL
, NORMAL_BUTTON
,
208 cancel_button
, 0, 0, "button-cancel"));
210 add_widget (conf_dlg
,
211 button_new (BY
, b2
, B_EXIT
, NORMAL_BUTTON
,
212 save_button
, 0, 0, "button-save"));
214 add_widget (conf_dlg
,
215 button_new (BY
, b1
, B_ENTER
, DEFPUSH_BUTTON
,
216 ok_button
, 0, 0, "button-ok"));
218 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options [i].tk
220 /* Add checkboxes for "other options" */
221 for (i
= 0; i
< OTHER_OPTIONS
; i
++) {
222 check_options
[i
].widget
=
223 check_new (OY
+ (OTHER_OPTIONS
- i
), OX
+ 2, XTRACT (i
));
224 add_widget (conf_dlg
, check_options
[i
].widget
);
228 radio_new (RY
+ 1, RX
+ 2, 3, pause_options
, 1, "pause-radio");
229 pause_radio
->sel
= pause_after_run
;
230 add_widget (conf_dlg
, pause_radio
);
232 /* Add checkboxes for "panel options" */
233 for (i
= 0; i
< PANEL_OPTIONS
; i
++) {
234 check_options
[i
+ OTHER_OPTIONS
].widget
=
235 check_new (PY
+ (6 - i
), PX
+ 2, XTRACT (i
+ OTHER_OPTIONS
));
236 add_widget (conf_dlg
, check_options
[i
+ OTHER_OPTIONS
].widget
);
241 void configure_box (void)
248 result
= conf_dlg
->ret_value
;
249 if (result
== B_ENTER
|| result
== B_EXIT
){
250 for (i
= 0; check_options
[i
].text
; i
++)
251 if (check_options
[i
].widget
->state
& C_CHANGE
){
252 if (check_options
[i
].toggle_function
)
253 (*check_options
[i
].toggle_function
)();
255 *check_options
[i
].variable
=
256 !(*check_options
[i
].variable
);
258 pause_after_run
= pause_radio
->sel
;
261 /* If they pressed the save button */
262 if (result
== B_EXIT
){
267 destroy_dlg (conf_dlg
);