keymap files: unification of Fxx keys: move to lower case.
[midnight-commander.git] / src / editor / editoptions.c
blobece015c0d74d28679555cb60e11d800e5619ed73
1 /* editor options dialog box
3 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2007
4 Free Software Foundation, Inc.
6 Authors: 1996, 1997 Paul Sheer
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA.
24 /** \file
25 * \brief Source: editor options dialog box
26 * \author Paul Sheer
27 * \date 1996, 1997
30 #include <config.h>
32 #include <stdlib.h> /* atoi(), NULL */
34 #include "lib/global.h"
35 #include "lib/widget.h"
37 #include "edit-widget.h"
38 #include "edit-impl.h"
39 #include "src/setup.h" /* option_tab_spacing */
41 /*** global variables ****************************************************************************/
43 /*** file scope macro definitions ****************************************************************/
45 #define OPT_DLG_H 17
46 #define OPT_DLG_W 74
48 /*** file scope type declarations ****************************************************************/
50 /*** file scope variables ************************************************************************/
52 static const char *wrap_str[] = {
53 N_("None"),
54 N_("Dynamic paragraphing"),
55 N_("Type writer wrap"),
56 NULL
59 /*** file scope functions ************************************************************************/
60 /* --------------------------------------------------------------------------------------------- */
62 #ifdef ENABLE_NLS
63 static void
64 i18n_translate_array (const char *array[])
66 while (*array != NULL)
68 *array = _(*array);
69 array++;
72 #endif /* ENABLE_NLS */
74 /* --------------------------------------------------------------------------------------------- */
75 /*** public functions ****************************************************************************/
76 /* --------------------------------------------------------------------------------------------- */
78 void
79 edit_options_dialog (WEdit * edit)
81 char wrap_length[16], tab_spacing[16], *p, *q;
82 int wrap_mode = 0;
83 int old_syntax_hl;
85 QuickWidget quick_widgets[] = {
86 /* 0 */ QUICK_BUTTON (6, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Cancel"), B_CANCEL, NULL),
87 /* 1 */ QUICK_BUTTON (2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&OK"), B_ENTER, NULL),
88 /* 2 */ QUICK_LABEL (OPT_DLG_W / 2 + 1, OPT_DLG_W, 12, OPT_DLG_H,
89 N_("Word wrap line length:")),
90 /* 3 */ QUICK_INPUT (OPT_DLG_W / 2 + 25, OPT_DLG_W, 12, OPT_DLG_H,
91 wrap_length, OPT_DLG_W / 2 - 4 - 24, 0, "edit-word-wrap", &p),
92 /* 4 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 11, OPT_DLG_H,
93 N_("&Group undo"), &option_group_undo),
94 /* 5 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 10, OPT_DLG_H,
95 N_("Cursor beyond end of line"), &option_cursor_beyond_eol),
96 /* 6 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 9, OPT_DLG_H,
97 N_("Pers&istent selection"), &option_persistent_selections),
98 /* 7 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 8, OPT_DLG_H,
99 N_("Synta&x highlighting"), &option_syntax_highlighting),
100 /* 8 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 7, OPT_DLG_H,
101 N_("Visible tabs"), &visible_tabs),
102 /* 9 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 6, OPT_DLG_H,
103 N_("Visible trailing spaces"), &visible_tws),
104 /* 10 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 5, OPT_DLG_H,
105 N_("Save file &position"), &option_save_position),
106 /* 11 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 4, OPT_DLG_H,
107 N_("Confir&m before saving"), &edit_confirm_save),
108 /* 12 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, 3, OPT_DLG_H,
109 N_("&Return does autoindent"), &option_return_does_auto_indent),
110 /* 13 */ QUICK_LABEL (3, OPT_DLG_W, 11, OPT_DLG_H, N_("Tab spacing:")),
111 /* 14 */ QUICK_INPUT (3 + 24, OPT_DLG_W, 11, OPT_DLG_H,
112 tab_spacing, OPT_DLG_W / 2 - 4 - 24, 0, "edit-tab-spacing", &q),
113 /* 15 */ QUICK_CHECKBOX (3, OPT_DLG_W, 10, OPT_DLG_H,
114 N_("Fill tabs with &spaces"), &option_fill_tabs_with_spaces),
115 /* 16 */ QUICK_CHECKBOX (3, OPT_DLG_W, 9, OPT_DLG_H,
116 N_("&Backspace through tabs"), &option_backspace_through_tabs),
117 /* 17 */ QUICK_CHECKBOX (3, OPT_DLG_W, 8, OPT_DLG_H,
118 N_("&Fake half tabs"), &option_fake_half_tabs),
119 /* 18 */ QUICK_RADIO (4, OPT_DLG_W, 4, OPT_DLG_H, 3, wrap_str, &wrap_mode),
120 /* 19 */ QUICK_LABEL (3, OPT_DLG_W, 3, OPT_DLG_H, N_("Wrap mode")),
121 QUICK_END
124 QuickDialog Quick_options = {
125 OPT_DLG_W, OPT_DLG_H, -1, -1, N_("Editor options"),
126 "[Editor options]", quick_widgets, NULL, FALSE
129 #ifdef ENABLE_NLS
130 static gboolean i18n_flag = FALSE;
132 if (!i18n_flag)
134 i18n_translate_array (wrap_str);
135 i18n_flag = TRUE;
137 #endif /* ENABLE_NLS */
139 g_snprintf (wrap_length, sizeof (wrap_length), "%d", option_word_wrap_line_length);
140 g_snprintf (tab_spacing, sizeof (tab_spacing), "%d", option_tab_spacing);
142 if (option_auto_para_formatting)
143 wrap_mode = 1;
144 else if (option_typewriter_wrap)
145 wrap_mode = 2;
146 else
147 wrap_mode = 0;
149 if (quick_dialog (&Quick_options) == B_CANCEL)
150 return;
152 old_syntax_hl = option_syntax_highlighting;
154 if (!option_cursor_beyond_eol)
155 edit->over_col = 0;
157 if (p != NULL)
159 option_word_wrap_line_length = atoi (p);
160 if (option_word_wrap_line_length <= 0)
161 option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
162 g_free (p);
165 if (q != NULL)
167 option_tab_spacing = atoi (q);
168 if (option_tab_spacing <= 0)
169 option_tab_spacing = DEFAULT_TAB_SPACING;
170 g_free (q);
173 if (wrap_mode == 1)
175 option_auto_para_formatting = 1;
176 option_typewriter_wrap = 0;
178 else if (wrap_mode == 2)
180 option_auto_para_formatting = 0;
181 option_typewriter_wrap = 1;
183 else
185 option_auto_para_formatting = 0;
186 option_typewriter_wrap = 0;
189 /* Load or unload syntax rules if the option has changed */
190 if (option_syntax_highlighting != old_syntax_hl)
191 edit_load_syntax (edit, NULL, edit->syntax_type);
194 /* --------------------------------------------------------------------------------------------- */