Ticket #4556: color definitions in the "c.syntax" highlight file.
[midnight-commander.git] / src / editor / editoptions.c
blobe9181f4cb90c207c21db66af517d325d4dafef85
1 /*
2 Editor options dialog box
4 Copyright (C) 1996-2024
5 Free Software Foundation, Inc.
7 Written by:
8 Paul Sheer, 1996, 1997
9 Andrew Borodin <aborodin@vmail.ru>, 2012-2022
11 This file is part of the Midnight Commander.
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.
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.
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/>.
27 /** \file
28 * \brief Source: editor options dialog box
29 * \author Paul Sheer
30 * \date 1996, 1997
33 #include <config.h>
35 #include <stdlib.h> /* atoi(), NULL */
37 #include "lib/global.h"
38 #include "lib/widget.h"
40 #include "editwidget.h"
41 #include "edit-impl.h"
43 /*** global variables ****************************************************************************/
45 /*** file scope macro definitions ****************************************************************/
47 /*** file scope type declarations ****************************************************************/
49 /*** forward declarations (file scope functions) *************************************************/
51 /*** file scope variables ************************************************************************/
53 static const char *wrap_str[] = {
54 N_("&None"),
55 N_("&Dynamic paragraphing"),
56 N_("Type &writer wrap"),
57 NULL
60 /* --------------------------------------------------------------------------------------------- */
61 /*** file scope functions ************************************************************************/
62 /* --------------------------------------------------------------------------------------------- */
64 #ifdef ENABLE_NLS
65 static void
66 i18n_translate_array (const char *array[])
68 while (*array != NULL)
70 *array = _(*array);
71 array++;
74 #endif /* ENABLE_NLS */
76 /* --------------------------------------------------------------------------------------------- */
77 /**
78 * Callback for the iteration of objects in the 'editors' array.
79 * Tear down 'over_col' property in all editors.
81 * @param data probably WEdit object
82 * @param user_data unused
85 static void
86 edit_reset_over_col (void *data, void *user_data)
88 (void) user_data;
90 if (edit_widget_is_editor (CONST_WIDGET (data)))
91 EDIT (data)->over_col = 0;
94 /* --------------------------------------------------------------------------------------------- */
95 /**
96 * Callback for the iteration of objects in the 'editors' array.
97 * Reload syntax lighlighting in all editors.
99 * @param data probably WEdit object
100 * @param user_data unused
103 static void
104 edit_reload_syntax (void *data, void *user_data)
106 (void) user_data;
108 if (edit_widget_is_editor (CONST_WIDGET (data)))
110 WEdit *edit = EDIT (data);
112 edit_load_syntax (edit, NULL, edit->syntax_type);
116 /* --------------------------------------------------------------------------------------------- */
117 /*** public functions ****************************************************************************/
118 /* --------------------------------------------------------------------------------------------- */
120 void
121 edit_options_dialog (WDialog *h)
123 char wrap_length[16], tab_spacing[16];
124 char *p, *q;
125 int wrap_mode = 0;
126 gboolean old_syntax_hl;
128 #ifdef ENABLE_NLS
129 static gboolean i18n_flag = FALSE;
131 if (!i18n_flag)
133 i18n_translate_array (wrap_str);
134 i18n_flag = TRUE;
136 #endif /* ENABLE_NLS */
138 g_snprintf (wrap_length, sizeof (wrap_length), "%d", edit_options.word_wrap_line_length);
139 g_snprintf (tab_spacing, sizeof (tab_spacing), "%d", TAB_SIZE);
141 if (edit_options.auto_para_formatting)
142 wrap_mode = 1;
143 else if (edit_options.typewriter_wrap)
144 wrap_mode = 2;
145 else
146 wrap_mode = 0;
149 quick_widget_t quick_widgets[] = {
150 /* *INDENT-OFF* */
151 QUICK_START_COLUMNS,
152 QUICK_START_GROUPBOX (N_("Wrap mode")),
153 QUICK_RADIO (3, wrap_str, &wrap_mode, NULL),
154 QUICK_STOP_GROUPBOX,
155 QUICK_SEPARATOR (FALSE),
156 QUICK_SEPARATOR (FALSE),
157 QUICK_START_GROUPBOX (N_("Tabulation")),
158 QUICK_CHECKBOX (N_("&Fake half tabs"), &edit_options.fake_half_tabs, NULL),
159 QUICK_CHECKBOX (N_("&Backspace through tabs"),
160 &edit_options.backspace_through_tabs, NULL),
161 QUICK_CHECKBOX (N_("Fill tabs with &spaces"),
162 &edit_options.fill_tabs_with_spaces, NULL),
163 QUICK_LABELED_INPUT (N_("Tab spacing:"), input_label_left, tab_spacing,
164 "edit-tab-spacing", &q, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE),
165 QUICK_STOP_GROUPBOX,
166 QUICK_NEXT_COLUMN,
167 QUICK_START_GROUPBOX (N_("Other options")),
168 QUICK_CHECKBOX (N_("&Return does autoindent"), &edit_options.return_does_auto_indent, NULL),
169 QUICK_CHECKBOX (N_("Confir&m before saving"), &edit_options.confirm_save, NULL),
170 QUICK_CHECKBOX (N_("Save file &position"), &edit_options.save_position, NULL),
171 QUICK_CHECKBOX (N_("&Visible trailing spaces"), &edit_options.visible_tws, NULL),
172 QUICK_CHECKBOX (N_("Visible &tabs"), &edit_options.visible_tabs, NULL),
173 QUICK_CHECKBOX (N_("Synta&x highlighting"), &edit_options.syntax_highlighting, NULL),
174 QUICK_CHECKBOX (N_("C&ursor after inserted block"),
175 &edit_options.cursor_after_inserted_block, NULL),
176 QUICK_CHECKBOX (N_("Pers&istent selection"), &edit_options.persistent_selections, NULL),
177 QUICK_CHECKBOX (N_("Cursor be&yond end of line"), &edit_options.cursor_beyond_eol, NULL),
178 QUICK_CHECKBOX (N_("&Group undo"), &edit_options.group_undo, NULL),
179 QUICK_LABELED_INPUT (N_("Word wrap line length:"), input_label_left, wrap_length,
180 "edit-word-wrap", &p, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE),
181 QUICK_STOP_GROUPBOX,
182 QUICK_STOP_COLUMNS,
183 QUICK_BUTTONS_OK_CANCEL,
184 QUICK_END
185 /* *INDENT-ON* */
188 WRect r = { -1, -1, 0, 74 };
190 quick_dialog_t qdlg = {
191 r, N_("Editor options"), "[Editor options]",
192 quick_widgets, NULL, NULL
195 if (quick_dialog (&qdlg) == B_CANCEL)
196 return;
199 old_syntax_hl = edit_options.syntax_highlighting;
201 if (!edit_options.cursor_beyond_eol)
202 g_list_foreach (GROUP (h)->widgets, edit_reset_over_col, NULL);
204 if (*p != '\0')
206 edit_options.word_wrap_line_length = atoi (p);
207 if (edit_options.word_wrap_line_length <= 0)
208 edit_options.word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
209 g_free (p);
212 if (*q != '\0')
214 TAB_SIZE = atoi (q);
215 if (TAB_SIZE <= 0)
216 TAB_SIZE = DEFAULT_TAB_SPACING;
217 g_free (q);
220 if (wrap_mode == 1)
222 edit_options.auto_para_formatting = TRUE;
223 edit_options.typewriter_wrap = FALSE;
225 else if (wrap_mode == 2)
227 edit_options.auto_para_formatting = FALSE;
228 edit_options.typewriter_wrap = TRUE;
230 else
232 edit_options.auto_para_formatting = FALSE;
233 edit_options.typewriter_wrap = FALSE;
236 /* Load or unload syntax rules if the option has changed */
237 if (edit_options.syntax_highlighting != old_syntax_hl)
238 g_list_foreach (GROUP (h)->widgets, edit_reload_syntax, NULL);
241 /* --------------------------------------------------------------------------------------------- */