Corrected some in-line help strings...
[midnight-commander.git] / src / option.c
blob2093bd6ded8bf666b7dfb80118fe09b1b0b6e52c
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.
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/stat.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
29 #include "global.h"
30 #include "tty.h"
31 #include "win.h"
32 #include "color.h"
33 #include "dlg.h"
34 #include "widget.h"
35 #include "setup.h" /* For save_setup() */
36 #include "dialog.h" /* For do_refresh() */
37 #include "main.h"
38 #include "profile.h" /* For sync_profiles */
40 #include "dir.h"
41 #include "panel.h" /* Needed for the externs */
42 #include "file.h"
43 #include "layout.h" /* For nice_rotating_dash */
44 #include "option.h"
45 #define PX 4
46 #define PY 2
48 #define RX 4
49 #define RY 12
51 #define BY 17
52 #define OY 2
54 static Dlg_head *conf_dlg;
56 static int r_but;
58 #define TOGGLE_VARIABLE 0
60 extern int use_internal_edit;
62 static int OX = 33, first_width = 27, second_width = 27;
63 static char *configure_title, *title1, *title2, *title3;
65 static struct {
66 char *text;
67 int *variable;
68 void (*toggle_function)(void);
69 WCheck *widget;
70 char *tk;
71 } check_options [] = {
72 {N_("safe de&Lete"), &know_not_what_am_i_doing, TOGGLE_VARIABLE,0, "safe-del" },
73 {N_("cd follows lin&Ks"), &cd_symlinks, TOGGLE_VARIABLE, 0, "cd-follow" },
74 {N_("advanced cho&Wn"), &advanced_chfns, TOGGLE_VARIABLE, 0, "achown" },
75 {N_("l&Ynx-like motion"), &navigate_with_arrows,TOGGLE_VARIABLE, 0, "lynx" },
76 {N_("rotatin&G dash"), &nice_rotating_dash,TOGGLE_VARIABLE, 0, "rotating" },
77 {N_("co&Mplete: show all"),&show_all_if_ambiguous,TOGGLE_VARIABLE, 0, "completion" },
78 {N_("&Use internal view"), &use_internal_view, TOGGLE_VARIABLE, 0, "view-int" },
79 {N_("use internal ed&It"), &use_internal_edit, TOGGLE_VARIABLE, 0, "edit-int" },
80 {N_("auto m&Enus"), &auto_menu, TOGGLE_VARIABLE, 0, "auto-menus" },
81 {N_("&Auto save setup"), &auto_save_setup, TOGGLE_VARIABLE, 0, "auto-save" },
82 {N_("shell &Patterns"), &easy_patterns, TOGGLE_VARIABLE, 0, "shell-patt" },
83 {N_("Compute &Totals"), &file_op_compute_totals, TOGGLE_VARIABLE, 0, "compute-totals" },
84 {N_("&Verbose operation"), &verbose, TOGGLE_VARIABLE, 0, "verbose" },
85 {N_("&Fast dir reload"), &fast_reload, toggle_fast_reload, 0, "fast-reload" },
86 {N_("mi&X all files"), &mix_all_files, toggle_mix_all_files, 0, "mix-files" },
87 {N_("&Drop down menus"), &drop_menus, TOGGLE_VARIABLE, 0, "drop-menus" },
88 {N_("ma&Rk moves down"), &mark_moves_down, TOGGLE_VARIABLE, 0, "mark-moves" },
89 {N_("show &Hidden files"), &show_dot_files, toggle_show_hidden, 0, "show-hidden" },
90 {N_("show &Backup files"), &show_backups, toggle_show_backup, 0, "show-backup" },
91 { 0, 0, 0, 0 }
94 static WRadio *pause_radio;
96 static char *pause_options [3] = {
97 N_("&Never"),
98 N_("on dumb &Terminals"),
99 N_("alwa&Ys") };
101 static int configure_callback (struct Dlg_head *h, int Id, int Msg)
103 switch (Msg) {
104 case DLG_DRAW:
105 attrset (COLOR_NORMAL);
106 dlg_erase (h);
107 draw_box (h, 1, 2, h->lines - 2, h->cols - 4);
108 draw_box (h, PY, PX, 8, first_width);
109 draw_box (h, RY, RX, 5, first_width);
110 draw_box (h, OY, OX, 15, second_width);
112 attrset (COLOR_HOT_NORMAL);
113 dlg_move (h, 1, (h->cols - strlen(configure_title))/2);
114 addstr (configure_title);
115 dlg_move (h, OY, OX+1);
116 addstr (title3);
117 dlg_move (h, RY, RX+1);
118 addstr (title2);
119 dlg_move (h, PY, PX+1);
120 addstr (title1);
121 break;
123 case DLG_END:
124 r_but = Id;
125 break;
127 return 0;
130 static void init_configure (void)
132 int i;
133 static int i18n_config_flag = 0;
134 static int b1, b2, b3;
135 char* ok_button = _("&Ok");
136 char* cancel_button = _("&Cancel");
137 char* save_button = _("&Save");
139 if (!i18n_config_flag)
141 register int l1;
143 /* Similar code is in layout.c (init_layout()) */
145 configure_title = _(" Configure options ");
146 title1 = _(" Panel options ");
147 title2 = _(" Pause after run... ");
148 title3 = _(" Other options ");
150 first_width = strlen (title1) + 1;
151 for (i = 13; i < 19; i++)
153 check_options[i].text = _(check_options[i].text);
154 l1 = strlen (check_options[i].text) + 7;
155 if (l1 > first_width)
156 first_width = l1;
159 i = sizeof(pause_options)/sizeof(char*);
160 while (i--)
162 pause_options [i] = _(pause_options [i]);
163 l1 = strlen (pause_options [i]) + 7;
164 if (l1 > first_width)
165 first_width = l1;
168 l1 = strlen (title2) + 1;
169 if (l1 > first_width)
170 first_width = l1;
172 OX = first_width + 5;
174 second_width = strlen (title3) + 1;
175 for (i = 0; i < 13; i++)
177 check_options[i].text = _(check_options[i].text);
178 l1 = strlen (check_options[i].text) + 7;
179 if (l1 > second_width)
180 second_width = l1;
183 l1 = 11 + strlen (ok_button)
184 + strlen (save_button)
185 + strlen (cancel_button);
187 i = (first_width + second_width - l1) / 4;
188 b1 = 5 + i;
189 b2 = b1 + strlen(ok_button) + i + 6;
190 b3 = b2 + strlen(save_button) + i + 4;
192 i18n_config_flag = 1;
195 conf_dlg = create_dlg (0, 0, 20, first_width + second_width + 9,
196 dialog_colors, configure_callback, "[Configuration]",
197 "option", DLG_CENTER | DLG_GRID);
199 x_set_dialog_title (conf_dlg, _("Configure options"));
201 add_widget (conf_dlg,
202 button_new (BY, b3, B_CANCEL, NORMAL_BUTTON,
203 cancel_button, 0, 0, "button-cancel"));
205 add_widget (conf_dlg,
206 button_new (BY, b2, B_EXIT, NORMAL_BUTTON,
207 save_button, 0, 0, "button-save"));
209 add_widget (conf_dlg,
210 button_new (BY, b1, B_ENTER, DEFPUSH_BUTTON,
211 ok_button, 0, 0, "button-ok"));
213 #define XTRACT(i) *check_options[i].variable, check_options[i].text, check_options [i].tk
215 /* Add all the checkboxes */
216 for (i = 0; i < 13; i++){
217 check_options [i].widget = check_new (OY + (13-i), OX+2, XTRACT(i));
218 add_widget (conf_dlg, check_options [i].widget);
221 pause_radio = radio_new (RY+1, RX+2, 3, pause_options, 1, "pause-radio");
222 pause_radio->sel = pause_after_run;
223 add_widget (conf_dlg, pause_radio);
224 for (i = 0; i < 6; i++){
225 check_options [i+13].widget = check_new (PY + (6-i), PX+2,
226 XTRACT(i+13));
227 add_widget (conf_dlg, check_options [i+13].widget);
232 void configure_box (void)
234 int result, i;
236 init_configure ();
237 run_dlg (conf_dlg);
239 result = conf_dlg->ret_value;
240 if (result == B_ENTER || result == B_EXIT){
241 for (i = 0; check_options [i].text; i++)
242 if (check_options [i].widget->state & C_CHANGE){
243 if (check_options [i].toggle_function)
244 (*check_options [i].toggle_function)();
245 else
246 *check_options [i].variable =
247 !(*check_options [i].variable);
249 pause_after_run = pause_radio->sel;
252 /* If they pressed the save button */
253 if (result == B_EXIT){
254 save_configure ();
255 sync_profiles ();
258 destroy_dlg (conf_dlg);