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-2025
   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 <https://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
  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
 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             // clang-format 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,
 165                                          INPUT_COMPLETE_NONE),
 166                 QUICK_STOP_GROUPBOX,
 167             QUICK_NEXT_COLUMN,
 168                 QUICK_START_GROUPBOX (N_ ("Other options")),
 169                     QUICK_CHECKBOX (N_ ("&Return does autoindent"),
 170                                     &edit_options.return_does_auto_indent, NULL),
 171                     QUICK_CHECKBOX (N_ ("Confir&m before saving"), &edit_options.confirm_save, NULL),
 172                     QUICK_CHECKBOX (N_ ("Save file &position"), &edit_options.save_position, NULL),
 173                     QUICK_CHECKBOX (N_ ("&Visible trailing spaces"), &edit_options.visible_tws,
 174                                     NULL),
 175                     QUICK_CHECKBOX (N_ ("Visible &tabs"), &edit_options.visible_tabs, NULL),
 176                     QUICK_CHECKBOX (N_ ("Synta&x highlighting"), &edit_options.syntax_highlighting,
 177                                     NULL),
 178                     QUICK_CHECKBOX (N_ ("C&ursor after inserted block"),
 179                                     &edit_options.cursor_after_inserted_block, NULL),
 180                     QUICK_CHECKBOX (N_ ("Pers&istent selection"),
 181                                     &edit_options.persistent_selections, NULL),
 182                     QUICK_CHECKBOX (N_ ("Cursor be&yond end of line"),
 183                                     &edit_options.cursor_beyond_eol, NULL),
 184                     QUICK_CHECKBOX (N_ ("&Group undo"), &edit_options.group_undo, NULL),
 185                     QUICK_LABELED_INPUT (N_ ("Word wrap line length:"), input_label_left, wrap_length,
 186                                          "edit-word-wrap", &p, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE),
 187                 QUICK_STOP_GROUPBOX,
 188             QUICK_STOP_COLUMNS,
 189             QUICK_BUTTONS_OK_CANCEL,
 190             QUICK_END,
 191             // clang-format on
 192         };
 193 
 194         WRect r = { -1, -1, 0, 74 };
 195 
 196         quick_dialog_t qdlg = {
 197             .rect = r,
 198             .title = N_ ("Editor options"),
 199             .help = "[Editor options]",
 200             .widgets = quick_widgets,
 201             .callback = NULL,
 202             .mouse_callback = NULL,
 203         };
 204 
 205         if (quick_dialog (&qdlg) == B_CANCEL)
 206             return;
 207     }
 208 
 209     old_syntax_hl = edit_options.syntax_highlighting;
 210 
 211     if (!edit_options.cursor_beyond_eol)
 212         g_list_foreach (GROUP (h)->widgets, edit_reset_over_col, NULL);
 213 
 214     if (*p != '\0')
 215     {
 216         edit_options.word_wrap_line_length = atoi (p);
 217         if (edit_options.word_wrap_line_length <= 0)
 218             edit_options.word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
 219         g_free (p);
 220     }
 221 
 222     if (*q != '\0')
 223     {
 224         TAB_SIZE = atoi (q);
 225         if (TAB_SIZE <= 0)
 226             TAB_SIZE = DEFAULT_TAB_SPACING;
 227         g_free (q);
 228     }
 229 
 230     if (wrap_mode == 1)
 231     {
 232         edit_options.auto_para_formatting = TRUE;
 233         edit_options.typewriter_wrap = FALSE;
 234     }
 235     else if (wrap_mode == 2)
 236     {
 237         edit_options.auto_para_formatting = FALSE;
 238         edit_options.typewriter_wrap = TRUE;
 239     }
 240     else
 241     {
 242         edit_options.auto_para_formatting = FALSE;
 243         edit_options.typewriter_wrap = FALSE;
 244     }
 245 
 246     // Load or unload syntax rules if the option has changed
 247     if (edit_options.syntax_highlighting != old_syntax_hl)
 248         g_list_foreach (GROUP (h)->widgets, edit_reload_syntax, NULL);
 249 }
 250 
 251 /* --------------------------------------------------------------------------------------------- */

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