editmenu.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /* editor menu definitions and initialisation
  2. Copyright (C) 1996, 1998, 2001, 2002, 2003, 2005, 2007
  3. Free Software Foundation, Inc.
  4. Authors: 1996, 1997 Paul Sheer
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301, USA.
  17. */
  18. #include <config.h>
  19. #include <stdio.h>
  20. #include <stdarg.h>
  21. #include <sys/types.h>
  22. #ifdef HAVE_UNISTD_H
  23. # include <unistd.h>
  24. #endif
  25. #include <string.h>
  26. #include <ctype.h>
  27. #include <errno.h>
  28. #include <sys/stat.h>
  29. #include <stdlib.h>
  30. #include "../src/global.h"
  31. #include "edit.h"
  32. #include "../src/cmd.h" /* save_setup_cmd() */
  33. #include "../src/wtools.h" /* query_dialog() */
  34. #include "../src/menu.h" /* menu_entry */
  35. #include "../src/tty.h" /* KEY_F */
  36. #include "../src/key.h" /* XCTRL */
  37. #include "../src/main.h" /* drop_menus */
  38. #include "../src/learn.h" /* learn_keys */
  39. #include "edit-widget.h"
  40. #include "editcmddef.h"
  41. static void
  42. menu_cmd (int command)
  43. {
  44. edit_execute_key_command (wedit, command, -1);
  45. edit_update_screen (wedit);
  46. }
  47. static void menu_key (int i)
  48. {
  49. send_message ((Widget *) wedit, WIDGET_KEY, i);
  50. }
  51. static void
  52. edit_about_cmd (void)
  53. {
  54. query_dialog (_(" About "),
  55. _("\n Cooledit v3.11.5\n\n"
  56. " Copyright (C) 1996 the Free Software Foundation\n\n"
  57. " A user friendly text editor written\n"
  58. " for the Midnight Commander.\n"), D_NORMAL,
  59. 1, _("&OK"));
  60. }
  61. static void
  62. menu_mail_cmd (void)
  63. {
  64. menu_cmd (CK_Mail);
  65. }
  66. static void
  67. menu_load_cmd (void)
  68. {
  69. menu_cmd (CK_Load);
  70. }
  71. static void
  72. menu_new_cmd (void)
  73. {
  74. menu_cmd (CK_New);
  75. }
  76. static void
  77. menu_save_cmd (void)
  78. {
  79. menu_cmd (CK_Save);
  80. }
  81. static void
  82. menu_save_as_cmd (void)
  83. {
  84. menu_cmd (CK_Save_As);
  85. }
  86. static void
  87. menu_insert_file_cmd (void)
  88. {
  89. menu_cmd (CK_Insert_File);
  90. }
  91. static void
  92. menu_quit_cmd (void)
  93. {
  94. menu_cmd (CK_Exit);
  95. }
  96. static void
  97. menu_mark_cmd (void)
  98. {
  99. menu_cmd (CK_Mark);
  100. }
  101. static void
  102. menu_markcol_cmd (void)
  103. {
  104. menu_cmd (CK_Column_Mark);
  105. }
  106. static void
  107. menu_ins_cmd (void)
  108. {
  109. menu_cmd (CK_Toggle_Insert);
  110. }
  111. static void
  112. menu_copy_cmd (void)
  113. {
  114. menu_cmd (CK_Copy);
  115. }
  116. static void
  117. menu_move_cmd (void)
  118. {
  119. menu_cmd (CK_Move);
  120. }
  121. static void
  122. menu_delete_cmd (void)
  123. {
  124. menu_cmd (CK_Remove);
  125. }
  126. static void
  127. menu_cut_cmd (void)
  128. {
  129. menu_cmd (CK_Save_Block);
  130. }
  131. static void
  132. menu_search_cmd (void)
  133. {
  134. menu_cmd (CK_Find);
  135. }
  136. static void
  137. menu_search_again_cmd (void)
  138. {
  139. menu_cmd (CK_Find_Again);
  140. }
  141. static void
  142. menu_replace_cmd (void)
  143. {
  144. menu_cmd (CK_Replace);
  145. }
  146. static void
  147. menu_begin_record_cmd (void)
  148. {
  149. menu_cmd (CK_Begin_Record_Macro);
  150. }
  151. static void
  152. menu_end_record_cmd (void)
  153. {
  154. menu_cmd (CK_End_Record_Macro);
  155. }
  156. static void
  157. menu_exec_macro_cmd (void)
  158. {
  159. menu_key (XCTRL ('a'));
  160. }
  161. static void
  162. menu_exec_macro_delete_cmd (void)
  163. {
  164. menu_cmd (CK_Delete_Macro);
  165. }
  166. static void
  167. menu_c_form_cmd (void)
  168. {
  169. menu_key (KEY_F (19));
  170. }
  171. static void
  172. menu_ispell_cmd (void)
  173. {
  174. menu_cmd (CK_Pipe_Block (1));
  175. }
  176. static void
  177. menu_sort_cmd (void)
  178. {
  179. menu_cmd (CK_Sort);
  180. }
  181. static void
  182. menu_ext_cmd (void)
  183. {
  184. menu_cmd (CK_ExtCmd);
  185. }
  186. static void
  187. menu_date_cmd (void)
  188. {
  189. menu_cmd (CK_Date);
  190. }
  191. static void
  192. menu_undo_cmd (void)
  193. {
  194. menu_cmd (CK_Undo);
  195. }
  196. static void
  197. menu_beginning_cmd (void)
  198. {
  199. menu_cmd (CK_Beginning_Of_Text);
  200. }
  201. static void
  202. menu_end_cmd (void)
  203. {
  204. menu_cmd (CK_End_Of_Text);
  205. }
  206. static void
  207. menu_refresh_cmd (void)
  208. {
  209. menu_cmd (CK_Refresh);
  210. }
  211. static void
  212. menu_goto_line (void)
  213. {
  214. menu_cmd (CK_Goto);
  215. }
  216. static void
  217. menu_goto_bracket (void)
  218. {
  219. menu_cmd (CK_Match_Bracket);
  220. }
  221. static void
  222. menu_lit_cmd (void)
  223. {
  224. menu_key (XCTRL ('q'));
  225. }
  226. static void
  227. menu_format_paragraph (void)
  228. {
  229. menu_cmd (CK_Paragraph_Format);
  230. }
  231. static void
  232. menu_options (void)
  233. {
  234. edit_options_dialog ();
  235. }
  236. static void
  237. menu_syntax (void)
  238. {
  239. edit_syntax_dialog ();
  240. }
  241. static void
  242. menu_user_menu_cmd (void)
  243. {
  244. menu_key (KEY_F (11));
  245. }
  246. static menu_entry FileMenu[] =
  247. {
  248. {' ', N_("&Open file..."), NULL_HOTKEY, menu_load_cmd},
  249. {' ', N_("&New C-n"), NULL_HOTKEY, menu_new_cmd},
  250. {' ', "", NULL_HOTKEY, 0},
  251. {' ', N_("&Save F2"), NULL_HOTKEY, menu_save_cmd},
  252. {' ', N_("Save &as... F12"), NULL_HOTKEY, menu_save_as_cmd},
  253. {' ', "", NULL_HOTKEY, 0},
  254. {' ', N_("&Insert file... F15"), NULL_HOTKEY, menu_insert_file_cmd},
  255. {' ', N_("Copy to &file... C-f"), NULL_HOTKEY, menu_cut_cmd},
  256. {' ', "", NULL_HOTKEY, 0},
  257. {' ', N_("&User menu... F11"), NULL_HOTKEY, menu_user_menu_cmd},
  258. {' ', "", NULL_HOTKEY, 0},
  259. {' ', N_("A&bout... "), NULL_HOTKEY, edit_about_cmd},
  260. {' ', "", NULL_HOTKEY, 0},
  261. {' ', N_("&Quit F10"), NULL_HOTKEY, menu_quit_cmd}
  262. };
  263. static menu_entry FileMenuEmacs[] =
  264. {
  265. {' ', N_("&Open file..."), NULL_HOTKEY, menu_load_cmd},
  266. {' ', N_("&New C-x k"), NULL_HOTKEY, menu_new_cmd},
  267. {' ', "", NULL_HOTKEY, 0},
  268. {' ', N_("&Save F2"), NULL_HOTKEY, menu_save_cmd},
  269. {' ', N_("Save &as... F12"), NULL_HOTKEY, menu_save_as_cmd},
  270. {' ', "", NULL_HOTKEY, 0},
  271. {' ', N_("&Insert file... F15"), NULL_HOTKEY, menu_insert_file_cmd},
  272. {' ', N_("Copy to &file... "), NULL_HOTKEY, menu_cut_cmd},
  273. {' ', "", NULL_HOTKEY, 0},
  274. {' ', N_("&User menu... F11"), NULL_HOTKEY, menu_user_menu_cmd},
  275. {' ', "", NULL_HOTKEY, 0},
  276. {' ', N_("A&bout... "), NULL_HOTKEY, edit_about_cmd},
  277. {' ', "", NULL_HOTKEY, 0},
  278. {' ', N_("&Quit F10"), NULL_HOTKEY, menu_quit_cmd}
  279. };
  280. static menu_entry EditMenu[] =
  281. {
  282. {' ', N_("&Toggle Mark F3"), NULL_HOTKEY, menu_mark_cmd},
  283. {' ', N_("&Mark Columns S-F3"), NULL_HOTKEY, menu_markcol_cmd},
  284. {' ', "", NULL_HOTKEY, 0},
  285. {' ', N_("Toggle &ins/overw Ins"), NULL_HOTKEY, menu_ins_cmd},
  286. {' ', "", NULL_HOTKEY, 0},
  287. {' ', N_("&Copy F5"), NULL_HOTKEY, menu_copy_cmd},
  288. {' ', N_("&Move F6"), NULL_HOTKEY, menu_move_cmd},
  289. {' ', N_("&Delete F8"), NULL_HOTKEY, menu_delete_cmd},
  290. {' ', "", NULL_HOTKEY, 0},
  291. {' ', N_("&Undo C-u"), NULL_HOTKEY, menu_undo_cmd},
  292. {' ', "", NULL_HOTKEY, 0},
  293. {' ', N_("&Beginning C-PgUp"), NULL_HOTKEY, menu_beginning_cmd},
  294. {' ', N_("&End C-PgDn"), NULL_HOTKEY, menu_end_cmd}
  295. };
  296. #define EditMenuEmacs EditMenu
  297. static menu_entry SearReplMenu[] =
  298. {
  299. {' ', N_("&Search... F7"), NULL_HOTKEY, menu_search_cmd},
  300. {' ', N_("Search &again F17"), NULL_HOTKEY, menu_search_again_cmd},
  301. {' ', N_("&Replace... F4"), NULL_HOTKEY, menu_replace_cmd}
  302. };
  303. #define SearReplMenuEmacs SearReplMenu
  304. static menu_entry CmdMenu[] =
  305. {
  306. {' ', N_("&Go to line... M-l"), NULL_HOTKEY, menu_goto_line},
  307. {' ', N_("Go to matching &bracket M-b"), NULL_HOTKEY, menu_goto_bracket},
  308. {' ', "", NULL_HOTKEY, 0},
  309. {' ', N_("Insert &literal... C-q"), NULL_HOTKEY, menu_lit_cmd},
  310. {' ', "", NULL_HOTKEY, 0},
  311. {' ', N_("&Refresh screen C-l"), NULL_HOTKEY, menu_refresh_cmd},
  312. {' ', "", NULL_HOTKEY, 0},
  313. {' ', N_("&Start record macro C-r"), NULL_HOTKEY, menu_begin_record_cmd},
  314. {' ', N_("&Finish record macro... C-r"), NULL_HOTKEY, menu_end_record_cmd},
  315. {' ', N_("&Execute macro... C-a, KEY"), NULL_HOTKEY, menu_exec_macro_cmd},
  316. {' ', N_("Delete macr&o... "), NULL_HOTKEY, menu_exec_macro_delete_cmd},
  317. {' ', "", NULL_HOTKEY, 0},
  318. {' ', N_("Insert &date/time "), NULL_HOTKEY, menu_date_cmd},
  319. {' ', "", NULL_HOTKEY, 0},
  320. {' ', N_("Format p&aragraph M-p"), NULL_HOTKEY, menu_format_paragraph},
  321. {' ', N_("'ispell' s&pell check C-p"), NULL_HOTKEY, menu_ispell_cmd},
  322. {' ', N_("Sor&t... M-t"), NULL_HOTKEY, menu_sort_cmd},
  323. {' ', N_("Paste o&utput of... M-u"), NULL_HOTKEY, menu_ext_cmd},
  324. {' ', N_("E&xternal Formatter F19"), NULL_HOTKEY, menu_c_form_cmd},
  325. {' ', N_("&Mail... "), NULL_HOTKEY, menu_mail_cmd}
  326. };
  327. static menu_entry CmdMenuEmacs[] =
  328. {
  329. {' ', N_("&Go to line... M-l"), NULL_HOTKEY, menu_goto_line},
  330. {' ', N_("Go to matching &bracket M-b"), NULL_HOTKEY, menu_goto_bracket},
  331. {' ', "", NULL_HOTKEY, 0},
  332. {' ', N_("Insert &literal... C-q"), NULL_HOTKEY, menu_lit_cmd},
  333. {' ', "", NULL_HOTKEY, 0},
  334. {' ', N_("&Refresh screen C-l"), NULL_HOTKEY, menu_refresh_cmd},
  335. {' ', "", NULL_HOTKEY, 0},
  336. {' ', N_("&Start record macro C-r"), NULL_HOTKEY, menu_begin_record_cmd},
  337. {' ', N_("&Finish record macro... C-r"), NULL_HOTKEY, menu_end_record_cmd},
  338. {' ', N_("&Execute macro... C-x e, KEY"), NULL_HOTKEY, menu_exec_macro_cmd},
  339. {' ', N_("Delete macr&o... "), NULL_HOTKEY, menu_exec_macro_delete_cmd},
  340. {' ', "", NULL_HOTKEY, 0},
  341. {' ', N_("Insert &date/time "), NULL_HOTKEY, menu_date_cmd},
  342. {' ', "", NULL_HOTKEY, 0},
  343. {' ', N_("Format p&aragraph M-p"), NULL_HOTKEY, menu_format_paragraph},
  344. {' ', N_("'ispell' s&pell check M-$"), NULL_HOTKEY, menu_ispell_cmd},
  345. {' ', N_("Sor&t... M-t"), NULL_HOTKEY, menu_sort_cmd},
  346. {' ', N_("Paste o&utput of... M-u"), NULL_HOTKEY, menu_ext_cmd},
  347. {' ', N_("E&xternal Formatter F19"), NULL_HOTKEY, menu_c_form_cmd},
  348. {' ', N_("&Mail... "), NULL_HOTKEY, menu_mail_cmd}
  349. };
  350. static menu_entry OptMenu[] =
  351. {
  352. {' ', N_("&General... "), NULL_HOTKEY, menu_options},
  353. {' ', N_("&Save mode..."), NULL_HOTKEY, menu_save_mode_cmd},
  354. {' ', N_("Learn &Keys..."), NULL_HOTKEY, learn_keys},
  355. {' ', N_("Syntax &Highlighting..."), NULL_HOTKEY, menu_syntax},
  356. {' ', "", NULL_HOTKEY, 0},
  357. {' ', N_("Save setu&p..."), NULL_HOTKEY, save_setup_cmd}
  358. };
  359. #define OptMenuEmacs OptMenu
  360. #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
  361. #define N_menus 5
  362. static Menu *EditMenuBar [N_menus];
  363. static void
  364. edit_init_menu_normal (void)
  365. {
  366. EditMenuBar[0] = create_menu (_(" File "), FileMenu, menu_entries (FileMenu),
  367. "[Internal File Editor]");
  368. EditMenuBar[1] = create_menu (_(" Edit "), EditMenu, menu_entries (EditMenu),
  369. "[Internal File Editor]");
  370. EditMenuBar[2] = create_menu (_(" Sear/Repl "), SearReplMenu, menu_entries (SearReplMenu),
  371. "[Internal File Editor]");
  372. EditMenuBar[3] = create_menu (_(" Command "), CmdMenu, menu_entries (CmdMenu),
  373. "[Internal File Editor]");
  374. EditMenuBar[4] = create_menu (_(" Options "), OptMenu, menu_entries (OptMenu),
  375. "[Internal File Editor]");
  376. }
  377. static void
  378. edit_init_menu_emacs (void)
  379. {
  380. EditMenuBar[0] = create_menu (_(" File "), FileMenuEmacs, menu_entries (FileMenuEmacs),
  381. "[Internal File Editor]");
  382. EditMenuBar[1] = create_menu (_(" Edit "), EditMenuEmacs, menu_entries (EditMenuEmacs),
  383. "[Internal File Editor]");
  384. EditMenuBar[2] = create_menu (_(" Sear/Repl "), SearReplMenuEmacs, menu_entries (SearReplMenuEmacs),
  385. "[Internal File Editor]");
  386. EditMenuBar[3] = create_menu (_(" Command "), CmdMenuEmacs, menu_entries (CmdMenuEmacs),
  387. "[Internal File Editor]");
  388. EditMenuBar[4] = create_menu (_(" Options "), OptMenuEmacs, menu_entries (OptMenuEmacs),
  389. "[Internal File Editor]");
  390. }
  391. static void
  392. edit_init_menu (void)
  393. {
  394. switch (edit_key_emulation) {
  395. default:
  396. case EDIT_KEY_EMULATION_NORMAL:
  397. edit_init_menu_normal ();
  398. break;
  399. case EDIT_KEY_EMULATION_EMACS:
  400. edit_init_menu_emacs ();
  401. break;
  402. }
  403. }
  404. struct WMenu *
  405. edit_create_menu (void)
  406. {
  407. edit_init_menu ();
  408. return menubar_new (0, 0, COLS, EditMenuBar, N_menus);
  409. }
  410. void
  411. edit_done_menu (struct WMenu *wmenu)
  412. {
  413. int i;
  414. for (i = 0; i < N_menus; i++)
  415. destroy_menu (wmenu->menu[i]);
  416. }
  417. void
  418. edit_reload_menu (void)
  419. {
  420. edit_done_menu (edit_menubar);
  421. edit_init_menu ();
  422. menubar_arrange (edit_menubar);
  423. }
  424. static void
  425. edit_drop_menu_cmd (WEdit *e, int which)
  426. {
  427. if (edit_menubar->active)
  428. return;
  429. edit_menubar->active = 1;
  430. edit_menubar->dropped = drop_menus;
  431. if (which >= 0) {
  432. edit_menubar->selected = which;
  433. }
  434. edit_menubar->previous_widget = e->widget.parent->current->dlg_id;
  435. dlg_select_widget (edit_menubar);
  436. }
  437. void edit_menu_cmd (WEdit * e)
  438. {
  439. edit_drop_menu_cmd (e, -1);
  440. }
  441. int edit_drop_hotkey_menu (WEdit * e, int key)
  442. {
  443. int m = 0;
  444. switch (key) {
  445. case ALT ('f'):
  446. if (edit_key_emulation == EDIT_KEY_EMULATION_EMACS)
  447. return 0;
  448. m = 0;
  449. break;
  450. case ALT ('e'):
  451. m = 1;
  452. break;
  453. case ALT ('s'):
  454. m = 2;
  455. break;
  456. case ALT ('c'):
  457. m = 3;
  458. break;
  459. case ALT ('o'):
  460. m = 4;
  461. break;
  462. default:
  463. return 0;
  464. }
  465. edit_drop_menu_cmd (e, m);
  466. return 1;
  467. }