Merge branch '277_konsole_256color'
[midnight-commander.git] / edit / editoptions.c
blob9112358ab1c8ad220fb18a5e1e0198ca6924da3c
1 /* editor options dialog box
3 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2007
4 Free Software Foundation, Inc.
6 Authors: 1996, 1997 Paul Sheer
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA.
24 /** \file
25 * \brief Source: editor options dialog box
26 * \author Paul Sheer
27 * \date 1996, 1997
30 #include <config.h>
32 #include <stdlib.h> /* atoi(), NULL */
34 #include "../src/global.h"
36 #include "edit-impl.h"
37 #include "usermap.h"
38 #include "../src/dialog.h" /* B_CANCEL */
39 #include "../src/wtools.h" /* QuickDialog */
41 #define OPT_DLG_H 21
42 #define OPT_DLG_W 72
44 static const char *key_emu_str[] =
45 {N_("Intuitive"), N_("Emacs"), N_("User-defined"), NULL};
47 static const char *wrap_str[] =
48 {N_("None"), N_("Dynamic paragraphing"), N_("Type writer wrap"), NULL};
50 static void
51 i18n_translate_array (const char *array[])
53 while (*array!=NULL) {
54 *array = _(*array);
55 array++;
59 void
60 edit_options_dialog (void)
62 char wrap_length[32], tab_spacing[32], *p, *q;
63 int wrap_mode = 0;
64 int old_syntax_hl;
65 int tedit_key_emulation = edit_key_emulation;
66 int toption_fill_tabs_with_spaces = option_fill_tabs_with_spaces;
67 int toption_save_position = option_save_position;
68 int tedit_confirm_save = edit_confirm_save;
69 int tedit_syntax_highlighting = option_syntax_highlighting;
70 int tedit_visible_tabs = visible_tabs;
71 int tedit_visible_tws = visible_tws;
72 int tedit_persistent_selections = option_persistent_selections;
73 int tedit_cursor_beyond_eol = option_cursor_beyond_eol;
74 int toption_return_does_auto_indent = option_return_does_auto_indent;
75 int toption_backspace_through_tabs = option_backspace_through_tabs;
76 int toption_fake_half_tabs = option_fake_half_tabs;
77 static int i18n_flag = 0;
79 QuickWidget quick_widgets[] = {
80 /* 0 */
81 {quick_button, 6, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Cancel"), 0,
82 B_CANCEL, 0, 0, NULL, NULL, NULL},
83 /* 1 */
84 {quick_button, 2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&OK"), 0,
85 B_ENTER, 0, 0, NULL, NULL, NULL},
86 /* 2 */
87 {quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H,
88 N_("Word wrap line length: "), 0, 0, 0, 0, NULL, NULL, NULL},
89 /* 3 */
90 {quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 5,
91 OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0, 0, 0, "edit-word-wrap", NULL, NULL},
92 /* 4 */
93 {quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H,
94 N_("Tab spacing: "), 0, 0, 0, 0, NULL, NULL, NULL},
95 /* 5 */
96 {quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 6,
97 OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0, 0, 0,
98 "edit-tab-spacing", NULL, NULL},
99 /* 6 */
100 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8,
101 OPT_DLG_H, N_("Cursor beyond end of line"), 8, 0, 0, 0, NULL, NULL, NULL},
102 /* 7 */
103 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9,
104 OPT_DLG_H, N_("Pers&istent selection"), 8, 0, 0, 0, NULL, NULL, NULL},
105 /* 8 */
106 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10,
107 OPT_DLG_H, N_("Synta&x highlighting"), 8, 0, 0, 0, NULL, NULL, NULL},
108 /* 9 */
109 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11,
110 OPT_DLG_H, N_("Visible tabs"), 8, 0, 0, 0, NULL, NULL, NULL},
111 /* 10 */
112 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12,
113 OPT_DLG_H, N_("Visible trailing spaces"), 8, 0, 0, 0, NULL, NULL, NULL},
114 /* 11 */
115 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 13,
116 OPT_DLG_H, N_("Save file &position"), 0, 0, 0, 0, NULL, NULL, NULL},
117 /* 12 */
118 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 14,
119 OPT_DLG_H, N_("Confir&m before saving"), 6, 0, 0, 0, NULL, NULL, NULL},
120 /* 13 */
121 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 15,
122 OPT_DLG_H, N_("Fill tabs with &spaces"), 0, 0, 0, 0, NULL, NULL, NULL},
123 /* 14 */
124 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 16,
125 OPT_DLG_H, N_("&Return does autoindent"), 0, 0, 0, 0, NULL, NULL, NULL},
126 /* 15 */
127 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 17,
128 OPT_DLG_H, N_("&Backspace through tabs"), 0, 0, 0, 0, NULL, NULL, NULL},
129 /* 16 */
130 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 18,
131 OPT_DLG_H, N_("&Fake half tabs"), 0, 0, 0, 0, NULL, NULL, NULL},
132 /* 17 */
133 {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, "", 3, 0, 0,
134 const_cast(char **, wrap_str), "wrapm", NULL, NULL},
135 /* 18 */
136 {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H,
137 N_("Wrap mode"), 0, 0, 0, 0, NULL, NULL, NULL},
138 /* 19 */
139 {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 17, OPT_DLG_H, "", 3, 0, 0,
140 const_cast(char **, key_emu_str), "keyemu", NULL, NULL},
141 /* 20 */
142 {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 18, OPT_DLG_H,
143 N_("Key emulation"), 0, 0, 0, 0, NULL, NULL, NULL},
144 NULL_QuickWidget
147 QuickDialog Quick_options =
148 { OPT_DLG_W, OPT_DLG_H, -1, 0, N_(" Editor options "), "", 0, 0 };
150 if (!i18n_flag) {
151 i18n_translate_array (key_emu_str);
152 i18n_translate_array (wrap_str);
153 i18n_flag = 1;
156 g_snprintf (wrap_length, sizeof (wrap_length), "%d",
157 option_word_wrap_line_length);
158 g_snprintf (tab_spacing, sizeof (tab_spacing), "%d",
159 option_tab_spacing);
161 quick_widgets[3].text = wrap_length;
162 quick_widgets[3].str_result = &p;
163 quick_widgets[5].text = tab_spacing;
164 quick_widgets[5].str_result = &q;
165 quick_widgets[6].result = &tedit_cursor_beyond_eol;
166 quick_widgets[7].result = &tedit_persistent_selections;
167 quick_widgets[8].result = &tedit_syntax_highlighting;
168 quick_widgets[9].result = &tedit_visible_tabs;
169 quick_widgets[10].result = &tedit_visible_tws;
170 quick_widgets[11].result = &toption_save_position;
171 quick_widgets[12].result = &tedit_confirm_save;
172 quick_widgets[13].result = &toption_fill_tabs_with_spaces;
173 quick_widgets[14].result = &toption_return_does_auto_indent;
174 quick_widgets[15].result = &toption_backspace_through_tabs;
175 quick_widgets[16].result = &toption_fake_half_tabs;
177 if (option_auto_para_formatting)
178 wrap_mode = 1;
179 else if (option_typewriter_wrap)
180 wrap_mode = 2;
181 else
182 wrap_mode = 0;
184 quick_widgets[17].result = &wrap_mode;
185 quick_widgets[17].value = wrap_mode;
187 quick_widgets[19].result = &tedit_key_emulation;
188 quick_widgets[19].value = tedit_key_emulation;
190 Quick_options.widgets = quick_widgets;
192 if (quick_dialog (&Quick_options) == B_CANCEL)
193 return;
195 old_syntax_hl = option_syntax_highlighting;
197 if (p) {
198 option_word_wrap_line_length = atoi (p);
199 g_free (p);
201 if (q) {
202 option_tab_spacing = atoi (q);
203 if (option_tab_spacing <= 0)
204 option_tab_spacing = 8;
205 g_free (q);
208 option_cursor_beyond_eol = tedit_cursor_beyond_eol;
209 option_persistent_selections = tedit_persistent_selections;
210 option_syntax_highlighting = tedit_syntax_highlighting;
211 visible_tabs = tedit_visible_tabs;
212 visible_tws = tedit_visible_tws;
213 edit_confirm_save = tedit_confirm_save;
214 option_save_position = toption_save_position;
215 option_fill_tabs_with_spaces = toption_fill_tabs_with_spaces;
216 option_return_does_auto_indent = toption_return_does_auto_indent;
217 option_backspace_through_tabs = toption_backspace_through_tabs;
218 option_fake_half_tabs = toption_fake_half_tabs;
220 if (wrap_mode == 1) {
221 option_auto_para_formatting = 1;
222 option_typewriter_wrap = 0;
223 } else if (wrap_mode == 2) {
224 option_auto_para_formatting = 0;
225 option_typewriter_wrap = 1;
226 } else {
227 option_auto_para_formatting = 0;
228 option_typewriter_wrap = 0;
231 /* Reload menu if key emulation has changed */
232 if (edit_key_emulation != tedit_key_emulation) {
233 edit_key_emulation = tedit_key_emulation;
234 edit_reload_menu ();
237 /* Load or unload syntax rules if the option has changed */
238 if (option_syntax_highlighting != old_syntax_hl)
239 edit_load_syntax (wedit, NULL, option_syntax_type);
240 /* Load usermap if it's needed */
241 edit_load_user_map (wedit);