2 Editor options dialog box
4 Copyright (C) 1996-2024
5 Free Software Foundation, Inc.
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/>.
28 * \brief Source: editor options dialog box
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
[] = {
55 N_("&Dynamic paragraphing"),
56 N_("Type &writer wrap"),
60 /* --------------------------------------------------------------------------------------------- */
61 /*** file scope functions ************************************************************************/
62 /* --------------------------------------------------------------------------------------------- */
66 i18n_translate_array (const char *array
[])
68 while (*array
!= NULL
)
74 #endif /* ENABLE_NLS */
76 /* --------------------------------------------------------------------------------------------- */
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
86 edit_reset_over_col (void *data
, void *user_data
)
90 if (edit_widget_is_editor (CONST_WIDGET (data
)))
91 EDIT (data
)->over_col
= 0;
94 /* --------------------------------------------------------------------------------------------- */
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
104 edit_reload_syntax (void *data
, 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 /* --------------------------------------------------------------------------------------------- */
121 edit_options_dialog (WDialog
*h
)
123 char wrap_length
[16], tab_spacing
[16];
126 gboolean old_syntax_hl
;
129 static gboolean i18n_flag
= FALSE
;
133 i18n_translate_array (wrap_str
);
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
)
143 else if (edit_options
.typewriter_wrap
)
149 quick_widget_t quick_widgets
[] = {
152 QUICK_START_GROUPBOX (N_("Wrap mode")),
153 QUICK_RADIO (3, wrap_str
, &wrap_mode
, NULL
),
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
),
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
),
183 QUICK_BUTTONS_OK_CANCEL
,
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
)
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
);
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
;
216 TAB_SIZE
= DEFAULT_TAB_SPACING
;
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
;
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 /* --------------------------------------------------------------------------------------------- */