Extend QUICK_INPUT and QUICK_LABELED_INPUT macros for getting completion flags via...
[midnight-commander.git] / src / editor / editoptions.c
blob08e9719a157f05f5d7a143153e4da165ba809236
1 /*
2 Editor options dialog box
4 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2007, 2011,
5 2012
6 The Free Software Foundation, Inc.
8 Written by:
9 Paul Sheer, 1996, 1997
10 Andrew Borodin <aborodin@vmail.ru>, 2012
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 /** \file
29 * \brief Source: editor options dialog box
30 * \author Paul Sheer
31 * \date 1996, 1997
34 #include <config.h>
36 #include <stdlib.h> /* atoi(), NULL */
38 #include "lib/global.h"
39 #include "lib/widget.h"
41 #include "editwidget.h"
42 #include "edit-impl.h"
43 #include "src/setup.h" /* option_tab_spacing */
45 /*** global variables ****************************************************************************/
47 /*** file scope macro definitions ****************************************************************/
49 /*** file scope type declarations ****************************************************************/
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 /*** file scope functions ************************************************************************/
61 /* --------------------------------------------------------------------------------------------- */
63 #ifdef ENABLE_NLS
64 static void
65 i18n_translate_array (const char *array[])
67 while (*array != NULL)
69 *array = _(*array);
70 array++;
73 #endif /* ENABLE_NLS */
74 /* --------------------------------------------------------------------------------------------- */
75 /**
76 * Callback for the iteration of objects in the 'editors' array.
77 * Tear down 'over_col' property in all editors.
79 * @param data probably WEdit object
80 * @param user_data unused
83 static void
84 edit_reset_over_col (void *data, void *user_data)
86 (void) user_data;
88 if (edit_widget_is_editor ((const Widget *) data))
89 ((WEdit *) data)->over_col = 0;
92 /* --------------------------------------------------------------------------------------------- */
93 /**
94 * Callback for the iteration of objects in the 'editors' array.
95 * Reload syntax lighlighting in all editors.
97 * @param data probably WEdit object
98 * @param user_data unused
101 static void
102 edit_reload_syntax (void *data, void *user_data)
104 (void) user_data;
106 if (edit_widget_is_editor (WIDGET (data)))
108 WEdit *edit = (WEdit *) data;
109 edit_load_syntax (edit, NULL, edit->syntax_type);
113 /* --------------------------------------------------------------------------------------------- */
114 /*** public functions ****************************************************************************/
115 /* --------------------------------------------------------------------------------------------- */
117 void
118 edit_options_dialog (WDialog * h)
120 char wrap_length[16], tab_spacing[16];
121 char *p, *q;
122 int wrap_mode = 0;
123 int old_syntax_hl;
125 #ifdef ENABLE_NLS
126 static gboolean i18n_flag = FALSE;
128 if (!i18n_flag)
130 i18n_translate_array (wrap_str);
131 i18n_flag = TRUE;
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)
139 wrap_mode = 1;
140 else if (option_typewriter_wrap)
141 wrap_mode = 2;
142 else
143 wrap_mode = 0;
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_START_GROUPBOX (N_("Tabulation")),
154 QUICK_CHECKBOX (N_("&Fake half tabs"), &option_fake_half_tabs, NULL),
155 QUICK_CHECKBOX (N_("&Backspace through tabs"), &option_backspace_through_tabs,
156 NULL),
157 QUICK_CHECKBOX (N_("Fill tabs with &spaces"), &option_fill_tabs_with_spaces,
158 NULL),
159 QUICK_LABELED_INPUT (N_("Tab spacing:"), input_label_left, tab_spacing,
160 "edit-tab-spacing", &q, NULL, FALSE, FALSE, INPUT_COMPLETE_DEFAULT),
161 QUICK_STOP_GROUPBOX,
162 QUICK_NEXT_COLUMN,
163 QUICK_START_GROUPBOX (N_("Other options")),
164 QUICK_CHECKBOX (N_("&Return does autoindent"), &option_return_does_auto_indent,
165 NULL),
166 QUICK_CHECKBOX (N_("Confir&m before saving"), &edit_confirm_save, NULL),
167 QUICK_CHECKBOX (N_("Save file &position"), &option_save_position, NULL),
168 QUICK_CHECKBOX (N_("&Visible trailing spaces"), &visible_tws, NULL),
169 QUICK_CHECKBOX (N_("Visible &tabs"), &visible_tabs, NULL),
170 QUICK_CHECKBOX (N_("Synta&x highlighting"), &option_syntax_highlighting, NULL),
171 QUICK_CHECKBOX (N_("C&ursor after inserted block"), &option_cursor_after_inserted_block, NULL),
172 QUICK_CHECKBOX (N_("Pers&istent selection"), &option_persistent_selections,
173 NULL),
174 QUICK_CHECKBOX (N_("Cursor be&yond end of line"), &option_cursor_beyond_eol,
175 NULL),
176 QUICK_CHECKBOX (N_("&Group undo"), &option_group_undo, NULL),
177 QUICK_LABELED_INPUT (N_("Word wrap line length:"), input_label_left, wrap_length,
178 "edit-word-wrap", &p, NULL, FALSE, FALSE, INPUT_COMPLETE_DEFAULT),
179 QUICK_STOP_GROUPBOX,
180 QUICK_STOP_COLUMNS,
181 QUICK_BUTTONS_OK_CANCEL,
182 QUICK_END
183 /* *INDENT-ON* */
186 quick_dialog_t qdlg = {
187 -1, -1, 74,
188 N_("Editor options"), "[Editor options]",
189 quick_widgets, NULL, NULL
192 if (quick_dialog (&qdlg) == B_CANCEL)
193 return;
196 old_syntax_hl = option_syntax_highlighting;
198 if (!option_cursor_beyond_eol)
199 g_list_foreach (h->widgets, edit_reset_over_col, NULL);
201 if (p != NULL)
203 option_word_wrap_line_length = atoi (p);
204 if (option_word_wrap_line_length <= 0)
205 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
206 g_free (p);
209 if (q != NULL)
211 option_tab_spacing = atoi (q);
212 if (option_tab_spacing <= 0)
213 option_tab_spacing = DEFAULT_TAB_SPACING;
214 g_free (q);
217 if (wrap_mode == 1)
219 option_auto_para_formatting = 1;
220 option_typewriter_wrap = 0;
222 else if (wrap_mode == 2)
224 option_auto_para_formatting = 0;
225 option_typewriter_wrap = 1;
227 else
229 option_auto_para_formatting = 0;
230 option_typewriter_wrap = 0;
233 /* Load or unload syntax rules if the option has changed */
234 if (option_syntax_highlighting != old_syntax_hl)
235 g_list_foreach (h->widgets, edit_reload_syntax, NULL);
238 /* --------------------------------------------------------------------------------------------- */