1 /* editor menu definitions and initialisation
3 Copyright (C) 1996 the Free Software Foundation
5 Authors: 1996, 1997 Paul Sheer
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #include "editcmddef.h"
28 #if defined (HAVE_MAD) && ! defined (MIDNIGHT) && ! defined (GTK)
34 #include "../src/mad.h"
36 extern int edit_key_emulation
;
38 extern WButtonBar
*edit_bar
;
39 extern Dlg_head
*edit_dlg
;
40 extern WMenu
*edit_menubar
;
42 #undef edit_message_dialog
43 #define edit_message_dialog(w,x,y,h,s) query_dialog (h, s, 0, 1, _("&Ok"))
46 static void menu_cmd (int i
)
48 send_message (wedit
->widget
.parent
, (Widget
*) wedit
, WIDGET_COMMAND
, i
);
51 static void menu_key (int i
)
53 send_message (wedit
->widget
.parent
, (Widget
*) wedit
, WIDGET_KEY
, i
);
60 sprintf (s
, "%d", option_word_wrap_line_length
);
61 f
= input_dialog (_(" Word wrap "),
62 /* Not essential to translate */
63 _(" Enter line length, 0 for off: "), s
);
66 option_word_wrap_line_length
= atoi (f
);
72 void edit_about_cmd ()
74 edit_message_dialog (wedit
->mainid
, 20, 20, _(" About "),
78 " Copyright (C) 1996 the Free Software Foundation\n"
80 " A user friendly text editor written\n"
81 " for the Midnight Commander.\n")
85 void menu_mail_cmd (void) { menu_cmd (CK_Mail
); }
86 void menu_load_cmd (void) { menu_cmd (CK_Load
); }
87 void menu_new_cmd (void) { menu_cmd (CK_New
); }
88 void menu_save_cmd (void) { menu_cmd (CK_Save
); }
89 void menu_save_as_cmd (void) { menu_cmd (CK_Save_As
); }
90 void menu_insert_file_cmd (void) { menu_cmd (CK_Insert_File
); }
91 void menu_quit_cmd (void) { menu_cmd (CK_Exit
); }
92 void menu_mark_cmd (void) { menu_cmd (CK_Mark
); }
93 void menu_markcol_cmd (void) { menu_cmd (CK_Column_Mark
); }
94 void menu_ins_cmd (void) { menu_cmd (CK_Toggle_Insert
); }
95 void menu_copy_cmd (void) { menu_cmd (CK_Copy
); }
96 void menu_move_cmd (void) { menu_cmd (CK_Move
); }
97 void menu_delete_cmd (void) { menu_cmd (CK_Remove
); }
98 void menu_cut_cmd (void) { menu_cmd (CK_Save_Block
); }
99 void menu_search_cmd (void) { menu_cmd (CK_Find
); }
100 void menu_search_again_cmd (void) { menu_cmd (CK_Find_Again
); }
101 void menu_replace_cmd (void) { menu_cmd (CK_Replace
); }
102 void menu_begin_record_cmd (void) { menu_cmd (CK_Begin_Record_Macro
); }
103 void menu_end_record_cmd (void) { menu_cmd (CK_End_Record_Macro
); }
104 void menu_wrap_cmd (void) { edit_wrap_cmd (); }
105 void menu_exec_macro_cmd (void) { menu_key (XCTRL ('a')); }
106 void menu_exec_macro_delete_cmd (void) { menu_cmd (CK_Delete_Macro
); }
107 void menu_c_form_cmd (void) { menu_key (KEY_F (19)); }
108 void menu_ispell_cmd (void) { menu_cmd (CK_Pipe_Block (1)); }
109 void menu_sort_cmd (void) { menu_cmd (CK_Sort
); }
110 void menu_date_cmd (void) { menu_cmd (CK_Date
); }
111 void menu_undo_cmd (void) { menu_cmd (CK_Undo
); }
112 void menu_beginning_cmd (void) { menu_cmd (CK_Beginning_Of_Text
); }
113 void menu_end_cmd (void) { menu_cmd (CK_End_Of_Text
); }
114 void menu_refresh_cmd (void) { menu_cmd (CK_Refresh
); }
115 void menu_goto_line (void) { menu_cmd (CK_Goto
); }
116 void menu_lit_cmd (void) { menu_key (XCTRL ('q')); }
117 void menu_format_paragraph (void) { menu_cmd (CK_Paragraph_Format
); }
118 void edit_options_dialog (void);
119 void menu_options (void) { edit_options_dialog (); }
121 static menu_entry FileMenu
[] =
123 {' ', N_("&Open/load... C-o"), 'O', menu_load_cmd
},
124 {' ', N_("&New C-n"), 'N', menu_new_cmd
},
126 {' ', N_("&Save F2"), 'S', menu_save_cmd
},
127 {' ', N_("save &As... F12"), 'A', menu_save_as_cmd
},
129 {' ', N_("&Insert file... F15"), 'I', menu_insert_file_cmd
},
130 {' ', N_("copy to &File... C-f"), 'F', menu_cut_cmd
},
132 {' ', N_("a&Bout... "), 'B', edit_about_cmd
},
134 {' ', N_("&Quit F10"), 'Q', menu_quit_cmd
}
137 static menu_entry FileMenuEmacs
[] =
139 {' ', N_("&Open/load... C-o"), 'O', menu_load_cmd
},
140 {' ', N_("&New C-x k"), 'N', menu_new_cmd
},
142 {' ', N_("&Save F2"), 'S', menu_save_cmd
},
143 {' ', N_("save &As... F12"), 'A', menu_save_as_cmd
},
145 {' ', N_("&Insert file... F15"), 'I', menu_insert_file_cmd
},
146 {' ', N_("copy to &File... "), 'F', menu_cut_cmd
},
148 {' ', N_("a&Bout... "), 'B', edit_about_cmd
},
150 {' ', N_("&Quit F10"), 'Q', menu_quit_cmd
}
153 static menu_entry EditMenu
[] =
155 {' ', N_("&Toggle Mark F3"), 'T', menu_mark_cmd
},
156 {' ', N_("&Mark Columns S-F3"), 'T', menu_markcol_cmd
},
158 {' ', N_("toggle &Ins/overw Ins"), 'I', menu_ins_cmd
},
160 {' ', N_("&Copy F5"), 'C', menu_copy_cmd
},
161 {' ', N_("&Move F6"), 'M', menu_move_cmd
},
162 {' ', N_("&Delete F8"), 'D', menu_delete_cmd
},
164 {' ', N_("&Undo C-u"), 'U', menu_undo_cmd
},
166 {' ', N_("&Beginning C-PgUp"), 'B', menu_beginning_cmd
},
167 {' ', N_("&End C-PgDn"), 'E', menu_end_cmd
}
170 static menu_entry EditMenuEmacs
[] =
172 {' ', N_("&Toggle Mark F3"), 'T', menu_mark_cmd
},
173 {' ', N_("&Mark Columns S-F3"), 'T', menu_markcol_cmd
},
175 {' ', N_("toggle &Ins/overw Ins"), 'I', menu_ins_cmd
},
177 {' ', N_("&Copy F5"), 'C', menu_copy_cmd
},
178 {' ', N_("&Move F6"), 'M', menu_move_cmd
},
179 {' ', N_("&Delete F8"), 'D', menu_delete_cmd
},
181 {' ', N_("&Undo C-u"), 'U', menu_undo_cmd
},
183 {' ', N_("&Beginning C-PgUp"), 'B', menu_beginning_cmd
},
184 {' ', N_("&End C-PgDn"), 'E', menu_end_cmd
}
187 static menu_entry SearReplMenu
[] =
189 {' ', N_("&Search... F7"), 'S', menu_search_cmd
},
190 {' ', N_("search &Again F17"), 'A', menu_search_again_cmd
},
191 {' ', N_("&Replace... F4"), 'R', menu_replace_cmd
}
194 static menu_entry SearReplMenuEmacs
[] =
196 {' ', N_("&Search... F7"), 'S', menu_search_cmd
},
197 {' ', N_("search &Again F17"), 'A', menu_search_again_cmd
},
198 {' ', N_("&Replace... F4"), 'R', menu_replace_cmd
}
201 static menu_entry CmdMenu
[] =
203 {' ', N_("&Goto line... M-l"), 'G', menu_goto_line
},
205 {' ', N_("insert &Literal... C-q"), 'L', menu_lit_cmd
},
207 {' ', N_("&Refresh screen C-l"), 'R', menu_refresh_cmd
},
209 {' ', N_("&Start record macro C-r"), 'S', menu_begin_record_cmd
},
210 {' ', N_("&Finish record macro... C-r"), 'F', menu_end_record_cmd
},
211 {' ', N_("&Execute macro... C-a, KEY"), 'E', menu_exec_macro_cmd
},
212 {' ', N_("delete macr&O... "), 'O', menu_exec_macro_delete_cmd
},
214 {' ', N_("insert &Date/time "), 'D', menu_date_cmd
},
216 {' ', N_("format p&Aragraph M-p"), 'A', menu_format_paragraph
},
217 {' ', N_("'ispell' s&Pell check C-p"), 'P', menu_ispell_cmd
},
218 {' ', N_("sor&T... M-t"), 'T', menu_sort_cmd
},
219 {' ', N_("'indent' &C Formatter F19"), 'C', menu_c_form_cmd
},
220 {' ', N_("&Mail... "), 'M', menu_mail_cmd
}
223 static menu_entry CmdMenuEmacs
[] =
225 {' ', N_("&Goto line... M-l"), 'G', menu_goto_line
},
227 {' ', N_("insert &Literal... C-q"), 'L', menu_lit_cmd
},
229 {' ', N_("&Refresh screen C-l"), 'R', menu_refresh_cmd
},
231 {' ', N_("&Start record macro C-r"), 'S', menu_begin_record_cmd
},
232 {' ', N_("&Finish record macro... C-r"), 'F', menu_end_record_cmd
},
233 {' ', N_("&Execute macro... C-x e, KEY"), 'E', menu_exec_macro_cmd
},
234 {' ', N_("delete macr&O... "), 'o', menu_exec_macro_delete_cmd
},
236 {' ', N_("insert &Date/time "), 'D', menu_date_cmd
},
238 {' ', N_("format p&Aragraph M-p"), 'a', menu_format_paragraph
},
239 {' ', N_("'ispell' s&Pell check M-$"), 'P', menu_ispell_cmd
},
240 {' ', N_("sor&T... M-t"), 'T', menu_sort_cmd
},
241 {' ', N_("'indent' &C Formatter F19"), 'C', menu_c_form_cmd
}
244 extern void menu_save_mode_cmd (void);
246 static menu_entry OptMenu
[] =
248 {' ', N_("&General... "), 'G', menu_options
},
249 {' ', N_("&Save mode..."), 'S', menu_save_mode_cmd
}
251 {' ', N_("&Layout..."), 'L', menu_layout_cmd
}
255 static menu_entry OptMenuEmacs
[] =
257 {' ', N_("&General... "), 'G', menu_options
},
258 {' ', N_("&Save mode..."), 'S', menu_save_mode_cmd
}
260 {' ', N_("&Layout..."), 'L', menu_layout_cmd
}
264 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
266 Menu EditMenuBar
[N_menus
];
268 void edit_init_menu_normal (void)
270 EditMenuBar
[0] = create_menu (_(" File "), FileMenu
, menu_entries (FileMenu
));
271 EditMenuBar
[1] = create_menu (_(" Edit "), EditMenu
, menu_entries (EditMenu
));
272 EditMenuBar
[2] = create_menu (_(" Sear/Repl "), SearReplMenu
, menu_entries (SearReplMenu
));
273 EditMenuBar
[3] = create_menu (_(" Command "), CmdMenu
, menu_entries (CmdMenu
));
274 EditMenuBar
[4] = create_menu (_(" Options "), OptMenu
, menu_entries (OptMenu
));
277 void edit_init_menu_emacs (void)
279 EditMenuBar
[0] = create_menu (_(" File "), FileMenuEmacs
, menu_entries (FileMenuEmacs
));
280 EditMenuBar
[1] = create_menu (_(" Edit "), EditMenuEmacs
, menu_entries (EditMenuEmacs
));
281 EditMenuBar
[2] = create_menu (_(" Sear/Repl "), SearReplMenuEmacs
, menu_entries (SearReplMenuEmacs
));
282 EditMenuBar
[3] = create_menu (_(" Command "), CmdMenuEmacs
, menu_entries (CmdMenuEmacs
));
283 EditMenuBar
[4] = create_menu (_(" Options "), OptMenuEmacs
, menu_entries (OptMenuEmacs
));
286 void edit_done_menu (void)
289 for (i
= 0; i
< N_menus
; i
++)
290 destroy_menu (EditMenuBar
[i
]);
294 void edit_drop_menu_cmd (WEdit
* e
, int which
)
296 if (edit_menubar
->active
)
298 edit_menubar
->active
= 1;
299 edit_menubar
->dropped
= drop_menus
;
300 edit_menubar
->previous_selection
= which
>= 0 ? which
: dlg_item_number (edit_dlg
);
302 edit_menubar
->selected
= which
;
303 dlg_select_widget (edit_dlg
, edit_menubar
);
307 void edit_menu_cmd (WEdit
* e
)
309 edit_drop_menu_cmd (e
, -1);
313 int edit_drop_hotkey_menu (WEdit
* e
, int key
)
318 if (edit_key_emulation
== EDIT_KEY_EMULATION_EMACS
)
338 edit_drop_menu_cmd (e
, m
);
343 #else /* !MIDNIGHT */
346 extern CWidget
*wedit
;
348 void CSetEditMenu (const char *ident
)
350 wedit
= CIdent (ident
);
353 CWidget
*CGetEditMenu (void)
358 static void menu_cmd (unsigned long i
)
362 memset (&e
, 0, sizeof (XEvent
));
363 e
.type
= EditorCommand
;
365 e
.xkey
.window
= wedit
->winid
;
371 void CEditMenuCommand (int i
)
373 menu_cmd ((unsigned long) i
);
376 static void menu_key (KeySym i
, int state
)
379 if (edit_translate_key (0, i
, state
, &cmd
, &ch
)) {
385 static void menu_ctrl_key (unsigned long i
)
387 menu_key ((KeySym
) i
, ControlMask
);
390 void CDrawEditMenuButtons (const char *ident
, Window parent
, Window focus_return
, int x
, int y
)
394 CDrawMenuButton (catstrs (ident
, ".filemenu", 0), parent
, focus_return
, x
, y
, AUTO_WIDTH
, AUTO_HEIGHT
, 8,
395 /* The following are menu options. Do not change the key bindings (eg. C-o) and preserve '\t' */
397 _("Open...\tC-o"), '~', menu_cmd
, (unsigned long) CK_Load
,
398 _("New\tC-n"), '~', menu_cmd
, (unsigned long) CK_New
,
399 "", ' ', (void *) 0, 0L,
400 _("Save\tF2"), '~', menu_cmd
, (unsigned long) CK_Save
,
401 _("Save as...\tF12"), '~', menu_cmd
, (unsigned long) CK_Save_As
,
402 "", ' ', (void *) 0, 0L,
403 _("Insert file...\tF15"), '~', menu_cmd
, (unsigned long) CK_Insert_File
,
404 _("Copy to file...\tC-f"), '~', menu_cmd
, (unsigned long) CK_Save_Block
407 CSetToolHint (catstrs (ident
, ".filemenu", 0), _("Disk operations and file indexing/searching"));
409 CGetHintPos (&x
, &d
);
411 CDrawMenuButton (catstrs (ident
, ".editmenu", 0), parent
, focus_return
, x
, y
, AUTO_WIDTH
, AUTO_HEIGHT
, 20,
413 _("Toggle mark\tF3"), '~', menu_cmd
, (unsigned long) CK_Mark
,
414 _("Toggle mark columns\tC-b"), '~', menu_cmd
, (unsigned long) CK_Column_Mark
,
415 "", ' ', (void *) 0, 0L,
416 _("Toggle book mark\tC-M-Ins"), '~', menu_cmd
, (unsigned long) CK_Toggle_Bookmark
,
417 _("Previous book mark\tC-M-Up"), '~', menu_cmd
, (unsigned long) CK_Prev_Bookmark
,
418 _("Next book mark\tC-M-Down"), '~', menu_cmd
, (unsigned long) CK_Next_Bookmark
,
419 _("Flush book marks"), '~', menu_cmd
, (unsigned long) CK_Flush_Bookmarks
,
420 "", ' ', (void *) 0, 0L,
421 _("Toggle insert/overwrite\tIns"), '~', menu_cmd
, (unsigned long) CK_Toggle_Insert
,
422 "", ' ', (void *) 0, 0L,
423 _("Copy block to cursor\tF5"), '~', menu_cmd
, (unsigned long) CK_Copy
,
424 _("Move block to cursor\tF6"), '~', menu_cmd
, (unsigned long) CK_Move
,
425 _("Delete block\tF8/C-Del"), '~', menu_cmd
, (unsigned long) CK_Remove
,
426 "", ' ', (void *) 0, 0L,
427 _("Copy block to clipbrd\tC-Ins"), '~', menu_cmd
, (unsigned long) CK_XStore
,
428 _("Cut block to clipbrd\tS-Del"), '~', menu_cmd
, (unsigned long) CK_XCut
,
429 _("Paste block from clipbrd\tS-Ins"), '~', menu_cmd
, (unsigned long) CK_XPaste
,
430 _("Selection history\tM-Ins"), '~', menu_cmd
, (unsigned long) CK_Selection_History
,
431 "", ' ', (void *) 0, 0L,
432 _("Undo\tC-BackSpace"), '~', menu_cmd
, (unsigned long) CK_Undo
435 CSetToolHint (catstrs (ident
, ".editmenu", 0), _("Manipulating blocks of text"));
437 CGetHintPos (&x
, &d
);
439 CDrawMenuButton (catstrs (ident
, ".searchmenu", 0), parent
, focus_return
, x
, y
, AUTO_WIDTH
, AUTO_HEIGHT
, 4,
441 _("Search...\tF7"), '~', menu_cmd
, (unsigned long) CK_Find
,
442 _("Search again\tF17"), '~', menu_cmd
, (unsigned long) CK_Find_Again
,
443 _("Replace...\tF4"), '~', menu_cmd
, (unsigned long) CK_Replace
,
444 _("Replace again\tF14"), '~', menu_cmd
, (unsigned long) CK_Replace_Again
447 CSetToolHint (catstrs (ident
, ".searchmenu", 0), _("Search for and replace text"));
449 CGetHintPos (&x
, &d
);
451 CDrawMenuButton (catstrs (ident
, ".commandmenu", 0), parent
, focus_return
, x
, y
, AUTO_WIDTH
, AUTO_HEIGHT
, 11,
453 _("Goto line...\tM-l"), '~', menu_cmd
, (unsigned long) CK_Goto
,
454 "", ' ', (void *) 0, 0L,
455 _("Start record macro\tC-r"), '~', menu_cmd
, (unsigned long) CK_Begin_Record_Macro
,
456 _("Finish record macro...\tC-r"), '~', menu_cmd
, (unsigned long) CK_End_Record_Macro
,
457 _("Execute macro...\tC-a, KEY"), '~', menu_ctrl_key
, (unsigned long) XK_a
,
458 _("Delete macro...\t"), '~', menu_cmd
, (unsigned long) CK_Delete_Macro
,
459 "", ' ', (void *) 0, 0L,
460 _("Insert date/time\tC-d"), '~', menu_cmd
, (unsigned long) CK_Date
,
461 _("Format paragraph\tM-p"), '~', menu_cmd
, (unsigned long) CK_Paragraph_Format
,
462 "", ' ', (void *) 0, 0L,
463 _("Refresh display\tC-l"), '~', menu_cmd
, (unsigned long) CK_Refresh
466 CSetToolHint (catstrs (ident
, ".commandmenu", 0), _("Macros and internal commands"));
470 #endif /* !MIDNIGHT */