Ticket #1563: Modified menu engine to create and modify menu dynamically.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2009-05-04 20:11:51 +04:00
parent a563b5d429
commit 7f7bc452e3
7 changed files with 839 additions and 672 deletions

View File

@ -145,8 +145,7 @@ extern const char VERTICAL_MAGIC[5];
extern int enable_show_tabs_tws;
int edit_drop_hotkey_menu (WEdit *e, int key);
void edit_menu_cmd (WEdit *e);
struct WMenu *edit_create_menu (void);
void edit_done_menu (struct WMenu *wmenu);
struct WMenuBar *edit_create_menu (void);
void edit_reload_menu (void);
void menu_save_mode_cmd (void);
int edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch);
@ -299,8 +298,7 @@ extern int edit_stack_iterator;
extern edit_stack_type edit_history_moveto [MAX_HISTORY_MOVETO];
extern WEdit *wedit;
struct WMenu;
extern struct WMenu *edit_menubar;
extern struct WMenuBar *edit_menubar;
extern int option_line_state_width;

View File

@ -373,273 +373,291 @@ menu_declare_forward (void)
menu_cmd (CK_Load_Next_File);
}
static menu_entry FileMenu[] =
static GPtrArray *
create_file_menu (void)
{
{' ', N_("&Open file..."), NULL_HOTKEY, menu_load_cmd},
{' ', N_("&New C-n"), NULL_HOTKEY, menu_new_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Save F2"), NULL_HOTKEY, menu_save_cmd},
{' ', N_("Save &as... F12"), NULL_HOTKEY, menu_save_as_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Insert file... F15"), NULL_HOTKEY, menu_insert_file_cmd},
{' ', N_("Copy to &file... C-f"), NULL_HOTKEY, menu_cut_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&User menu... F11"), NULL_HOTKEY, menu_user_menu_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("A&bout... "), NULL_HOTKEY, edit_about_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Quit F10"), NULL_HOTKEY, menu_quit_cmd}
};
GPtrArray *entries = g_ptr_array_new ();
static menu_entry FileMenuEmacs[] =
g_ptr_array_add (entries, menu_entry_create (_("&Open file..."), menu_load_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&New C-n"), menu_new_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Save F2"), menu_save_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Save &as... F12"), menu_save_as_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Insert file... F15"), menu_insert_file_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Copy to &file... C-f"), menu_cut_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&User menu... F11"), menu_user_menu_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("A&bout... "), edit_about_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Quit F10"), menu_quit_cmd));
return entries;
}
static GPtrArray *
create_file_menu_emacs (void)
{
{' ', N_("&Open file..."), NULL_HOTKEY, menu_load_cmd},
{' ', N_("&New C-x k"), NULL_HOTKEY, menu_new_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Save F2"), NULL_HOTKEY, menu_save_cmd},
{' ', N_("Save &as... F12"), NULL_HOTKEY, menu_save_as_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Insert file... F15"), NULL_HOTKEY, menu_insert_file_cmd},
{' ', N_("Copy to &file... "), NULL_HOTKEY, menu_cut_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&User menu... F11"), NULL_HOTKEY, menu_user_menu_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("A&bout... "), NULL_HOTKEY, edit_about_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Quit F10"), NULL_HOTKEY, menu_quit_cmd}
};
GPtrArray *entries = g_ptr_array_new ();
static menu_entry EditMenu[] =
g_ptr_array_add (entries, menu_entry_create (_("&Open file..."), menu_load_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&New C-x k"), menu_new_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Save F2"), menu_save_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Save &as... F12"), menu_save_as_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Insert file... F15"), menu_insert_file_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Copy to &file... "), menu_cut_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&User menu... F11"), menu_user_menu_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("A&bout... "), edit_about_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Quit F10"), menu_quit_cmd));
return entries;
}
static GPtrArray *
create_edit_menu (void)
{
{' ', N_("&Toggle mark F3"), NULL_HOTKEY, menu_mark_cmd},
{' ', N_("Mar&k columns S-F3"), NULL_HOTKEY, menu_markcol_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Toggle &ins/overw Ins"), NULL_HOTKEY, menu_ins_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Copy F5"), NULL_HOTKEY, menu_copy_cmd},
{' ', N_("&Move F6"), NULL_HOTKEY, menu_move_cmd},
{' ', N_("&Delete F8"), NULL_HOTKEY, menu_delete_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("C&opy to clipfile C-Ins"), NULL_HOTKEY, menu_xstore_cmd},
{' ', N_("C&ut to clipfile S-Del"), NULL_HOTKEY, menu_xcut_cmd},
{' ', N_("&Paste from clipfile S-Ins"), NULL_HOTKEY, menu_xpaste_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Toggle bookmar&k M-k"), NULL_HOTKEY, menu_toggle_bookmark_cmd},
{' ', N_("&Next bookmark M-j"), NULL_HOTKEY, menu_next_bookmark_cmd},
{' ', N_("Pre&v bookmark M-i"), NULL_HOTKEY, menu_prev_bookmark_cmd},
{' ', N_("&Flush bookmark M-o"), NULL_HOTKEY, menu_flush_bookmark_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Undo C-u"), NULL_HOTKEY, menu_undo_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Beginning C-PgUp"), NULL_HOTKEY, menu_beginning_cmd},
{' ', N_("&End C-PgDn"), NULL_HOTKEY, menu_end_cmd}
};
GPtrArray *entries = g_ptr_array_new ();
static menu_entry EditMenuEmacs[] =
g_ptr_array_add (entries, menu_entry_create (_("&Toggle Mark F3"), menu_mark_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Mark Columns S-F3"), menu_markcol_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Toggle &ins/overw Ins"), menu_ins_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Copy F5"), menu_copy_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Move F6"), menu_move_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Delete F8"), menu_delete_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("C&opy to clipfile C-Ins"), menu_xstore_cmd));
g_ptr_array_add (entries, menu_entry_create (_("C&ut to clipfile S-Del"), menu_xcut_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Paste from clipfile S-Ins"), menu_xpaste_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Toggle bookmar&k M-k"), menu_toggle_bookmark_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Next bookmark M-j"), menu_next_bookmark_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Pre&v bookmark M-i"), menu_prev_bookmark_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Flush bookmark M-o"), menu_flush_bookmark_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Undo C-u"), menu_undo_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Beginning C-PgUp"), menu_beginning_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&End C-PgDn"), menu_end_cmd));
return entries;
}
static GPtrArray *
create_edit_menu_emacs (void)
{
{' ', N_("&Toggle mark F3"), NULL_HOTKEY, menu_mark_cmd},
{' ', N_("Mar&k columns S-F3"), NULL_HOTKEY, menu_markcol_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Toggle &ins/overw Ins"), NULL_HOTKEY, menu_ins_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Copy F5"), NULL_HOTKEY, menu_copy_cmd},
{' ', N_("&Move F6"), NULL_HOTKEY, menu_move_cmd},
{' ', N_("&Delete F8"), NULL_HOTKEY, menu_delete_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("C&opy to clipfile M-w"), NULL_HOTKEY, menu_xstore_cmd},
{' ', N_("C&ut to clipfile C-w"), NULL_HOTKEY, menu_xcut_cmd},
{' ', N_("&Paste from clipfile C-y"), NULL_HOTKEY, menu_xpaste_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Toggle bookmar&k "), NULL_HOTKEY, menu_toggle_bookmark_cmd},
{' ', N_("&Next bookmark "), NULL_HOTKEY, menu_next_bookmark_cmd},
{' ', N_("Pre&v bookmark "), NULL_HOTKEY, menu_prev_bookmark_cmd},
{' ', N_("&Flush bookmark "), NULL_HOTKEY, menu_flush_bookmark_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Undo C-u"), NULL_HOTKEY, menu_undo_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Beginning C-PgUp"), NULL_HOTKEY, menu_beginning_cmd},
{' ', N_("&End C-PgDn"), NULL_HOTKEY, menu_end_cmd}
};
GPtrArray *entries = g_ptr_array_new ();
static menu_entry SearReplMenu[] =
g_ptr_array_add (entries, menu_entry_create (_("&Toggle mark F3"), menu_mark_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Mar&k columns S-F3"), menu_markcol_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Toggle &ins/overw Ins"), menu_ins_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Copy F5"), menu_copy_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Move F6"), menu_move_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Delete F8"), menu_delete_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("C&opy to clipfile M-w"), menu_xstore_cmd));
g_ptr_array_add (entries, menu_entry_create (_("C&ut to clipfile C-w"), menu_xcut_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Paste from clipfile C-y"), menu_xpaste_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Toggle bookmar&k "), menu_toggle_bookmark_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Next bookmark "), menu_next_bookmark_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Pre&v bookmark "), menu_prev_bookmark_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Flush bookmark "), menu_flush_bookmark_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Undo C-u"), menu_undo_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Beginning C-PgUp"), menu_beginning_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&End C-PgDn"), menu_end_cmd));
return entries;
}
static GPtrArray *
create_search_replace_menu (void)
{
{' ', N_("&Search... F7"), NULL_HOTKEY, menu_search_cmd},
{' ', N_("Search &again F17"), NULL_HOTKEY, menu_search_again_cmd},
{' ', N_("&Replace... F4"), NULL_HOTKEY, menu_replace_cmd}
};
GPtrArray *entries = g_ptr_array_new ();
#define SearReplMenuEmacs SearReplMenu
g_ptr_array_add (entries, menu_entry_create (_("&Search... F7"), menu_search_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Search &again F17"), menu_search_again_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Replace... F4"), menu_replace_cmd));
static menu_entry CmdMenu[] =
return entries;
}
static GPtrArray *
create_command_menu (void)
{
{' ', N_("&Go to line... M-l"), NULL_HOTKEY, menu_goto_line},
{' ', N_("Toggle li&ne state M-n"), NULL_HOTKEY, menu_toggle_line_state},
{' ', N_("Go to matching &bracket M-b"), NULL_HOTKEY, menu_goto_bracket},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Find declaration A-Enter"), NULL_HOTKEY, menu_find_declare},
{' ', N_("Back from declaration M--"), NULL_HOTKEY, menu_declare_back},
{' ', N_("Forward to declaration M-+"), NULL_HOTKEY, menu_declare_forward},
GPtrArray *entries = g_ptr_array_new ();
g_ptr_array_add (entries, menu_entry_create (_("&Go to line... M-l"), menu_goto_line));
g_ptr_array_add (entries, menu_entry_create (_("Toggle li&ne state M-n"), menu_toggle_line_state));
g_ptr_array_add (entries, menu_entry_create (_("Go to matching &bracket M-b"), menu_goto_bracket));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Find declaration A-Enter"), menu_find_declare));
g_ptr_array_add (entries, menu_entry_create (_("Back from declaration M--"), menu_declare_back));
g_ptr_array_add (entries, menu_entry_create (_("Forward to declaration M-+"), menu_declare_forward));
#ifdef HAVE_CHARSET
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Encod&ing... M-e"), NULL_HOTKEY, menu_select_codepage_cmd},
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Encod&ing... M-e"), menu_select_codepage_cmd));
#endif
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Insert &literal... C-q"), NULL_HOTKEY, menu_lit_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Refresh screen C-l"), NULL_HOTKEY, menu_refresh_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Start record macro C-r"), NULL_HOTKEY, menu_begin_record_cmd},
{' ', N_("&Finish record macro... C-r"), NULL_HOTKEY, menu_end_record_cmd},
{' ', N_("&Execute macro... C-a, KEY"), NULL_HOTKEY, menu_exec_macro_cmd},
{' ', N_("Delete macr&o... "), NULL_HOTKEY, menu_exec_macro_delete_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Insert &date/time "), NULL_HOTKEY, menu_date_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Format p&aragraph M-p"), NULL_HOTKEY, menu_format_paragraph},
{' ', N_("'ispell' s&pell check C-p"), NULL_HOTKEY, menu_ispell_cmd},
{' ', N_("Sor&t... M-t"), NULL_HOTKEY, menu_sort_cmd},
{' ', N_("Paste o&utput of... M-u"), NULL_HOTKEY, menu_ext_cmd},
{' ', N_("E&xternal Formatter F19"), NULL_HOTKEY, menu_c_form_cmd},
{' ', N_("&Mail... "), NULL_HOTKEY, menu_mail_cmd}
};
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Insert &literal... C-q"), menu_lit_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Refresh screen C-l"), menu_refresh_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Start record macro C-r"), menu_begin_record_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Finish record macro... C-r"), menu_end_record_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Execute macro... C-a, KEY"), menu_exec_macro_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Delete macr&o... "), menu_exec_macro_delete_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Insert &date/time "), menu_date_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Format p&aragraph M-p"), menu_format_paragraph));
g_ptr_array_add (entries, menu_entry_create (_("'ispell' s&pell check C-p"), menu_ispell_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Sor&t... M-t"), menu_sort_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Paste o&utput of... M-u"), menu_ext_cmd));
g_ptr_array_add (entries, menu_entry_create (_("E&xternal Formatter F19"), menu_c_form_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Mail... "), menu_mail_cmd));
static menu_entry CmdMenuEmacs[] =
return entries;
}
static GPtrArray *
create_command_menu_emacs (void)
{
{' ', N_("&Go to line... M-l"), NULL_HOTKEY, menu_goto_line},
{' ', N_("Toggle li&ne state M-n"), NULL_HOTKEY, menu_toggle_line_state},
{' ', N_("Go to matching &bracket M-b"), NULL_HOTKEY, menu_goto_bracket},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Insert &literal... C-q"), NULL_HOTKEY, menu_lit_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Refresh screen C-l"), NULL_HOTKEY, menu_refresh_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Start record macro C-r"), NULL_HOTKEY, menu_begin_record_cmd},
{' ', N_("&Finish record macro... C-r"), NULL_HOTKEY, menu_end_record_cmd},
{' ', N_("&Execute macro... C-x e, KEY"), NULL_HOTKEY, menu_exec_macro_cmd},
{' ', N_("Delete macr&o... "), NULL_HOTKEY, menu_exec_macro_delete_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Insert &date/time "), NULL_HOTKEY, menu_date_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Format p&aragraph M-p"), NULL_HOTKEY, menu_format_paragraph},
{' ', N_("'ispell' s&pell check M-$"), NULL_HOTKEY, menu_ispell_cmd},
{' ', N_("Sor&t... M-t"), NULL_HOTKEY, menu_sort_cmd},
{' ', N_("Paste o&utput of... M-u"), NULL_HOTKEY, menu_ext_cmd},
{' ', N_("E&xternal Formatter F19"), NULL_HOTKEY, menu_c_form_cmd},
{' ', N_("&Mail... "), NULL_HOTKEY, menu_mail_cmd}
};
GPtrArray *entries = g_ptr_array_new ();
static menu_entry OptMenu[] =
g_ptr_array_add (entries, menu_entry_create (_("&Go to line... M-l"), menu_goto_line));
g_ptr_array_add (entries, menu_entry_create (_("Toggle li&ne state M-n"), menu_toggle_line_state));
g_ptr_array_add (entries, menu_entry_create (_("Go to matching &bracket M-b"), menu_goto_bracket));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Find declaration A-Enter"), menu_find_declare));
g_ptr_array_add (entries, menu_entry_create (_("Back from declaration M--"), menu_declare_back));
g_ptr_array_add (entries, menu_entry_create (_("Forward to declaration M-+"), menu_declare_forward));
#ifdef HAVE_CHARSET
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Encod&ing... C-t"), menu_select_codepage_cmd));
#endif
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Insert &literal... C-q"), menu_lit_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Refresh screen C-l"), menu_refresh_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Start record macro C-r"), menu_begin_record_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Finish record macro... C-r"), menu_end_record_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Execute macro... C-x e, KEY"), menu_exec_macro_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Delete macr&o... "), menu_exec_macro_delete_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Insert &date/time "), menu_date_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Format p&aragraph M-p"), menu_format_paragraph));
g_ptr_array_add (entries, menu_entry_create (_("'ispell' s&pell check M-$"), menu_ispell_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Sor&t... M-t"), menu_sort_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Paste o&utput of... M-u"), menu_ext_cmd));
g_ptr_array_add (entries, menu_entry_create (_("E&xternal Formatter F19"), menu_c_form_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Mail... "), menu_mail_cmd));
return entries;
}
static GPtrArray *
create_options_menu (void)
{
{' ', N_("&General... "), NULL_HOTKEY, edit_options_dialog},
{' ', N_("&Save mode..."), NULL_HOTKEY, menu_save_mode_cmd},
{' ', N_("Learn &Keys..."), NULL_HOTKEY, learn_keys},
{' ', N_("Syntax &Highlighting..."), NULL_HOTKEY, edit_syntax_dialog},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("S&yntax file"), NULL_HOTKEY, menu_edit_syntax_file_cmd},
{' ', N_("&Menu file"), NULL_HOTKEY, menu_edit_menu_file_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Save setu&p"), NULL_HOTKEY, save_setup_cmd}
};
GPtrArray *entries = g_ptr_array_new ();
#define OptMenuEmacs OptMenu
g_ptr_array_add (entries, menu_entry_create (_("&General... "), edit_options_dialog));
g_ptr_array_add (entries, menu_entry_create (_("&Save mode..."), menu_save_mode_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Learn &Keys..."), learn_keys));
g_ptr_array_add (entries, menu_entry_create (_("Syntax &Highlighting..."), edit_syntax_dialog));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("S&yntax file"), menu_edit_syntax_file_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Menu file"), menu_edit_menu_file_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("Save setu&p..."), save_setup_cmd));
#define menu_entries(x) sizeof(x)/sizeof(menu_entry)
#define N_menus 5
static Menu *EditMenuBar [N_menus];
static void
edit_init_menu_normal (void)
{
EditMenuBar[0] = create_menu (_(" File "), FileMenu, menu_entries (FileMenu),
"[Internal File Editor]");
EditMenuBar[1] = create_menu (_(" Edit "), EditMenu, menu_entries (EditMenu),
"[Internal File Editor]");
EditMenuBar[2] = create_menu (_(" Sear/Repl "), SearReplMenu, menu_entries (SearReplMenu),
"[Internal File Editor]");
EditMenuBar[3] = create_menu (_(" Command "), CmdMenu, menu_entries (CmdMenu),
"[Internal File Editor]");
EditMenuBar[4] = create_menu (_(" Options "), OptMenu, menu_entries (OptMenu),
"[Internal File Editor]");
return entries;
}
static void
edit_init_menu_emacs (void)
edit_init_menu_normal (struct WMenuBar *menubar)
{
EditMenuBar[0] = create_menu (_(" File "), FileMenuEmacs, menu_entries (FileMenuEmacs),
"[Internal File Editor]");
EditMenuBar[1] = create_menu (_(" Edit "), EditMenuEmacs, menu_entries (EditMenuEmacs),
"[Internal File Editor]");
EditMenuBar[2] = create_menu (_(" Sear/Repl "), SearReplMenuEmacs, menu_entries (SearReplMenuEmacs),
"[Internal File Editor]");
EditMenuBar[3] = create_menu (_(" Command "), CmdMenuEmacs, menu_entries (CmdMenuEmacs),
"[Internal File Editor]");
EditMenuBar[4] = create_menu (_(" Options "), OptMenuEmacs, menu_entries (OptMenuEmacs),
"[Internal File Editor]");
menubar_add_menu (menubar, create_menu (_(" &File "), create_file_menu (), "[Internal File Editor]"));
menubar_add_menu (menubar, create_menu (_(" &Edit "), create_edit_menu (), "[Internal File Editor]"));
menubar_add_menu (menubar, create_menu (_(" &Sear/Repl "), create_search_replace_menu (), "[Internal File Editor]"));
menubar_add_menu (menubar, create_menu (_(" &Command "), create_command_menu (), "[Internal File Editor]"));
menubar_add_menu (menubar, create_menu (_(" &Options "), create_options_menu (), "[Internal File Editor]"));
}
static void
edit_init_menu (void)
edit_init_menu_emacs (struct WMenuBar *menubar)
{
menubar_add_menu (menubar, create_menu (_(" &File "), create_file_menu_emacs (), "[Internal File Editor]"));
menubar_add_menu (menubar, create_menu (_(" &Edit "), create_edit_menu_emacs (), "[Internal File Editor]"));
menubar_add_menu (menubar, create_menu (_(" &Sear/Repl "), create_search_replace_menu (), "[Internal File Editor]"));
menubar_add_menu (menubar, create_menu (_(" &Command "), create_command_menu_emacs (), "[Internal File Editor]"));
menubar_add_menu (menubar, create_menu (_(" &Options "), create_options_menu (), "[Internal File Editor]"));
}
static void
edit_init_menu (struct WMenuBar *menubar)
{
switch (edit_key_emulation) {
default:
case EDIT_KEY_EMULATION_NORMAL:
edit_init_menu_normal ();
edit_init_menu_normal (menubar);
break;
case EDIT_KEY_EMULATION_EMACS:
edit_init_menu_emacs ();
edit_init_menu_emacs (menubar);
break;
}
}
struct WMenu *
struct WMenuBar *
edit_create_menu (void)
{
edit_init_menu ();
return menubar_new (0, 0, COLS, EditMenuBar, N_menus);
}
struct WMenuBar *menubar;
void
edit_done_menu (struct WMenu *wmenu)
{
int i;
for (i = 0; i < N_menus; i++)
destroy_menu (wmenu->menu[i]);
menubar = menubar_new (0, 0, COLS, NULL);
edit_init_menu (menubar);
return menubar;
}
void
edit_reload_menu (void)
{
edit_done_menu (edit_menubar);
edit_init_menu ();
menubar_arrange (edit_menubar);
menubar_set_menu (edit_menubar, NULL);
edit_init_menu (edit_menubar);
}
static void
edit_drop_menu_cmd (WEdit *e, int which)
{
if (edit_menubar->active)
if (edit_menubar->is_active)
return;
edit_menubar->active = 1;
edit_menubar->dropped = drop_menus;
if (which >= 0) {
edit_menubar->is_active = TRUE;
edit_menubar->is_dropped = (drop_menus != 0);
if (which >= 0)
edit_menubar->selected = which;
}
edit_menubar->previous_widget = e->widget.parent->current->dlg_id;
dlg_select_widget (edit_menubar);
}
void edit_menu_cmd (WEdit * e)
{
edit_drop_menu_cmd (e, -1);
}
int edit_drop_hotkey_menu (WEdit * e, int key)
{
int m = 0;

View File

@ -51,7 +51,7 @@
#include "../src/menu.h" /* menubar_new() */
WEdit *wedit;
struct WMenu *edit_menubar;
struct WMenuBar *edit_menubar;
int column_highlighting = 0;
@ -213,8 +213,6 @@ edit_file (const char *_file, int line)
run_dlg (edit_dlg);
edit_done_menu (edit_menubar); /* editmenu.c */
destroy_dlg (edit_dlg);
return 1;

View File

@ -14,6 +14,6 @@ extern WLabel *the_prompt;
extern WLabel *the_hint;
extern Dlg_head *midnight_dlg;
extern struct WMenu *the_menubar;
extern struct WMenuBar *the_menubar;
#endif

View File

@ -118,7 +118,7 @@ mc_fhl_t *mc_filehighlight;
WTree *the_tree = NULL;
/* The Menubar */
struct WMenu *the_menubar = NULL;
struct WMenuBar *the_menubar = NULL;
/* Pointers to the selected and unselected panel */
WPanel *current_panel = NULL;
@ -666,178 +666,194 @@ listmode_cmd (void)
#endif /* LISTMODE_EDITOR */
/* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
static menu_entry LeftMenu[] = {
{' ', N_("&Listing mode..."), NULL_HOTKEY, listing_cmd},
{' ', N_("&Quick view C-x q"), NULL_HOTKEY, quick_view_cmd},
{' ', N_("&Info C-x i"), NULL_HOTKEY, info_cmd},
{' ', N_("&Tree"), NULL_HOTKEY, tree_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Sort order..."), NULL_HOTKEY, sort_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Filter..."), NULL_HOTKEY, filter_cmd},
static GPtrArray *
create_left_menu (void)
{
GPtrArray *entries = g_ptr_array_new ();
g_ptr_array_add (entries, menu_entry_create (_("&Listing mode..."), listing_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Quick view C-x q"), quick_view_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Info C-x i" ), info_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Tree"), tree_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Sort order..."), sort_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Filter..."), filter_cmd));
#ifdef HAVE_CHARSET
{' ', "",NULL_HOTKEY, 0},
{' ', N_("&Encoding... M-e"), NULL_HOTKEY, encoding_cmd},
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Encoding... M-e"), encoding_cmd));
#endif
#ifdef USE_NETCODE
{' ', "", NULL_HOTKEY, 0},
g_ptr_array_add (entries, menu_separator_create ());
#ifdef ENABLE_VFS_MCFS
{' ', N_("&Network link..."), NULL_HOTKEY, netlink_cmd},
g_ptr_array_add (entries, menu_entry_create (_("&Network link..."), netlink_cmd));
#endif
{' ', N_("FT&P link..."), NULL_HOTKEY, ftplink_cmd},
{' ', N_("S&hell link..."), NULL_HOTKEY, fishlink_cmd},
g_ptr_array_add (entries, menu_entry_create (_("FT&P link..."), ftplink_cmd));
g_ptr_array_add (entries, menu_entry_create (_("S&hell link..."), fishlink_cmd));
#ifdef WITH_SMBFS
{' ', N_("SM&B link..."), NULL_HOTKEY, smblink_cmd},
g_ptr_array_add (entries, menu_entry_create (_("SM&B link..."), smblink_cmd));
#endif
#endif
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Rescan C-r"), NULL_HOTKEY, reread_cmd}
};
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Rescan C-r"), reread_cmd));
static menu_entry RightMenu[] = {
{' ', N_("&Listing mode..."), NULL_HOTKEY, listing_cmd},
{' ', N_("&Quick view C-x q"), NULL_HOTKEY, quick_view_cmd},
{' ', N_("&Info C-x i"), NULL_HOTKEY, info_cmd},
{' ', N_("&Tree"), NULL_HOTKEY, tree_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Sort order..."), NULL_HOTKEY, sort_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Filter..."), NULL_HOTKEY, filter_cmd},
return entries;
}
static GPtrArray *
create_right_menu (void)
{
GPtrArray *entries = g_ptr_array_new ();
g_ptr_array_add (entries, menu_entry_create (_("&Listing mode..."), listing_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Quick view C-x q"), quick_view_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Info C-x i" ), info_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Tree"), tree_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Sort order..."), sort_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Filter..."), filter_cmd));
#ifdef HAVE_CHARSET
{' ', "",NULL_HOTKEY, 0},
{' ', N_("&Encoding... M-e"), NULL_HOTKEY, encoding_cmd},
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Encoding... M-e"), encoding_cmd));
#endif
#ifdef USE_NETCODE
{' ', "", NULL_HOTKEY, 0},
g_ptr_array_add (entries, menu_separator_create ());
#ifdef ENABLE_VFS_MCFS
{' ', N_("&Network link..."), NULL_HOTKEY, netlink_cmd},
g_ptr_array_add (entries, menu_entry_create (_("&Network link..."), netlink_cmd));
#endif
{' ', N_("FT&P link..."), NULL_HOTKEY, ftplink_cmd},
{' ', N_("S&hell link..."), NULL_HOTKEY, fishlink_cmd},
g_ptr_array_add (entries, menu_entry_create (_("FT&P link..."), ftplink_cmd));
g_ptr_array_add (entries, menu_entry_create (_("S&hell link..."), fishlink_cmd));
#ifdef WITH_SMBFS
{' ', N_("SM&B link..."), NULL_HOTKEY, smblink_cmd},
g_ptr_array_add (entries, menu_entry_create (_("SM&B link..."), smblink_cmd));
#endif
#endif
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Rescan C-r"), NULL_HOTKEY, reread_cmd}
};
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Rescan C-r"), reread_cmd));
static menu_entry FileMenu[] = {
{' ', N_("&View F3"), NULL_HOTKEY, view_cmd},
{' ', N_("Vie&w file... "), NULL_HOTKEY, view_file_cmd},
{' ', N_("&Filtered view M-!"), NULL_HOTKEY, filtered_view_cmd},
{' ', N_("&Edit F4"), NULL_HOTKEY, edit_cmd},
{' ', N_("&Copy F5"), NULL_HOTKEY, copy_cmd},
{' ', N_("c&Hmod C-x c"), NULL_HOTKEY, chmod_cmd},
{' ', N_("&Link C-x l"), NULL_HOTKEY, link_cmd},
{' ', N_("&SymLink C-x s"), NULL_HOTKEY, symlink_cmd},
{' ', N_("edit s&Ymlink C-x C-s"), NULL_HOTKEY, edit_symlink_cmd},
{' ', N_("ch&Own C-x o"), NULL_HOTKEY, chown_cmd},
{' ', N_("&Advanced chown "), NULL_HOTKEY, chown_advanced_cmd},
{' ', N_("&Rename/Move F6"), NULL_HOTKEY, ren_cmd},
{' ', N_("&Mkdir F7"), NULL_HOTKEY, mkdir_cmd},
{' ', N_("&Delete F8"), NULL_HOTKEY, delete_cmd},
{' ', N_("&Quick cd M-c"), NULL_HOTKEY, quick_cd_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("select &Group M-+"), NULL_HOTKEY, select_cmd},
{' ', N_("u&Nselect group M-\\"), NULL_HOTKEY, unselect_cmd},
{' ', N_("reverse selec&Tion M-*"), NULL_HOTKEY, reverse_selection_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("e&Xit F10"), NULL_HOTKEY, quit_cmd}
};
return entries;
}
static menu_entry CmdMenu[] = {
{' ', N_("&User menu F2"), NULL_HOTKEY, user_file_menu_cmd},
static GPtrArray *
create_file_menu (void)
{
GPtrArray *entries = g_ptr_array_new ();
g_ptr_array_add (entries, menu_entry_create (_("&View F3"), view_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Vie&w file... "), view_file_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Filtered view M-!"), filtered_view_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Edit F4"), edit_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Copy F5"), copy_cmd));
g_ptr_array_add (entries, menu_entry_create (_("c&Hmod C-x c"), chmod_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Link C-x l"), link_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&SymLink C-x s"), symlink_cmd));
g_ptr_array_add (entries, menu_entry_create (_("edit s&Ymlink C-x C-s"), edit_symlink_cmd));
g_ptr_array_add (entries, menu_entry_create (_("ch&Own C-x o"), chown_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Advanced chown "), chown_advanced_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Rename/Move F6"), ren_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Mkdir F7"), mkdir_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Delete F8"), delete_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Quick cd M-c"), quick_cd_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("select &Group M-+"), select_cmd));
g_ptr_array_add (entries, menu_entry_create (_("u&Nselect group M-\\"), unselect_cmd));
g_ptr_array_add (entries, menu_entry_create (_("reverse selec&Tion M-*"), reverse_selection_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("e&Xit F10"), quit_cmd));
return entries;
}
static GPtrArray *
create_command_menu (void)
{
/* I know, I'm lazy, but the tree widget when it's not running
* as a panel still has some problems, I have not yet finished
* the WTree widget port, sorry.
*/
{' ', N_("&Directory tree"), NULL_HOTKEY, treebox_cmd},
{' ', N_("&Find file M-?"), NULL_HOTKEY, find_cmd},
{' ', N_("s&Wap panels C-u"), NULL_HOTKEY, swap_cmd},
{' ', N_("switch &Panels on/off C-o"), NULL_HOTKEY, view_other_cmd},
{' ', N_("&Compare directories C-x d"), NULL_HOTKEY, compare_dirs_cmd},
{' ', N_("e&Xternal panelize C-x !"), NULL_HOTKEY, external_panelize},
{' ', N_("show directory s&Izes"), NULL_HOTKEY, dirsizes_cmd},
{' ', "", NULL_HOTKEY, 0},
{' ', N_("Command &history M-h"), NULL_HOTKEY, history_cmd},
{' ', N_("di&Rectory hotlist C-\\"), NULL_HOTKEY, quick_chdir_cmd},
GPtrArray *entries = g_ptr_array_new ();
g_ptr_array_add (entries, menu_entry_create (_("&User menu F2"), user_file_menu_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Directory tree"), treebox_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Find file M-?"), find_cmd));
g_ptr_array_add (entries, menu_entry_create (_("s&Wap panels C-u"), swap_cmd));
g_ptr_array_add (entries, menu_entry_create (_("switch &Panels on/off C-o"), view_other_cmd));
g_ptr_array_add (entries, menu_entry_create (_("&Compare directories C-x d"), compare_dirs_cmd));
g_ptr_array_add (entries, menu_entry_create (_("e&Xternal panelize C-x !"), external_panelize));
g_ptr_array_add (entries, menu_entry_create (_("show directory s&Izes"), dirsizes_cmd));
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("command &History"), history_cmd));
g_ptr_array_add (entries, menu_entry_create (_("di&Rectory hotlist C-\\"), quick_chdir_cmd));
#ifdef USE_VFS
{' ', N_("&Active VFS list C-x a"), NULL_HOTKEY, reselect_vfs},
g_ptr_array_add (entries, menu_entry_create (_("&Active VFS list C-x a"), reselect_vfs));
#endif
#ifdef WITH_BACKGROUND
{' ', N_("&Background jobs C-x j"), NULL_HOTKEY, jobs_cmd},
g_ptr_array_add (entries, menu_entry_create (_("&Background jobs C-x j"), jobs_cmd));
#endif
{' ', "", NULL_HOTKEY, 0},
g_ptr_array_add (entries, menu_separator_create ());
#ifdef USE_EXT2FSLIB
{' ', N_("&Undelete files (ext2fs only)"), NULL_HOTKEY, undelete_cmd},
g_ptr_array_add (entries, menu_entry_create (_("&Undelete files (ext2fs only)"), undelete_cmd));
#endif
#ifdef LISTMODE_EDITOR
{' ', N_("&Listing format edit"), NULL_HOTKEY, listmode_cmd},
g_ptr_array_add (entries, menu_entry_create (_("&Listing format edit"), listmode_cmd));
#endif
#if defined (USE_EXT2FSLIB) || defined (LISTMODE_EDITOR)
{' ', "", NULL_HOTKEY, 0},
g_ptr_array_add (entries, menu_separator_create ());
#endif
{' ', N_("Edit &extension file"), NULL_HOTKEY, ext_cmd},
{' ', N_("Edit &menu file"), NULL_HOTKEY, edit_mc_menu_cmd},
{' ', N_("Edit hi&ghlighting group file"), NULL_HOTKEY, edit_fhl_cmd}
};
g_ptr_array_add (entries, menu_entry_create (_("Edit &extension file"), ext_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Edit &menu file"), edit_mc_menu_cmd));
g_ptr_array_add (entries, menu_entry_create (_("Edit hi&ghlighting group file"), edit_fhl_cmd));
/* Must keep in sync with the constants in menu_cmd */
static menu_entry OptMenu[] = {
{' ', N_("&Configuration..."), NULL_HOTKEY, configure_box},
{' ', N_("&Layout..."), NULL_HOTKEY, layout_cmd},
{' ', N_("c&Onfirmation..."), NULL_HOTKEY, confirm_box},
{' ', N_("&Display bits..."), NULL_HOTKEY, display_bits_box},
{' ', N_("learn &Keys..."), NULL_HOTKEY, learn_keys},
return entries;
}
static GPtrArray *
create_options_menu (void)
{
GPtrArray *entries = g_ptr_array_new ();
g_ptr_array_add (entries, menu_entry_create (_("&Configuration..."), configure_box));
g_ptr_array_add (entries, menu_entry_create (_("&Layout..."), layout_cmd));
g_ptr_array_add (entries, menu_entry_create (_("c&Onfirmation..."), confirm_box));
g_ptr_array_add (entries, menu_entry_create (_("&Display bits..."), display_bits_box));
g_ptr_array_add (entries, menu_entry_create (_("learn &Keys..."), learn_keys));
#ifdef USE_VFS
{' ', N_("&Virtual FS..."), NULL_HOTKEY, configure_vfs},
#endif /* !USE_VFS */
{' ', "", NULL_HOTKEY, 0},
{' ', N_("&Save setup"), NULL_HOTKEY, save_setup_cmd}
};
g_ptr_array_add (entries, menu_entry_create (_("&Virtual FS..."), configure_vfs));
#endif
g_ptr_array_add (entries, menu_separator_create ());
g_ptr_array_add (entries, menu_entry_create (_("&Save setup"), save_setup_cmd));
#define menu_entries(x) sizeof(x)/sizeof(menu_entry)
static Menu *MenuBar[5];
return entries;
}
void
init_menu (void)
{
MenuBar[0] =
menubar_add_menu (the_menubar,
create_menu (horizontal_split ? _(" &Above ") : _(" &Left "),
LeftMenu, menu_entries (LeftMenu),
"[Left and Right Menus]");
MenuBar[1] =
create_menu (_(" &File "), FileMenu, menu_entries (FileMenu),
"[File Menu]");
MenuBar[2] =
create_menu (_(" &Command "), CmdMenu, menu_entries (CmdMenu),
"[Command Menu]");
MenuBar[3] =
create_menu (_(" &Options "), OptMenu, menu_entries (OptMenu),
"[Options Menu]");
MenuBar[4] =
create_left_menu (), "[Left and Right Menus]"));
menubar_add_menu (the_menubar,
create_menu (_(" &File "), create_file_menu (), "[File Menu]"));
menubar_add_menu (the_menubar,
create_menu (_(" &Command "), create_command_menu (), "[Command Menu]"));
menubar_add_menu (the_menubar,
create_menu (_(" &Options "), create_options_menu (), "[Options Menu]"));
menubar_add_menu (the_menubar,
create_menu (horizontal_split ? _(" &Below ") : _(" &Right "),
RightMenu, menu_entries (RightMenu),
"[Left and Right Menus]");
create_right_menu (), "[Left and Right Menus]"));
}
void
done_menu (void)
{
int i;
for (i = 0; i < 5; i++) {
destroy_menu (MenuBar[i]);
}
menubar_set_menu (the_menubar, NULL);
}
static void
menu_last_selected_cmd (void)
{
the_menubar->active = 1;
the_menubar->dropped = drop_menus;
the_menubar->is_active = TRUE;
the_menubar->is_dropped = (drop_menus != 0);
the_menubar->previous_widget = midnight_dlg->current->dlg_id;
dlg_select_widget (the_menubar);
}
@ -845,13 +861,13 @@ menu_last_selected_cmd (void)
static void
menu_cmd (void)
{
if (the_menubar->active)
if (the_menubar->is_active)
return;
if ((get_current_index () == 0) ^ (!current_panel->active))
if ((get_current_index () == 0) == (current_panel->active != 0))
the_menubar->selected = 0;
else
the_menubar->selected = 4;
the_menubar->selected = the_menubar->menu->len - 1;
menu_last_selected_cmd ();
}
@ -976,7 +992,8 @@ create_panels (void)
the_hint->auto_adjust_cols = 0;
the_hint->widget.cols = COLS;
the_menubar = menubar_new (0, 0, COLS, MenuBar, 5);
the_menubar = menubar_new (0, 0, COLS, NULL);
init_menu ();
}
static void
@ -1290,7 +1307,6 @@ static void
setup_mc (void)
{
setup_pre ();
init_menu ();
create_panels ();
setup_panels ();
@ -1453,7 +1469,7 @@ midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
}
/* FIXME: should handle all menu shortcuts before this point */
if (the_menubar->active)
if (the_menubar->is_active)
return MSG_NOT_HANDLED;
if (parm == KEY_F (10)) {
@ -1568,7 +1584,7 @@ midnight_callback (struct Dlg_head *h, dlg_msg_t msg, int parm)
return MSG_HANDLED;
case DLG_POST_KEY:
if (!the_menubar->active)
if (!the_menubar->is_active)
update_dirty_panels ();
return MSG_HANDLED;

View File

@ -1,12 +1,11 @@
/* Pulldown menu code.
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007 Free Software Foundation, Inc.
/* Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2009 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -43,110 +42,168 @@
int menubar_visible = 1; /* This is the new default */
menu_entry_t *
menu_entry_create (const char *name, menu_exec_fn cmd)
{
menu_entry_t *entry;
entry = g_new (menu_entry_t, 1);
entry->first_letter = ' ';
entry->text = parse_hotkey (name);
entry->callback = cmd;
return entry;
}
void
menu_entry_free (menu_entry_t *entry)
{
if (entry != NULL) {
release_hotkey (entry->text);
g_free (entry);
}
}
static void
menu_arrange (Menu* menu)
{
if (menu != NULL) {
unsigned int i;
for (i = 0; i < menu->entries->len; i++) {
menu_entry_t *entry;
size_t len;
entry = g_ptr_array_index (menu->entries, i);
if (entry != NULL) {
len = (size_t) hotkey_width (entry->text);
menu->max_entry_len = max (menu->max_entry_len, len);
}
}
}
}
Menu *
create_menu (const char *name, menu_entry *entries, int count, const char *help_node)
create_menu (const char *name, GPtrArray *entries, const char *help_node)
{
Menu *menu;
menu = g_new (Menu, 1);
menu->count = count;
menu->max_entry_len = 20;
menu->entries = entries;
menu->text = parse_hotkey (name);
if (entries != (menu_entry*) NULL) {
int len;
register menu_entry* mp;
for (mp = entries; count--; mp++) {
if (mp->label[0] != '\0') {
mp->text = parse_hotkey (_(mp->label));
len = hotkey_width (mp->text);
menu->max_entry_len = max (len, menu->max_entry_len);
}
}
}
menu->start_x = 0;
menu->text = parse_hotkey (name);
menu->entries = entries;
menu->max_entry_len = 1;
menu->selected = 0;
menu->help_node = g_strdup (help_node);
menu_arrange (menu);
return menu;
}
static void menubar_drop_compute (WMenu *menubar)
void
destroy_menu (Menu *menu)
{
menubar->max_entry_len = menubar->menu [menubar->selected]->max_entry_len;
release_hotkey (menu->text);
g_ptr_array_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
g_ptr_array_free (menu->entries, TRUE);
g_free (menu->help_node);
g_free (menu);
}
static void menubar_paint_idx (WMenu *menubar, int idx, int color)
void
menu_add_entry (Menu *menu, const char *name, menu_exec_fn cmd)
{
const Menu *menu = menubar->menu[menubar->selected];
if (menu->entries == NULL)
menu->entries = g_ptr_array_new ();
g_ptr_array_add (menu->entries,
menu_entry_create (name, cmd));
menu_arrange (menu);
}
void
menu_add_separator (Menu *menu)
{
if (menu->entries == NULL)
menu->entries = g_ptr_array_new ();
g_ptr_array_add (menu->entries, menu_separator_create ());
}
static void
menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color)
{
const Menu *menu = g_ptr_array_index (menubar->menu, menubar->selected);
const menu_entry_t *entry = g_ptr_array_index (menu->entries, idx);
const int y = 2 + idx;
int x = menu->start_x;
const menu_entry *entry = &menu->entries[idx];
if (x + menubar->max_entry_len + 3 > menubar->widget.cols)
x = menubar->widget.cols - menubar->max_entry_len - 3;
if (x + menu->max_entry_len + 3 > menubar->widget.cols)
x = menubar->widget.cols - menu->max_entry_len - 3;
if (entry->text.start == NULL) {
/* menu separator */
tty_setcolor (MENU_ENTRY_COLOR);
if (entry == NULL) {
/* menu separator */
tty_setcolor (MENU_ENTRY_COLOR);
widget_move (&menubar->widget, y, x - 1);
tty_print_alt_char (ACS_LTEE);
widget_move (&menubar->widget, y, x - 1);
tty_print_alt_char (ACS_LTEE);
tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x,
ACS_HLINE, menubar->max_entry_len + 2);
tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x,
ACS_HLINE, menu->max_entry_len + 2);
widget_move (&menubar->widget, y, x + menubar->max_entry_len + 2);
tty_print_alt_char (ACS_RTEE);
widget_move (&menubar->widget, y, x + menu->max_entry_len + 2);
tty_print_alt_char (ACS_RTEE);
} else {
/* menu text */
tty_setcolor (color);
widget_move (&menubar->widget, y, x);
tty_print_char ((unsigned char) entry->first_letter);
tty_draw_hline (-1, -1, ' ', menubar->max_entry_len + 1); /* clear line */
tty_print_string (entry->text.start);
/* menu text */
tty_setcolor (color);
widget_move (&menubar->widget, y, x);
tty_print_char ((unsigned char) entry->first_letter);
tty_draw_hline (-1, -1, ' ', menu->max_entry_len + 1); /* clear line */
tty_print_string (entry->text.start);
if (entry->text.hotkey != NULL) {
tty_setcolor (color == MENU_SELECTED_COLOR ?
MENU_HOTSEL_COLOR : MENU_HOT_COLOR);
tty_print_string (entry->text.hotkey);
tty_setcolor(color);
}
if (entry->text.hotkey != NULL) {
tty_setcolor (color == MENU_SELECTED_COLOR ?
MENU_HOTSEL_COLOR : MENU_HOT_COLOR);
tty_print_string (entry->text.hotkey);
tty_setcolor (color);
}
if (entry->text.end != NULL)
tty_print_string (entry->text.end);
if (entry->text.end != NULL)
tty_print_string (entry->text.end);
/* move cursor to the start of entry text */
widget_move (&menubar->widget, y, x + 1);
/* move cursor to the start of entry text */
widget_move (&menubar->widget, y, x + 1);
}
}
static void menubar_draw_drop (WMenu *menubar)
static void
menubar_draw_drop (WMenuBar *menubar)
{
const int count = menubar->menu [menubar->selected]->count;
int column = menubar->menu [menubar->selected]->start_x - 1;
int i;
const Menu *menu = g_ptr_array_index (menubar->menu, menubar->selected);
const unsigned int count = menu->entries->len;
int column = menu->start_x - 1;
unsigned int i;
if (column + menubar->max_entry_len + 4 > menubar->widget.cols)
column = menubar->widget.cols - menubar->max_entry_len - 4;
if (column + menu->max_entry_len + 4 > menubar->widget.cols)
column = menubar->widget.cols - menu->max_entry_len - 4;
tty_setcolor (MENU_ENTRY_COLOR);
draw_box (menubar->widget.parent,
menubar->widget.y + 1, menubar->widget.x + column,
count + 2, menubar->max_entry_len + 4);
menubar->widget.y + 1, menubar->widget.x + column,
count + 2, menu->max_entry_len + 4);
/* draw items except selected */
for (i = 0; i < count; i++)
if (i != menubar->subsel)
menubar_paint_idx (menubar, i, MENU_ENTRY_COLOR);
if (i != menu->selected)
menubar_paint_idx (menubar, i, MENU_ENTRY_COLOR);
/* draw selected item at last to move cursot to the nice location */
menubar_paint_idx (menubar, menubar->subsel, MENU_SELECTED_COLOR);
/* draw selected item at last to move cursor to the nice location */
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
}
static void menubar_set_color (WMenu *menubar, int current, gboolean hotkey)
static void
menubar_set_color (WMenuBar *menubar, int current, gboolean hotkey)
{
if (!menubar->active)
if (!menubar->is_active)
tty_setcolor (hotkey ? COLOR_HOT_FOCUS : SELECTED_COLOR);
else if (current == menubar->selected)
tty_setcolor (hotkey ? MENU_HOTSEL_COLOR : MENU_SELECTED_COLOR);
@ -154,71 +211,76 @@ static void menubar_set_color (WMenu *menubar, int current, gboolean hotkey)
tty_setcolor (hotkey ? MENU_HOT_COLOR : MENU_ENTRY_COLOR);
}
static void menubar_draw (WMenu *menubar)
static void
menubar_draw (WMenuBar *menubar)
{
const int items = menubar->items;
int i;
unsigned int i;
/* First draw the complete menubar */
tty_setcolor (menubar->active ? MENU_ENTRY_COLOR : SELECTED_COLOR);
tty_setcolor (menubar->is_active ? MENU_ENTRY_COLOR : SELECTED_COLOR);
tty_draw_hline (menubar->widget.y, menubar->widget.x, ' ', menubar->widget.cols);
/* Now each one of the entries */
for (i = 0; i < items; i++){
for (i = 0; i < menubar->menu->len; i++) {
Menu *menu = g_ptr_array_index (menubar->menu, i);
menubar_set_color (menubar, i, FALSE);
widget_move (&menubar->widget, 0, menubar->menu [i]->start_x);
widget_move (&menubar->widget, 0, menu->start_x);
tty_print_string (menubar->menu[i]->text.start);
tty_print_string (menu->text.start);
if (menubar->menu[i]->text.hotkey != NULL) {
if (menu->text.hotkey != NULL) {
menubar_set_color (menubar, i, TRUE);
tty_print_string (menubar->menu[i]->text.hotkey);
tty_print_string (menu->text.hotkey);
menubar_set_color (menubar, i, FALSE);
}
if (menubar->menu[i]->text.end != NULL)
tty_print_string (menubar->menu[i]->text.end);
}
if (menu->text.end != NULL)
tty_print_string (menu->text.end);
}
if (menubar->dropped)
if (menubar->is_dropped)
menubar_draw_drop (menubar);
else
widget_move (&menubar->widget, 0,
menubar-> menu[menubar->selected]->start_x);
}
static void menubar_remove (WMenu *menubar)
{
menubar->subsel = 0;
if (menubar->dropped) {
menubar->dropped = 0;
do_refresh ();
menubar->dropped = 1;
}
}
static void menubar_left (WMenu *menu)
{
menubar_remove (menu);
menu->selected = (menu->selected - 1) % menu->items;
if (menu->selected < 0)
menu->selected = menu->items -1;
menubar_drop_compute (menu);
menubar_draw (menu);
}
static void menubar_right (WMenu *menu)
{
menubar_remove (menu);
menu->selected = (menu->selected + 1) % menu->items;
menubar_drop_compute (menu);
menubar_draw (menu);
((Menu *) g_ptr_array_index (menubar->menu,
menubar->selected))->start_x);
}
static void
menubar_finish (WMenu *menubar)
menubar_remove (WMenuBar *menubar)
{
menubar->dropped = 0;
menubar->active = 0;
if (menubar->is_dropped) {
menubar->is_dropped = FALSE;
do_refresh ();
menubar->is_dropped = TRUE;
}
}
static void
menubar_left (WMenuBar *menubar)
{
menubar_remove (menubar);
if (menubar->selected == 0)
menubar->selected = menubar->menu->len - 1;
else
menubar->selected--;
menubar_draw (menubar);
}
static void
menubar_right (WMenuBar *menubar)
{
menubar_remove (menubar);
menubar->selected = (menubar->selected + 1) % menubar->menu->len;
menubar_draw (menubar);
}
static void
menubar_finish (WMenuBar *menubar)
{
menubar->is_dropped = FALSE;
menubar->is_active = FALSE;
menubar->widget.lines = 1;
widget_want_hotkey (menubar->widget, 0);
@ -226,138 +288,173 @@ menubar_finish (WMenu *menubar)
do_refresh ();
}
static void menubar_drop (WMenu *menubar, int selected)
static void
menubar_drop (WMenuBar *menubar, unsigned int selected)
{
menubar->dropped = 1;
menubar->is_dropped = TRUE;
menubar->selected = selected;
menubar->subsel = 0;
menubar_drop_compute (menubar);
menubar_draw (menubar);
}
static void menubar_execute (WMenu *menubar, int entry)
static void
menubar_execute (WMenuBar *menubar, unsigned int idx)
{
const Menu *menu = menubar->menu [menubar->selected];
const callfn call_back = menu->entries [entry].call_back;
is_right = menubar->selected != 0;
const Menu *menu = g_ptr_array_index (menubar->menu, menubar->selected);
const menu_entry_t *entry = g_ptr_array_index (menu->entries, idx);
if ((entry == NULL) || (entry->callback == NULL))
return;
is_right = (menubar->selected != 0);
/* This used to be the other way round, i.e. first callback and
then menubar_finish. The new order (hack?) is needed to make
change_panel () work which is used in quick_view_cmd () -- Norbert
*/
menubar_finish (menubar);
(*call_back) ();
(*entry->callback) ();
do_refresh ();
}
static void menubar_move (WMenu *menubar, int step)
static void
menubar_down (WMenuBar *menubar)
{
const Menu *menu = menubar->menu [menubar->selected];
Menu *menu = g_ptr_array_index (menubar->menu, menubar->selected);
menu_entry_t *entry;
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
menubar_paint_idx (menubar, menubar->subsel, MENU_ENTRY_COLOR);
do {
menubar->subsel += step;
if (menubar->subsel < 0)
menubar->subsel = menu->count - 1;
menubar->subsel %= menu->count;
} while (!menu->entries [menubar->subsel].call_back);
menubar_paint_idx (menubar, menubar->subsel, MENU_SELECTED_COLOR);
menu->selected = (menu->selected + 1) % menu->entries->len;
entry = (menu_entry_t *) g_ptr_array_index (menu->entries, menu->selected);
} while ((entry == NULL) || (entry->callback == NULL));
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
}
static int menubar_handle_key (WMenu *menubar, int key)
static void
menubar_up (WMenuBar *menubar)
{
int i;
Menu *menu = g_ptr_array_index (menubar->menu, menubar->selected);
menu_entry_t *entry;
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
do {
if (menu->selected == 0)
menu->selected = menu->entries->len - 1;
else
menu->selected--;
entry = (menu_entry_t *) g_ptr_array_index (menu->entries, menu->selected);
} while ((entry == NULL) || (entry->callback == NULL));
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
}
static int
menubar_handle_key (WMenuBar *menubar, int key)
{
/* Lowercase */
if (isascii (key)) key = g_ascii_tolower (key);
if (is_abort_char (key)){
if (isascii (key))
key = g_ascii_tolower (key);
if (is_abort_char (key)) {
menubar_finish (menubar);
return 1;
}
if (key == KEY_F(1)) {
if (menubar->dropped) {
/* menubar help or menubar navigation */
switch (key) {
case KEY_F(1):
if (menubar->is_dropped)
interactive_display (NULL,
(menubar->menu [menubar->selected])->help_node);
} else {
((Menu *) g_ptr_array_index (menubar->menu,
menubar->selected))->help_node);
else
interactive_display (NULL, "[Menu Bar]");
}
menubar_draw (menubar);
return 1;
}
if (key == KEY_LEFT || key == XCTRL('b')){
case KEY_LEFT:
case XCTRL('b'):
menubar_left (menubar);
return 1;
} else if (key == KEY_RIGHT || key == XCTRL ('f')){
case KEY_RIGHT:
case XCTRL ('f'):
menubar_right (menubar);
return 1;
}
if (!menubar->dropped){
const int items = menubar->items;
for (i = 0; i < items; i++) {
const Menu *menu = menubar->menu [i];
if (!menubar->is_dropped) {
unsigned int i;
if (menu->text.hotkey != NULL) {
if (g_ascii_tolower(menu->text.hotkey[0]) == key) {
menubar_drop (menubar, i);
return 1;
/* drop menu by hotkey */
for (i = 0; i < menubar->menu->len; i++) {
Menu *menu = g_ptr_array_index (menubar->menu, i);
if ((menu->text.hotkey != NULL)
&& (key == g_ascii_tolower (menu->text.hotkey[0]))) {
menubar_drop (menubar, i);
return 1;
}
}
}
if (key == KEY_ENTER || key == XCTRL ('n')
|| key == KEY_DOWN || key == '\n') {
/* drop menu by Enter or Dowwn key */
if (key == KEY_ENTER || key == XCTRL ('n')
|| key == KEY_DOWN || key == '\n')
menubar_drop (menubar, menubar->selected);
return 1;
}
return 1;
} else {
const int selected = menubar->selected;
const Menu *menu = menubar->menu [selected];
const int items = menu->count;
for (i = 0; i < items; i++) {
if (!menu->entries [i].call_back)
continue;
}
if (menu->entries[i].text.hotkey != NULL) {
if (key != g_ascii_tolower (menu->entries[i].text.hotkey[0]))
continue;
{
const Menu *menu = g_ptr_array_index (menubar->menu, menubar->selected);
unsigned int i;
menubar_execute (menubar, i);
/* execute menu callback by hotkey */
for (i = 0; i < menu->entries->len; i++) {
const menu_entry_t *entry = g_ptr_array_index (menu->entries, i);
if ((entry != NULL) && (entry->callback != NULL)
&& (entry->text.hotkey != NULL)
&& (key == g_ascii_tolower (entry->text.hotkey[0]))) {
menubar_execute (menubar, i);
return 1;
}
}
/* menu execute by Enter or menu navigation */
switch (key) {
case KEY_ENTER:
case '\n':
menubar_execute (menubar, menu->selected);
return 1;
case KEY_DOWN:
case XCTRL ('n'):
menubar_down (menubar);
break;
case KEY_UP:
case XCTRL ('p'):
menubar_up (menubar);
break;
}
}
if (key == KEY_ENTER || key == '\n') {
menubar_execute (menubar, menubar->subsel);
return 1;
}
if (key == KEY_DOWN || key == XCTRL ('n'))
menubar_move (menubar, 1);
if (key == KEY_UP || key == XCTRL ('p'))
menubar_move (menubar, -1);
}
return 0;
}
static cb_ret_t
menubar_callback (Widget *w, widget_msg_t msg, int parm)
{
WMenu *menubar = (WMenu *) w;
WMenuBar *menubar = (WMenuBar *) w;
switch (msg) {
/* We do not want the focus unless we have been activated */
case WIDGET_FOCUS:
if (!menubar->active)
if (!menubar->is_active)
return MSG_NOT_HANDLED;
widget_want_cursor (menubar->widget, 1);
@ -367,31 +464,28 @@ menubar_callback (Widget *w, widget_msg_t msg, int parm)
/* Trick to get all of the hotkeys */
widget_want_hotkey (menubar->widget, 1);
menubar->subsel = 0;
menubar_drop_compute (menubar);
menubar_draw (menubar);
return MSG_HANDLED;
/* We don't want the buttonbar to activate while using the menubar */
case WIDGET_HOTKEY:
case WIDGET_KEY:
if (menubar->active) {
if (menubar->is_active) {
menubar_handle_key (menubar, parm);
return MSG_HANDLED;
} else
return MSG_NOT_HANDLED;
}
return MSG_NOT_HANDLED;
case WIDGET_CURSOR:
/* Put the cursor in a suitable place */
return MSG_NOT_HANDLED;
case WIDGET_UNFOCUS:
if (menubar->active)
if (menubar->is_active)
return MSG_NOT_HANDLED;
else {
widget_want_cursor (menubar->widget, 0);
return MSG_HANDLED;
}
widget_want_cursor (menubar->widget, 0);
return MSG_HANDLED;
case WIDGET_DRAW:
if (menubar_visible) {
@ -405,6 +499,11 @@ menubar_callback (Widget *w, widget_msg_t msg, int parm)
send_message (w, WIDGET_FOCUS, 0);
return MSG_HANDLED;
case WIDGET_DESTROY:
menubar_set_menu (menubar, NULL);
return MSG_HANDLED;
default:
return default_proc (msg, parm);
}
@ -413,30 +512,30 @@ menubar_callback (Widget *w, widget_msg_t msg, int parm)
static int
menubar_event (Gpm_Event *event, void *data)
{
WMenu *menubar = data;
Menu *menu = menubar->menu [menubar->selected];
int was_active = 1;
WMenuBar *menubar = data;
gboolean was_active = TRUE;
int left_x, right_x, bottom_y;
Menu *menu;
/* ignore unsupported events */
if ((event->type & (GPM_UP | GPM_DOWN | GPM_DRAG)) == 0)
return MOU_NORMAL;
/* ignore wheel events if menu is inactive */
if (!menubar->active && (event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)))
if (!menubar->is_active
&& ((event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)) != 0))
return MOU_NORMAL;
/* detect the menu state */
if (!menubar->dropped) {
if (!menubar->is_dropped) {
menubar->previous_widget = menubar->widget.parent->current->dlg_id;
menubar->active = 1;
menubar->dropped = 1;
was_active = 0;
menubar->is_active = TRUE;
menubar->is_dropped = TRUE;
was_active = FALSE;
}
/* Mouse operations on the menubar */
if (event->y == 1 || !was_active){
if (event->type & GPM_UP)
if (event->y == 1 || !was_active) {
if ((event->type & GPM_UP) != 0)
return MOU_NORMAL;
/* wheel events on menubar */
@ -447,12 +546,13 @@ menubar_event (Gpm_Event *event, void *data)
else {
int new_selection = 0;
while (new_selection < menubar->items
&& event->x > menubar->menu[new_selection]->start_x)
while ((new_selection < menubar->menu->len)
&& (event->x > ((Menu *) g_ptr_array_index (menubar->menu,
new_selection))->start_x))
new_selection++;
if (new_selection) /* Don't set the invalid value -1 */
--new_selection;
if (new_selection != 0) /* Don't set the invalid value -1 */
new_selection--;
if (!was_active) {
menubar->selected = new_selection;
@ -461,145 +561,157 @@ menubar_event (Gpm_Event *event, void *data)
menubar_remove (menubar);
menubar->selected = new_selection;
}
menubar_drop_compute (menubar);
menubar_draw (menubar);
}
return MOU_NORMAL;
}
if (!menubar->dropped || (event->y < 2))
if (!menubar->is_dropped || (event->y < 2))
return MOU_NORMAL;
/* middle click -- everywhere */
if ((event->buttons & GPM_B_MIDDLE) && (event->type & GPM_DOWN)) {
menubar_execute (menubar, menubar->subsel);
if (((event->buttons & GPM_B_MIDDLE) != 0)
&& ((event->type & GPM_DOWN) != 0)) {
Menu *menu = (Menu *) g_ptr_array_index (menubar->menu, menubar->selected);
menubar_execute (menubar, menu->selected);
return MOU_NORMAL;
}
/* the mouse operation is on the menus or it is not */
menu = (Menu *) g_ptr_array_index (menubar->menu, menubar->selected);
left_x = menu->start_x;
right_x = left_x + menubar->max_entry_len + 3;
right_x = left_x + menu->max_entry_len + 3;
if (right_x > menubar->widget.cols) {
left_x = menubar->widget.cols - menubar->max_entry_len - 3;
left_x = menubar->widget.cols - menu->max_entry_len - 3;
right_x = menubar->widget.cols;
}
bottom_y = menu->count + 3;
bottom_y = menu->entries->len + 3;
if ((event->x >= left_x) && (event->x <= right_x) && (event->y <= bottom_y)){
int pos = event->y - 3;
const menu_entry_t *entry = g_ptr_array_index (menu->entries, pos);
/* mouse wheel */
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN)) {
menubar_move (menubar, -1);
menubar_up (menubar);
return MOU_NORMAL;
}
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN)) {
menubar_move (menubar, 1);
menubar_down (menubar);
return MOU_NORMAL;
}
/* ignore events above and below dropped down menu */
if ((pos < 0) || (pos >= menu->count))
if ((pos < 0) || (pos >= menu->entries->len))
return MOU_NORMAL;
if (menubar->menu [menubar->selected]->entries [pos].call_back) {
menubar_paint_idx (menubar, menubar->subsel, MENU_ENTRY_COLOR);
menubar->subsel = pos;
menubar_paint_idx (menubar, menubar->subsel, MENU_SELECTED_COLOR);
if ((entry != NULL) && (entry->callback != NULL)) {
menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
menu->selected = pos;
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
if (event->type & GPM_UP)
menubar_execute (menubar, menubar->subsel);
if ((event->type & GPM_UP) != 0)
menubar_execute (menubar, pos);
}
} else
/* use click not wheel to close menu */
if ((event->type & GPM_DOWN) && !(event->buttons & (GPM_B_UP | GPM_B_DOWN)))
if (((event->type & GPM_DOWN) != 0)
&& ((event->buttons & (GPM_B_UP | GPM_B_DOWN)) == 0))
menubar_finish (menubar);
return MOU_NORMAL;
}
WMenuBar *
menubar_new (int y, int x, int cols, GPtrArray *menu)
{
WMenuBar *menubar = g_new0 (WMenuBar, 1);
init_widget (&menubar->widget, y, x, 1, cols,
menubar_callback, menubar_event);
widget_want_cursor (menubar->widget, 0);
menubar_set_menu (menubar, menu);
return menubar;
}
void
menubar_set_menu (WMenuBar *menubar, GPtrArray *menu)
{
/* delete previous menu */
if (menubar->menu != NULL) {
g_ptr_array_foreach (menubar->menu, (GFunc) destroy_menu, NULL);
g_ptr_array_free (menubar->menu, TRUE);
}
/* add new menu */
menubar->is_active = FALSE;
menubar->is_dropped = FALSE;
menubar->menu = menu;
menubar->selected = 0;
menubar_arrange (menubar);
}
void
menubar_add_menu (WMenuBar *menubar, Menu *menu)
{
if (menubar->menu == NULL)
menubar->menu = g_ptr_array_new ();
if (menu != NULL)
g_ptr_array_add (menubar->menu, menu);
menubar_arrange (menubar);
}
/*
* Properly space menubar items. Should be called when menubar is created
* and also when widget width is changed (i.e. upon xterm resize).
*/
void
menubar_arrange(WMenu* menubar)
menubar_arrange (WMenuBar* menubar)
{
register int i, start_x = 1;
int items = menubar->items;
int start_x = 1;
unsigned int i;
int gap;
if ((menubar->menu == NULL) || (menubar->menu->len == 0))
return;
#ifndef RESIZABLE_MENUBAR
int gap = 3;
gap = 3;
for (i = 0; i < items; i++)
{
int len = hotkey_width (menubar->menu[i]->text);
menubar->menu[i]->start_x = start_x;
start_x += len + gap;
}
for (i = 0; i < menubar->menu->len; i++) {
Menu *menu = g_ptr_array_index (menubar->menu, i);
int len = hotkey_width (menu->text);
menu->start_x = start_x;
start_x += len + gap;
}
#else /* RESIZABLE_MENUBAR */
gap = menubar->widget.cols - 2;
int gap = menubar->widget.cols - 2;
/* First, calculate gap between items... */
for (i = 0; i < items; i++)
{
/* preserve length here, to be used below */
gap -= (menubar->menu[i]->start_x = hotkey_width (menubar->menu[i]->text));
}
gap /= (items - 1);
if (gap <= 0)
{
/* We are out of luck - window is too narrow... */
gap = 1;
}
/* ...and now fix start positions of menubar items */
for (i = 0; i < items; i++)
{
int len = menubar->menu[i]->start_x;
menubar->menu[i]->start_x = start_x;
start_x += len + gap;
}
#endif /* RESIZABLE_MENUBAR */
}
void
destroy_menu (Menu *menu)
{
release_hotkey (menu->text);
if (menu->entries != NULL) {
int me;
for (me = 0; me < menu->count; me++) {
if (menu->entries[me].label[0] != '\0') {
release_hotkey (menu->entries[me].text);
}
}
/* First, calculate gap between items... */
for (i = 0; i < menubar->menu->len; i++) {
Menu *menu = g_ptr_array_index (menubar->menu, i);
/* preserve length here, to be used below */
menu->start_x = hotkey_width (menu->text);
gap -= menu->start_x;
}
g_free (menu->help_node);
g_free (menu);
}
WMenu *
menubar_new (int y, int x, int cols, Menu *menu[], int items)
{
WMenu *menubar = g_new0 (WMenu, 1);
init_widget (&menubar->widget, y, x, 1, cols,
menubar_callback, menubar_event);
menubar->menu = menu;
menubar->active = 0;
menubar->dropped = 0;
menubar->items = items;
menubar->selected = 0;
menubar->subsel = 0;
widget_want_cursor (menubar->widget, 0);
menubar_arrange (menubar);
return menubar;
gap /= (menubar->menu->len - 1);
if (gap <= 0) {
/* We are out of luck - window is too narrow... */
gap = 1;
}
/* ...and now fix start positions of menubar items */
for (i = 0; i < menubar->menu->len; i++) {
Menu *menu = g_ptr_array_index (menubar->menu, i);
int len = menu->start_x;
menu->start_x = start_x;
start_x += len + gap;
}
#endif /* RESIZABLE_MENUBAR */
}

View File

@ -1,4 +1,22 @@
/* Header file for pulldown menu engine for Midnignt Commander
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2009 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/** \file menu.h
* \brief Header: pulldown menu code
*/
@ -6,47 +24,54 @@
#ifndef MC_MENU_H
#define MC_MENU_H
#include "global.h"
#include "widget.h"
typedef void (*callfn) (void);
typedef struct {
char first_letter;
const char *label;
struct hotkey_t text;
callfn call_back;
} menu_entry;
typedef struct Menu {
struct hotkey_t text;
int count;
int max_entry_len;
int selected;
menu_entry *entries;
int start_x; /* position relative to menubar start */
char *help_node;
} Menu;
extern int menubar_visible;
typedef void (*menu_exec_fn) (void);
typedef struct menu_entry_t {
unsigned char first_letter;
struct hotkey_t text;
menu_exec_fn callback;
} menu_entry_t;
menu_entry_t *menu_entry_create (const char *name, menu_exec_fn cmd);
void menu_entry_free (menu_entry_t *me);
#define menu_separator_create() NULL
typedef struct Menu {
int start_x; /* position relative to menubar start */
struct hotkey_t text;
GPtrArray *entries;
size_t max_entry_len;
unsigned int selected; /* pointer to current menu entry */
char *help_node;
} Menu;
Menu *create_menu (const char *name, GPtrArray *entries,
const char *help_node);
void destroy_menu (Menu *menu);
void menu_add_entry (Menu *menu, const char *name, menu_exec_fn cmd);
void menu_add_separator (Menu *menu);
/* The button bar menu */
typedef struct WMenu {
typedef struct WMenuBar {
Widget widget;
int active; /* If the menubar is in use */
int dropped; /* If the menubar has dropped */
Menu **menu; /* The actual menus */
int items;
int selected; /* Selected menu on the top bar */
int subsel; /* Selected entry on the submenu */
int max_entry_len; /* Cache value for the columns in a box */
int previous_widget; /* Selected widget ID before activating menu */
} WMenu;
gboolean is_active; /* If the menubar is in use */
gboolean is_dropped; /* If the menubar has dropped */
GPtrArray *menu; /* The actual menus */
unsigned int selected; /* Selected menu on the top bar */
int previous_widget; /* Selected widget ID before activating menu */
} WMenuBar;
Menu *create_menu (const char *name, menu_entry *entries, int count,
const char *help_node);
void destroy_menu (Menu *menu);
WMenu *menubar_new (int y, int x, int cols, Menu *menu[], int items);
void menubar_arrange (WMenu *menubar);
WMenuBar *menubar_new (int y, int x, int cols, GPtrArray *menu);
void menubar_set_menu (WMenuBar *menubar, GPtrArray *menu);
void menubar_add_menu (WMenuBar *menubar, Menu *menu);
void menubar_arrange (WMenuBar *menubar);
#endif
#endif /* MC_MENU_H */