- Rearrange reactos.dff according to rosapps rearrange.
[reactos.git] / rosapps / mc / src / option.c
1 /* Configure box module for the Midnight Commander
2 Copyright (C) 1994 Radek Doulik
3
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.
8
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.
13
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., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <config.h>
20 #include <string.h>
21 #include <stdio.h>
22 /* Needed for the extern declarations of integer parameters */
23 #include <sys/types.h>
24 #include <sys/param.h>
25 #include <sys/stat.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 #include "tty.h"
30 #include "mad.h"
31 #include "util.h"
32 #include "win.h"
33 #include "color.h"
34 #include "dlg.h"
35 #include "widget.h"
36 #include "setup.h" /* For save_setup() */
37 #include "dialog.h" /* For do_refresh() */
38 #include "main.h"
39 #include "profile.h" /* For sync_profiles */
40
41 #include "dir.h"
42 #include "panel.h" /* Needed for the externs */
43 #include "file.h"
44 #include "layout.h" /* For nice_rotating_dash */
45 #define PX 4
46 #define PY 2
47
48 #define RX 4
49 #define RY 11
50
51 #define BY 16
52 #define OY 2
53
54 static Dlg_head *conf_dlg;
55
56 static int r_but;
57
58 #define TOGGLE_VARIABLE 0
59
60 extern int use_internal_edit;
61
62 int dummy;
63
64 static int OX = 33, first_width = 27, second_width = 27;
65 static char *configure_title, *title1, *title2, *title3;
66
67 static struct {
68 char *text;
69 int *variable;
70 void (*toggle_function)(void);
71 WCheck *widget;
72 char *tk;
73 } check_options [] = {
74 {N_("safe de&Lete"), &know_not_what_am_i_doing, TOGGLE_VARIABLE,0, "safe-del" },
75 {N_("cd follows lin&Ks"), &cd_symlinks, TOGGLE_VARIABLE, 0, "cd-follow" },
76 {N_("advanced cho&Wn"), &advanced_chfns, TOGGLE_VARIABLE, 0, "achown" },
77 {N_("l&Ynx-like motion"), &navigate_with_arrows,TOGGLE_VARIABLE, 0, "lynx" },
78 #ifdef HAVE_GNOME
79 {N_("Animation"), &dummy, TOGGLE_VARIABLE, 0, "dummy" },
80 #else
81 {N_("ro&Tating dash"), &nice_rotating_dash,TOGGLE_VARIABLE, 0, "rotating" },
82 #endif
83 {N_("co&Mplete: show all"),&show_all_if_ambiguous,TOGGLE_VARIABLE, 0, "completion" },
84 {N_("&Use internal view"), &use_internal_view, TOGGLE_VARIABLE, 0, "view-int" },
85 {N_("use internal ed&It"), &use_internal_edit, TOGGLE_VARIABLE, 0, "edit-int" },
86 {N_("auto m&Enus"), &auto_menu, TOGGLE_VARIABLE, 0, "auto-menus" },
87 {N_("&Auto save setup"), &auto_save_setup, TOGGLE_VARIABLE, 0, "auto-save" },
88 {N_("shell &Patterns"), &easy_patterns, TOGGLE_VARIABLE, 0, "shell-patt" },
89 {N_("&Verbose operation"), &verbose, TOGGLE_VARIABLE, 0, "verbose" },
90 {N_("&Fast dir reload"), &fast_reload, toggle_fast_reload, 0, "fast-reload" },
91 {N_("mi&X all files"), &mix_all_files, toggle_mix_all_files, 0, "mix-files" },
92 {N_("&Drop down menus"), &drop_menus, TOGGLE_VARIABLE, 0, "drop-menus" },
93 {N_("ma&Rk moves down"), &mark_moves_down, TOGGLE_VARIABLE, 0, "mark-moves" },
94 {N_("show &Hidden files"), &show_dot_files, toggle_show_hidden, 0, "show-hidden" },
95 {N_("show &Backup files"), &show_backups, toggle_show_backup, 0, "show-backup" },
96 { 0, 0, 0, 0 }
97 };
98
99 static WRadio *pause_radio;
100
101 static char *pause_options [3] = {
102 N_("&Never"),
103 N_("on dumb &Terminals"),
104 N_("alwa&Ys") };
105
106 static int configure_callback (struct Dlg_head *h, int Id, int Msg)
107 {
108 switch (Msg) {
109 case DLG_DRAW:
110 #ifndef HAVE_X
111 attrset (COLOR_NORMAL);
112 dlg_erase (h);
113 draw_box (h, 1, 2, h->lines - 2, h->cols - 4);
114 draw_box (h, PY, PX, 8, first_width);
115 draw_box (h, RY, RX, 5, first_width);
116 draw_box (h, OY, OX, 14, second_width);
117
118 attrset (COLOR_HOT_NORMAL);
119 dlg_move (h, 1, (h->cols - strlen(configure_title))/2);
120 addstr (configure_title);
121 dlg_move (h, OY, OX+1);
122 addstr (title3);
123 dlg_move (h, RY, RX+1);
124 addstr (title2);
125 dlg_move (h, PY, PX+1);
126 addstr (title1);
127 #endif
128 break;
129
130 case DLG_END:
131 r_but = Id;
132 break;
133 }
134 return 0;
135 }
136
137 static void init_configure (void)
138 {
139 int i;
140 static int i18n_config_flag = 0;
141 static int b1, b2, b3;
142 char* ok_button = _("&Ok");
143 char* cancel_button = _("&Cancel");
144 char* save_button = _("&Save");
145
146 if (!i18n_config_flag)
147 {
148 register int l1;
149
150 /* Similar code is in layout.c (init_layout()) */
151
152 configure_title = _(" Configure options ");
153 title1 = _(" Panel options ");
154 title2 = _(" Pause after run... ");
155 title3 = _(" Other options ");
156
157 first_width = strlen (title1) + 1;
158 for (i = 12; i < 18; i++)
159 {
160 check_options[i].text = _(check_options[i].text);
161 l1 = strlen (check_options[i].text) + 7;
162 if (l1 > first_width)
163 first_width = l1;
164 }
165
166 i = sizeof(pause_options)/sizeof(char*);
167 while (i--)
168 {
169 pause_options [i] = _(pause_options [i]);
170 l1 = strlen (pause_options [i]) + 7;
171 if (l1 > first_width)
172 first_width = l1;
173 }
174
175 l1 = strlen (title2) + 1;
176 if (l1 > first_width)
177 first_width = l1;
178
179 OX = first_width + 5;
180
181 second_width = strlen (title3) + 1;
182 for (i = 0; i < 12; i++)
183 {
184 check_options[i].text = _(check_options[i].text);
185 l1 = strlen (check_options[i].text) + 7;
186 if (l1 > second_width)
187 second_width = l1;
188 }
189
190 l1 = 11 + strlen (ok_button)
191 + strlen (save_button)
192 + strlen (cancel_button);
193
194 i = (first_width + second_width - l1) / 4;
195 b1 = 5 + i;
196 b2 = b1 + strlen(ok_button) + i + 6;
197 b3 = b2 + strlen(save_button) + i + 4;
198
199 i18n_config_flag = 1;
200 }
201
202 conf_dlg = create_dlg (0, 0, 19, first_width + second_width + 9,
203 dialog_colors, configure_callback, "[Options Menu]",
204 "option", DLG_CENTER | DLG_GRID);
205
206 x_set_dialog_title (conf_dlg, _("Configure options"));
207
208 add_widgetl (conf_dlg,
209 button_new (BY, b3, B_CANCEL, NORMAL_BUTTON, cancel_button, 0, 0, "button-cancel"),
210 XV_WLAY_RIGHTOF);
211
212 add_widgetl (conf_dlg,
213 button_new (BY, b2, B_EXIT, NORMAL_BUTTON, save_button, 0, 0, "button-save"),
214 XV_WLAY_RIGHTOF);
215
216 add_widgetl (conf_dlg,
217 button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON, ok_button, 0, 0, "button-ok"),
218 XV_WLAY_CENTERROW);
219
220 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options [i].tk
221
222 /* Add all the checkboxes */
223 for (i = 0; i < 12; i++){
224 check_options [i].widget = check_new (OY + (12-i), OX+2, XTRACT(i));
225 add_widgetl (conf_dlg, check_options [i].widget,
226 XV_WLAY_BELOWCLOSE);
227 }
228
229 pause_radio = radio_new (RY+1, RX+2, 3, pause_options, 1, "pause-radio");
230 pause_radio->sel = pause_after_run;
231 #ifndef HAVE_GNOME
232 add_widgetl (conf_dlg, pause_radio, XV_WLAY_BELOWCLOSE);
233 #endif
234 for (i = 0; i < 6; i++){
235 check_options [i+12].widget = check_new (PY + (6-i), PX+2,
236 XTRACT(i+12));
237 add_widgetl (conf_dlg, check_options [i+12].widget,
238 XV_WLAY_BELOWCLOSE);
239 }
240 #ifdef HAVE_XVIEW
241 add_widgetl (conf_dlg, label_new (OY, OX + 1, _("Other options"), "label-other"),
242 XV_WLAY_NEXTCOLUMN);
243 add_widgetl (conf_dlg, label_new (RY, RX + 1, _("Pause after run..."), "label-pause"),
244 XV_WLAY_BELOWOF);
245 add_widgetl (conf_dlg, label_new (PY, PX + 1, _("Panel options"), "label-panel"),
246 XV_WLAY_NEXTCOLUMN);
247 #endif
248 }
249
250
251 void configure_box (void)
252 {
253 int result, i;
254
255 init_configure ();
256 run_dlg (conf_dlg);
257
258 result = conf_dlg->ret_value;
259 if (result == B_ENTER || result == B_EXIT){
260 for (i = 0; check_options [i].text; i++)
261 if (check_options [i].widget->state & C_CHANGE){
262 if (check_options [i].toggle_function)
263 (*check_options [i].toggle_function)();
264 else
265 *check_options [i].variable =
266 !(*check_options [i].variable);
267 }
268 pause_after_run = pause_radio->sel;
269 }
270
271 /* If they pressed the save button */
272 if (result == B_EXIT){
273 save_configure ();
274 sync_profiles ();
275 }
276
277 destroy_dlg (conf_dlg);
278 }