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

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