editoptions.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. {
  34. N_("Intuitive"),
  35. N_("Emacs"),
  36. N_("User-defined"),
  37. NULL
  38. };
  39. static const char *wrap_str[] =
  40. {
  41. N_("None"),
  42. N_("Dynamic paragraphing"),
  43. N_("Type writer wrap"),
  44. NULL
  45. };
  46. static void
  47. i18n_translate_array (const char *array[])
  48. {
  49. while (*array != NULL) {
  50. *array = _(*array);
  51. array++;
  52. }
  53. }
  54. void
  55. edit_options_dialog (void)
  56. {
  57. char wrap_length[16], tab_spacing[16], *p, *q;
  58. int wrap_mode = 0;
  59. int old_syntax_hl;
  60. int tedit_key_emulation = edit_key_emulation;
  61. QuickWidget quick_widgets[] =
  62. {
  63. /* 0 */ QUICK_BUTTON (6, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&Cancel"), B_CANCEL, NULL),
  64. /* 1 */ QUICK_BUTTON (2, 10, OPT_DLG_H - 3, OPT_DLG_H, N_("&OK"), B_ENTER, NULL),
  65. /* 2 */ QUICK_LABEL (OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H, N_("Word wrap line length: ")),
  66. /* 3 */ QUICK_INPUT (OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H,
  67. wrap_length, OPT_DLG_W / 2 - 4 - 24, 0, "edit-word-wrap", &p),
  68. /* 4 */ QUICK_LABEL (OPT_DLG_W / 2, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, N_("Tab spacing: ")),
  69. /* 5 */ QUICK_INPUT (OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H,
  70. tab_spacing, OPT_DLG_W / 2 - 4 - 24, 0, "edit-tab-spacing", &q),
  71. /* 6 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8, OPT_DLG_H,
  72. N_("Cursor beyond end of line"), &option_cursor_beyond_eol),
  73. /* 7 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9, OPT_DLG_H,
  74. N_("Pers&istent selection"), &option_persistent_selections),
  75. /* 8 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10, OPT_DLG_H,
  76. N_("Synta&x highlighting"), &option_syntax_highlighting),
  77. /* 9 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H,
  78. N_("Visible tabs"), &visible_tabs),
  79. /* 10 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H,
  80. N_("Visible trailing spaces"), &visible_tws),
  81. /* 11 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 13, OPT_DLG_H,
  82. N_("Save file &position"), &option_save_position),
  83. /* 12 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 14, OPT_DLG_H,
  84. N_("Confir&m before saving"), &edit_confirm_save),
  85. /* 13 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 15, OPT_DLG_H,
  86. N_("Fill tabs with &spaces"), &option_fill_tabs_with_spaces),
  87. /* 14 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 16, OPT_DLG_H,
  88. N_("&Return does autoindent"), &option_return_does_auto_indent),
  89. /* 15 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 17, OPT_DLG_H,
  90. N_("&Backspace through tabs"), &option_backspace_through_tabs),
  91. /* 16 */ QUICK_CHECKBOX (OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 18, OPT_DLG_H,
  92. N_("&Fake half tabs"), &option_fake_half_tabs),
  93. /* 17 */ QUICK_RADIO (5, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, 3, wrap_str, &wrap_mode),
  94. /* 18 */ QUICK_LABEL (4, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, N_("Wrap mode")),
  95. /* 19 */ QUICK_RADIO (5, OPT_DLG_W, OPT_DLG_H - 17, OPT_DLG_H, 3, key_emu_str, &tedit_key_emulation),
  96. /* 10 */ QUICK_LABEL (4, OPT_DLG_W, OPT_DLG_H - 18, OPT_DLG_H, N_("Key emulation")),
  97. QUICK_END
  98. };
  99. QuickDialog Quick_options =
  100. {
  101. OPT_DLG_W, OPT_DLG_H, -1, -1, N_(" Editor options "),
  102. "[Editor options]", quick_widgets, FALSE
  103. };
  104. #ifdef ENABLE_NLS
  105. static gboolean i18n_flag = FALSE;
  106. if (!i18n_flag) {
  107. i18n_translate_array (key_emu_str);
  108. i18n_translate_array (wrap_str);
  109. i18n_flag = TRUE;
  110. }
  111. #endif
  112. g_snprintf (wrap_length, sizeof (wrap_length), "%d",
  113. option_word_wrap_line_length);
  114. g_snprintf (tab_spacing, sizeof (tab_spacing), "%d",
  115. option_tab_spacing);
  116. if (option_auto_para_formatting)
  117. wrap_mode = 1;
  118. else if (option_typewriter_wrap)
  119. wrap_mode = 2;
  120. else
  121. wrap_mode = 0;
  122. if (quick_dialog (&Quick_options) == B_CANCEL)
  123. return;
  124. old_syntax_hl = option_syntax_highlighting;
  125. if (p) {
  126. option_word_wrap_line_length = atoi (p);
  127. g_free (p);
  128. }
  129. if (q) {
  130. option_tab_spacing = atoi (q);
  131. if (option_tab_spacing <= 0)
  132. option_tab_spacing = 8;
  133. g_free (q);
  134. }
  135. if (wrap_mode == 1) {
  136. option_auto_para_formatting = 1;
  137. option_typewriter_wrap = 0;
  138. } else if (wrap_mode == 2) {
  139. option_auto_para_formatting = 0;
  140. option_typewriter_wrap = 1;
  141. } else {
  142. option_auto_para_formatting = 0;
  143. option_typewriter_wrap = 0;
  144. }
  145. /* Reload menu if key emulation has changed */
  146. if (edit_key_emulation != tedit_key_emulation) {
  147. edit_key_emulation = tedit_key_emulation;
  148. edit_reload_menu ();
  149. }
  150. /* Load or unload syntax rules if the option has changed */
  151. if (option_syntax_highlighting != old_syntax_hl)
  152. edit_load_syntax (wedit, NULL, option_syntax_type);
  153. /* Load usermap if it's needed */
  154. edit_load_user_map (wedit);
  155. }