Ticket #1545: Don't escape tilde on cmdline, this is not necessary.
[midnight-commander.git] / edit / editmenu.c
blobf5954978d715f61364eae8bad258c388f9d3a3d4
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 "../src/global.h"
44 #include "edit-impl.h"
45 #include "edit-widget.h"
46 #include "editcmddef.h"
48 #include "../src/tty/tty.h" /* KEY_F */
49 #include "../src/tty/key.h" /* XCTRL */
51 #include "../src/cmd.h" /* save_setup_cmd() */
52 #include "../src/wtools.h" /* query_dialog() */
53 #include "../src/menu.h" /* menu_entry */
54 #include "../src/main.h" /* drop_menus */
55 #include "../src/learn.h" /* learn_keys */
57 static void
58 menu_cmd (int command)
60 edit_execute_key_command (wedit, command, -1);
61 edit_update_screen (wedit);
64 static void menu_key (int i)
66 send_message ((Widget *) wedit, WIDGET_KEY, i);
69 static void
70 edit_about_cmd (void)
72 query_dialog (_(" About "),
73 _("\n Cooledit v3.11.5\n\n"
74 " Copyright (C) 1996 the Free Software Foundation\n\n"
75 " A user friendly text editor written\n"
76 " for the Midnight Commander.\n"), D_NORMAL,
77 1, _("&OK"));
80 static void
81 menu_mail_cmd (void)
83 menu_cmd (CK_Mail);
86 static void
87 menu_load_cmd (void)
89 menu_cmd (CK_Load);
92 static void
93 menu_new_cmd (void)
95 menu_cmd (CK_New);
98 static void
99 menu_save_cmd (void)
101 menu_cmd (CK_Save);
104 static void
105 menu_save_as_cmd (void)
107 menu_cmd (CK_Save_As);
110 static void
111 menu_insert_file_cmd (void)
113 menu_cmd (CK_Insert_File);
116 static void
117 menu_quit_cmd (void)
119 menu_cmd (CK_Exit);
122 static void
123 menu_mark_cmd (void)
125 menu_cmd (CK_Mark);
128 static void
129 menu_markcol_cmd (void)
131 menu_cmd (CK_Column_Mark);
134 static void
135 menu_ins_cmd (void)
137 menu_cmd (CK_Toggle_Insert);
140 static void
141 menu_copy_cmd (void)
143 menu_cmd (CK_Copy);
146 static void
147 menu_move_cmd (void)
149 menu_cmd (CK_Move);
152 static void
153 menu_delete_cmd (void)
155 menu_cmd (CK_Remove);
158 static void
159 menu_xstore_cmd (void)
161 menu_cmd (CK_XStore);
164 static void
165 menu_xcut_cmd (void)
167 menu_cmd (CK_XCut);
170 static void
171 menu_xpaste_cmd (void)
173 menu_cmd (CK_XPaste);
176 static void
177 menu_toggle_bookmark_cmd (void)
179 menu_cmd (CK_Toggle_Bookmark);
182 static void
183 menu_flush_bookmark_cmd (void)
185 menu_cmd (CK_Flush_Bookmarks);
188 static void
189 menu_next_bookmark_cmd (void)
191 menu_cmd (CK_Next_Bookmark);
194 static void
195 menu_prev_bookmark_cmd (void)
197 menu_cmd (CK_Prev_Bookmark);
200 static void
201 menu_cut_cmd (void)
203 menu_cmd (CK_Save_Block);
206 static void
207 menu_search_cmd (void)
209 menu_cmd (CK_Find);
212 static void
213 menu_search_again_cmd (void)
215 menu_cmd (CK_Find_Again);
218 static void
219 menu_replace_cmd (void)
221 menu_cmd (CK_Replace);
224 static void
225 menu_select_codepage_cmd (void)
227 menu_cmd (CK_Select_Codepage);
230 static void
231 menu_begin_record_cmd (void)
233 menu_cmd (CK_Begin_Record_Macro);
236 static void
237 menu_end_record_cmd (void)
239 menu_cmd (CK_End_Record_Macro);
242 static void
243 menu_exec_macro_cmd (void)
245 menu_key (XCTRL ('a'));
248 static void
249 menu_exec_macro_delete_cmd (void)
251 menu_cmd (CK_Delete_Macro);
254 static void
255 menu_c_form_cmd (void)
257 menu_key (KEY_F (19));
260 static void
261 menu_ispell_cmd (void)
263 menu_cmd (CK_Pipe_Block (1));
266 static void
267 menu_sort_cmd (void)
269 menu_cmd (CK_Sort);
272 static void
273 menu_ext_cmd (void)
275 menu_cmd (CK_ExtCmd);
278 static void
279 menu_date_cmd (void)
281 menu_cmd (CK_Date);
284 static void
285 menu_undo_cmd (void)
287 menu_cmd (CK_Undo);
290 static void
291 menu_beginning_cmd (void)
293 menu_cmd (CK_Beginning_Of_Text);
296 static void
297 menu_end_cmd (void)
299 menu_cmd (CK_End_Of_Text);
302 static void
303 menu_refresh_cmd (void)
305 menu_cmd (CK_Refresh);
308 static void
309 menu_goto_line (void)
311 menu_cmd (CK_Goto);
314 static void
315 menu_toggle_line_state (void)
317 menu_cmd (CK_Toggle_Line_State);
320 static void
321 menu_goto_bracket (void)
323 menu_cmd (CK_Match_Bracket);
326 static void
327 menu_lit_cmd (void)
329 menu_key (XCTRL ('q'));
332 static void
333 menu_format_paragraph (void)
335 menu_cmd (CK_Paragraph_Format);
338 static void
339 menu_edit_syntax_file_cmd (void)
341 menu_cmd (CK_Load_Syntax_File);
344 static void
345 menu_edit_menu_file_cmd (void)
347 menu_cmd (CK_Load_Menu_File);
350 static void
351 menu_user_menu_cmd (void)
353 menu_key (KEY_F (11));
356 static void
357 menu_find_declare (void)
359 menu_cmd (CK_Find_Definition);
362 static void
363 menu_declare_back (void)
365 menu_cmd (CK_Load_Prev_File);
368 static void
369 menu_declare_forward (void)
371 menu_cmd (CK_Load_Next_File);
374 static menu_entry FileMenu[] =
376 {' ', N_("&Open file..."), NULL_HOTKEY, menu_load_cmd},
377 {' ', N_("&New C-n"), NULL_HOTKEY, menu_new_cmd},
378 {' ', "", NULL_HOTKEY, 0},
379 {' ', N_("&Save F2"), NULL_HOTKEY, menu_save_cmd},
380 {' ', N_("Save &as... F12"), NULL_HOTKEY, menu_save_as_cmd},
381 {' ', "", NULL_HOTKEY, 0},
382 {' ', N_("&Insert file... F15"), NULL_HOTKEY, menu_insert_file_cmd},
383 {' ', N_("Copy to &file... C-f"), NULL_HOTKEY, menu_cut_cmd},
384 {' ', "", NULL_HOTKEY, 0},
385 {' ', N_("&User menu... F11"), NULL_HOTKEY, menu_user_menu_cmd},
386 {' ', "", NULL_HOTKEY, 0},
387 {' ', N_("A&bout... "), NULL_HOTKEY, edit_about_cmd},
388 {' ', "", NULL_HOTKEY, 0},
389 {' ', N_("&Quit F10"), NULL_HOTKEY, menu_quit_cmd}
392 static menu_entry FileMenuEmacs[] =
394 {' ', N_("&Open file..."), NULL_HOTKEY, menu_load_cmd},
395 {' ', N_("&New C-x k"), NULL_HOTKEY, menu_new_cmd},
396 {' ', "", NULL_HOTKEY, 0},
397 {' ', N_("&Save F2"), NULL_HOTKEY, menu_save_cmd},
398 {' ', N_("Save &as... F12"), NULL_HOTKEY, menu_save_as_cmd},
399 {' ', "", NULL_HOTKEY, 0},
400 {' ', N_("&Insert file... F15"), NULL_HOTKEY, menu_insert_file_cmd},
401 {' ', N_("Copy to &file... "), NULL_HOTKEY, menu_cut_cmd},
402 {' ', "", NULL_HOTKEY, 0},
403 {' ', N_("&User menu... F11"), NULL_HOTKEY, menu_user_menu_cmd},
404 {' ', "", NULL_HOTKEY, 0},
405 {' ', N_("A&bout... "), NULL_HOTKEY, edit_about_cmd},
406 {' ', "", NULL_HOTKEY, 0},
407 {' ', N_("&Quit F10"), NULL_HOTKEY, menu_quit_cmd}
410 static menu_entry EditMenu[] =
412 {' ', N_("&Toggle mark F3"), NULL_HOTKEY, menu_mark_cmd},
413 {' ', N_("Mar&k columns S-F3"), NULL_HOTKEY, menu_markcol_cmd},
414 {' ', "", NULL_HOTKEY, 0},
415 {' ', N_("Toggle &ins/overw Ins"), NULL_HOTKEY, menu_ins_cmd},
416 {' ', "", NULL_HOTKEY, 0},
417 {' ', N_("&Copy F5"), NULL_HOTKEY, menu_copy_cmd},
418 {' ', N_("&Move F6"), NULL_HOTKEY, menu_move_cmd},
419 {' ', N_("&Delete F8"), NULL_HOTKEY, menu_delete_cmd},
420 {' ', "", NULL_HOTKEY, 0},
421 {' ', N_("C&opy to clipfile C-Ins"), NULL_HOTKEY, menu_xstore_cmd},
422 {' ', N_("C&ut to clipfile S-Del"), NULL_HOTKEY, menu_xcut_cmd},
423 {' ', N_("&Paste from clipfile S-Ins"), NULL_HOTKEY, menu_xpaste_cmd},
424 {' ', "", NULL_HOTKEY, 0},
425 {' ', N_("Toggle bookmar&k M-k"), NULL_HOTKEY, menu_toggle_bookmark_cmd},
426 {' ', N_("&Next bookmark M-j"), NULL_HOTKEY, menu_next_bookmark_cmd},
427 {' ', N_("Pre&v bookmark M-i"), NULL_HOTKEY, menu_prev_bookmark_cmd},
428 {' ', N_("&Flush bookmark M-o"), NULL_HOTKEY, menu_flush_bookmark_cmd},
429 {' ', "", NULL_HOTKEY, 0},
430 {' ', N_("&Undo C-u"), NULL_HOTKEY, menu_undo_cmd},
431 {' ', "", NULL_HOTKEY, 0},
432 {' ', N_("&Beginning C-PgUp"), NULL_HOTKEY, menu_beginning_cmd},
433 {' ', N_("&End C-PgDn"), NULL_HOTKEY, menu_end_cmd}
436 static menu_entry EditMenuEmacs[] =
438 {' ', N_("&Toggle mark F3"), NULL_HOTKEY, menu_mark_cmd},
439 {' ', N_("Mar&k columns S-F3"), NULL_HOTKEY, menu_markcol_cmd},
440 {' ', "", NULL_HOTKEY, 0},
441 {' ', N_("Toggle &ins/overw Ins"), NULL_HOTKEY, menu_ins_cmd},
442 {' ', "", NULL_HOTKEY, 0},
443 {' ', N_("&Copy F5"), NULL_HOTKEY, menu_copy_cmd},
444 {' ', N_("&Move F6"), NULL_HOTKEY, menu_move_cmd},
445 {' ', N_("&Delete F8"), NULL_HOTKEY, menu_delete_cmd},
446 {' ', "", NULL_HOTKEY, 0},
447 {' ', N_("C&opy to clipfile M-w"), NULL_HOTKEY, menu_xstore_cmd},
448 {' ', N_("C&ut to clipfile C-w"), NULL_HOTKEY, menu_xcut_cmd},
449 {' ', N_("&Paste from clipfile C-y"), NULL_HOTKEY, menu_xpaste_cmd},
450 {' ', "", NULL_HOTKEY, 0},
451 {' ', N_("Toggle bookmar&k "), NULL_HOTKEY, menu_toggle_bookmark_cmd},
452 {' ', N_("&Next bookmark "), NULL_HOTKEY, menu_next_bookmark_cmd},
453 {' ', N_("Pre&v bookmark "), NULL_HOTKEY, menu_prev_bookmark_cmd},
454 {' ', N_("&Flush bookmark "), NULL_HOTKEY, menu_flush_bookmark_cmd},
455 {' ', "", NULL_HOTKEY, 0},
456 {' ', N_("&Undo C-u"), NULL_HOTKEY, menu_undo_cmd},
457 {' ', "", NULL_HOTKEY, 0},
458 {' ', N_("&Beginning C-PgUp"), NULL_HOTKEY, menu_beginning_cmd},
459 {' ', N_("&End C-PgDn"), NULL_HOTKEY, menu_end_cmd}
462 static menu_entry SearReplMenu[] =
464 {' ', N_("&Search... F7"), NULL_HOTKEY, menu_search_cmd},
465 {' ', N_("Search &again F17"), NULL_HOTKEY, menu_search_again_cmd},
466 {' ', N_("&Replace... F4"), NULL_HOTKEY, menu_replace_cmd}
469 #define SearReplMenuEmacs SearReplMenu
471 static menu_entry CmdMenu[] =
473 {' ', N_("&Go to line... M-l"), NULL_HOTKEY, menu_goto_line},
474 {' ', N_("Toggle li&ne state M-n"), NULL_HOTKEY, menu_toggle_line_state},
475 {' ', N_("Go to matching &bracket M-b"), NULL_HOTKEY, menu_goto_bracket},
476 {' ', "", NULL_HOTKEY, 0},
477 {' ', N_("Find declaration A-Enter"), NULL_HOTKEY, menu_find_declare},
478 {' ', N_("Back from declaration M--"), NULL_HOTKEY, menu_declare_back},
479 {' ', N_("Forward to declaration M-+"), NULL_HOTKEY, menu_declare_forward},
480 #ifdef HAVE_CHARSET
481 {' ', "", NULL_HOTKEY, 0},
482 {' ', N_("Encod&ing... C-t"), NULL_HOTKEY, menu_select_codepage_cmd},
483 #endif
484 {' ', "", NULL_HOTKEY, 0},
485 {' ', N_("Insert &literal... C-q"), NULL_HOTKEY, menu_lit_cmd},
486 {' ', "", NULL_HOTKEY, 0},
487 {' ', N_("&Refresh screen C-l"), NULL_HOTKEY, menu_refresh_cmd},
488 {' ', "", NULL_HOTKEY, 0},
489 {' ', N_("&Start record macro C-r"), NULL_HOTKEY, menu_begin_record_cmd},
490 {' ', N_("&Finish record macro... C-r"), NULL_HOTKEY, menu_end_record_cmd},
491 {' ', N_("&Execute macro... C-a, KEY"), NULL_HOTKEY, menu_exec_macro_cmd},
492 {' ', N_("Delete macr&o... "), NULL_HOTKEY, menu_exec_macro_delete_cmd},
493 {' ', "", NULL_HOTKEY, 0},
494 {' ', N_("Insert &date/time "), NULL_HOTKEY, menu_date_cmd},
495 {' ', "", NULL_HOTKEY, 0},
496 {' ', N_("Format p&aragraph M-p"), NULL_HOTKEY, menu_format_paragraph},
497 {' ', N_("'ispell' s&pell check C-p"), NULL_HOTKEY, menu_ispell_cmd},
498 {' ', N_("Sor&t... M-t"), NULL_HOTKEY, menu_sort_cmd},
499 {' ', N_("Paste o&utput of... M-u"), NULL_HOTKEY, menu_ext_cmd},
500 {' ', N_("E&xternal Formatter F19"), NULL_HOTKEY, menu_c_form_cmd},
501 {' ', N_("&Mail... "), NULL_HOTKEY, menu_mail_cmd}
504 static menu_entry CmdMenuEmacs[] =
506 {' ', N_("&Go to line... M-l"), NULL_HOTKEY, menu_goto_line},
507 {' ', N_("Toggle li&ne state M-n"), NULL_HOTKEY, menu_toggle_line_state},
508 {' ', N_("Go to matching &bracket M-b"), NULL_HOTKEY, menu_goto_bracket},
509 {' ', "", NULL_HOTKEY, 0},
510 {' ', N_("Insert &literal... C-q"), NULL_HOTKEY, menu_lit_cmd},
511 {' ', "", NULL_HOTKEY, 0},
512 {' ', N_("&Refresh screen C-l"), NULL_HOTKEY, menu_refresh_cmd},
513 {' ', "", NULL_HOTKEY, 0},
514 {' ', N_("&Start record macro C-r"), NULL_HOTKEY, menu_begin_record_cmd},
515 {' ', N_("&Finish record macro... C-r"), NULL_HOTKEY, menu_end_record_cmd},
516 {' ', N_("&Execute macro... C-x e, KEY"), NULL_HOTKEY, menu_exec_macro_cmd},
517 {' ', N_("Delete macr&o... "), NULL_HOTKEY, menu_exec_macro_delete_cmd},
518 {' ', "", NULL_HOTKEY, 0},
519 {' ', N_("Insert &date/time "), NULL_HOTKEY, menu_date_cmd},
520 {' ', "", NULL_HOTKEY, 0},
521 {' ', N_("Format p&aragraph M-p"), NULL_HOTKEY, menu_format_paragraph},
522 {' ', N_("'ispell' s&pell check M-$"), NULL_HOTKEY, menu_ispell_cmd},
523 {' ', N_("Sor&t... M-t"), NULL_HOTKEY, menu_sort_cmd},
524 {' ', N_("Paste o&utput of... M-u"), NULL_HOTKEY, menu_ext_cmd},
525 {' ', N_("E&xternal Formatter F19"), NULL_HOTKEY, menu_c_form_cmd},
526 {' ', N_("&Mail... "), NULL_HOTKEY, menu_mail_cmd}
529 static menu_entry OptMenu[] =
531 {' ', N_("&General... "), NULL_HOTKEY, edit_options_dialog},
532 {' ', N_("&Save mode..."), NULL_HOTKEY, menu_save_mode_cmd},
533 {' ', N_("Learn &Keys..."), NULL_HOTKEY, learn_keys},
534 {' ', N_("Syntax &Highlighting..."), NULL_HOTKEY, edit_syntax_dialog},
535 {' ', "", NULL_HOTKEY, 0},
536 {' ', N_("S&yntax file"), NULL_HOTKEY, menu_edit_syntax_file_cmd},
537 {' ', N_("&Menu file"), NULL_HOTKEY, menu_edit_menu_file_cmd},
538 {' ', "", NULL_HOTKEY, 0},
539 {' ', N_("Save setu&p"), NULL_HOTKEY, save_setup_cmd}
542 #define OptMenuEmacs OptMenu
544 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
546 #define N_menus 5
548 static Menu *EditMenuBar [N_menus];
550 static void
551 edit_init_menu_normal (void)
553 EditMenuBar[0] = create_menu (_(" File "), FileMenu, menu_entries (FileMenu),
554 "[Internal File Editor]");
555 EditMenuBar[1] = create_menu (_(" Edit "), EditMenu, menu_entries (EditMenu),
556 "[Internal File Editor]");
557 EditMenuBar[2] = create_menu (_(" Sear/Repl "), SearReplMenu, menu_entries (SearReplMenu),
558 "[Internal File Editor]");
559 EditMenuBar[3] = create_menu (_(" Command "), CmdMenu, menu_entries (CmdMenu),
560 "[Internal File Editor]");
561 EditMenuBar[4] = create_menu (_(" Options "), OptMenu, menu_entries (OptMenu),
562 "[Internal File Editor]");
565 static void
566 edit_init_menu_emacs (void)
568 EditMenuBar[0] = create_menu (_(" File "), FileMenuEmacs, menu_entries (FileMenuEmacs),
569 "[Internal File Editor]");
570 EditMenuBar[1] = create_menu (_(" Edit "), EditMenuEmacs, menu_entries (EditMenuEmacs),
571 "[Internal File Editor]");
572 EditMenuBar[2] = create_menu (_(" Sear/Repl "), SearReplMenuEmacs, menu_entries (SearReplMenuEmacs),
573 "[Internal File Editor]");
574 EditMenuBar[3] = create_menu (_(" Command "), CmdMenuEmacs, menu_entries (CmdMenuEmacs),
575 "[Internal File Editor]");
576 EditMenuBar[4] = create_menu (_(" Options "), OptMenuEmacs, menu_entries (OptMenuEmacs),
577 "[Internal File Editor]");
580 static void
581 edit_init_menu (void)
583 switch (edit_key_emulation) {
584 default:
585 case EDIT_KEY_EMULATION_NORMAL:
586 edit_init_menu_normal ();
587 break;
588 case EDIT_KEY_EMULATION_EMACS:
589 edit_init_menu_emacs ();
590 break;
594 struct WMenu *
595 edit_create_menu (void)
597 edit_init_menu ();
598 return menubar_new (0, 0, COLS, EditMenuBar, N_menus);
601 void
602 edit_done_menu (struct WMenu *wmenu)
604 int i;
605 for (i = 0; i < N_menus; i++)
606 destroy_menu (wmenu->menu[i]);
610 void
611 edit_reload_menu (void)
613 edit_done_menu (edit_menubar);
614 edit_init_menu ();
615 menubar_arrange (edit_menubar);
619 static void
620 edit_drop_menu_cmd (WEdit *e, int which)
622 if (edit_menubar->active)
623 return;
624 edit_menubar->active = 1;
625 edit_menubar->dropped = drop_menus;
626 if (which >= 0) {
627 edit_menubar->selected = which;
630 edit_menubar->previous_widget = e->widget.parent->current->dlg_id;
631 dlg_select_widget (edit_menubar);
635 void edit_menu_cmd (WEdit * e)
637 edit_drop_menu_cmd (e, -1);
641 int edit_drop_hotkey_menu (WEdit * e, int key)
643 int m = 0;
644 switch (key) {
645 case ALT ('f'):
646 if (edit_key_emulation == EDIT_KEY_EMULATION_EMACS)
647 return 0;
648 m = 0;
649 break;
650 case ALT ('e'):
651 m = 1;
652 break;
653 case ALT ('s'):
654 m = 2;
655 break;
656 case ALT ('c'):
657 m = 3;
658 break;
659 case ALT ('o'):
660 m = 4;
661 break;
662 default:
663 return 0;
666 edit_drop_menu_cmd (e, m);
667 return 1;