Implemented display of actual shortcuts in main menu.

Many shortcuts are not defined in keymap file and therefore
not displayed in menu.

Editor menu is not reimplemented yet.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2009-10-24 12:58:02 +04:00
parent 82b7c4fdee
commit 41989bd0c6
13 changed files with 208 additions and 140 deletions

View File

@ -142,12 +142,14 @@ typedef enum {
} LineBreaks;
#define LB_NAMES (LB_MAC + 1)
struct WMenuBar;
extern const char VERTICAL_MAGIC[5];
/* if enable_show_tabs_tws ==1 then use visible_tab visible_tws */
extern int enable_show_tabs_tws;
int edit_drop_hotkey_menu (WEdit *e, int key);
void edit_menu_cmd (WEdit *e);
struct WMenuBar *edit_create_menu (void);
void edit_init_menu (struct WMenuBar *menubar);
cb_ret_t edit_menu_execute (int command);
void edit_reload_menu (void);
void menu_save_mode_cmd (void);

View File

@ -294,7 +294,7 @@ edit_init_menu_emacs (struct WMenuBar *menubar)
menubar_add_menu (menubar, create_menu (_(" &Options "), create_options_menu (), "[Internal File Editor]"));
}
static void
void
edit_init_menu (struct WMenuBar *menubar)
{
switch (edit_key_emulation) {
@ -308,16 +308,6 @@ edit_init_menu (struct WMenuBar *menubar)
}
}
struct WMenuBar *
edit_create_menu (void)
{
struct WMenuBar *menubar;
menubar = menubar_new (0, 0, COLS, NULL);
edit_init_menu (menubar);
return menubar;
}
void
edit_reload_menu (void)
{

View File

@ -204,14 +204,14 @@ edit_file (const char *_file, int line)
widget_want_cursor (wedit->widget, 1);
edit_bar = buttonbar_new (1);
edit_menubar = edit_create_menu ();
add_widget (edit_dlg, edit_bar);
add_widget (edit_dlg, wedit);
add_widget (edit_dlg, edit_menubar);
edit_dlg->menu_executor = edit_menu_execute;
edit_menubar = menubar_new (0, 0, COLS, NULL);
add_widget (edit_dlg, edit_menubar);
edit_init_menu (edit_menubar);
run_dlg (edit_dlg);

View File

@ -249,7 +249,7 @@ create_dlg (int y1, int x1, int lines, int cols, const int *color_set,
memmove (new_d->color, color_set, sizeof (int) * DLG_COLOR_NUM);
}
new_d->help_ctx = help_ctx;
new_d->callback = callback ? callback : default_dlg_callback;
new_d->callback = (callback != NULL) ? callback : default_dlg_callback;
new_d->x = x1;
new_d->y = y1;
new_d->flags = flags;
@ -260,12 +260,14 @@ create_dlg (int y1, int x1, int lines, int cols, const int *color_set,
/* Strip existing spaces, add one space before and after the title */
if (title) {
char *t;
t = g_strstrip (g_strdup (title));
new_d->title = g_strconcat (" ", t, " ", (char *) NULL);
if (*t != '\0')
new_d->title = g_strdup_printf (" %s ", t);
g_free (t);
}
return (new_d);
return new_d;
}
void

View File

@ -87,6 +87,10 @@ typedef cb_ret_t (*dlg_cb_fn)(struct Dlg_head *h, dlg_msg_t msg, int parm);
/* menu command execution */
typedef cb_ret_t (*menu_exec_fn) (int command);
/* get string representation of shortcut assigned with command */
/* as menu is a widget of dialog, ask dialog about shortcut string */
typedef char * (*dlg_shortcut_str) (int command);
/* Dialog color constants */
#define DLG_COLOR_NUM 4
#define DLG_NORMALC(h) ((h)->color[0])
@ -96,30 +100,31 @@ typedef cb_ret_t (*menu_exec_fn) (int command);
typedef struct Dlg_head {
/* Set by the user */
int flags; /* User flags */
const char *help_ctx; /* Name of the help entry */
int *color; /* Color set. Unused in viewer and editor */
/*notconst*/ char *title; /* Title of the dialog */
int flags; /* User flags */
const char *help_ctx; /* Name of the help entry */
int *color; /* Color set. Unused in viewer and editor */
/*notconst*/ char *title; /* Title of the dialog */
/* Set and received by the user */
int ret_value; /* Result of run_dlg() */
int ret_value; /* Result of run_dlg() */
/* Geometry */
int x, y; /* Position relative to screen origin */
int cols, lines; /* Width and height of the window */
int x, y; /* Position relative to screen origin */
int cols, lines; /* Width and height of the window */
/* Internal flags */
unsigned int running:1; /* The dialog is currently active */
unsigned int fullscreen:1; /* Parents dialogs don't need refresh */
int mouse_status; /* For the autorepeat status of the mouse */
unsigned int running:1; /* The dialog is currently active */
unsigned int fullscreen:1; /* Parents dialogs don't need refresh */
int mouse_status; /* For the autorepeat status of the mouse */
/* Internal variables */
int count; /* Number of widgets */
struct Widget *current; /* Curently active widget */
void *data; /* data can be passed to dialog */
int count; /* Number of widgets */
struct Widget *current; /* Curently active widget */
void *data; /* Data can be passed to dialog */
dlg_cb_fn callback;
menu_exec_fn menu_executor; /* execute menu commands */
struct Dlg_head *parent; /* Parent dialog */
menu_exec_fn menu_executor; /* Execute menu commands */
dlg_shortcut_str get_shortcut; /* Shortcut string */
struct Dlg_head *parent; /* Parent dialog */
} Dlg_head;
/* Color styles for normal and error dialogs */

View File

@ -399,7 +399,6 @@ static const name_keymap_t command_names[] = {
/* viewer/actions_cmd.c */
const global_keymap_t default_viewer_keymap[] = {
{ '?', CK_ViewSearch, "?" },
{ '/', CK_ViewSearch, "/" },
{ XCTRL ('r'), CK_ViewContinueSearch, "C-r" },
@ -448,11 +447,11 @@ const global_keymap_t default_viewer_keymap[] = {
{ ALT ('e'), CK_SelectCodepage, "M-e" },
{ XCTRL ('o'), CK_ShowCommandLine, "C-o" },
{ 0, 0, "" }
};
const global_keymap_t default_viewer_hex_keymap[] = {
{ '\t', CK_HexViewToggleNavigationMode, "Tab" },
{ XCTRL ('a'), CK_ViewMoveToBol, "C-a" },
{ XCTRL ('e'), CK_ViewMoveToEol, "C-e" },
@ -602,7 +601,6 @@ const global_keymap_t default_editor_x_keymap[] = {
/* screen.c */
const global_keymap_t default_panel_keymap[] = {
{ ALT ('o'), CK_PanelChdirOtherPanel, "M-o" },
{ ALT ('l'), CK_PanelChdirToReadlink, "M-l" },
{ KEY_F (15), CK_PanelCmdCopyLocal, "S-F5" },
@ -637,6 +635,7 @@ const global_keymap_t default_panel_keymap[] = {
{ XCTRL ('s'), CK_PanelStartSearch, "C-s" },
{ ALT ('s'), CK_PanelStartSearch, "M-s" },
{ ALT ('i'), CK_PanelSyncOtherPanel, "M-i" },
{ 0, 0 , "" }
};
@ -667,33 +666,36 @@ const global_keymap_t default_main_map[] = {
{ XCTRL ('o'), CK_ShowCommandLine, "C-o" },
{ ALT ('.'), CK_ToggleShowHidden, "M-." },
{ XCTRL ('x'), CK_StartExtMap1, "C-x" },
{ 0, 0, "" }
};
const global_keymap_t default_main_x_map[] = {
{ XCTRL ('c'), CK_QuitCmd, "C-x C-c" },
{ 'd', CK_CompareDirsCmd, "C-x d" },
{ XCTRL ('c'), CK_QuitCmd, "C-c" },
{ 'd', CK_CompareDirsCmd, "d" },
#ifdef USE_VFS
{ 'a', CK_ReselectVfs, "C-x a"},
{ 'a', CK_ReselectVfs, "a"},
#endif /* USE_VFS */
{ 'p', CK_CopyCurrentPathname, "C-x p" },
{ XCTRL ('p'), CK_CopyOtherPathname, "C-x C-p" },
{ 't', CK_CopyCurrentTagged, "C-x t" },
{ XCTRL ('t'), CK_CopyOtherTarget, "C-x C-t" },
{ 'c', CK_ChmodCmd, "C-x c" },
{ 'o', CK_ChownCmd, "C-x o" },
{ 'r', CK_CopyCurrentReadlink, "C-x r" },
{ XCTRL ('r'), CK_CopyOtherReadlink, "C-x C-r" },
{ 'l', CK_LinkCmd, "C-x l" },
{ 's', CK_SymlinkCmd, "C-x s" },
{ XCTRL ('s'), CK_EditSymlinkCmd, "C-x C-s" },
{ 'i', CK_InfoCmd, "C-x i" },
{ 'q', CK_QuickViewCmd, "C-x q" },
{ 'h', CK_AddHotlist, "C-x h" },
{ '!', CK_ExternalPanelize, "C-x !" },
{ 'p', CK_CopyCurrentPathname, "p" },
{ XCTRL ('p'), CK_CopyOtherPathname, "C-p" },
{ 't', CK_CopyCurrentTagged, "t" },
{ XCTRL ('t'), CK_CopyOtherTarget, "C-t" },
{ 'c', CK_ChmodCmd, "c" },
{ 'o', CK_ChownCmd, "o" },
{ 'r', CK_CopyCurrentReadlink, "r" },
{ XCTRL ('r'), CK_CopyOtherReadlink, "C-r" },
{ 'l', CK_LinkCmd, "l" },
{ 's', CK_SymlinkCmd, "s" },
{ XCTRL ('s'), CK_EditSymlinkCmd, "C-s" },
{ 'i', CK_MenuInfoCmd, "i" },
{ 'i', CK_InfoCmd, "i" },
{ 'q', CK_QuickViewCmd, "q" },
{ 'h', CK_AddHotlist, "h" },
{ '!', CK_ExternalPanelize, "!" },
#ifdef WITH_BACKGROUND
{ 'j', CK_JobsCmd, "C-x j" },
{ 'j', CK_JobsCmd, "j" },
#endif /* WITH_BACKGROUND */
{ 0, 0, "" }
};
@ -736,6 +738,7 @@ const global_keymap_t default_input_keymap[] = {
/* Completion */
{ ALT ('\t'), CK_InputComplete, "M-tab" },
{ 0, 0, "" }
};
@ -775,3 +778,15 @@ keybind_cmd_bind (GArray *keymap, const char *keybind, int action)
keymap_add (keymap, key, action, caption);
g_free (caption);
}
const char *
lookup_keymap_shortcut (const global_keymap_t *keymap, int action)
{
unsigned int i;
for (i = 0; keymap[i].key != 0; i++)
if (keymap[i].command == action)
return (keymap[i].caption[0] != '\0') ? keymap[i]. caption : NULL;
return NULL;
}

View File

@ -26,6 +26,7 @@ typedef struct global_keymap_t {
int lookup_action (const char *keyname);
void keybind_cmd_bind (GArray *keymap, const char *keybind, int action);
const char *lookup_keymap_shortcut (const global_keymap_t *keymap, int action);
/* viewer/actions_cmd.c */
extern const global_keymap_t default_viewer_keymap[];
@ -47,6 +48,4 @@ extern const global_keymap_t default_input_keymap[];
extern const global_keymap_t default_main_map[];
extern const global_keymap_t default_main_x_map[];
extern const global_keymap_t default_input_keymap[];
#endif /* MC_KEYBIND_H */

View File

@ -675,31 +675,31 @@ create_panel_menu (void)
{
GList *entries = NULL;
entries = g_list_append (entries, menu_entry_create (_("&Listing mode..."), CK_ListingCmd));
entries = g_list_append (entries, menu_entry_create (_("&Quick view C-x q"), CK_MenuQuickViewCmd));
entries = g_list_append (entries, menu_entry_create (_("&Info C-x i" ), CK_MenuInfoCmd));
entries = g_list_append (entries, menu_entry_create (_("&Tree"), CK_TreeCmd));
entries = g_list_append (entries, menu_entry_create (_("&Listing mode..."), CK_ListingCmd));
entries = g_list_append (entries, menu_entry_create (_("&Quick view"), CK_MenuQuickViewCmd));
entries = g_list_append (entries, menu_entry_create (_("&Info" ), CK_MenuInfoCmd));
entries = g_list_append (entries, menu_entry_create (_("&Tree"), CK_TreeCmd));
entries = g_list_append (entries, menu_separator_create ());
entries = g_list_append (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
entries = g_list_append (entries, menu_entry_create (_("&Sort order..."), CK_Sort));
entries = g_list_append (entries, menu_separator_create ());
entries = g_list_append (entries, menu_entry_create (_("&Filter..."), CK_FilterCmd));
entries = g_list_append (entries, menu_entry_create (_("&Filter..."), CK_FilterCmd));
#ifdef HAVE_CHARSET
entries = g_list_append (entries, menu_separator_create ());
entries = g_list_append (entries, menu_entry_create (_("&Encoding... M-e"), CK_PanelSetPanelEncoding));
entries = g_list_append (entries, menu_entry_create (_("&Encoding..."), CK_PanelSetPanelEncoding));
#endif
#ifdef USE_NETCODE
entries = g_list_append (entries, menu_separator_create ());
#ifdef ENABLE_VFS_MCFS
entries = g_list_append (entries, menu_entry_create (_("&Network link..."), CK_NetlinkCmd));
entries = g_list_append (entries, menu_entry_create (_("&Network link..."), CK_NetlinkCmd));
#endif
entries = g_list_append (entries, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd));
entries = g_list_append (entries, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd));
entries = g_list_append (entries, menu_entry_create (_("FT&P link..."), CK_FtplinkCmd));
entries = g_list_append (entries, menu_entry_create (_("S&hell link..."), CK_FishlinkCmd));
#ifdef WITH_SMBFS
entries = g_list_append (entries, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd));
entries = g_list_append (entries, menu_entry_create (_("SM&B link..."), CK_SmblinkCmd));
#endif
#endif
entries = g_list_append (entries, menu_separator_create ());
entries = g_list_append (entries, menu_entry_create (_("&Rescan C-r"), CK_RereadCmd));
entries = g_list_append (entries, menu_entry_create (_("&Rescan"), CK_RereadCmd));
return entries;
}
@ -709,27 +709,27 @@ create_file_menu (void)
{
GList *entries = NULL;
entries = g_list_append (entries, menu_entry_create (_("&View F3"), CK_ViewCmd));
entries = g_list_append (entries, menu_entry_create (_("Vie&w file... "), CK_ViewFileCmd));
entries = g_list_append (entries, menu_entry_create (_("&Filtered view M-!"), CK_FilteredViewCmd));
entries = g_list_append (entries, menu_entry_create (_("&Edit F4"), CK_EditCmd));
entries = g_list_append (entries, menu_entry_create (_("&Copy F5"), CK_CopyCmd));
entries = g_list_append (entries, menu_entry_create (_("c&Hmod C-x c"), CK_ChmodCmd));
entries = g_list_append (entries, menu_entry_create (_("&Link C-x l"), CK_LinkCmd));
entries = g_list_append (entries, menu_entry_create (_("&SymLink C-x s"), CK_SymlinkCmd));
entries = g_list_append (entries, menu_entry_create (_("edit s&Ymlink C-x C-s"), CK_EditSymlinkCmd));
entries = g_list_append (entries, menu_entry_create (_("ch&Own C-x o"), CK_ChownCmd));
entries = g_list_append (entries, menu_entry_create (_("&Advanced chown "), CK_ChownAdvancedCmd));
entries = g_list_append (entries, menu_entry_create (_("&Rename/Move F6"), CK_RenCmd));
entries = g_list_append (entries, menu_entry_create (_("&Mkdir F7"), CK_MkdirCmd));
entries = g_list_append (entries, menu_entry_create (_("&Delete F8"), CK_DeleteCmd));
entries = g_list_append (entries, menu_entry_create (_("&Quick cd M-c"), CK_QuickCdCmd));
entries = g_list_append (entries, menu_entry_create (_("&View"), CK_ViewCmd));
entries = g_list_append (entries, menu_entry_create (_("Vie&w file..."), CK_ViewFileCmd));
entries = g_list_append (entries, menu_entry_create (_("&Filtered view"), CK_FilteredViewCmd));
entries = g_list_append (entries, menu_entry_create (_("&Edit"), CK_EditCmd));
entries = g_list_append (entries, menu_entry_create (_("&Copy"), CK_CopyCmd));
entries = g_list_append (entries, menu_entry_create (_("C&hmod"), CK_ChmodCmd));
entries = g_list_append (entries, menu_entry_create (_("&Link"), CK_LinkCmd));
entries = g_list_append (entries, menu_entry_create (_("&SymLink"), CK_SymlinkCmd));
entries = g_list_append (entries, menu_entry_create (_("Edit s&ymlink"), CK_EditSymlinkCmd));
entries = g_list_append (entries, menu_entry_create (_("Ch&own"), CK_ChownCmd));
entries = g_list_append (entries, menu_entry_create (_("&Advanced chown"), CK_ChownAdvancedCmd));
entries = g_list_append (entries, menu_entry_create (_("&Rename/Move"), CK_RenCmd));
entries = g_list_append (entries, menu_entry_create (_("&Mkdir"), CK_MkdirCmd));
entries = g_list_append (entries, menu_entry_create (_("&Delete"), CK_DeleteCmd));
entries = g_list_append (entries, menu_entry_create (_("&Quick cd"), CK_QuickCdCmd));
entries = g_list_append (entries, menu_separator_create ());
entries = g_list_append (entries, menu_entry_create (_("select &Group M-+"), CK_SelectCmd));
entries = g_list_append (entries, menu_entry_create (_("u&Nselect group M-\\"), CK_UnselectCmd));
entries = g_list_append (entries, menu_entry_create (_("reverse selec&Tion M-*"), CK_ReverseSelectionCmd));
entries = g_list_append (entries, menu_entry_create (_("Select &group"), CK_SelectCmd));
entries = g_list_append (entries, menu_entry_create (_("U&nselect group"), CK_UnselectCmd));
entries = g_list_append (entries, menu_entry_create (_("Reverse selec&tion"), CK_ReverseSelectionCmd));
entries = g_list_append (entries, menu_separator_create ());
entries = g_list_append (entries, menu_entry_create (_("e&Xit F10"), CK_QuitCmd));
entries = g_list_append (entries, menu_entry_create (_("E&xit"), CK_QuitCmd));
return entries;
}
@ -743,22 +743,22 @@ create_command_menu (void)
*/
GList *entries = NULL;
entries = g_list_append (entries, menu_entry_create (_("&User menu F2"), CK_UserMenuCmd));
entries = g_list_append (entries, menu_entry_create (_("&User menu"), CK_UserMenuCmd));
entries = g_list_append (entries, menu_entry_create (_("&Directory tree"), CK_TreeBoxCmd));
entries = g_list_append (entries, menu_entry_create (_("&Find file M-?"), CK_FindCmd));
entries = g_list_append (entries, menu_entry_create (_("s&Wap panels C-u"), CK_SwapCmd));
entries = g_list_append (entries, menu_entry_create (_("switch &Panels on/off C-o"), CK_ShowCommandLine));
entries = g_list_append (entries, menu_entry_create (_("&Compare directories C-x d"), CK_CompareDirsCmd));
entries = g_list_append (entries, menu_entry_create (_("e&Xternal panelize C-x !"), CK_ExternalPanelize));
entries = g_list_append (entries, menu_entry_create (_("show directory s&Izes"), CK_SingleDirsizeCmd));
entries = g_list_append (entries, menu_entry_create (_("&Find file"), CK_FindCmd));
entries = g_list_append (entries, menu_entry_create (_("S&wap panels"), CK_SwapCmd));
entries = g_list_append (entries, menu_entry_create (_("Switch &panels on/off"), CK_ShowCommandLine));
entries = g_list_append (entries, menu_entry_create (_("&Compare directories"), CK_CompareDirsCmd));
entries = g_list_append (entries, menu_entry_create (_("E&xternal panelize"), CK_ExternalPanelize));
entries = g_list_append (entries, menu_entry_create (_("Show directory s&izes"), CK_SingleDirsizeCmd));
entries = g_list_append (entries, menu_separator_create ());
entries = g_list_append (entries, menu_entry_create (_("command &History"), CK_HistoryCmd));
entries = g_list_append (entries, menu_entry_create (_("di&Rectory hotlist C-\\"), CK_QuickChdirCmd));
entries = g_list_append (entries, menu_entry_create (_("Command &history"), CK_HistoryCmd));
entries = g_list_append (entries, menu_entry_create (_("Di&rectory hotlist"), CK_QuickChdirCmd));
#ifdef USE_VFS
entries = g_list_append (entries, menu_entry_create (_("&Active VFS list C-x a"), CK_ReselectVfs));
entries = g_list_append (entries, menu_entry_create (_("&Active VFS list"), CK_ReselectVfs));
#endif
#ifdef WITH_BACKGROUND
entries = g_list_append (entries, menu_entry_create (_("&Background jobs C-x j"), CK_JobsCmd));
entries = g_list_append (entries, menu_entry_create (_("&Background jobs"), CK_JobsCmd));
#endif
entries = g_list_append (entries, menu_separator_create ());
#ifdef USE_EXT2FSLIB
@ -784,9 +784,9 @@ create_options_menu (void)
entries = g_list_append (entries, menu_entry_create (_("&Configuration..."), CK_ConfigureBox));
entries = g_list_append (entries, menu_entry_create (_("&Layout..."), CK_LayoutCmd));
entries = g_list_append (entries, menu_entry_create (_("c&Onfirmation..."), CK_ConfirmBox));
entries = g_list_append (entries, menu_entry_create (_("C&onfirmation..."), CK_ConfirmBox));
entries = g_list_append (entries, menu_entry_create (_("&Display bits..."), CK_DisplayBitsBox));
entries = g_list_append (entries, menu_entry_create (_("learn &Keys..."), CK_LearnKeys));
entries = g_list_append (entries, menu_entry_create (_("Learn &keys..."), CK_LearnKeys));
#ifdef USE_VFS
entries = g_list_append (entries, menu_entry_create (_("&Virtual FS..."), CK_ConfigureVfs));
#endif
@ -800,17 +800,17 @@ void
init_menu (void)
{
menubar_add_menu (the_menubar,
create_menu (horizontal_split ? _(" &Above ") : _(" &Left "),
create_panel_menu (), "[Left and Right Menus]"));
create_menu (horizontal_split ? _("&Above") : _("&Left"),
create_panel_menu (), "[Left and Right Menus]"));
menubar_add_menu (the_menubar,
create_menu (_(" &File "), create_file_menu (), "[File Menu]"));
create_menu (_("&File"), create_file_menu (), "[File Menu]"));
menubar_add_menu (the_menubar,
create_menu (_(" &Command "), create_command_menu (), "[Command Menu]"));
create_menu (_("&Command"), create_command_menu (), "[Command Menu]"));
menubar_add_menu (the_menubar,
create_menu (_(" &Options "), create_options_menu (), "[Options Menu]"));
create_menu (_("&Options"), create_options_menu (), "[Options Menu]"));
menubar_add_menu (the_menubar,
create_menu (horizontal_split ? _(" &Below ") : _(" &Right "),
create_panel_menu (), "[Left and Right Menus]"));
create_menu (horizontal_split ? _("&Below") : _("&Right"),
create_panel_menu (), "[Left and Right Menus]"));
}
void
@ -841,6 +841,30 @@ menu_cmd (void)
menu_last_selected_cmd ();
}
static char *
midnight_get_shortcut (int command)
{
const char *ext_map;
const char *shortcut = NULL;
ext_map = lookup_keymap_shortcut (main_map, CK_StartExtMap1);
if (ext_map != NULL)
shortcut = lookup_keymap_shortcut (main_x_map, command);
if (shortcut != NULL)
return g_strdup_printf ("%s %s", ext_map, shortcut);
shortcut = lookup_keymap_shortcut (main_map, command);
if (shortcut != NULL)
return g_strdup (shortcut);
shortcut = lookup_keymap_shortcut (panel_map, command);
if (shortcut != NULL)
return g_strdup (shortcut);
return NULL;
}
/* Flag toggling functions */
void
toggle_fast_reload (void)
@ -963,7 +987,6 @@ create_panels (void)
the_hint->widget.cols = COLS;
the_menubar = menubar_new (0, 0, COLS, NULL);
init_menu ();
}
static void
@ -1103,7 +1126,7 @@ ctl_x_cmd (void)
}
static cb_ret_t
midnight_execute_cmd(int command)
midnight_execute_cmd (int command)
{
cb_ret_t res = MSG_HANDLED;
@ -1759,7 +1782,12 @@ load_hint (int force)
static void
setup_panels_and_run_mc (void)
{
midnight_dlg->menu_executor = midnight_execute_cmd;
midnight_dlg->get_shortcut = midnight_get_shortcut;
add_widget (midnight_dlg, the_menubar);
init_menu ();
add_widget (midnight_dlg, get_panel_widget (0));
add_widget (midnight_dlg, get_panel_widget (1));
add_widget (midnight_dlg, the_hint);
@ -1768,7 +1796,6 @@ setup_panels_and_run_mc (void)
add_widget (midnight_dlg, the_bar);
init_labels ();
midnight_dlg->menu_executor = midnight_execute_cmd;
if (boot_current_is_left)
dlg_select_widget (get_panel_widget (0));
@ -1835,7 +1862,7 @@ do_nc (void)
midnight_colors[2] = mc_skin_color_get("dialog", "hotnormal");
midnight_colors[3] = mc_skin_color_get("dialog", "hotfocus");
panel_init();
panel_init ();
midnight_dlg = create_dlg (0, 0, LINES, COLS, midnight_colors, midnight_callback,
"[main]", NULL, DLG_WANT_IDLE);
@ -1846,7 +1873,8 @@ do_nc (void)
setup_mc ();
/* start check display_codepage and source_codepage */
check_codeset();
check_codeset ();
main_map = default_main_map;
if (main_keymap && main_keymap->len > 0)
@ -1882,7 +1910,7 @@ do_nc (void)
done_mc ();
}
destroy_dlg (midnight_dlg);
panel_deinit();
panel_deinit ();
current_panel = 0;
done_mc_profile ();
}
@ -2215,7 +2243,7 @@ main (int argc, char *argv[])
flush_extension_file (); /* does only free memory */
mc_fhl_free (&mc_filehighlight);
mc_skin_deinit();
mc_skin_deinit ();
tty_shutdown ();

View File

@ -51,6 +51,7 @@ menu_entry_create (const char *name, int command)
entry->first_letter = ' ';
entry->text = parse_hotkey (name);
entry->command = command;
entry->shortcut = NULL;
return entry;
}
@ -60,24 +61,41 @@ menu_entry_free (menu_entry_t *entry)
{
if (entry != NULL) {
release_hotkey (entry->text);
g_free (entry->shortcut);
g_free (entry);
}
}
static void
menu_arrange (Menu *menu)
menu_arrange (Menu *menu, dlg_shortcut_str get_shortcut)
{
if (menu != NULL) {
GList *i;
size_t max_shortcut_len = 0;
menu->max_entry_len = 1;
menu->max_hotkey_len = 1;
for (i = menu->entries; i != NULL; i = g_list_next (i)) {
menu_entry_t *entry = i->data;
if (entry != NULL) {
const size_t len = (size_t) hotkey_width (entry->text);
menu->max_entry_len = max (menu->max_entry_len, len);
size_t len;
len = (size_t) hotkey_width (entry->text);
menu->max_hotkey_len = max (menu->max_hotkey_len, len);
if (get_shortcut != NULL)
entry->shortcut = get_shortcut (entry->command);
if (entry->shortcut != NULL) {
len = (size_t) str_term_width1 (entry->shortcut);
max_shortcut_len = max (max_shortcut_len, len);
}
}
}
menu->max_entry_len = menu->max_hotkey_len + max_shortcut_len;
}
}
@ -91,9 +109,9 @@ create_menu (const char *name, GList *entries, const char *help_node)
menu->text = parse_hotkey (name);
menu->entries = entries;
menu->max_entry_len = 1;
menu->max_hotkey_len = 0;
menu->selected = 0;
menu->help_node = g_strdup (help_node);
menu_arrange (menu);
return menu;
}
@ -116,8 +134,8 @@ menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color)
const int y = 2 + idx;
int x = menu->start_x;
if (x + menu->max_entry_len + 3 > menubar->widget.cols)
x = menubar->widget.cols - menu->max_entry_len - 3;
if (x + menu->max_entry_len + 4 > menubar->widget.cols)
x = menubar->widget.cols - menu->max_entry_len - 4;
if (entry == NULL) {
/* menu separator */
@ -127,16 +145,16 @@ menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color)
tty_print_alt_char (ACS_LTEE);
tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x,
ACS_HLINE, menu->max_entry_len + 2);
ACS_HLINE, menu->max_entry_len + 3);
widget_move (&menubar->widget, y, x + menu->max_entry_len + 2);
widget_move (&menubar->widget, y, x + menu->max_entry_len + 3);
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, ' ', menu->max_entry_len + 1); /* clear line */
tty_draw_hline (-1, -1, ' ', menu->max_entry_len + 2); /* clear line */
tty_print_string (entry->text.start);
if (entry->text.hotkey != NULL) {
@ -149,6 +167,11 @@ menubar_paint_idx (WMenuBar *menubar, unsigned int idx, int color)
if (entry->text.end != NULL)
tty_print_string (entry->text.end);
if (entry->shortcut != NULL) {
widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3);
tty_print_string (entry->shortcut);
}
/* move cursor to the start of entry text */
widget_move (&menubar->widget, y, x + 1);
}
@ -162,13 +185,13 @@ menubar_draw_drop (WMenuBar *menubar)
int column = menu->start_x - 1;
unsigned int i;
if (column + menu->max_entry_len + 4 > menubar->widget.cols)
column = menubar->widget.cols - menu->max_entry_len - 4;
if (column + menu->max_entry_len + 5 > menubar->widget.cols)
column = menubar->widget.cols - menu->max_entry_len - 5;
tty_setcolor (MENU_ENTRY_COLOR);
draw_box (menubar->widget.parent,
menubar->widget.y + 1, menubar->widget.x + column,
count + 2, menu->max_entry_len + 4);
count + 2, menu->max_entry_len + 5);
/* draw items except selected */
for (i = 0; i < count; i++)
@ -207,6 +230,7 @@ menubar_draw (WMenuBar *menubar)
menubar_set_color (menubar, is_selected, FALSE);
widget_move (&menubar->widget, 0, menu->start_x);
tty_print_char (' ');
tty_print_string (menu->text.start);
if (menu->text.hotkey != NULL) {
@ -217,6 +241,8 @@ menubar_draw (WMenuBar *menubar)
if (menu->text.end != NULL)
tty_print_string (menu->text.end);
tty_print_char (' ');
}
if (menubar->is_dropped)
@ -688,8 +714,10 @@ menubar_set_menu (WMenuBar *menubar, GList *menu)
void
menubar_add_menu (WMenuBar *menubar, Menu *menu)
{
if (menu != NULL)
if (menu != NULL) {
menu_arrange (menu, menubar->widget.parent->get_shortcut);
menubar->menu = g_list_append (menubar->menu, menu);
}
menubar_arrange (menubar);
}
@ -713,7 +741,7 @@ menubar_arrange (WMenuBar* menubar)
for (i = menubar->menu; i != NULL; i = g_list_next (i)) {
Menu *menu = i->data;
int len = hotkey_width (menu->text);
int len = hotkey_width (menu->text) + 2;
menu->start_x = start_x;
start_x += len + gap;
@ -725,7 +753,7 @@ menubar_arrange (WMenuBar* menubar)
for (i = menubar->menu; i != NULL; i = g_list_nwxt (i)) {
Menu *menu = i->data;
/* preserve length here, to be used below */
menu->start_x = hotkey_width (menu->text);
menu->start_x = hotkey_width (menu->text) + 2;
gap -= menu->start_x;
}

View File

@ -33,6 +33,7 @@ typedef struct menu_entry_t {
unsigned char first_letter;
struct hotkey_t text;
int command;
char *shortcut;
} menu_entry_t;
menu_entry_t *menu_entry_create (const char *name, int command);
@ -43,7 +44,8 @@ typedef struct Menu {
int start_x; /* position relative to menubar start */
struct hotkey_t text;
GList *entries;
size_t max_entry_len;
size_t max_entry_len; /* cached max length of entry texts (text + shortcut) */
size_t max_hotkey_len; /* cached max length of shortcuts */
unsigned int selected; /* pointer to current menu entry */
char *help_node;
} Menu;

View File

@ -974,13 +974,11 @@ load_keymap_defs (void)
viewer_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section ("viewer", viewer_keymap, mc_global_keymap);
viewer_hex_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section ("viewer:hex", viewer_hex_keymap, mc_global_keymap);
main_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section ("main", main_keymap, mc_global_keymap);
main_x_keymap = g_array_new (TRUE, FALSE, sizeof (global_keymap_t));
load_keymap_from_section ("main:xmap", main_x_keymap, mc_global_keymap);
@ -992,5 +990,4 @@ load_keymap_defs (void)
mc_config_deinit (mc_global_keymap);
}
}

View File

@ -1229,7 +1229,7 @@ check_movement_keys (int key, int page_size, void *data, move_fn backfn,
}
static int
lookup_keyname (char *keyname, int *index)
lookup_keyname (const char *keyname, int *index)
{
if (keyname[0] != '\0') {
int i;
@ -1252,7 +1252,7 @@ lookup_keyname (char *keyname, int *index)
/* Return the code associated with the symbolic name keyname */
int
lookup_key (char *keyname, char **label)
lookup_key (const char *keyname, char **label)
{
char **keys, **p;
int k = -1;
@ -1266,9 +1266,9 @@ lookup_key (char *keyname, char **label)
if (keyname == NULL)
return 0;
g_strstrip (keyname);
keyname = g_strstrip (g_strdup (keyname));
p = keys = g_strsplit_set (keyname, "-+ ", -1);
g_free ((char *) keyname);
while ((p != NULL) && (*p != NULL)) {
if ((*p)[0] != '\0') {

View File

@ -21,7 +21,7 @@ void done_key (void);
typedef void (*move_fn) (void *data, int param);
cb_ret_t check_movement_keys (int key, int page_size, void *data,
move_fn backfn, move_fn forfn, move_fn topfn, move_fn bottomfn);
int lookup_key (char *keyname, char **label);
int lookup_key (const char *keyname, char **label);
typedef const struct {
int code;