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
28 #include <sys/types.h>
39 #include "../src/global.h"
43 #include "../src/dialog.h" /* B_CANCEL */
44 #include "../src/wtools.h" /* QuickDialog */
49 #ifndef USE_INTERNAL_EDIT
50 #define USE_INTERNAL_EDIT 1
53 static const char *key_emu_str
[] =
54 {N_("Intuitive"), N_("Emacs"), N_("User-defined"), NULL
};
56 static const char *wrap_str
[] =
57 {N_("None"), N_("Dynamic paragraphing"), N_("Type writer wrap"), NULL
};
60 i18n_translate_array (const char *array
[])
62 while (*array
!=NULL
) {
69 edit_options_dialog (void)
71 char wrap_length
[32], tab_spacing
[32], *p
, *q
;
74 int tedit_key_emulation
= edit_key_emulation
;
75 int toption_fill_tabs_with_spaces
= option_fill_tabs_with_spaces
;
76 int toption_save_position
= option_save_position
;
77 int tedit_confirm_save
= edit_confirm_save
;
78 int tedit_syntax_highlighting
= option_syntax_highlighting
;
79 int toption_return_does_auto_indent
= option_return_does_auto_indent
;
80 int toption_backspace_through_tabs
= option_backspace_through_tabs
;
81 int toption_fake_half_tabs
= option_fake_half_tabs
;
82 static int i18n_flag
= 0;
84 QuickWidget quick_widgets
[] = {
86 {quick_button
, 6, 10, OPT_DLG_H
- 3, OPT_DLG_H
, N_("&Cancel"), 0,
87 B_CANCEL
, 0, 0, NULL
},
89 {quick_button
, 2, 10, OPT_DLG_H
- 3, OPT_DLG_H
, N_("&OK"), 0,
92 {quick_label
, OPT_DLG_W
/ 2, OPT_DLG_W
, OPT_DLG_H
- 5, OPT_DLG_H
,
93 N_("Word wrap line length: "), 0, 0, 0, 0, NULL
},
95 {quick_input
, OPT_DLG_W
/ 2 + 24, OPT_DLG_W
, OPT_DLG_H
- 5,
96 OPT_DLG_H
, "", OPT_DLG_W
/ 2 - 4 - 24, 0, 0, 0, "edit-word-wrap"},
98 {quick_label
, OPT_DLG_W
/ 2, OPT_DLG_W
, OPT_DLG_H
- 6, OPT_DLG_H
,
99 N_("Tab spacing: "), 0, 0, 0, 0, NULL
},
101 {quick_input
, OPT_DLG_W
/ 2 + 24, OPT_DLG_W
, OPT_DLG_H
- 6,
102 OPT_DLG_H
, "", OPT_DLG_W
/ 2 - 4 - 24, 0, 0, 0,
105 {quick_checkbox
, OPT_DLG_W
/ 2 + 1, OPT_DLG_W
, OPT_DLG_H
- 8,
106 OPT_DLG_H
, N_("Synta&x highlighting"), 8, 0, 0, 0, NULL
},
108 {quick_checkbox
, OPT_DLG_W
/ 2 + 1, OPT_DLG_W
, OPT_DLG_H
- 9,
109 OPT_DLG_H
, N_("Save file &position"), 0, 0, 0, 0, NULL
},
111 {quick_checkbox
, OPT_DLG_W
/ 2 + 1, OPT_DLG_W
, OPT_DLG_H
- 10,
112 OPT_DLG_H
, N_("Confir&m before saving"), 6, 0, 0, 0, NULL
},
114 {quick_checkbox
, OPT_DLG_W
/ 2 + 1, OPT_DLG_W
, OPT_DLG_H
- 11,
115 OPT_DLG_H
, N_("Fill tabs with &spaces"), 0, 0, 0, 0, NULL
},
117 {quick_checkbox
, OPT_DLG_W
/ 2 + 1, OPT_DLG_W
, OPT_DLG_H
- 12,
118 OPT_DLG_H
, N_("&Return does autoindent"), 0, 0, 0, 0, NULL
},
120 {quick_checkbox
, OPT_DLG_W
/ 2 + 1, OPT_DLG_W
, OPT_DLG_H
- 13,
121 OPT_DLG_H
, N_("&Backspace through tabs"), 0, 0, 0, 0, NULL
},
123 {quick_checkbox
, OPT_DLG_W
/ 2 + 1, OPT_DLG_W
, OPT_DLG_H
- 14,
124 OPT_DLG_H
, N_("&Fake half tabs"), 0, 0, 0, 0, NULL
},
126 {quick_radio
, 5, OPT_DLG_W
, OPT_DLG_H
- 7, OPT_DLG_H
, "", 3, 0, 0,
127 const_cast(char **, wrap_str
), "wrapm"},
129 {quick_label
, 4, OPT_DLG_W
, OPT_DLG_H
- 8, OPT_DLG_H
,
130 N_("Wrap mode"), 0, 0,
133 {quick_radio
, 5, OPT_DLG_W
, OPT_DLG_H
- 13, OPT_DLG_H
, "", 3, 0, 0,
134 const_cast(char **, key_emu_str
), "keyemu"},
136 {quick_label
, 4, OPT_DLG_W
, OPT_DLG_H
- 14, OPT_DLG_H
,
137 N_("Key emulation"), 0, 0, 0, 0, NULL
},
141 QuickDialog Quick_options
=
142 { OPT_DLG_W
, OPT_DLG_H
, -1, 0, N_(" Editor options "), "", 0, 0 };
145 i18n_translate_array (key_emu_str
);
146 i18n_translate_array (wrap_str
);
150 snprintf (wrap_length
, sizeof (wrap_length
), "%d",
151 option_word_wrap_line_length
);
152 snprintf (tab_spacing
, sizeof (tab_spacing
), "%d",
155 quick_widgets
[3].text
= wrap_length
;
156 quick_widgets
[3].str_result
= &p
;
157 quick_widgets
[5].text
= tab_spacing
;
158 quick_widgets
[5].str_result
= &q
;
159 quick_widgets
[6].result
= &tedit_syntax_highlighting
;
160 quick_widgets
[7].result
= &toption_save_position
;
161 quick_widgets
[8].result
= &tedit_confirm_save
;
162 quick_widgets
[9].result
= &toption_fill_tabs_with_spaces
;
163 quick_widgets
[10].result
= &toption_return_does_auto_indent
;
164 quick_widgets
[11].result
= &toption_backspace_through_tabs
;
165 quick_widgets
[12].result
= &toption_fake_half_tabs
;
167 if (option_auto_para_formatting
)
169 else if (option_typewriter_wrap
)
174 quick_widgets
[13].result
= &wrap_mode
;
175 quick_widgets
[13].value
= wrap_mode
;
177 quick_widgets
[15].result
= &tedit_key_emulation
;
178 quick_widgets
[15].value
= tedit_key_emulation
;
180 Quick_options
.widgets
= quick_widgets
;
182 if (quick_dialog (&Quick_options
) == B_CANCEL
)
185 old_syntax_hl
= option_syntax_highlighting
;
188 option_word_wrap_line_length
= atoi (p
);
192 option_tab_spacing
= atoi (q
);
193 if (option_tab_spacing
<= 0)
194 option_tab_spacing
= 8;
198 option_syntax_highlighting
= tedit_syntax_highlighting
;
199 edit_confirm_save
= tedit_confirm_save
;
200 option_save_position
= toption_save_position
;
201 option_fill_tabs_with_spaces
= toption_fill_tabs_with_spaces
;
202 option_return_does_auto_indent
= toption_return_does_auto_indent
;
203 option_backspace_through_tabs
= toption_backspace_through_tabs
;
204 option_fake_half_tabs
= toption_fake_half_tabs
;
206 if (wrap_mode
== 1) {
207 option_auto_para_formatting
= 1;
208 option_typewriter_wrap
= 0;
209 } else if (wrap_mode
== 2) {
210 option_auto_para_formatting
= 0;
211 option_typewriter_wrap
= 1;
213 option_auto_para_formatting
= 0;
214 option_typewriter_wrap
= 0;
217 /* Reload menu if key emulation has changed */
218 if (edit_key_emulation
!= tedit_key_emulation
) {
219 edit_key_emulation
= tedit_key_emulation
;
223 /* Load or unload syntax rules if the option has changed */
224 if (option_syntax_highlighting
!= old_syntax_hl
)
225 edit_load_syntax (wedit
, NULL
, option_syntax_type
);
226 /* Load usermap if it's needed */
227 edit_load_user_map (wedit
);