1 /*
2 Editor options dialog box
3
4 Copyright (C) 1996-2021
5 Free Software Foundation, Inc.
6
7 Written by:
8 Paul Sheer, 1996, 1997
9 Andrew Borodin <aborodin@vmail.ru>, 2012
10
11 This file is part of the Midnight Commander.
12
13 The Midnight Commander is free software: you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation, either version 3 of the License,
16 or (at your option) any later version.
17
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27 /** \file
28 * \brief Source: editor options dialog box
29 * \author Paul Sheer
30 * \date 1996, 1997
31 */
32
33 #include <config.h>
34
35 #include <stdlib.h> /* atoi(), NULL */
36
37 #include "lib/global.h"
38 #include "lib/widget.h"
39
40 #include "editwidget.h"
41 #include "edit-impl.h"
42 #include "src/setup.h" /* option_tab_spacing */
43
44 /*** global variables ****************************************************************************/
45
46 /*** file scope macro definitions ****************************************************************/
47
48 /*** file scope type declarations ****************************************************************/
49
50 /*** file scope variables ************************************************************************/
51
52 static const char *wrap_str[] = {
53 N_("&None"),
54 N_("&Dynamic paragraphing"),
55 N_("Type &writer wrap"),
56 NULL
57 };
58
59 /*** file scope functions ************************************************************************/
60 /* --------------------------------------------------------------------------------------------- */
61
62 #ifdef ENABLE_NLS
63 static void
i18n_translate_array(const char * array[])64 i18n_translate_array (const char *array[])
65 {
66 while (*array != NULL)
67 {
68 *array = _(*array);
69 array++;
70 }
71 }
72 #endif /* ENABLE_NLS */
73 /* --------------------------------------------------------------------------------------------- */
74 /**
75 * Callback for the iteration of objects in the 'editors' array.
76 * Tear down 'over_col' property in all editors.
77 *
78 * @param data probably WEdit object
79 * @param user_data unused
80 */
81
82 static void
edit_reset_over_col(void * data,void * user_data)83 edit_reset_over_col (void *data, void *user_data)
84 {
85 (void) user_data;
86
87 if (edit_widget_is_editor (CONST_WIDGET (data)))
88 ((WEdit *) data)->over_col = 0;
89 }
90
91 /* --------------------------------------------------------------------------------------------- */
92 /**
93 * Callback for the iteration of objects in the 'editors' array.
94 * Reload syntax lighlighting in all editors.
95 *
96 * @param data probably WEdit object
97 * @param user_data unused
98 */
99
100 static void
edit_reload_syntax(void * data,void * user_data)101 edit_reload_syntax (void *data, void *user_data)
102 {
103 (void) user_data;
104
105 if (edit_widget_is_editor (CONST_WIDGET (data)))
106 {
107 WEdit *edit = (WEdit *) data;
108
109 edit_load_syntax (edit, NULL, edit->syntax_type);
110 }
111 }
112
113 /* --------------------------------------------------------------------------------------------- */
114 /*** public functions ****************************************************************************/
115 /* --------------------------------------------------------------------------------------------- */
116
117 void
edit_options_dialog(WDialog * h)118 edit_options_dialog (WDialog * h)
119 {
120 char wrap_length[16], tab_spacing[16];
121 char *p, *q;
122 int wrap_mode = 0;
123 gboolean old_syntax_hl;
124
125 #ifdef ENABLE_NLS
126 static gboolean i18n_flag = FALSE;
127
128 if (!i18n_flag)
129 {
130 i18n_translate_array (wrap_str);
131 i18n_flag = TRUE;
132 }
133 #endif /* ENABLE_NLS */
134
135 g_snprintf (wrap_length, sizeof (wrap_length), "%d", option_word_wrap_line_length);
136 g_snprintf (tab_spacing, sizeof (tab_spacing), "%d", option_tab_spacing);
137
138 if (option_auto_para_formatting)
139 wrap_mode = 1;
140 else if (option_typewriter_wrap)
141 wrap_mode = 2;
142 else
143 wrap_mode = 0;
144
145 {
146 quick_widget_t quick_widgets[] = {
147 /* *INDENT-OFF* */
148 QUICK_START_COLUMNS,
149 QUICK_START_GROUPBOX (N_("Wrap mode")),
150 QUICK_RADIO (3, wrap_str, &wrap_mode, NULL),
151 QUICK_STOP_GROUPBOX,
152 QUICK_SEPARATOR (FALSE),
153 QUICK_SEPARATOR (FALSE),
154 QUICK_START_GROUPBOX (N_("Tabulation")),
155 QUICK_CHECKBOX (N_("&Fake half tabs"), &option_fake_half_tabs, NULL),
156 QUICK_CHECKBOX (N_("&Backspace through tabs"), &option_backspace_through_tabs,
157 NULL),
158 QUICK_CHECKBOX (N_("Fill tabs with &spaces"), &option_fill_tabs_with_spaces,
159 NULL),
160 QUICK_LABELED_INPUT (N_("Tab spacing:"), input_label_left, tab_spacing,
161 "edit-tab-spacing", &q, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE),
162 QUICK_STOP_GROUPBOX,
163 QUICK_NEXT_COLUMN,
164 QUICK_START_GROUPBOX (N_("Other options")),
165 QUICK_CHECKBOX (N_("&Return does autoindent"), &option_return_does_auto_indent,
166 NULL),
167 QUICK_CHECKBOX (N_("Confir&m before saving"), &edit_confirm_save, NULL),
168 QUICK_CHECKBOX (N_("Save file &position"), &option_save_position, NULL),
169 QUICK_CHECKBOX (N_("&Visible trailing spaces"), &visible_tws, NULL),
170 QUICK_CHECKBOX (N_("Visible &tabs"), &visible_tabs, NULL),
171 QUICK_CHECKBOX (N_("Synta&x highlighting"), &option_syntax_highlighting, NULL),
172 QUICK_CHECKBOX (N_("C&ursor after inserted block"), &option_cursor_after_inserted_block, NULL),
173 QUICK_CHECKBOX (N_("Pers&istent selection"), &option_persistent_selections,
174 NULL),
175 QUICK_CHECKBOX (N_("Cursor be&yond end of line"), &option_cursor_beyond_eol,
176 NULL),
177 QUICK_CHECKBOX (N_("&Group undo"), &option_group_undo, NULL),
178 QUICK_LABELED_INPUT (N_("Word wrap line length:"), input_label_left, wrap_length,
179 "edit-word-wrap", &p, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE),
180 QUICK_STOP_GROUPBOX,
181 QUICK_STOP_COLUMNS,
182 QUICK_BUTTONS_OK_CANCEL,
183 QUICK_END
184 /* *INDENT-ON* */
185 };
186
187 quick_dialog_t qdlg = {
188 -1, -1, 74,
189 N_("Editor options"), "[Editor options]",
190 quick_widgets, NULL, NULL
191 };
192
193 if (quick_dialog (&qdlg) == B_CANCEL)
194 return;
195 }
196
197 old_syntax_hl = option_syntax_highlighting;
198
199 if (!option_cursor_beyond_eol)
200 g_list_foreach (GROUP (h)->widgets, edit_reset_over_col, NULL);
201
202 if (p != NULL)
203 {
204 option_word_wrap_line_length = atoi (p);
205 if (option_word_wrap_line_length <= 0)
206 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
207 g_free (p);
208 }
209
210 if (q != NULL)
211 {
212 option_tab_spacing = atoi (q);
213 if (option_tab_spacing <= 0)
214 option_tab_spacing = DEFAULT_TAB_SPACING;
215 g_free (q);
216 }
217
218 if (wrap_mode == 1)
219 {
220 option_auto_para_formatting = TRUE;
221 option_typewriter_wrap = FALSE;
222 }
223 else if (wrap_mode == 2)
224 {
225 option_auto_para_formatting = FALSE;
226 option_typewriter_wrap = TRUE;
227 }
228 else
229 {
230 option_auto_para_formatting = FALSE;
231 option_typewriter_wrap = FALSE;
232 }
233
234 /* Load or unload syntax rules if the option has changed */
235 if (option_syntax_highlighting != old_syntax_hl)
236 g_list_foreach (GROUP (h)->widgets, edit_reload_syntax, NULL);
237 }
238
239 /* --------------------------------------------------------------------------------------------- */
240