root/src/editor/editoptions.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. i18n_translate_array
  2. edit_reset_over_col
  3. edit_reload_syntax
  4. edit_options_dialog

   1 /*
   2    Editor options dialog box
   3 
   4    Copyright (C) 1996-2024
   5    Free Software Foundation, Inc.
   6 
   7    Written by:
   8    Paul Sheer, 1996, 1997
   9    Andrew Borodin <aborodin@vmail.ru>, 2012-2022
  10 
  11    This file is part of the Midnight Commander.
  12 
  13    The Midnight Commander is free software: you can redistribute it
  14    and/or modify it under the terms of the GNU General Public License as
  15    published by the Free Software Foundation, either version 3 of the License,
  16    or (at your option) any later version.
  17 
  18    The Midnight Commander is distributed in the hope that it will be useful,
  19    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21    GNU General Public License for more details.
  22 
  23    You should have received a copy of the GNU General Public License
  24    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  25  */
  26 
  27 /** \file
  28  *  \brief Source: editor options dialog box
  29  *  \author Paul Sheer
  30  *  \date 1996, 1997
  31  */
  32 
  33 #include <config.h>
  34 
  35 #include <stdlib.h>             /* atoi(), NULL */
  36 
  37 #include "lib/global.h"
  38 #include "lib/widget.h"
  39 
  40 #include "editwidget.h"
  41 #include "edit-impl.h"
  42 
  43 /*** global variables ****************************************************************************/
  44 
  45 /*** file scope macro definitions ****************************************************************/
  46 
  47 /*** file scope type declarations ****************************************************************/
  48 
  49 /*** forward declarations (file scope functions) *************************************************/
  50 
  51 /*** file scope variables ************************************************************************/
  52 
  53 static const char *wrap_str[] = {
  54     N_("&None"),
  55     N_("&Dynamic paragraphing"),
  56     N_("Type &writer wrap"),
  57     NULL
  58 };
  59 
  60 /* --------------------------------------------------------------------------------------------- */
  61 /*** file scope functions ************************************************************************/
  62 /* --------------------------------------------------------------------------------------------- */
  63 
  64 #ifdef ENABLE_NLS
  65 static void
  66 i18n_translate_array (const char *array[])
     /* [previous][next][first][last][top][bottom][index][help]  */
  67 {
  68     while (*array != NULL)
  69     {
  70         *array = _(*array);
  71         array++;
  72     }
  73 }
  74 #endif /* ENABLE_NLS */
  75 
  76 /* --------------------------------------------------------------------------------------------- */
  77 /**
  78  * Callback for the iteration of objects in the 'editors' array.
  79  * Tear down 'over_col' property in all editors.
  80  *
  81  * @param data      probably WEdit object
  82  * @param user_data unused
  83  */
  84 
  85 static void
  86 edit_reset_over_col (void *data, void *user_data)
     /* [previous][next][first][last][top][bottom][index][help]  */
  87 {
  88     (void) user_data;
  89 
  90     if (edit_widget_is_editor (CONST_WIDGET (data)))
  91         EDIT (data)->over_col = 0;
  92 }
  93 
  94 /* --------------------------------------------------------------------------------------------- */
  95 /**
  96  * Callback for the iteration of objects in the 'editors' array.
  97  * Reload syntax lighlighting in all editors.
  98  *
  99  * @param data      probably WEdit object
 100  * @param user_data unused
 101  */
 102 
 103 static void
 104 edit_reload_syntax (void *data, void *user_data)
     /* [previous][next][first][last][top][bottom][index][help]  */
 105 {
 106     (void) user_data;
 107 
 108     if (edit_widget_is_editor (CONST_WIDGET (data)))
 109     {
 110         WEdit *edit = EDIT (data);
 111 
 112         edit_load_syntax (edit, NULL, edit->syntax_type);
 113     }
 114 }
 115 
 116 /* --------------------------------------------------------------------------------------------- */
 117 /*** public functions ****************************************************************************/
 118 /* --------------------------------------------------------------------------------------------- */
 119 
 120 void
 121 edit_options_dialog (WDialog *h)
     /* [previous][next][first][last][top][bottom][index][help]  */
 122 {
 123     char wrap_length[16], tab_spacing[16];
 124     char *p, *q;
 125     int wrap_mode = 0;
 126     gboolean old_syntax_hl;
 127 
 128 #ifdef ENABLE_NLS
 129     static gboolean i18n_flag = FALSE;
 130 
 131     if (!i18n_flag)
 132     {
 133         i18n_translate_array (wrap_str);
 134         i18n_flag = TRUE;
 135     }
 136 #endif /* ENABLE_NLS */
 137 
 138     g_snprintf (wrap_length, sizeof (wrap_length), "%d", edit_options.word_wrap_line_length);
 139     g_snprintf (tab_spacing, sizeof (tab_spacing), "%d", TAB_SIZE);
 140 
 141     if (edit_options.auto_para_formatting)
 142         wrap_mode = 1;
 143     else if (edit_options.typewriter_wrap)
 144         wrap_mode = 2;
 145     else
 146         wrap_mode = 0;
 147 
 148     {
 149         quick_widget_t quick_widgets[] = {
 150             /* *INDENT-OFF* */
 151             QUICK_START_COLUMNS,
 152                 QUICK_START_GROUPBOX (N_("Wrap mode")),
 153                     QUICK_RADIO (3, wrap_str, &wrap_mode, NULL),
 154                 QUICK_STOP_GROUPBOX,
 155                 QUICK_SEPARATOR (FALSE),
 156                 QUICK_SEPARATOR (FALSE),
 157                 QUICK_START_GROUPBOX (N_("Tabulation")),
 158                     QUICK_CHECKBOX (N_("&Fake half tabs"), &edit_options.fake_half_tabs, NULL),
 159                     QUICK_CHECKBOX (N_("&Backspace through tabs"),
 160                                     &edit_options.backspace_through_tabs, NULL),
 161                     QUICK_CHECKBOX (N_("Fill tabs with &spaces"),
 162                                     &edit_options.fill_tabs_with_spaces, NULL),
 163                     QUICK_LABELED_INPUT (N_("Tab spacing:"), input_label_left, tab_spacing,
 164                                          "edit-tab-spacing", &q, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE),
 165                 QUICK_STOP_GROUPBOX,
 166             QUICK_NEXT_COLUMN,
 167                 QUICK_START_GROUPBOX (N_("Other options")),
 168                     QUICK_CHECKBOX (N_("&Return does autoindent"), &edit_options.return_does_auto_indent, NULL),
 169                     QUICK_CHECKBOX (N_("Confir&m before saving"), &edit_options.confirm_save, NULL),
 170                     QUICK_CHECKBOX (N_("Save file &position"), &edit_options.save_position, NULL),
 171                     QUICK_CHECKBOX (N_("&Visible trailing spaces"), &edit_options.visible_tws, NULL),
 172                     QUICK_CHECKBOX (N_("Visible &tabs"), &edit_options.visible_tabs, NULL),
 173                     QUICK_CHECKBOX (N_("Synta&x highlighting"), &edit_options.syntax_highlighting, NULL),
 174                     QUICK_CHECKBOX (N_("C&ursor after inserted block"),
 175                                     &edit_options.cursor_after_inserted_block, NULL),
 176                     QUICK_CHECKBOX (N_("Pers&istent selection"), &edit_options.persistent_selections, NULL),
 177                     QUICK_CHECKBOX (N_("Cursor be&yond end of line"), &edit_options.cursor_beyond_eol, NULL),
 178                     QUICK_CHECKBOX (N_("&Group undo"), &edit_options.group_undo, NULL),
 179                     QUICK_LABELED_INPUT (N_("Word wrap line length:"), input_label_left, wrap_length,
 180                                          "edit-word-wrap", &p, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE),
 181                 QUICK_STOP_GROUPBOX,
 182             QUICK_STOP_COLUMNS,
 183             QUICK_BUTTONS_OK_CANCEL,
 184             QUICK_END
 185             /* *INDENT-ON* */
 186         };
 187 
 188         WRect r = { -1, -1, 0, 74 };
 189 
 190         quick_dialog_t qdlg = {
 191             r, N_("Editor options"), "[Editor options]",
 192             quick_widgets, NULL, NULL
 193         };
 194 
 195         if (quick_dialog (&qdlg) == B_CANCEL)
 196             return;
 197     }
 198 
 199     old_syntax_hl = edit_options.syntax_highlighting;
 200 
 201     if (!edit_options.cursor_beyond_eol)
 202         g_list_foreach (GROUP (h)->widgets, edit_reset_over_col, NULL);
 203 
 204     if (*p != '\0')
 205     {
 206         edit_options.word_wrap_line_length = atoi (p);
 207         if (edit_options.word_wrap_line_length <= 0)
 208             edit_options.word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
 209         g_free (p);
 210     }
 211 
 212     if (*q != '\0')
 213     {
 214         TAB_SIZE = atoi (q);
 215         if (TAB_SIZE <= 0)
 216             TAB_SIZE = DEFAULT_TAB_SPACING;
 217         g_free (q);
 218     }
 219 
 220     if (wrap_mode == 1)
 221     {
 222         edit_options.auto_para_formatting = TRUE;
 223         edit_options.typewriter_wrap = FALSE;
 224     }
 225     else if (wrap_mode == 2)
 226     {
 227         edit_options.auto_para_formatting = FALSE;
 228         edit_options.typewriter_wrap = TRUE;
 229     }
 230     else
 231     {
 232         edit_options.auto_para_formatting = FALSE;
 233         edit_options.typewriter_wrap = FALSE;
 234     }
 235 
 236     /* Load or unload syntax rules if the option has changed */
 237     if (edit_options.syntax_highlighting != old_syntax_hl)
 238         g_list_foreach (GROUP (h)->widgets, edit_reload_syntax, NULL);
 239 }
 240 
 241 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */