root/src/editor/editmenu.c

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

DEFINITIONS

This source file includes following definitions.
  1. create_file_menu
  2. create_edit_menu
  3. create_search_replace_menu
  4. create_command_menu
  5. create_format_menu
  6. create_window_menu
  7. create_options_menu
  8. edit_drop_menu_cmd
  9. edit_init_menu
  10. edit_menu_cmd
  11. edit_drop_hotkey_menu

   1 /*
   2    Editor menu definitions and initialisation
   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
  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 menu definitions and initialisation
  29  *  \author Paul Sheer
  30  *  \date 1996, 1997
  31  */
  32 
  33 #include <config.h>
  34 
  35 #include <stdio.h>
  36 #include <stdarg.h>
  37 #include <sys/types.h>
  38 #include <unistd.h>
  39 #include <string.h>
  40 #include <ctype.h>
  41 #include <sys/stat.h>
  42 #include <stdlib.h>
  43 
  44 #include "lib/global.h"
  45 
  46 #include "lib/tty/key.h"        /* ALT */
  47 #include "lib/widget.h"
  48 
  49 #include "src/setup.h"          /* drop_menus */
  50 
  51 #include "edit-impl.h"
  52 #include "editwidget.h"
  53 
  54 /*** global variables ****************************************************************************/
  55 
  56 /*** file scope macro definitions ****************************************************************/
  57 
  58 /*** file scope type declarations ****************************************************************/
  59 
  60 /*** forward declarations (file scope functions) *************************************************/
  61 
  62 /*** file scope variables ************************************************************************/
  63 
  64 /* --------------------------------------------------------------------------------------------- */
  65 /*** file scope functions ************************************************************************/
  66 /* --------------------------------------------------------------------------------------------- */
  67 
  68 static GList *
  69 create_file_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  70 {
  71     GList *entries = NULL;
  72 
  73     entries = g_list_prepend (entries, menu_entry_new (_("&Open file..."), CK_EditFile));
  74     entries = g_list_prepend (entries, menu_entry_new (_("&New"), CK_EditNew));
  75     entries = g_list_prepend (entries, menu_entry_new (_("&Close"), CK_Close));
  76     entries = g_list_prepend (entries, menu_entry_new (_("&History..."), CK_History));
  77     entries = g_list_prepend (entries, menu_separator_new ());
  78     entries = g_list_prepend (entries, menu_entry_new (_("&Save"), CK_Save));
  79     entries = g_list_prepend (entries, menu_entry_new (_("Save &as..."), CK_SaveAs));
  80     entries = g_list_prepend (entries, menu_separator_new ());
  81     entries = g_list_prepend (entries, menu_entry_new (_("&Insert file..."), CK_InsertFile));
  82     entries = g_list_prepend (entries, menu_entry_new (_("Cop&y to file..."), CK_BlockSave));
  83     entries = g_list_prepend (entries, menu_separator_new ());
  84     entries = g_list_prepend (entries, menu_entry_new (_("&User menu..."), CK_UserMenu));
  85     entries = g_list_prepend (entries, menu_separator_new ());
  86     entries = g_list_prepend (entries, menu_entry_new (_("A&bout..."), CK_About));
  87     entries = g_list_prepend (entries, menu_separator_new ());
  88     entries = g_list_prepend (entries, menu_entry_new (_("&Quit"), CK_Quit));
  89 
  90     return g_list_reverse (entries);
  91 }
  92 
  93 /* --------------------------------------------------------------------------------------------- */
  94 
  95 static GList *
  96 create_edit_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
  97 {
  98     GList *entries = NULL;
  99 
 100     entries = g_list_prepend (entries, menu_entry_new (_("&Undo"), CK_Undo));
 101     entries = g_list_prepend (entries, menu_entry_new (_("&Redo"), CK_Redo));
 102     entries = g_list_prepend (entries, menu_separator_new ());
 103     entries = g_list_prepend (entries, menu_entry_new (_("&Toggle ins/overw"), CK_InsertOverwrite));
 104     entries = g_list_prepend (entries, menu_separator_new ());
 105     entries = g_list_prepend (entries, menu_entry_new (_("To&ggle mark"), CK_Mark));
 106     entries = g_list_prepend (entries, menu_entry_new (_("&Mark columns"), CK_MarkColumn));
 107     entries = g_list_prepend (entries, menu_entry_new (_("Mark &all"), CK_MarkAll));
 108     entries = g_list_prepend (entries, menu_entry_new (_("Unmar&k"), CK_Unmark));
 109     entries = g_list_prepend (entries, menu_separator_new ());
 110     entries = g_list_prepend (entries, menu_entry_new (_("Cop&y"), CK_Copy));
 111     entries = g_list_prepend (entries, menu_entry_new (_("Mo&ve"), CK_Move));
 112     entries = g_list_prepend (entries, menu_entry_new (_("&Delete"), CK_Remove));
 113     entries = g_list_prepend (entries, menu_separator_new ());
 114     entries = g_list_prepend (entries, menu_entry_new (_("Co&py to clipfile"), CK_Store));
 115     entries = g_list_prepend (entries, menu_entry_new (_("&Cut to clipfile"), CK_Cut));
 116     entries = g_list_prepend (entries, menu_entry_new (_("Pa&ste from clipfile"), CK_Paste));
 117     entries = g_list_prepend (entries, menu_separator_new ());
 118     entries = g_list_prepend (entries, menu_entry_new (_("&Beginning"), CK_Top));
 119     entries = g_list_prepend (entries, menu_entry_new (_("&End"), CK_Bottom));
 120 
 121     return g_list_reverse (entries);
 122 }
 123 
 124 /* --------------------------------------------------------------------------------------------- */
 125 
 126 static GList *
 127 create_search_replace_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 128 {
 129     GList *entries = NULL;
 130 
 131     entries = g_list_prepend (entries, menu_entry_new (_("&Search..."), CK_Search));
 132     entries = g_list_prepend (entries, menu_entry_new (_("Search &again"), CK_SearchContinue));
 133     entries = g_list_prepend (entries, menu_entry_new (_("&Replace..."), CK_Replace));
 134     entries = g_list_prepend (entries, menu_separator_new ());
 135     entries = g_list_prepend (entries, menu_entry_new (_("&Toggle bookmark"), CK_Bookmark));
 136     entries = g_list_prepend (entries, menu_entry_new (_("&Next bookmark"), CK_BookmarkNext));
 137     entries = g_list_prepend (entries, menu_entry_new (_("&Prev bookmark"), CK_BookmarkPrev));
 138     entries = g_list_prepend (entries, menu_entry_new (_("&Flush bookmarks"), CK_BookmarkFlush));
 139 
 140     return g_list_reverse (entries);
 141 }
 142 
 143 /* --------------------------------------------------------------------------------------------- */
 144 
 145 static GList *
 146 create_command_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 147 {
 148     GList *entries = NULL;
 149 
 150     entries = g_list_prepend (entries, menu_entry_new (_("&Go to line..."), CK_Goto));
 151     entries = g_list_prepend (entries, menu_entry_new (_("&Toggle line state"), CK_ShowNumbers));
 152     entries =
 153         g_list_prepend (entries, menu_entry_new (_("Go to matching &bracket"), CK_MatchBracket));
 154     entries =
 155         g_list_prepend (entries, menu_entry_new (_("Toggle s&yntax highlighting"), CK_SyntaxOnOff));
 156     entries = g_list_prepend (entries, menu_separator_new ());
 157     entries = g_list_prepend (entries, menu_entry_new (_("&Find declaration"), CK_Find));
 158     entries = g_list_prepend (entries, menu_entry_new (_("Back from &declaration"), CK_FilePrev));
 159     entries = g_list_prepend (entries, menu_entry_new (_("For&ward to declaration"), CK_FileNext));
 160 #ifdef HAVE_CHARSET
 161     entries = g_list_prepend (entries, menu_separator_new ());
 162     entries = g_list_prepend (entries, menu_entry_new (_("Encod&ing..."), CK_SelectCodepage));
 163 #endif
 164     entries = g_list_prepend (entries, menu_separator_new ());
 165     entries = g_list_prepend (entries, menu_entry_new (_("&Refresh screen"), CK_Refresh));
 166     entries = g_list_prepend (entries, menu_separator_new ());
 167     entries =
 168         g_list_prepend (entries,
 169                         menu_entry_new (_("&Start/Stop record macro"), CK_MacroStartStopRecord));
 170     entries = g_list_prepend (entries, menu_entry_new (_("Delete macr&o..."), CK_MacroDelete));
 171     entries =
 172         g_list_prepend (entries,
 173                         menu_entry_new (_("Record/Repeat &actions"), CK_RepeatStartStopRecord));
 174     entries = g_list_prepend (entries, menu_separator_new ());
 175 #ifdef HAVE_ASPELL
 176     if (strcmp (spell_language, "NONE") != 0)
 177     {
 178         entries = g_list_prepend (entries, menu_entry_new (_("S&pell check"), CK_SpellCheck));
 179         entries =
 180             g_list_prepend (entries, menu_entry_new (_("C&heck word"), CK_SpellCheckCurrentWord));
 181         entries =
 182             g_list_prepend (entries,
 183                             menu_entry_new (_("Change spelling &language..."),
 184                                             CK_SpellCheckSelectLang));
 185         entries = g_list_prepend (entries, menu_separator_new ());
 186     }
 187 #endif /* HAVE_ASPELL */
 188     entries = g_list_prepend (entries, menu_entry_new (_("&Mail..."), CK_EditMail));
 189 
 190 
 191     return g_list_reverse (entries);
 192 }
 193 
 194 /* --------------------------------------------------------------------------------------------- */
 195 
 196 static GList *
 197 create_format_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 198 {
 199     GList *entries = NULL;
 200 
 201     entries = g_list_prepend (entries, menu_entry_new (_("Insert &literal..."), CK_InsertLiteral));
 202     entries = g_list_prepend (entries, menu_entry_new (_("Insert &date/time"), CK_Date));
 203     entries = g_list_prepend (entries, menu_separator_new ());
 204     entries = g_list_prepend (entries, menu_entry_new (_("&Format paragraph"), CK_ParagraphFormat));
 205     entries = g_list_prepend (entries, menu_entry_new (_("&Sort..."), CK_Sort));
 206     entries =
 207         g_list_prepend (entries, menu_entry_new (_("&Paste output of..."), CK_ExternalCommand));
 208     entries = g_list_prepend (entries, menu_entry_new (_("&External formatter"), CK_PipeBlock (0)));
 209 
 210     return g_list_reverse (entries);
 211 }
 212 
 213 /* --------------------------------------------------------------------------------------------- */
 214 /**
 215  * Create the 'window' popup menu
 216  */
 217 
 218 static GList *
 219 create_window_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 220 {
 221     GList *entries = NULL;
 222 
 223     entries = g_list_prepend (entries, menu_entry_new (_("&Move"), CK_WindowMove));
 224     entries = g_list_prepend (entries, menu_entry_new (_("&Resize"), CK_WindowResize));
 225     entries =
 226         g_list_prepend (entries, menu_entry_new (_("&Toggle fullscreen"), CK_WindowFullscreen));
 227     entries = g_list_prepend (entries, menu_separator_new ());
 228     entries = g_list_prepend (entries, menu_entry_new (_("&Next"), CK_WindowNext));
 229     entries = g_list_prepend (entries, menu_entry_new (_("&Previous"), CK_WindowPrev));
 230     entries = g_list_prepend (entries, menu_entry_new (_("&List..."), CK_WindowList));
 231 
 232     return g_list_reverse (entries);
 233 }
 234 
 235 /* --------------------------------------------------------------------------------------------- */
 236 
 237 static GList *
 238 create_options_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 239 {
 240     GList *entries = NULL;
 241 
 242     entries = g_list_prepend (entries, menu_entry_new (_("&General..."), CK_Options));
 243     entries = g_list_prepend (entries, menu_entry_new (_("Save &mode..."), CK_OptionsSaveMode));
 244     entries = g_list_prepend (entries, menu_entry_new (_("Learn &keys..."), CK_LearnKeys));
 245     entries =
 246         g_list_prepend (entries, menu_entry_new (_("Syntax &highlighting..."), CK_SyntaxChoose));
 247     entries = g_list_prepend (entries, menu_separator_new ());
 248     entries = g_list_prepend (entries, menu_entry_new (_("S&yntax file"), CK_EditSyntaxFile));
 249     entries = g_list_prepend (entries, menu_entry_new (_("&Menu file"), CK_EditUserMenu));
 250     entries = g_list_prepend (entries, menu_separator_new ());
 251     entries = g_list_prepend (entries, menu_entry_new (_("&Save setup"), CK_SaveSetup));
 252 
 253     return g_list_reverse (entries);
 254 }
 255 
 256 /* --------------------------------------------------------------------------------------------- */
 257 
 258 static void
 259 edit_drop_menu_cmd (WDialog *h, int which)
     /* [previous][next][first][last][top][bottom][index][help]  */
 260 {
 261     WMenuBar *menubar;
 262 
 263     menubar = menubar_find (h);
 264     menubar_activate (menubar, drop_menus, which);
 265 }
 266 
 267 /* --------------------------------------------------------------------------------------------- */
 268 /*** public functions ****************************************************************************/
 269 /* --------------------------------------------------------------------------------------------- */
 270 
 271 void
 272 edit_init_menu (WMenuBar *menubar)
     /* [previous][next][first][last][top][bottom][index][help]  */
 273 {
 274     menubar_add_menu (menubar,
 275                       menu_new (_("&File"), create_file_menu (), "[Internal File Editor]"));
 276     menubar_add_menu (menubar,
 277                       menu_new (_("&Edit"), create_edit_menu (), "[Internal File Editor]"));
 278     menubar_add_menu (menubar,
 279                       menu_new (_("&Search"), create_search_replace_menu (),
 280                                 "[Internal File Editor]"));
 281     menubar_add_menu (menubar,
 282                       menu_new (_("&Command"), create_command_menu (), "[Internal File Editor]"));
 283     menubar_add_menu (menubar,
 284                       menu_new (_("For&mat"), create_format_menu (), "[Internal File Editor]"));
 285     menubar_add_menu (menubar,
 286                       menu_new (_("&Window"), create_window_menu (), "[Internal File Editor]"));
 287     menubar_add_menu (menubar,
 288                       menu_new (_("&Options"), create_options_menu (), "[Internal File Editor]"));
 289 }
 290 
 291 /* --------------------------------------------------------------------------------------------- */
 292 
 293 void
 294 edit_menu_cmd (WDialog *h)
     /* [previous][next][first][last][top][bottom][index][help]  */
 295 {
 296     edit_drop_menu_cmd (h, -1);
 297 }
 298 
 299 /* --------------------------------------------------------------------------------------------- */
 300 
 301 gboolean
 302 edit_drop_hotkey_menu (WDialog *h, int key)
     /* [previous][next][first][last][top][bottom][index][help]  */
 303 {
 304     int m = 0;
 305     switch (key)
 306     {
 307     case ALT ('f'):
 308         m = 0;
 309         break;
 310     case ALT ('e'):
 311         m = 1;
 312         break;
 313     case ALT ('s'):
 314         m = 2;
 315         break;
 316     case ALT ('c'):
 317         m = 3;
 318         break;
 319     case ALT ('m'):
 320         m = 4;
 321         break;
 322     case ALT ('w'):
 323         m = 5;
 324         break;
 325     case ALT ('o'):
 326         m = 6;
 327         break;
 328     default:
 329         return FALSE;
 330     }
 331 
 332     edit_drop_menu_cmd (h, m);
 333     return TRUE;
 334 }
 335 
 336 /* --------------------------------------------------------------------------------------------- */

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