Used .TP for coherency all over the key description pages.
[midnight-commander.git] / edit / editoptions.c
blob9c0ded70b48ef063b4275a8dd1f9b08fd83870f7
1 /* editor options dialog box
3 Copyright (C) 1996, 1997 the Free Software Foundation
5 Authors: 1996, 1997 Paul Sheer
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307, USA.
23 #include <config.h>
24 #include "edit.h"
26 #define OPT_DLG_H 15
27 #define OPT_DLG_W 72
29 #ifndef USE_INTERNAL_EDIT
30 #define USE_INTERNAL_EDIT 1
31 #endif
33 static char *key_emu_str[] =
34 {N_("Intuitive"), N_("Emacs"), NULL};
36 static char *wrap_str[] =
37 {N_("None"), N_("Dynamic paragraphing"), N_("Type writer wrap"), NULL};
39 void i18n_translate_array (char *array[])
41 while (*array!=NULL) {
42 *array = _(*array);
43 array++;
47 void edit_options_dialog (void)
49 char wrap_length[32], tab_spacing[32], *p, *q;
50 int wrap_mode = 0;
51 int tedit_key_emulation = edit_key_emulation;
52 int toption_fill_tabs_with_spaces = option_fill_tabs_with_spaces;
53 int tedit_confirm_save = edit_confirm_save;
54 int tedit_syntax_highlighting = option_syntax_highlighting;
55 int toption_return_does_auto_indent = option_return_does_auto_indent;
56 int toption_backspace_through_tabs = option_backspace_through_tabs;
57 int toption_fake_half_tabs = option_fake_half_tabs;
59 QuickWidget quick_widgets[] =
61 /*0 */
62 {quick_button, 6, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Cancel"), 0, B_CANCEL, 0,
63 0, NULL},
64 /*1 */
65 {quick_button, 2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&OK"), 0, B_ENTER, 0,
66 0, NULL},
67 /*2 */
68 {quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 4, OPT_DLG_H, N_("Word wrap line length : "), 0, 0,
69 0, 0, NULL},
70 /*3 */
71 {quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 4, OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0,
72 0, 0, "edit-word-wrap"},
73 /*4 */
74 {quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H, N_("Tab spacing : "), 0, 0,
75 0, 0, NULL},
76 /*5 */
77 {quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0,
78 0, 0, "edit-tab-spacing"},
79 /*6 */
80 #ifdef HAVE_SYNTAXH
81 #define OA 1
82 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, N_("synta&X highlighting"), 8, 0,
83 0, 0, NULL},
84 #else
85 #define OA 0
86 #endif /* !HAVE_SYNTAXH */
87 /*7 */
88 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8, OPT_DLG_H, N_("confir&M before saving"), 6, 0,
89 0, 0, NULL},
90 /*8 */
91 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9, OPT_DLG_H, N_("fill tabs with &Spaces"), 0, 0,
92 0, 0, NULL},
93 /*9 */
94 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10, OPT_DLG_H, N_("&Return does autoindent"), 0, 0,
95 0, 0, NULL},
96 /*10 */
97 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, N_("&Backspace through tabs"), 0, 0,
98 0, 0, NULL},
99 /*11 */
100 {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, N_("&Fake half tabs"), 0, 0,
101 0, 0, NULL},
102 /*12 */
103 {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H, "", 3, 0,
104 0, wrap_str, "wrapm"},
105 /*13 */
106 {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, N_("Wrap mode"), 0, 0,
107 0, 0, NULL},
108 /*14 */
109 {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, "", 2, 0,
110 0, key_emu_str, "keyemu"},
111 /*15 */
112 {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, N_("Key emulation"), 0, 0,
113 0, 0, NULL},
114 {0}};
116 static int i18n_flag = 0;
118 if (!i18n_flag) {
119 i18n_translate_array (key_emu_str);
120 i18n_translate_array (wrap_str);
121 i18n_flag = 1;
124 sprintf (wrap_length, "%d", option_word_wrap_line_length);
125 sprintf (tab_spacing, "%d", option_tab_spacing);
127 quick_widgets[3].text = wrap_length;
128 quick_widgets[3].str_result = &p;
129 quick_widgets[5].text = tab_spacing;
130 quick_widgets[5].str_result = &q;
131 quick_widgets[5 + OA].result = &tedit_syntax_highlighting;
132 quick_widgets[6 + OA].result = &tedit_confirm_save;
133 quick_widgets[7 + OA].result = &toption_fill_tabs_with_spaces;
134 quick_widgets[8 + OA].result = &toption_return_does_auto_indent;
135 quick_widgets[9 + OA].result = &toption_backspace_through_tabs;
136 quick_widgets[10 + OA].result = &toption_fake_half_tabs;
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;
145 quick_widgets[11 + OA].result = &wrap_mode;
146 quick_widgets[11 + OA].value = wrap_mode;
148 quick_widgets[13 + OA].result = &tedit_key_emulation;
149 quick_widgets[13 + OA].value = tedit_key_emulation;
152 QuickDialog Quick_options =
153 {OPT_DLG_W, OPT_DLG_H, -1, 0, N_(" Editor options "), "", 0};
155 Quick_options.widgets = quick_widgets;
157 if (quick_dialog (&Quick_options) != B_CANCEL) {
158 int old_syntax_hl = option_syntax_highlighting;
160 if (p) {
161 option_word_wrap_line_length = atoi (p);
162 free (p);
164 if (q) {
165 option_tab_spacing = atoi (q);
166 if (option_tab_spacing <= 0)
167 option_tab_spacing = 8;
168 free (q);
170 option_syntax_highlighting = *quick_widgets[5 + OA].result;
171 edit_confirm_save = *quick_widgets[6 + OA].result;
172 option_fill_tabs_with_spaces = *quick_widgets[7 + OA].result;
173 option_return_does_auto_indent = *quick_widgets[8 + OA].result;
174 option_backspace_through_tabs = *quick_widgets[9 + OA].result;
175 option_fake_half_tabs = *quick_widgets[10 + OA].result;
177 if (*quick_widgets[11 + OA].result == 1) {
178 option_auto_para_formatting = 1;
179 option_typewriter_wrap = 0;
180 } else if (*quick_widgets[11 + OA].result == 2) {
181 option_auto_para_formatting = 0;
182 option_typewriter_wrap = 1;
183 } else {
184 option_auto_para_formatting = 0;
185 option_typewriter_wrap = 0;
188 edit_key_emulation = *quick_widgets[13 + OA].result;
190 /* Load or unload syntax rules if the option has changed */
191 if (option_syntax_highlighting != old_syntax_hl)
192 edit_load_syntax (wedit, 0, 0);
194 return;
195 } else {
196 return;