keymap files: unification of Fxx keys: move to lower case.
[midnight-commander.git] / src / editor / editmenu.c
blobee32346943c0a543dd8008fe0ba91806fbcb89d4
1 /* editor menu definitions and initialisation
3 Copyright (C) 1996, 1998, 2001, 2002, 2003, 2005, 2007
4 Free Software Foundation, Inc.
6 Authors: 1996, 1997 Paul Sheer
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA.
24 /** \file
25 * \brief Source: editor menu definitions and initialisation
26 * \author Paul Sheer
27 * \date 1996, 1997
30 #include <config.h>
32 #include <stdio.h>
33 #include <stdarg.h>
34 #include <sys/types.h>
35 #include <unistd.h>
36 #include <string.h>
37 #include <ctype.h>
38 #include <errno.h>
39 #include <sys/stat.h>
40 #include <stdlib.h>
42 #include "lib/global.h"
44 #include "lib/tty/tty.h" /* KEY_F */
45 #include "lib/tty/key.h" /* XCTRL */
46 #include "lib/widget.h"
48 #include "src/setup.h" /* drop_menus */
49 #include "src/keybind-defaults.h"
51 #include "edit-impl.h"
52 #include "edit-widget.h"
54 /*** global variables ****************************************************************************/
56 /*** file scope macro definitions ****************************************************************/
58 /*** file scope type declarations ****************************************************************/
60 /*** file scope variables ************************************************************************/
62 /*** file scope functions ************************************************************************/
63 /* --------------------------------------------------------------------------------------------- */
65 static GList *
66 create_file_menu (void)
68 GList *entries = NULL;
70 entries = g_list_append (entries, menu_entry_create (_("&Open file..."), CK_EditFile));
71 entries = g_list_append (entries, menu_entry_create (_("&New"), CK_EditNew));
72 entries = g_list_append (entries, menu_separator_create ());
73 entries = g_list_append (entries, menu_entry_create (_("&Save"), CK_Save));
74 entries = g_list_append (entries, menu_entry_create (_("Save &as..."), CK_SaveAs));
75 entries = g_list_append (entries, menu_separator_create ());
76 entries = g_list_append (entries, menu_entry_create (_("&Insert file..."), CK_InsertFile));
77 entries = g_list_append (entries, menu_entry_create (_("Cop&y to file..."), CK_BlockSave));
78 entries = g_list_append (entries, menu_separator_create ());
79 entries = g_list_append (entries, menu_entry_create (_("&User menu..."), CK_UserMenu));
80 entries = g_list_append (entries, menu_separator_create ());
81 entries = g_list_append (entries, menu_entry_create (_("A&bout..."), CK_About));
82 entries = g_list_append (entries, menu_separator_create ());
83 entries = g_list_append (entries, menu_entry_create (_("&Quit"), CK_Quit));
85 return entries;
88 /* --------------------------------------------------------------------------------------------- */
90 static GList *
91 create_edit_menu (void)
93 GList *entries = NULL;
95 entries = g_list_append (entries, menu_entry_create (_("&Undo"), CK_Undo));
96 entries = g_list_append (entries, menu_entry_create (_("&Redo"), CK_Redo));
97 entries = g_list_append (entries, menu_separator_create ());
98 entries =
99 g_list_append (entries, menu_entry_create (_("&Toggle ins/overw"), CK_InsertOverwrite));
100 entries = g_list_append (entries, menu_separator_create ());
101 entries = g_list_append (entries, menu_entry_create (_("To&ggle mark"), CK_Mark));
102 entries = g_list_append (entries, menu_entry_create (_("&Mark columns"), CK_MarkColumn));
103 entries = g_list_append (entries, menu_entry_create (_("Mark &all"), CK_MarkAll));
104 entries = g_list_append (entries, menu_entry_create (_("Unmar&k"), CK_Unmark));
105 entries = g_list_append (entries, menu_separator_create ());
106 entries = g_list_append (entries, menu_entry_create (_("Cop&y"), CK_Copy));
107 entries = g_list_append (entries, menu_entry_create (_("Mo&ve"), CK_Move));
108 entries = g_list_append (entries, menu_entry_create (_("&Delete"), CK_Remove));
109 entries = g_list_append (entries, menu_separator_create ());
110 entries = g_list_append (entries, menu_entry_create (_("Co&py to clipfile"), CK_Store));
111 entries = g_list_append (entries, menu_entry_create (_("&Cut to clipfile"), CK_Cut));
112 entries = g_list_append (entries, menu_entry_create (_("Pa&ste from clipfile"), CK_Paste));
113 entries = g_list_append (entries, menu_separator_create ());
114 entries = g_list_append (entries, menu_entry_create (_("&Beginning"), CK_Top));
115 entries = g_list_append (entries, menu_entry_create (_("&End"), CK_Bottom));
117 return entries;
120 /* --------------------------------------------------------------------------------------------- */
122 static GList *
123 create_search_replace_menu (void)
125 GList *entries = NULL;
127 entries = g_list_append (entries, menu_entry_create (_("&Search..."), CK_Search));
128 entries = g_list_append (entries, menu_entry_create (_("Search &again"), CK_SearchContinue));
129 entries = g_list_append (entries, menu_entry_create (_("&Replace..."), CK_Replace));
130 entries = g_list_append (entries, menu_separator_create ());
131 entries = g_list_append (entries, menu_entry_create (_("&Toggle bookmark"), CK_Bookmark));
132 entries = g_list_append (entries, menu_entry_create (_("&Next bookmark"), CK_BookmarkNext));
133 entries = g_list_append (entries, menu_entry_create (_("&Prev bookmark"), CK_BookmarkPrev));
134 entries = g_list_append (entries, menu_entry_create (_("&Flush bookmarks"), CK_BookmarkFlush));
136 return entries;
139 /* --------------------------------------------------------------------------------------------- */
141 static GList *
142 create_command_menu (void)
144 GList *entries = NULL;
146 entries = g_list_append (entries, menu_entry_create (_("&Go to line..."), CK_Goto));
147 entries =
148 g_list_append (entries, menu_entry_create (_("&Toggle line state"), CK_ShowNumbers));
149 entries =
150 g_list_append (entries, menu_entry_create (_("Go to matching &bracket"), CK_MatchBracket));
151 entries =
152 g_list_append (entries,
153 menu_entry_create (_("Toggle s&yntax highlighting"), CK_SyntaxOnOff));
154 entries = g_list_append (entries, menu_separator_create ());
155 entries =
156 g_list_append (entries, menu_entry_create (_("&Find declaration"), CK_Find));
157 entries = g_list_append (entries, menu_entry_create (_("Back from &declaration"), CK_FilePrev));
158 entries =
159 g_list_append (entries, menu_entry_create (_("For&ward to declaration"), CK_FileNext));
160 #ifdef HAVE_CHARSET
161 entries = g_list_append (entries, menu_separator_create ());
162 entries = g_list_append (entries, menu_entry_create (_("Encod&ing..."), CK_SelectCodepage));
163 #endif
164 entries = g_list_append (entries, menu_separator_create ());
165 entries = g_list_append (entries, menu_entry_create (_("&Refresh screen"), CK_Refresh));
166 entries = g_list_append (entries, menu_separator_create ());
167 entries =
168 g_list_append (entries,
169 menu_entry_create (_("&Start/Stop record macro"), CK_MacroStartStopRecord));
170 entries = g_list_append (entries, menu_entry_create (_("Delete macr&o..."), CK_MacroDelete));
171 entries =
172 g_list_append (entries,
173 menu_entry_create (_("Record/Repeat &actions"), CK_RepeatStartStopRecord));
174 entries = g_list_append (entries, menu_separator_create ());
175 entries =
176 g_list_append (entries, menu_entry_create (_("'ispell' s&pell check"), CK_PipeBlock (1)));
177 entries = g_list_append (entries, menu_entry_create (_("&Mail..."), CK_Mail));
179 return entries;
182 /* --------------------------------------------------------------------------------------------- */
184 static GList *
185 create_format_menu (void)
187 GList *entries = NULL;
189 entries =
190 g_list_append (entries, menu_entry_create (_("Insert &literal..."), CK_InsertLiteral));
191 entries = g_list_append (entries, menu_entry_create (_("Insert &date/time"), CK_Date));
192 entries = g_list_append (entries, menu_separator_create ());
193 entries =
194 g_list_append (entries, menu_entry_create (_("&Format paragraph"), CK_ParagraphFormat));
195 entries = g_list_append (entries, menu_entry_create (_("&Sort..."), CK_Sort));
196 entries =
197 g_list_append (entries, menu_entry_create (_("&Paste output of..."), CK_ExternalCommand));
198 entries =
199 g_list_append (entries, menu_entry_create (_("&External formatter"), CK_PipeBlock (0)));
201 return entries;
204 /* --------------------------------------------------------------------------------------------- */
206 static GList *
207 create_options_menu (void)
209 GList *entries = NULL;
211 entries = g_list_append (entries, menu_entry_create (_("&General..."), CK_Options));
212 entries = g_list_append (entries, menu_entry_create (_("Save &mode..."), CK_OptionsSaveMode));
213 entries = g_list_append (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
214 entries =
215 g_list_append (entries, menu_entry_create (_("Syntax &highlighting..."), CK_SyntaxChoose));
216 entries = g_list_append (entries, menu_separator_create ());
217 entries = g_list_append (entries, menu_entry_create (_("S&yntax file"), CK_EditSyntaxFile));
218 entries = g_list_append (entries, menu_entry_create (_("&Menu file"), CK_EditUserMenu));
219 entries = g_list_append (entries, menu_separator_create ());
220 entries = g_list_append (entries, menu_entry_create (_("&Save setup"), CK_SaveSetup));
222 return entries;
225 /* --------------------------------------------------------------------------------------------- */
227 static void
228 edit_drop_menu_cmd (WEdit * e, int which)
230 WMenuBar *menubar;
232 menubar = find_menubar (e->widget.owner);
234 if (!menubar->is_active)
236 menubar->is_active = TRUE;
237 menubar->is_dropped = (drop_menus != 0);
238 if (which >= 0)
239 menubar->selected = which;
241 menubar->previous_widget = dlg_get_current_widget_id (e->widget.owner);
242 dlg_select_widget (menubar);
246 /* --------------------------------------------------------------------------------------------- */
247 /*** public functions ****************************************************************************/
248 /* --------------------------------------------------------------------------------------------- */
250 void
251 edit_init_menu (struct WMenuBar *menubar)
253 menubar_add_menu (menubar,
254 create_menu (_("&File"), create_file_menu (), "[Internal File Editor]"));
255 menubar_add_menu (menubar,
256 create_menu (_("&Edit"), create_edit_menu (), "[Internal File Editor]"));
257 menubar_add_menu (menubar,
258 create_menu (_("&Search"), create_search_replace_menu (),
259 "[Internal File Editor]"));
260 menubar_add_menu (menubar,
261 create_menu (_("&Command"), create_command_menu (),
262 "[Internal File Editor]"));
263 menubar_add_menu (menubar,
264 create_menu (_("For&mat"), create_format_menu (), "[Internal File Editor]"));
265 menubar_add_menu (menubar,
266 create_menu (_("&Options"), create_options_menu (),
267 "[Internal File Editor]"));
270 /* --------------------------------------------------------------------------------------------- */
272 void
273 edit_menu_cmd (WEdit * e)
275 edit_drop_menu_cmd (e, -1);
278 /* --------------------------------------------------------------------------------------------- */
281 edit_drop_hotkey_menu (WEdit * e, int key)
283 int m = 0;
284 switch (key)
286 case ALT ('f'):
287 m = 0;
288 break;
289 case ALT ('e'):
290 m = 1;
291 break;
292 case ALT ('s'):
293 m = 2;
294 break;
295 case ALT ('c'):
296 m = 3;
297 break;
298 case ALT ('m'):
299 m = 4;
300 break;
301 case ALT ('o'):
302 m = 5;
303 break;
304 default:
305 return 0;
308 edit_drop_menu_cmd (e, m);
309 return 1;
312 /* --------------------------------------------------------------------------------------------- */