Fixed editor menu reloading.

edit/edit.h: moved N_menus 5 macro to editmenu.c. Renamed edit_init_menu()
to edit_create_menu().

edit/editmenu.c: added static variable EditMenuBar to store editor menus.
Reimplemented menu creation. Added new edit_create_menu() function.

edit/editwidget.c (edit_file): used edit_create_menu() instead of
edit_init_menu().
This commit is contained in:
Andrew Borodin 2009-05-01 21:10:52 +04:00
parent aadcca8048
commit 3c477cbdfd
3 changed files with 19 additions and 18 deletions

View File

@ -25,8 +25,6 @@
#include <stdio.h>
#define N_menus 5
#define SEARCH_DIALOG_OPTION_NO_SCANF (1 << 0)
#define SEARCH_DIALOG_OPTION_NO_REGEX (1 << 1)
#define SEARCH_DIALOG_OPTION_NO_CASE (1 << 2)
@ -122,7 +120,7 @@ struct Menu;
int edit_drop_hotkey_menu (WEdit *e, int key);
void edit_menu_cmd (WEdit *e);
struct WMenu *edit_init_menu (void);
struct WMenu *edit_create_menu (void);
void edit_done_menu (struct WMenu *wmenu);
void edit_reload_menu (void);
void menu_save_mode_cmd (void);

View File

@ -421,8 +421,12 @@ static menu_entry OptMenu[] =
#define menu_entries(x) sizeof(x)/sizeof(menu_entry)
#define N_menus 5
static Menu *EditMenuBar [N_menus];
static void
edit_init_menu_normal (struct Menu *EditMenuBar[])
edit_init_menu_normal (void)
{
EditMenuBar[0] = create_menu (_(" File "), FileMenu, menu_entries (FileMenu),
"[Internal File Editor]");
@ -437,7 +441,7 @@ edit_init_menu_normal (struct Menu *EditMenuBar[])
}
static void
edit_init_menu_emacs (struct Menu *EditMenuBar[])
edit_init_menu_emacs (void)
{
EditMenuBar[0] = create_menu (_(" File "), FileMenuEmacs, menu_entries (FileMenuEmacs),
"[Internal File Editor]");
@ -451,20 +455,24 @@ edit_init_menu_emacs (struct Menu *EditMenuBar[])
"[Internal File Editor]");
}
struct WMenu *
static void
edit_init_menu (void)
{
struct Menu **EditMenuBar = g_new(struct Menu *, N_menus);
switch (edit_key_emulation) {
default:
case EDIT_KEY_EMULATION_NORMAL:
edit_init_menu_normal (EditMenuBar);
edit_init_menu_normal ();
break;
case EDIT_KEY_EMULATION_EMACS:
edit_init_menu_emacs (EditMenuBar);
edit_init_menu_emacs ();
break;
}
}
struct WMenu *
edit_create_menu (void)
{
edit_init_menu ();
return menubar_new (0, 0, COLS, EditMenuBar, N_menus);
}
@ -474,20 +482,15 @@ edit_done_menu (struct WMenu *wmenu)
int i;
for (i = 0; i < N_menus; i++)
destroy_menu (wmenu->menu[i]);
g_free(wmenu->menu);
}
void
edit_reload_menu (void)
{
struct WMenu *new_edit_menubar;
new_edit_menubar = edit_init_menu ();
dlg_replace_widget (&edit_menubar->widget, &new_edit_menubar->widget);
edit_done_menu (edit_menubar);
edit_menubar = new_edit_menubar;
edit_init_menu ();
menubar_arrange (edit_menubar);
}

View File

@ -195,7 +195,7 @@ edit_file (const char *_file, int line)
edit_bar = buttonbar_new (1);
edit_menubar = edit_init_menu ();
edit_menubar = edit_create_menu ();
add_widget (edit_dlg, edit_bar);
add_widget (edit_dlg, wedit);