mirror of
https://github.com/MidnightCommander/mc
synced 2025-04-01 12:42:57 +03:00
Menu improvements.
menubar_set_visible(): new function to get rid of menubar_visible global variable in widgtes library. menu_set_name(): new function to avoid total recreation of main menu after change panel layout. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
f70e06b37a
commit
3d92a0846a
@ -42,8 +42,6 @@
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
int menubar_visible = 1; /* This is the new default */
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
@ -558,7 +556,7 @@ menubar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
return menubar->is_active ? MSG_NOT_HANDLED : MSG_HANDLED;
|
||||
|
||||
case WIDGET_DRAW:
|
||||
if (menubar_visible)
|
||||
if (menubar->is_visible)
|
||||
{
|
||||
menubar_draw (menubar);
|
||||
return MSG_HANDLED;
|
||||
@ -758,6 +756,15 @@ create_menu (const char *name, GList * entries, const char *help_node)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
menu_set_name (Menu * menu, const char *name)
|
||||
{
|
||||
release_hotkey (menu->text);
|
||||
menu->text = parse_hotkey (name);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
destroy_menu (Menu * menu)
|
||||
{
|
||||
@ -773,11 +780,14 @@ destroy_menu (Menu * menu)
|
||||
WMenuBar *
|
||||
menubar_new (int y, int x, int cols, GList * menu)
|
||||
{
|
||||
WMenuBar *menubar = g_new0 (WMenuBar, 1);
|
||||
WMenuBar *menubar;
|
||||
|
||||
menubar = g_new0 (WMenuBar, 1);
|
||||
init_widget (&menubar->widget, y, x, 1, cols, menubar_callback, menubar_event);
|
||||
widget_want_cursor (menubar->widget, 0);
|
||||
widget_want_cursor (menubar->widget, FALSE);
|
||||
menubar->is_visible = TRUE; /* by default */
|
||||
menubar_set_menu (menubar, menu);
|
||||
|
||||
return menubar;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
typedef struct menu_entry_t
|
||||
{
|
||||
unsigned char first_letter;
|
||||
struct hotkey_t text;
|
||||
hotkey_t text;
|
||||
unsigned long command;
|
||||
char *shortcut;
|
||||
} menu_entry_t;
|
||||
@ -42,7 +42,7 @@ typedef struct menu_entry_t
|
||||
typedef struct Menu
|
||||
{
|
||||
int start_x; /* position relative to menubar start */
|
||||
struct hotkey_t text;
|
||||
hotkey_t text;
|
||||
GList *entries;
|
||||
size_t max_entry_len; /* cached max length of entry texts (text + shortcut) */
|
||||
size_t max_hotkey_len; /* cached max length of shortcuts */
|
||||
@ -55,6 +55,7 @@ typedef struct WMenuBar
|
||||
{
|
||||
Widget widget;
|
||||
|
||||
gboolean is_visible; /* If the menubar is visible */
|
||||
gboolean is_active; /* If the menubar is in use */
|
||||
gboolean is_dropped; /* If the menubar has dropped */
|
||||
GList *menu; /* The actual menus */
|
||||
@ -64,15 +65,13 @@ typedef struct WMenuBar
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern int menubar_visible;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
menu_entry_t *menu_entry_create (const char *name, unsigned long command);
|
||||
void menu_entry_free (menu_entry_t * me);
|
||||
|
||||
Menu *create_menu (const char *name, GList * entries, const char *help_node);
|
||||
|
||||
void menu_set_name (Menu * menu, const char *name);
|
||||
void destroy_menu (Menu * menu);
|
||||
|
||||
WMenuBar *menubar_new (int y, int x, int cols, GList * menu);
|
||||
@ -84,4 +83,10 @@ WMenuBar *find_menubar (const Dlg_head * h);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
static inline void
|
||||
menubar_set_visible (WMenuBar * menubar, gboolean visible)
|
||||
{
|
||||
menubar->is_visible = visible;
|
||||
}
|
||||
|
||||
#endif /* MC__WIDGET_MENU_H */
|
||||
|
@ -94,6 +94,9 @@ int output_lines = 0;
|
||||
/* Set if the command prompt is to be displayed */
|
||||
int command_prompt = 1;
|
||||
|
||||
/* Set if the main menu is visible */
|
||||
int menubar_visible = 1;
|
||||
|
||||
/* Set if the nice and useful keybar is visible */
|
||||
int keybar_visible = 1;
|
||||
|
||||
@ -632,11 +635,9 @@ void
|
||||
layout_change (void)
|
||||
{
|
||||
setup_panels ();
|
||||
/* re-init the menu, because perhaps there was a change in the way
|
||||
/* re-init the menu, because perhaps there was a change in the way
|
||||
how the panel are split (horizontal/vertical). */
|
||||
done_menu ();
|
||||
init_menu ();
|
||||
menubar_arrange (the_menubar);
|
||||
update_menu ();
|
||||
load_hint (1);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ extern int equal_split;
|
||||
extern int first_panel_size;
|
||||
extern int output_lines;
|
||||
extern int command_prompt;
|
||||
extern int menubar_visible;
|
||||
extern int keybar_visible;
|
||||
extern int output_start_y;
|
||||
extern int message_visible;
|
||||
|
55
src/main.c
55
src/main.c
@ -120,6 +120,7 @@ WTree *the_tree = NULL;
|
||||
|
||||
/* The Menubar */
|
||||
struct WMenuBar *the_menubar = NULL;
|
||||
static Menu *left_menu, *right_menu;
|
||||
|
||||
/* Pointers to the selected and unselected panel */
|
||||
WPanel *current_panel = NULL;
|
||||
@ -547,6 +548,24 @@ create_options_menu (void)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_menu (void)
|
||||
{
|
||||
left_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
|
||||
menubar_add_menu (the_menubar, left_menu);
|
||||
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]"));
|
||||
right_menu = create_menu ("", create_panel_menu (), "[Left and Right Menus]");
|
||||
menubar_add_menu (the_menubar, right_menu);
|
||||
update_menu ();
|
||||
menubar_set_visible (the_menubar, menubar_visible);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menu_last_selected_cmd (void)
|
||||
{
|
||||
@ -1829,6 +1848,16 @@ change_panel (void)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
update_menu (void)
|
||||
{
|
||||
menu_set_name (left_menu, horizontal_split ? _("&Above") : _("&Left"));
|
||||
menu_set_name (right_menu, horizontal_split ? _("&Below") : _("&Right"));
|
||||
menubar_arrange (the_menubar);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
quiet_quit_cmd (void)
|
||||
{
|
||||
@ -1939,32 +1968,6 @@ sort_cmd (void)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
init_menu (void)
|
||||
{
|
||||
menubar_add_menu (the_menubar,
|
||||
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]"));
|
||||
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"),
|
||||
create_panel_menu (), "[Left and Right Menus]"));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
done_menu (void)
|
||||
{
|
||||
menubar_set_menu (the_menubar, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
toggle_show_hidden (void)
|
||||
{
|
||||
|
@ -144,8 +144,7 @@ void print_vfs_message (const char *msg, ...) __attribute__ ((format (__printf__
|
||||
|
||||
char *get_mc_lib_dir (void);
|
||||
|
||||
void done_menu (void);
|
||||
void init_menu (void);
|
||||
void update_menu (void);
|
||||
|
||||
char *remove_encoding_from_path (const char *);
|
||||
|
||||
|
@ -49,6 +49,7 @@
|
||||
|
||||
#include "src/main.h"
|
||||
#include "src/charsets.h"
|
||||
#include "src/layout.h" /* menubar_visible */
|
||||
#include "src/main-widgets.h" /* the_menubar */
|
||||
|
||||
#include "internal.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user