editoptions.c 6.6 KB

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