Aggressive use WIDGET macro.
[midnight-commander.git] / src / editor / editoptions.c
blobc6a08f6ac4ed3c3755ab6cf31ce1efbb1dc8923a
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 #define OPT_DLG_H 17
50 #define OPT_DLG_W 74
52 /*** file scope type declarations ****************************************************************/
54 /*** file scope variables ************************************************************************/
56 static const char *wrap_str[] = {
57 N_("None"),
58 N_("Dynamic paragraphing"),
59 N_("Type writer wrap"),
60 NULL
63 /*** file scope functions ************************************************************************/
64 /* --------------------------------------------------------------------------------------------- */
66 #ifdef ENABLE_NLS
67 static void
68 i18n_translate_array (const char *array[])
70 while (*array != NULL)
72 *array = _(*array);
73 array++;
76 #endif /* ENABLE_NLS */
77 /* --------------------------------------------------------------------------------------------- */
78 /**
79 * Callback for the iteration of objects in the 'editors' array.
80 * Tear down 'over_col' property in all editors.
82 * @param data probably WEdit object
83 * @param user_data unused
86 static void
87 edit_reset_over_col (void *data, void *user_data)
89 (void) user_data;
91 if (edit_widget_is_editor ((const Widget *) data))
92 ((WEdit *) data)->over_col = 0;
95 /* --------------------------------------------------------------------------------------------- */
96 /**
97 * Callback for the iteration of objects in the 'editors' array.
98 * Reload syntax lighlighting in all editors.
100 * @param data probably WEdit object
101 * @param user_data unused
104 static void
105 edit_reload_syntax (void *data, void *user_data)
107 (void) user_data;
109 if (edit_widget_is_editor (WIDGET (data)))
111 WEdit *edit = (WEdit *) data;
112 edit_load_syntax (edit, NULL, edit->syntax_type);
116 /* --------------------------------------------------------------------------------------------- */
117 /*** public functions ****************************************************************************/
118 /* --------------------------------------------------------------------------------------------- */
120 void
121 edit_options_dialog (Dlg_head * h)
123 char wrap_length[16], tab_spacing[16], *p, *q;
124 int wrap_mode = 0;
125 int old_syntax_hl;
127 QuickWidget quick_widgets[] = {
128 /* 0 */ QUICK_BUTTON (6, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Cancel"), B_CANCEL, NULL),
129 /* 1 */ QUICK_BUTTON (2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&OK"), B_ENTER, NULL),
130 /* 2 */ QUICK_LABEL (OPT_DLG_W / 2 + 1, OPT_DLG_W, 12, OPT_DLG_H,
131 N_("Word wrap line length:")),
132 /* 3 */ QUICK_INPUT (OPT_DLG_W / 2 + 25, OPT_DLG_W, 12, OPT_DLG_H,
133 wrap_length, OPT_DLG_W / 2 - 4 - 24, 0, "edit-word-wrap", &p),
134 /* 4 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 11, OPT_DLG_H,
135 N_("&Group undo"), &option_group_undo),
136 /* 5 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 10, OPT_DLG_H,
137 N_("Cursor beyond end of line"), &option_cursor_beyond_eol),
138 /* 6 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 9, OPT_DLG_H,
139 N_("Pers&istent selection"), &option_persistent_selections),
140 /* 7 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 8, OPT_DLG_H,
141 N_("Synta&x highlighting"), &option_syntax_highlighting),
142 /* 8 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 7, OPT_DLG_H,
143 N_("Visible tabs"), &visible_tabs),
144 /* 9 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 6, OPT_DLG_H,
145 N_("Visible trailing spaces"), &visible_tws),
146 /* 10 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 5, OPT_DLG_H,
147 N_("Save file &position"), &option_save_position),
148 /* 11 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 4, OPT_DLG_H,
149 N_("Confir&m before saving"), &edit_confirm_save),
150 /* 12 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 3, OPT_DLG_H,
151 N_("&Return does autoindent"), &option_return_does_auto_indent),
152 /* 13 */ QUICK_LABEL (3, OPT_DLG_W, 11, OPT_DLG_H, N_("Tab spacing:")),
153 /* 14 */ QUICK_INPUT (3 + 24, OPT_DLG_W, 11, OPT_DLG_H,
154 tab_spacing, OPT_DLG_W / 2 - 4 - 24, 0, "edit-tab-spacing", &q),
155 /* 15 */ QUICK_CHECKBOX (3, OPT_DLG_W, 10, OPT_DLG_H,
156 N_("Fill tabs with &spaces"), &option_fill_tabs_with_spaces),
157 /* 16 */ QUICK_CHECKBOX (3, OPT_DLG_W, 9, OPT_DLG_H,
158 N_("&Backspace through tabs"), &option_backspace_through_tabs),
159 /* 17 */ QUICK_CHECKBOX (3, OPT_DLG_W, 8, OPT_DLG_H,
160 N_("&Fake half tabs"), &option_fake_half_tabs),
161 /* 18 */ QUICK_RADIO (4, OPT_DLG_W, 4, OPT_DLG_H, 3, wrap_str, &wrap_mode),
162 /* 19 */ QUICK_LABEL (3, OPT_DLG_W, 3, OPT_DLG_H, N_("Wrap mode")),
163 QUICK_END
166 QuickDialog Quick_options = {
167 OPT_DLG_W, OPT_DLG_H, -1, -1, N_("Editor options"),
168 "[Editor options]", quick_widgets, NULL, NULL, FALSE
171 #ifdef ENABLE_NLS
172 static gboolean i18n_flag = FALSE;
174 if (!i18n_flag)
176 i18n_translate_array (wrap_str);
177 i18n_flag = TRUE;
179 #endif /* ENABLE_NLS */
181 g_snprintf (wrap_length, sizeof (wrap_length), "%d", option_word_wrap_line_length);
182 g_snprintf (tab_spacing, sizeof (tab_spacing), "%d", option_tab_spacing);
184 if (option_auto_para_formatting)
185 wrap_mode = 1;
186 else if (option_typewriter_wrap)
187 wrap_mode = 2;
188 else
189 wrap_mode = 0;
191 if (quick_dialog (&Quick_options) == B_CANCEL)
192 return;
194 old_syntax_hl = option_syntax_highlighting;
196 if (!option_cursor_beyond_eol)
197 g_list_foreach (h->widgets, edit_reset_over_col, NULL);
199 if (p != NULL)
201 option_word_wrap_line_length = atoi (p);
202 if (option_word_wrap_line_length <= 0)
203 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
204 g_free (p);
207 if (q != NULL)
209 option_tab_spacing = atoi (q);
210 if (option_tab_spacing <= 0)
211 option_tab_spacing = DEFAULT_TAB_SPACING;
212 g_free (q);
215 if (wrap_mode == 1)
217 option_auto_para_formatting = 1;
218 option_typewriter_wrap = 0;
220 else if (wrap_mode == 2)
222 option_auto_para_formatting = 0;
223 option_typewriter_wrap = 1;
225 else
227 option_auto_para_formatting = 0;
228 option_typewriter_wrap = 0;
231 /* Load or unload syntax rules if the option has changed */
232 if (option_syntax_highlighting != old_syntax_hl)
233 g_list_foreach (h->widgets, edit_reload_syntax, NULL);
236 /* --------------------------------------------------------------------------------------------- */