editoptions.c 5.2 KB

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