editoptions.c 5.9 KB

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