2 Editor options dialog box
4 Copyright (C) 1996-2016
5 Free Software Foundation, Inc.
9 Andrew Borodin <aborodin@vmail.ru>, 2012
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"
42 #include "src/setup.h" /* option_tab_spacing */
44 /*** global variables ****************************************************************************/
46 /*** file scope macro definitions ****************************************************************/
48 /*** file scope type declarations ****************************************************************/
50 /*** file scope variables ************************************************************************/
52 static const char *wrap_str
[] = {
54 N_("&Dynamic paragraphing"),
55 N_("Type &writer wrap"),
59 /*** file scope functions ************************************************************************/
60 /* --------------------------------------------------------------------------------------------- */
64 i18n_translate_array (const char *array
[])
66 while (*array
!= NULL
)
72 #endif /* ENABLE_NLS */
73 /* --------------------------------------------------------------------------------------------- */
75 * Callback for the iteration of objects in the 'editors' array.
76 * Tear down 'over_col' property in all editors.
78 * @param data probably WEdit object
79 * @param user_data unused
83 edit_reset_over_col (void *data
, void *user_data
)
87 if (edit_widget_is_editor (CONST_WIDGET (data
)))
88 ((WEdit
*) data
)->over_col
= 0;
91 /* --------------------------------------------------------------------------------------------- */
93 * Callback for the iteration of objects in the 'editors' array.
94 * Reload syntax lighlighting in all editors.
96 * @param data probably WEdit object
97 * @param user_data unused
101 edit_reload_syntax (void *data
, void *user_data
)
105 if (edit_widget_is_editor (CONST_WIDGET (data
)))
107 WEdit
*edit
= (WEdit
*) data
;
109 edit_load_syntax (edit
, NULL
, edit
->syntax_type
);
113 /* --------------------------------------------------------------------------------------------- */
114 /*** public functions ****************************************************************************/
115 /* --------------------------------------------------------------------------------------------- */
118 edit_options_dialog (WDialog
* h
)
120 char wrap_length
[16], tab_spacing
[16];
126 static gboolean i18n_flag
= FALSE
;
130 i18n_translate_array (wrap_str
);
133 #endif /* ENABLE_NLS */
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
);
138 if (option_auto_para_formatting
)
140 else if (option_typewriter_wrap
)
146 quick_widget_t quick_widgets
[] = {
149 QUICK_START_GROUPBOX (N_("Wrap mode")),
150 QUICK_RADIO (3, wrap_str
, &wrap_mode
, NULL
),
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
,
158 QUICK_CHECKBOX (N_("Fill tabs with &spaces"), &option_fill_tabs_with_spaces
,
160 QUICK_LABELED_INPUT (N_("Tab spacing:"), input_label_left
, tab_spacing
,
161 "edit-tab-spacing", &q
, NULL
, FALSE
, FALSE
, INPUT_COMPLETE_NONE
),
164 QUICK_START_GROUPBOX (N_("Other options")),
165 QUICK_CHECKBOX (N_("&Return does autoindent"), &option_return_does_auto_indent
,
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
,
175 QUICK_CHECKBOX (N_("Cursor be&yond end of line"), &option_cursor_beyond_eol
,
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
),
182 QUICK_BUTTONS_OK_CANCEL
,
187 quick_dialog_t qdlg
= {
189 N_("Editor options"), "[Editor options]",
190 quick_widgets
, NULL
, NULL
193 if (quick_dialog (&qdlg
) == B_CANCEL
)
197 old_syntax_hl
= option_syntax_highlighting
;
199 if (!option_cursor_beyond_eol
)
200 g_list_foreach (h
->widgets
, edit_reset_over_col
, NULL
);
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
;
212 option_tab_spacing
= atoi (q
);
213 if (option_tab_spacing
<= 0)
214 option_tab_spacing
= DEFAULT_TAB_SPACING
;
220 option_auto_para_formatting
= 1;
221 option_typewriter_wrap
= 0;
223 else if (wrap_mode
== 2)
225 option_auto_para_formatting
= 0;
226 option_typewriter_wrap
= 1;
230 option_auto_para_formatting
= 0;
231 option_typewriter_wrap
= 0;
234 /* Load or unload syntax rules if the option has changed */
235 if (option_syntax_highlighting
!= old_syntax_hl
)
236 g_list_foreach (h
->widgets
, edit_reload_syntax
, NULL
);
239 /* --------------------------------------------------------------------------------------------- */