editmenu.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. /** \file
  19. * \brief Source: editor menu definitions and initialisation
  20. * \author Paul Sheer
  21. * \date 1996, 1997
  22. */
  23. #include <config.h>
  24. #include <stdio.h>
  25. #include <stdarg.h>
  26. #include <sys/types.h>
  27. #include <unistd.h>
  28. #include <string.h>
  29. #include <ctype.h>
  30. #include <errno.h>
  31. #include <sys/stat.h>
  32. #include <stdlib.h>
  33. #include "../src/global.h"
  34. #include "../src/tty/tty.h" /* KEY_F */
  35. #include "../src/tty/key.h" /* XCTRL */
  36. #include "../src/menu.h" /* menu_entry */
  37. #include "../src/main.h" /* drop_menus */
  38. #include "../src/dialog.h" /* cb_ret_t */
  39. #include "../src/cmddef.h"
  40. #include "edit-impl.h"
  41. #include "edit-widget.h"
  42. static GList *
  43. create_file_menu (void)
  44. {
  45. GList *entries = NULL;
  46. entries = g_list_append (entries, menu_entry_create (_("&Open file..."), CK_Load));
  47. entries = g_list_append (entries, menu_entry_create (_("&New"), CK_New));
  48. entries = g_list_append (entries, menu_separator_create ());
  49. entries = g_list_append (entries, menu_entry_create (_("&Save"), CK_Save));
  50. entries = g_list_append (entries, menu_entry_create (_("Save &as..."), CK_Save_As));
  51. entries = g_list_append (entries, menu_separator_create ());
  52. entries = g_list_append (entries, menu_entry_create (_("&Insert file..."), CK_Insert_File));
  53. entries = g_list_append (entries, menu_entry_create (_("Cop&y to file..."), CK_Save_Block));
  54. entries = g_list_append (entries, menu_separator_create ());
  55. entries = g_list_append (entries, menu_entry_create (_("&User menu..."), CK_User_Menu));
  56. entries = g_list_append (entries, menu_separator_create ());
  57. entries = g_list_append (entries, menu_entry_create (_("A&bout..."), CK_About));
  58. entries = g_list_append (entries, menu_separator_create ());
  59. entries = g_list_append (entries, menu_entry_create (_("&Quit"), CK_Quit));
  60. return entries;
  61. }
  62. static GList *
  63. create_edit_menu (void)
  64. {
  65. GList *entries = NULL;
  66. entries = g_list_append (entries, menu_entry_create (_("&Toggle mark"), CK_Mark));
  67. entries = g_list_append (entries, menu_entry_create (_("&Mark columns"), CK_Column_Mark));
  68. entries = g_list_append (entries, menu_separator_create ());
  69. entries = g_list_append (entries, menu_entry_create (_("Toggle &ins/overw"), CK_Toggle_Insert));
  70. entries = g_list_append (entries, menu_separator_create ());
  71. entries = g_list_append (entries, menu_entry_create (_("&Copy"), CK_Copy));
  72. entries = g_list_append (entries, menu_entry_create (_("&Move"), CK_Move));
  73. entries = g_list_append (entries, menu_entry_create (_("&Delete"), CK_Remove));
  74. entries = g_list_append (entries, menu_separator_create ());
  75. entries = g_list_append (entries, menu_entry_create (_("C&opy to clipfile"), CK_XStore));
  76. entries = g_list_append (entries, menu_entry_create (_("C&ut to clipfile"), CK_XCut));
  77. entries = g_list_append (entries, menu_entry_create (_("&Paste from clipfile"), CK_XPaste));
  78. entries = g_list_append (entries, menu_separator_create ());
  79. entries = g_list_append (entries, menu_entry_create (_("Toggle bookmar&k"), CK_Toggle_Bookmark));
  80. entries = g_list_append (entries, menu_entry_create (_("&Next bookmark"), CK_Next_Bookmark));
  81. entries = g_list_append (entries, menu_entry_create (_("Pre&v bookmark"), CK_Prev_Bookmark));
  82. entries = g_list_append (entries, menu_entry_create (_("&Flush bookmark"), CK_Flush_Bookmarks));
  83. entries = g_list_append (entries, menu_separator_create ());
  84. entries = g_list_append (entries, menu_entry_create (_("&Undo"), CK_Undo));
  85. entries = g_list_append (entries, menu_separator_create ());
  86. entries = g_list_append (entries, menu_entry_create (_("&Beginning"), CK_Beginning_Of_Text));
  87. entries = g_list_append (entries, menu_entry_create (_("&End"), CK_End_Of_Text));
  88. return entries;
  89. }
  90. static GList *
  91. create_search_replace_menu (void)
  92. {
  93. GList *entries = NULL;
  94. entries = g_list_append (entries, menu_entry_create (_("&Search..."), CK_Find));
  95. entries = g_list_append (entries, menu_entry_create (_("Search &again"), CK_Find_Again));
  96. entries = g_list_append (entries, menu_entry_create (_("&Replace..."), CK_Replace));
  97. return entries;
  98. }
  99. static GList *
  100. create_command_menu (void)
  101. {
  102. GList *entries = NULL;
  103. entries = g_list_append (entries, menu_entry_create (_("&Go to line..."), CK_Goto));
  104. entries = g_list_append (entries, menu_entry_create (_("Toggle li&ne state"), CK_Toggle_Line_State));
  105. entries = g_list_append (entries, menu_entry_create (_("Go to matching &bracket"), CK_Match_Bracket));
  106. entries = g_list_append (entries, menu_separator_create ());
  107. entries = g_list_append (entries, menu_entry_create (_("Find declaration"), CK_Find_Definition));
  108. entries = g_list_append (entries, menu_entry_create (_("Back from declaration"), CK_Load_Prev_File));
  109. entries = g_list_append (entries, menu_entry_create (_("Forward to declaration"), CK_Load_Next_File));
  110. #ifdef HAVE_CHARSET
  111. entries = g_list_append (entries, menu_separator_create ());
  112. entries = g_list_append (entries, menu_entry_create (_("Encod&ing..."), CK_SelectCodepage));
  113. #endif
  114. entries = g_list_append (entries, menu_separator_create ());
  115. entries = g_list_append (entries, menu_entry_create (_("&Refresh screen"), CK_Refresh));
  116. entries = g_list_append (entries, menu_separator_create ());
  117. entries = g_list_append (entries, menu_entry_create (_("&Start record macro"), CK_Begin_Record_Macro));
  118. entries = g_list_append (entries, menu_entry_create (_("&Finish record macro..."), CK_End_Record_Macro));
  119. entries = g_list_append (entries, menu_entry_create (_("&Execute macro..."), CK_Execute_Macro));
  120. entries = g_list_append (entries, menu_entry_create (_("Delete macr&o..."), CK_Delete_Macro));
  121. entries = g_list_append (entries, menu_separator_create ());
  122. entries = g_list_append (entries, menu_entry_create (_("'ispell' s&pell check"), CK_Pipe_Block (1)));
  123. entries = g_list_append (entries, menu_entry_create (_("&Mail..."), CK_Mail));
  124. return entries;
  125. }
  126. static GList *
  127. create_format_menu (void)
  128. {
  129. GList *entries = NULL;
  130. entries = g_list_append (entries, menu_entry_create (_("Insert &literal..."), CK_Insert_Literal));
  131. entries = g_list_append (entries, menu_entry_create (_("Insert &date/time"), CK_Date));
  132. entries = g_list_append (entries, menu_separator_create ());
  133. entries = g_list_append (entries, menu_entry_create (_("Format p&aragraph"), CK_Paragraph_Format));
  134. entries = g_list_append (entries, menu_entry_create (_("Sor&t..."), CK_Sort));
  135. entries = g_list_append (entries, menu_entry_create (_("Paste o&utput of..."), CK_ExtCmd));
  136. entries = g_list_append (entries, menu_entry_create (_("E&xternal formatter"), CK_Pipe_Block (0)));
  137. return entries;
  138. }
  139. static GList *
  140. create_options_menu (void)
  141. {
  142. GList *entries = NULL;
  143. entries = g_list_append (entries, menu_entry_create (_("&General... "), CK_Edit_Options));
  144. entries = g_list_append (entries, menu_entry_create (_("Save &mode..."), CK_Edit_Save_Mode));
  145. entries = g_list_append (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
  146. entries = g_list_append (entries, menu_entry_create (_("Syntax &highlighting..."), CK_Choose_Syntax));
  147. entries = g_list_append (entries, menu_separator_create ());
  148. entries = g_list_append (entries, menu_entry_create (_("S&yntax file"), CK_Load_Syntax_File));
  149. entries = g_list_append (entries, menu_entry_create (_("&Menu file"), CK_Load_Menu_File));
  150. entries = g_list_append (entries, menu_separator_create ());
  151. entries = g_list_append (entries, menu_entry_create (_("&Save setup"), CK_SaveSetupCmd));
  152. return entries;
  153. }
  154. void
  155. edit_init_menu (struct WMenuBar *menubar)
  156. {
  157. menubar_add_menu (menubar, create_menu (_("&File"), create_file_menu (), "[Internal File Editor]"));
  158. menubar_add_menu (menubar, create_menu (_("&Edit"), create_edit_menu (), "[Internal File Editor]"));
  159. menubar_add_menu (menubar, create_menu (_("&Search"), create_search_replace_menu (), "[Internal File Editor]"));
  160. menubar_add_menu (menubar, create_menu (_("&Command"), create_command_menu (), "[Internal File Editor]"));
  161. menubar_add_menu (menubar, create_menu (_("For&mat"), create_format_menu (), "[Internal File Editor]"));
  162. menubar_add_menu (menubar, create_menu (_("&Options"), create_options_menu (), "[Internal File Editor]"));
  163. }
  164. static void
  165. edit_drop_menu_cmd (WEdit *e, int which)
  166. {
  167. if (!edit_menubar->is_active) {
  168. edit_menubar->is_active = TRUE;
  169. edit_menubar->is_dropped = (drop_menus != 0);
  170. if (which >= 0)
  171. edit_menubar->selected = which;
  172. edit_menubar->previous_widget = e->widget.parent->current->dlg_id;
  173. dlg_select_widget (edit_menubar);
  174. }
  175. }
  176. void
  177. edit_menu_cmd (WEdit *e)
  178. {
  179. edit_drop_menu_cmd (e, -1);
  180. }
  181. int
  182. edit_drop_hotkey_menu (WEdit *e, int key)
  183. {
  184. int m = 0;
  185. switch (key) {
  186. case ALT ('f'):
  187. m = 0;
  188. break;
  189. case ALT ('e'):
  190. m = 1;
  191. break;
  192. case ALT ('s'):
  193. m = 2;
  194. break;
  195. case ALT ('c'):
  196. m = 3;
  197. break;
  198. case ALT ('m'):
  199. m = 4;
  200. break;
  201. case ALT ('o'):
  202. m = 5;
  203. break;
  204. default:
  205. return 0;
  206. }
  207. edit_drop_menu_cmd (e, m);
  208. return 1;
  209. }