2 Editor options dialog box
4 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2007, 2011,
6 The Free Software Foundation, Inc.
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/>.
29 * \brief Source: editor options dialog box
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 ****************************************************************/
52 /*** file scope type declarations ****************************************************************/
54 /*** file scope variables ************************************************************************/
56 static const char *wrap_str
[] = {
58 N_("Dynamic paragraphing"),
59 N_("Type writer wrap"),
63 /*** file scope functions ************************************************************************/
64 /* --------------------------------------------------------------------------------------------- */
68 i18n_translate_array (const char *array
[])
70 while (*array
!= NULL
)
76 #endif /* ENABLE_NLS */
77 /* --------------------------------------------------------------------------------------------- */
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
87 edit_reset_over_col (void *data
, void *user_data
)
91 if (edit_widget_is_editor ((const Widget
*) data
))
92 ((WEdit
*) data
)->over_col
= 0;
95 /* --------------------------------------------------------------------------------------------- */
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
105 edit_reload_syntax (void *data
, 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 /* --------------------------------------------------------------------------------------------- */
121 edit_options_dialog (Dlg_head
* h
)
123 char wrap_length
[16], tab_spacing
[16], *p
, *q
;
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")),
166 QuickDialog Quick_options
= {
167 OPT_DLG_W
, OPT_DLG_H
, -1, -1, N_("Editor options"),
168 "[Editor options]", quick_widgets
, NULL
, NULL
, FALSE
172 static gboolean i18n_flag
= FALSE
;
176 i18n_translate_array (wrap_str
);
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
)
186 else if (option_typewriter_wrap
)
191 if (quick_dialog (&Quick_options
) == B_CANCEL
)
194 old_syntax_hl
= option_syntax_highlighting
;
196 if (!option_cursor_beyond_eol
)
197 g_list_foreach (h
->widgets
, edit_reset_over_col
, 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
;
209 option_tab_spacing
= atoi (q
);
210 if (option_tab_spacing
<= 0)
211 option_tab_spacing
= DEFAULT_TAB_SPACING
;
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;
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 /* --------------------------------------------------------------------------------------------- */