Just a little correction at the it.po file.
[midnight-commander.git] / src / option.c
blob935a87fab379653a5a9ffbafefe2c62792d4ddc4
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 "panel.h" /* Needed for the externs */
41 #include "file.h" /* safe_delete */
42 #include "layout.h" /* For nice_rotating_dash */
43 #include "option.h"
44 static Dlg_head *conf_dlg;
46 static int r_but;
48 #define TOGGLE_VARIABLE 0
50 static int first_width, second_width;
51 static char *title1, *title2, *title3;
53 static struct {
54 char *text;
55 int *variable;
56 void (*toggle_function)(void);
57 WCheck *widget;
58 char *tk;
59 } check_options [] = {
60 /* other 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" },
73 /* panel options */
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" },
80 { 0, 0, 0, 0 }
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] = {
90 N_("&Never"),
91 N_("on dumb &Terminals"),
92 N_("Alwa&ys") };
94 #define PAUSE_OPTIONS (sizeof(pause_options) / sizeof(char *))
96 /* Heights of the panes */
97 #define PY 3
98 #define OY PY
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 */
105 #define X_MARGIN 3
106 #define X_PANE_GAP 1
107 #define PX X_MARGIN
108 #define RX X_MARGIN
109 #define OX (first_width + X_MARGIN + X_PANE_GAP)
111 static int configure_callback (struct Dlg_head *h, int Id, int Msg)
113 switch (Msg) {
114 case DLG_DRAW:
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);
124 addstr (title3);
125 dlg_move (h, RY, RX+1);
126 addstr (title2);
127 dlg_move (h, PY, PX+1);
128 addstr (title1);
129 break;
131 case DLG_END:
132 r_but = Id;
133 break;
135 return 0;
138 /* Create the "Configure options" dialog */
139 static void
140 init_configure (void)
142 int i;
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) {
150 register int l1;
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)
166 first_width = l1;
167 } else {
168 if (l1 > second_width)
169 second_width = l1;
173 i = sizeof (pause_options) / sizeof (char *);
174 while (i--) {
175 pause_options[i] = _(pause_options[i]);
176 l1 = strlen (pause_options[i]) + 7;
177 if (l1 > first_width)
178 first_width = l1;
181 l1 = strlen (title2) + 1;
182 if (l1 > first_width)
183 first_width = l1;
185 l1 = 11 + strlen (ok_button)
186 + strlen (save_button)
187 + strlen (cancel_button);
189 i = (first_width + second_width - l1) / 4;
190 b1 = 5 + i;
191 b2 = b1 + strlen (ok_button) + i + 6;
192 b3 = b2 + strlen (save_button) + i + 4;
194 i18n_config_flag = 1;
197 conf_dlg =
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);
224 pause_radio =
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)
241 int result, i;
243 init_configure ();
244 run_dlg (conf_dlg);
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)();
252 else
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){
261 save_configure ();
262 sync_profiles ();
265 destroy_dlg (conf_dlg);