editoptions.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. #define OPT_DLG_H 15
  20. #define OPT_DLG_W 72
  21. #ifndef USE_INTERNAL_EDIT
  22. #define USE_INTERNAL_EDIT 1
  23. #endif
  24. static char *key_emu_str[] =
  25. {N_("Intuitive"), N_("Emacs"), NULL};
  26. static char *wrap_str[] =
  27. {N_("None"), N_("Dynamic paragraphing"), N_("Type writer wrap"), NULL};
  28. void i18n_translate_array (char *array[])
  29. {
  30. while (*array!=NULL) {
  31. *array = _(*array);
  32. array++;
  33. }
  34. }
  35. void edit_options_dialog (void)
  36. {
  37. char wrap_length[32], tab_spacing[32], *p, *q;
  38. int wrap_mode = 0;
  39. int tedit_key_emulation = edit_key_emulation;
  40. int toption_fill_tabs_with_spaces = option_fill_tabs_with_spaces;
  41. int tedit_confirm_save = edit_confirm_save;
  42. int tedit_syntax_highlighting = option_syntax_highlighting;
  43. int toption_return_does_auto_indent = option_return_does_auto_indent;
  44. int toption_backspace_through_tabs = option_backspace_through_tabs;
  45. int toption_fake_half_tabs = option_fake_half_tabs;
  46. QuickWidget quick_widgets[] =
  47. {
  48. /*0 */
  49. {quick_button, 6, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Cancel"), 0, B_CANCEL, 0,
  50. 0, NULL},
  51. /*1 */
  52. {quick_button, 2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Ok"), 0, B_ENTER, 0,
  53. 0, NULL},
  54. /*2 */
  55. {quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 4, OPT_DLG_H, N_("Word wrap line length : "), 0, 0,
  56. 0, 0, NULL},
  57. /*3 */
  58. {quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 4, OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0,
  59. 0, 0, "edit-word-wrap"},
  60. /*4 */
  61. {quick_label, OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H, N_("Tab spacing : "), 0, 0,
  62. 0, 0, NULL},
  63. /*5 */
  64. {quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0,
  65. 0, 0, "edit-tab-spacing"},
  66. /*6 */
  67. #ifdef HAVE_SYNTAXH
  68. #define OA 1
  69. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, N_("synta&X highlighting"), 8, 0,
  70. 0, 0, NULL},
  71. #else
  72. #define OA 0
  73. #endif /* !HAVE_SYNTAXH */
  74. /*7 */
  75. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8, OPT_DLG_H, N_("confir&M before saving"), 6, 0,
  76. 0, 0, NULL},
  77. /*8 */
  78. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9, OPT_DLG_H, N_("fill tabs with &Spaces"), 0, 0,
  79. 0, 0, NULL},
  80. /*9 */
  81. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10, OPT_DLG_H, N_("&Return does autoindent"), 0, 0,
  82. 0, 0, NULL},
  83. /*10 */
  84. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, N_("&Backspace through tabs"), 0, 0,
  85. 0, 0, NULL},
  86. /*11 */
  87. {quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, N_("&Fake half tabs"), 0, 0,
  88. 0, 0, NULL},
  89. /*12 */
  90. {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H, "", 3, 0,
  91. 0, wrap_str, "wrapm"},
  92. /*13 */
  93. {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, N_("Wrap mode"), 0, 0,
  94. 0, 0, NULL},
  95. /*14 */
  96. {quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, "", 2, 0,
  97. 0, key_emu_str, "keyemu"},
  98. /*15 */
  99. {quick_label, 4, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, N_("Key emulation"), 0, 0,
  100. 0, 0, NULL},
  101. {0}};
  102. static int i18n_flag = 0;
  103. if (!i18n_flag) {
  104. i18n_translate_array (key_emu_str);
  105. i18n_translate_array (wrap_str);
  106. i18n_flag = 1;
  107. }
  108. sprintf (wrap_length, "%d", option_word_wrap_line_length);
  109. sprintf (tab_spacing, "%d", option_tab_spacing);
  110. quick_widgets[3].text = wrap_length;
  111. quick_widgets[3].str_result = &p;
  112. quick_widgets[5].text = tab_spacing;
  113. quick_widgets[5].str_result = &q;
  114. quick_widgets[5 + OA].result = &tedit_syntax_highlighting;
  115. quick_widgets[6 + OA].result = &tedit_confirm_save;
  116. quick_widgets[7 + OA].result = &toption_fill_tabs_with_spaces;
  117. quick_widgets[8 + OA].result = &toption_return_does_auto_indent;
  118. quick_widgets[9 + OA].result = &toption_backspace_through_tabs;
  119. quick_widgets[10 + OA].result = &toption_fake_half_tabs;
  120. if (option_auto_para_formatting)
  121. wrap_mode = 1;
  122. else if (option_typewriter_wrap)
  123. wrap_mode = 2;
  124. else
  125. wrap_mode = 0;
  126. quick_widgets[11 + OA].result = &wrap_mode;
  127. quick_widgets[11 + OA].value = wrap_mode;
  128. quick_widgets[13 + OA].result = &tedit_key_emulation;
  129. quick_widgets[13 + OA].value = tedit_key_emulation;
  130. {
  131. QuickDialog Quick_options =
  132. {OPT_DLG_W, OPT_DLG_H, -1, 0, N_(" Editor options "), "", 0};
  133. Quick_options.widgets = quick_widgets;
  134. if (quick_dialog (&Quick_options) != B_CANCEL) {
  135. int old_syntax_hl = option_syntax_highlighting;
  136. if (p) {
  137. option_word_wrap_line_length = atoi (p);
  138. free (p);
  139. }
  140. if (q) {
  141. option_tab_spacing = atoi (q);
  142. if (option_tab_spacing < 0)
  143. option_tab_spacing = 2;
  144. free (q);
  145. }
  146. option_syntax_highlighting = *quick_widgets[5 + OA].result;
  147. edit_confirm_save = *quick_widgets[6 + OA].result;
  148. option_fill_tabs_with_spaces = *quick_widgets[7 + OA].result;
  149. option_return_does_auto_indent = *quick_widgets[8 + OA].result;
  150. option_backspace_through_tabs = *quick_widgets[9 + OA].result;
  151. option_fake_half_tabs = *quick_widgets[10 + OA].result;
  152. if (*quick_widgets[11 + OA].result == 1) {
  153. option_auto_para_formatting = 1;
  154. option_typewriter_wrap = 0;
  155. } else if (*quick_widgets[11 + OA].result == 2) {
  156. option_auto_para_formatting = 0;
  157. option_typewriter_wrap = 1;
  158. } else {
  159. option_auto_para_formatting = 0;
  160. option_typewriter_wrap = 0;
  161. }
  162. edit_key_emulation = *quick_widgets[13 + OA].result;
  163. /* Load or unload syntax rules if the option has changed */
  164. if (option_syntax_highlighting != old_syntax_hl)
  165. edit_load_syntax (wedit, 0, 0);
  166. return;
  167. } else {
  168. return;
  169. }
  170. }
  171. }