editoptions.c 5.1 KB

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