editoptions.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. #include <config.h>
  19. #include <stdio.h>
  20. #include <stdarg.h>
  21. #include <sys/types.h>
  22. #ifdef HAVE_UNISTD_H
  23. # include <unistd.h>
  24. #endif
  25. #include <string.h>
  26. #include <ctype.h>
  27. #include <errno.h>
  28. #include <sys/stat.h>
  29. #include <stdlib.h>
  30. #include "../src/global.h"
  31. #include "edit.h"
  32. #include "usermap.h"
  33. #include "../src/dialog.h" /* B_CANCEL */
  34. #include "../src/wtools.h" /* QuickDialog */
  35. #define OPT_DLG_H 19
  36. #define OPT_DLG_W 72
  37. #ifndef USE_INTERNAL_EDIT
  38. #define USE_INTERNAL_EDIT 1
  39. #endif
  40. static const char *key_emu_str[] =
  41. {N_("Intuitive"), N_("Emacs"), N_("User-defined"), NULL};
  42. static const char *wrap_str[] =
  43. {N_("None"), N_("Dynamic paragraphing"), N_("Type writer wrap"), NULL};
  44. static void
  45. i18n_translate_array (const char *array[])
  46. {
  47. while (*array!=NULL) {
  48. *array = _(*array);
  49. array++;
  50. }
  51. }
  52. void
  53. edit_options_dialog (void)
  54. {
  55. char wrap_length[32], tab_spacing[32], *p, *q;
  56. int wrap_mode = 0;
  57. int old_syntax_hl;
  58. int tedit_key_emulation = edit_key_emulation;
  59. int toption_fill_tabs_with_spaces = option_fill_tabs_with_spaces;
  60. int toption_save_position = option_save_position;
  61. int tedit_confirm_save = edit_confirm_save;
  62. int tedit_syntax_highlighting = option_syntax_highlighting;
  63. int tedit_persistent_selections = option_persistent_selections;
  64. int toption_return_does_auto_indent = option_return_does_auto_indent;
  65. int toption_backspace_through_tabs = option_backspace_through_tabs;
  66. int toption_fake_half_tabs = option_fake_half_tabs;
  67. static int i18n_flag = 0;
  68. QuickWidget quick_widgets[] = {
  69. /* 0 */
  70. {quick_button, 6, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Cancel"), 0,
  71. B_CANCEL, 0, 0, NULL, NULL, NULL},
  72. /* 1 */
  73. {quick_button, 2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&OK"), 0,
  74. B_ENTER, 0, 0, NULL, NULL, NULL},
  75. /* 2 */
  76. {quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H,
  77. N_("Word wrap line length: "), 0, 0, 0, 0, NULL, NULL, NULL},
  78. /* 3 */
  79. {quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 7,
  80. OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0, 0, 0, "edit-word-wrap", NULL, NULL},
  81. /* 4 */
  82. {quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H,
  83. N_("Tab spacing: "), 0, 0, 0, 0, NULL, NULL, NULL},
  84. /* 5 */
  85. {quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 6,
  86. OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0, 0, 0,
  87. "edit-tab-spacing", NULL, NULL},
  88. /* 6 */
  89. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9,
  90. OPT_DLG_H, N_("Pers&istent selection"), 8, 0, 0, 0, NULL, NULL, NULL},
  91. /* 7 */
  92. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10,
  93. OPT_DLG_H, N_("Synta&x highlighting"), 8, 0, 0, 0, NULL, NULL, NULL},
  94. /* 7 */
  95. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11,
  96. OPT_DLG_H, N_("Save file &position"), 0, 0, 0, 0, NULL, NULL, NULL},
  97. /* 9 */
  98. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12,
  99. OPT_DLG_H, N_("Confir&m before saving"), 6, 0, 0, 0, NULL, NULL, NULL},
  100. /* 10 */
  101. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 13,
  102. OPT_DLG_H, N_("Fill tabs with &spaces"), 0, 0, 0, 0, NULL, NULL, NULL},
  103. /* 11 */
  104. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 14,
  105. OPT_DLG_H, N_("&Return does autoindent"), 0, 0, 0, 0, NULL, NULL, NULL},
  106. /* 12 */
  107. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 15,
  108. OPT_DLG_H, N_("&Backspace through tabs"), 0, 0, 0, 0, NULL, NULL, NULL},
  109. /* 13 */
  110. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 16,
  111. OPT_DLG_H, N_("&Fake half tabs"), 0, 0, 0, 0, NULL, NULL, NULL},
  112. /* 14 */
  113. {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 9, OPT_DLG_H, "", 3, 0, 0,
  114. const_cast(char **, wrap_str), "wrapm", NULL, NULL},
  115. /* 15 */
  116. {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 10, OPT_DLG_H,
  117. N_("Wrap mode"), 0, 0,
  118. 0, 0, NULL, NULL, NULL},
  119. /* 16 */
  120. {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 15, OPT_DLG_H, "", 3, 0, 0,
  121. const_cast(char **, key_emu_str), "keyemu", NULL, NULL},
  122. /* 17 */
  123. {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 16, OPT_DLG_H,
  124. N_("Key emulation"), 0, 0, 0, 0, NULL, NULL, NULL},
  125. NULL_QuickWidget
  126. };
  127. QuickDialog Quick_options =
  128. { OPT_DLG_W, OPT_DLG_H, -1, 0, N_(" Editor options "), "", 0, 0 };
  129. if (!i18n_flag) {
  130. i18n_translate_array (key_emu_str);
  131. i18n_translate_array (wrap_str);
  132. i18n_flag = 1;
  133. }
  134. g_snprintf (wrap_length, sizeof (wrap_length), "%d",
  135. option_word_wrap_line_length);
  136. g_snprintf (tab_spacing, sizeof (tab_spacing), "%d",
  137. option_tab_spacing);
  138. quick_widgets[3].text = wrap_length;
  139. quick_widgets[3].str_result = &p;
  140. quick_widgets[5].text = tab_spacing;
  141. quick_widgets[5].str_result = &q;
  142. quick_widgets[6].result = &tedit_persistent_selections;
  143. quick_widgets[7].result = &tedit_syntax_highlighting;
  144. quick_widgets[8].result = &toption_save_position;
  145. quick_widgets[9].result = &tedit_confirm_save;
  146. quick_widgets[10].result = &toption_fill_tabs_with_spaces;
  147. quick_widgets[11].result = &toption_return_does_auto_indent;
  148. quick_widgets[12].result = &toption_backspace_through_tabs;
  149. quick_widgets[13].result = &toption_fake_half_tabs;
  150. if (option_auto_para_formatting)
  151. wrap_mode = 1;
  152. else if (option_typewriter_wrap)
  153. wrap_mode = 2;
  154. else
  155. wrap_mode = 0;
  156. quick_widgets[14].result = &wrap_mode;
  157. quick_widgets[14].value = wrap_mode;
  158. quick_widgets[16].result = &tedit_key_emulation;
  159. quick_widgets[16].value = tedit_key_emulation;
  160. Quick_options.widgets = quick_widgets;
  161. if (quick_dialog (&Quick_options) == B_CANCEL)
  162. return;
  163. old_syntax_hl = option_syntax_highlighting;
  164. if (p) {
  165. option_word_wrap_line_length = atoi (p);
  166. g_free (p);
  167. }
  168. if (q) {
  169. option_tab_spacing = atoi (q);
  170. if (option_tab_spacing <= 0)
  171. option_tab_spacing = 8;
  172. g_free (q);
  173. }
  174. option_persistent_selections = tedit_persistent_selections;
  175. option_syntax_highlighting = tedit_syntax_highlighting;
  176. edit_confirm_save = tedit_confirm_save;
  177. option_save_position = toption_save_position;
  178. option_fill_tabs_with_spaces = toption_fill_tabs_with_spaces;
  179. option_return_does_auto_indent = toption_return_does_auto_indent;
  180. option_backspace_through_tabs = toption_backspace_through_tabs;
  181. option_fake_half_tabs = toption_fake_half_tabs;
  182. if (wrap_mode == 1) {
  183. option_auto_para_formatting = 1;
  184. option_typewriter_wrap = 0;
  185. } else if (wrap_mode == 2) {
  186. option_auto_para_formatting = 0;
  187. option_typewriter_wrap = 1;
  188. } else {
  189. option_auto_para_formatting = 0;
  190. option_typewriter_wrap = 0;
  191. }
  192. /* Reload menu if key emulation has changed */
  193. if (edit_key_emulation != tedit_key_emulation) {
  194. edit_key_emulation = tedit_key_emulation;
  195. edit_reload_menu ();
  196. }
  197. /* Load or unload syntax rules if the option has changed */
  198. if (option_syntax_highlighting != old_syntax_hl)
  199. edit_load_syntax (wedit, NULL, option_syntax_type);
  200. /* Load usermap if it's needed */
  201. edit_load_user_map (wedit);
  202. }