* removed edit/usermap.c edit/usermap.h
[midnight-commander.git] / edit / editoptions.c
bloba3d62763f2dccf7f8b5a99501787ba462c8ebe25
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 "../src/global.h"
36 #include "edit-impl.h"
37 #include "../src/dialog.h" /* B_CANCEL */
38 #include "../src/wtools.h" /* QuickDialog */
40 #define OPT_DLG_H 21
41 #define OPT_DLG_W 72
43 static const char *key_emu_str[] =
45 N_("Intuitive"),
46 N_("Emacs"),
47 N_("User-defined"),
48 NULL
51 static const char *wrap_str[] =
53 N_("None"),
54 N_("Dynamic paragraphing"),
55 N_("Type writer wrap"),
56 NULL
59 static void
60 i18n_translate_array (const char *array[])
62 while (*array != NULL) {
63 *array = _(*array);
64 array++;
68 void
69 edit_options_dialog (void)
71 char wrap_length[16], tab_spacing[16], *p, *q;
72 int wrap_mode = 0;
73 int old_syntax_hl;
74 int tedit_key_emulation = edit_key_emulation;
76 QuickWidget quick_widgets[] =
78 /* 0 */ QUICK_BUTTON (6, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Cancel"), B_CANCEL, NULL),
79 /* 1 */ QUICK_BUTTON (2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&OK"), B_ENTER, NULL),
80 /* 2 */ QUICK_LABEL (OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H, N_("Word wrap line length: ")),
81 /* 3 */ QUICK_INPUT (OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H,
82 wrap_length, OPT_DLG_W / 2 - 4 - 24, 0, "edit-word-wrap", &p),
83 /* 4 */ QUICK_LABEL (OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, N_("Tab spacing: ")),
84 /* 5 */ QUICK_INPUT (OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H,
85 tab_spacing, OPT_DLG_W / 2 - 4 - 24, 0, "edit-tab-spacing", &q),
86 /* 6 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8, OPT_DLG_H,
87 N_("Cursor beyond end of line"), &option_cursor_beyond_eol),
88 /* 7 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9, OPT_DLG_H,
89 N_("Pers&istent selection"), &option_persistent_selections),
90 /* 8 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10, OPT_DLG_H,
91 N_("Synta&x highlighting"), &option_syntax_highlighting),
92 /* 9 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H,
93 N_("Visible tabs"), &visible_tabs),
94 /* 10 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H,
95 N_("Visible trailing spaces"), &visible_tws),
96 /* 11 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 13, OPT_DLG_H,
97 N_("Save file &position"), &option_save_position),
98 /* 12 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 14, OPT_DLG_H,
99 N_("Confir&m before saving"), &edit_confirm_save),
100 /* 13 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 15, OPT_DLG_H,
101 N_("Fill tabs with &spaces"), &option_fill_tabs_with_spaces),
102 /* 14 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 16, OPT_DLG_H,
103 N_("&Return does autoindent"), &option_return_does_auto_indent),
104 /* 15 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 17, OPT_DLG_H,
105 N_("&Backspace through tabs"), &option_backspace_through_tabs),
106 /* 16 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 18, OPT_DLG_H,
107 N_("&Fake half tabs"), &option_fake_half_tabs),
108 /* 17 */ QUICK_RADIO (5, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, 3, wrap_str, &wrap_mode),
109 /* 18 */ QUICK_LABEL (4, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, N_("Wrap mode")),
110 /* 19 */ QUICK_RADIO (5, OPT_DLG_W, OPT_DLG_H - 17, OPT_DLG_H, 3, key_emu_str, &tedit_key_emulation),
111 /* 10 */ QUICK_LABEL (4, OPT_DLG_W, OPT_DLG_H - 18, OPT_DLG_H, N_("Key emulation")),
112 QUICK_END
115 QuickDialog Quick_options =
117 OPT_DLG_W, OPT_DLG_H, -1, -1, N_(" Editor options "),
118 "[Editor options]", quick_widgets, FALSE
121 #ifdef ENABLE_NLS
122 static gboolean i18n_flag = FALSE;
124 if (!i18n_flag) {
125 i18n_translate_array (key_emu_str);
126 i18n_translate_array (wrap_str);
127 i18n_flag = TRUE;
129 #endif
131 g_snprintf (wrap_length, sizeof (wrap_length), "%d",
132 option_word_wrap_line_length);
133 g_snprintf (tab_spacing, sizeof (tab_spacing), "%d",
134 option_tab_spacing);
136 if (option_auto_para_formatting)
137 wrap_mode = 1;
138 else if (option_typewriter_wrap)
139 wrap_mode = 2;
140 else
141 wrap_mode = 0;
143 if (quick_dialog (&Quick_options) == B_CANCEL)
144 return;
146 old_syntax_hl = option_syntax_highlighting;
148 if (p) {
149 option_word_wrap_line_length = atoi (p);
150 g_free (p);
152 if (q) {
153 option_tab_spacing = atoi (q);
154 if (option_tab_spacing <= 0)
155 option_tab_spacing = 8;
156 g_free (q);
159 if (wrap_mode == 1) {
160 option_auto_para_formatting = 1;
161 option_typewriter_wrap = 0;
162 } else if (wrap_mode == 2) {
163 option_auto_para_formatting = 0;
164 option_typewriter_wrap = 1;
165 } else {
166 option_auto_para_formatting = 0;
167 option_typewriter_wrap = 0;
170 /* Reload menu if key emulation has changed */
171 if (edit_key_emulation != tedit_key_emulation) {
172 edit_key_emulation = tedit_key_emulation;
173 edit_reload_menu ();
176 /* Load or unload syntax rules if the option has changed */
177 if (option_syntax_highlighting != old_syntax_hl)
178 edit_load_syntax (wedit, NULL, option_syntax_type);