editoptions.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* editor options dialog box
  2. Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2007
  3. Free Software Foundation, Inc.
  4. Authors: 1996, 1997 Paul Sheer
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301, USA.
  17. */
  18. /** \file
  19. * \brief Source: editor options dialog box
  20. * \author Paul Sheer
  21. * \date 1996, 1997
  22. */
  23. #include <config.h>
  24. #include <stdlib.h> /* atoi(), NULL */
  25. #include "../src/global.h"
  26. #include "edit-impl.h"
  27. #include "usermap.h"
  28. #include "../src/dialog.h" /* B_CANCEL */
  29. #include "../src/wtools.h" /* QuickDialog */
  30. #define OPT_DLG_H 21
  31. #define OPT_DLG_W 72
  32. static const char *key_emu_str[] =
  33. {N_("Intuitive"), N_("Emacs"), N_("User-defined"), NULL};
  34. static const char *wrap_str[] =
  35. {N_("None"), N_("Dynamic paragraphing"), N_("Type writer wrap"), NULL};
  36. static void
  37. i18n_translate_array (const char *array[])
  38. {
  39. while (*array!=NULL) {
  40. *array = _(*array);
  41. array++;
  42. }
  43. }
  44. void
  45. edit_options_dialog (void)
  46. {
  47. char wrap_length[32], tab_spacing[32], *p, *q;
  48. int wrap_mode = 0;
  49. int old_syntax_hl;
  50. int tedit_key_emulation = edit_key_emulation;
  51. int toption_fill_tabs_with_spaces = option_fill_tabs_with_spaces;
  52. int toption_save_position = option_save_position;
  53. int tedit_confirm_save = edit_confirm_save;
  54. int tedit_syntax_highlighting = option_syntax_highlighting;
  55. int tedit_visible_tabs = visible_tabs;
  56. int tedit_visible_tws = visible_tws;
  57. int tedit_persistent_selections = option_persistent_selections;
  58. int tedit_cursor_beyond_eol = option_cursor_beyond_eol;
  59. int toption_return_does_auto_indent = option_return_does_auto_indent;
  60. int toption_backspace_through_tabs = option_backspace_through_tabs;
  61. int toption_fake_half_tabs = option_fake_half_tabs;
  62. static int i18n_flag = 0;
  63. QuickWidget quick_widgets[] = {
  64. /* 0 */
  65. {quick_button, 6, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Cancel"), 0,
  66. B_CANCEL, 0, 0, NULL, NULL, NULL},
  67. /* 1 */
  68. {quick_button, 2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&OK"), 0,
  69. B_ENTER, 0, 0, NULL, NULL, NULL},
  70. /* 2 */
  71. {quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H,
  72. N_("Word wrap line length: "), 0, 0, 0, 0, NULL, NULL, NULL},
  73. /* 3 */
  74. {quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 5,
  75. OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0, 0, 0, "edit-word-wrap", NULL, NULL},
  76. /* 4 */
  77. {quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H,
  78. N_("Tab spacing: "), 0, 0, 0, 0, NULL, NULL, NULL},
  79. /* 5 */
  80. {quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 6,
  81. OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0, 0, 0,
  82. "edit-tab-spacing", NULL, NULL},
  83. /* 6 */
  84. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8,
  85. OPT_DLG_H, N_("Cursor beyond end of line"), 8, 0, 0, 0, NULL, NULL, NULL},
  86. /* 7 */
  87. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9,
  88. OPT_DLG_H, N_("Pers&istent selection"), 8, 0, 0, 0, NULL, NULL, NULL},
  89. /* 8 */
  90. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10,
  91. OPT_DLG_H, N_("Synta&x highlighting"), 8, 0, 0, 0, NULL, NULL, NULL},
  92. /* 9 */
  93. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11,
  94. OPT_DLG_H, N_("Visible tabs"), 8, 0, 0, 0, NULL, NULL, NULL},
  95. /* 10 */
  96. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12,
  97. OPT_DLG_H, N_("Visible trailing spaces"), 8, 0, 0, 0, NULL, NULL, NULL},
  98. /* 11 */
  99. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 13,
  100. OPT_DLG_H, N_("Save file &position"), 0, 0, 0, 0, NULL, NULL, NULL},
  101. /* 12 */
  102. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 14,
  103. OPT_DLG_H, N_("Confir&m before saving"), 6, 0, 0, 0, NULL, NULL, NULL},
  104. /* 13 */
  105. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 15,
  106. OPT_DLG_H, N_("Fill tabs with &spaces"), 0, 0, 0, 0, NULL, NULL, NULL},
  107. /* 14 */
  108. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 16,
  109. OPT_DLG_H, N_("&Return does autoindent"), 0, 0, 0, 0, NULL, NULL, NULL},
  110. /* 15 */
  111. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 17,
  112. OPT_DLG_H, N_("&Backspace through tabs"), 0, 0, 0, 0, NULL, NULL, NULL},
  113. /* 16 */
  114. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 18,
  115. OPT_DLG_H, N_("&Fake half tabs"), 0, 0, 0, 0, NULL, NULL, NULL},
  116. /* 17 */
  117. {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, "", 3, 0, 0,
  118. const_cast(char **, wrap_str), "wrapm", NULL, NULL},
  119. /* 18 */
  120. {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H,
  121. N_("Wrap mode"), 0, 0, 0, 0, NULL, NULL, NULL},
  122. /* 19 */
  123. {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 17, OPT_DLG_H, "", 3, 0, 0,
  124. const_cast(char **, key_emu_str), "keyemu", NULL, NULL},
  125. /* 20 */
  126. {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 18, OPT_DLG_H,
  127. N_("Key emulation"), 0, 0, 0, 0, NULL, NULL, NULL},
  128. NULL_QuickWidget
  129. };
  130. QuickDialog Quick_options =
  131. { OPT_DLG_W, OPT_DLG_H, -1, 0, N_(" Editor options "), "", 0, 0 };
  132. if (!i18n_flag) {
  133. i18n_translate_array (key_emu_str);
  134. i18n_translate_array (wrap_str);
  135. i18n_flag = 1;
  136. }
  137. g_snprintf (wrap_length, sizeof (wrap_length), "%d",
  138. option_word_wrap_line_length);
  139. g_snprintf (tab_spacing, sizeof (tab_spacing), "%d",
  140. option_tab_spacing);
  141. quick_widgets[3].text = wrap_length;
  142. quick_widgets[3].str_result = &p;
  143. quick_widgets[5].text = tab_spacing;
  144. quick_widgets[5].str_result = &q;
  145. quick_widgets[6].result = &tedit_cursor_beyond_eol;
  146. quick_widgets[7].result = &tedit_persistent_selections;
  147. quick_widgets[8].result = &tedit_syntax_highlighting;
  148. quick_widgets[9].result = &tedit_visible_tabs;
  149. quick_widgets[10].result = &tedit_visible_tws;
  150. quick_widgets[11].result = &toption_save_position;
  151. quick_widgets[12].result = &tedit_confirm_save;
  152. quick_widgets[13].result = &toption_fill_tabs_with_spaces;
  153. quick_widgets[14].result = &toption_return_does_auto_indent;
  154. quick_widgets[15].result = &toption_backspace_through_tabs;
  155. quick_widgets[16].result = &toption_fake_half_tabs;
  156. if (option_auto_para_formatting)
  157. wrap_mode = 1;
  158. else if (option_typewriter_wrap)
  159. wrap_mode = 2;
  160. else
  161. wrap_mode = 0;
  162. quick_widgets[17].result = &wrap_mode;
  163. quick_widgets[17].value = wrap_mode;
  164. quick_widgets[19].result = &tedit_key_emulation;
  165. quick_widgets[19].value = tedit_key_emulation;
  166. Quick_options.widgets = quick_widgets;
  167. if (quick_dialog (&Quick_options) == B_CANCEL)
  168. return;
  169. old_syntax_hl = option_syntax_highlighting;
  170. if (p) {
  171. option_word_wrap_line_length = atoi (p);
  172. g_free (p);
  173. }
  174. if (q) {
  175. option_tab_spacing = atoi (q);
  176. if (option_tab_spacing <= 0)
  177. option_tab_spacing = 8;
  178. g_free (q);
  179. }
  180. option_cursor_beyond_eol = tedit_cursor_beyond_eol;
  181. option_persistent_selections = tedit_persistent_selections;
  182. option_syntax_highlighting = tedit_syntax_highlighting;
  183. visible_tabs = tedit_visible_tabs;
  184. visible_tws = tedit_visible_tws;
  185. edit_confirm_save = tedit_confirm_save;
  186. option_save_position = toption_save_position;
  187. option_fill_tabs_with_spaces = toption_fill_tabs_with_spaces;
  188. option_return_does_auto_indent = toption_return_does_auto_indent;
  189. option_backspace_through_tabs = toption_backspace_through_tabs;
  190. option_fake_half_tabs = toption_fake_half_tabs;
  191. if (wrap_mode == 1) {
  192. option_auto_para_formatting = 1;
  193. option_typewriter_wrap = 0;
  194. } else if (wrap_mode == 2) {
  195. option_auto_para_formatting = 0;
  196. option_typewriter_wrap = 1;
  197. } else {
  198. option_auto_para_formatting = 0;
  199. option_typewriter_wrap = 0;
  200. }
  201. /* Reload menu if key emulation has changed */
  202. if (edit_key_emulation != tedit_key_emulation) {
  203. edit_key_emulation = tedit_key_emulation;
  204. edit_reload_menu ();
  205. }
  206. /* Load or unload syntax rules if the option has changed */
  207. if (option_syntax_highlighting != old_syntax_hl)
  208. edit_load_syntax (wedit, NULL, option_syntax_type);
  209. /* Load usermap if it's needed */
  210. edit_load_user_map (wedit);
  211. }