Commit 660f5243 authored by twanvl's avatar twanvl

Add 'insert symbol menu' in EVT_MENU_OPEN instead of updateUI, this fixes crash on wxGTK

parent 111264d7
...@@ -284,18 +284,38 @@ void CardsPanel::onUpdateUI(wxUpdateUIEvent& ev) { ...@@ -284,18 +284,38 @@ void CardsPanel::onUpdateUI(wxUpdateUIEvent& ev) {
case ID_INSERT_SYMBOL: { case ID_INSERT_SYMBOL: {
wxMenu* menu = editor->getMenu(ID_INSERT_SYMBOL); wxMenu* menu = editor->getMenu(ID_INSERT_SYMBOL);
ev.Enable(menu); ev.Enable(menu);
/*
if (insertSymbolMenu->GetSubMenu() != menu || (menu && menu->GetParent() != menuFormat)) { if (insertSymbolMenu->GetSubMenu() != menu || (menu && menu->GetParent() != menuFormat)) {
// re-add the menu // re-add the menu
fprintf(stderr,"insert1 %p %p\n", menuFormat,insertSymbolMenu);fflush(stderr);
menuFormat->Remove(ID_INSERT_SYMBOL); menuFormat->Remove(ID_INSERT_SYMBOL);
fprintf(stderr,"insert2\n");fflush(stderr);
insertSymbolMenu->SetSubMenu(menu); insertSymbolMenu->SetSubMenu(menu);
fprintf(stderr,"insert3\n");fflush(stderr);
menuFormat->Append(insertSymbolMenu); menuFormat->Append(insertSymbolMenu);
} fprintf(stderr,"insert4\n");fflush(stderr);
}*/
break; break;
} }
#endif #endif
} }
} }
void CardsPanel::onMenuOpen(wxMenuEvent& ev) {
if (ev.GetMenu() != menuFormat) return;
wxMenu* menu = editor->getMenu(ID_INSERT_SYMBOL);
if (insertSymbolMenu->GetSubMenu() != menu || (menu && menu->GetParent() != menuFormat)) {
// re-add the menu
fprintf(stderr,"insert1 %p %p\n", menuFormat,insertSymbolMenu);fflush(stderr);
menuFormat->Remove(ID_INSERT_SYMBOL);
fprintf(stderr,"insert2\n");fflush(stderr);
insertSymbolMenu->SetSubMenu(menu);
fprintf(stderr,"insert3\n");fflush(stderr);
menuFormat->Append(insertSymbolMenu);
fprintf(stderr,"insert4\n");fflush(stderr);
}
}
void CardsPanel::onCommand(int id) { void CardsPanel::onCommand(int id) {
switch (id) { switch (id) {
case ID_CARD_PREV: case ID_CARD_PREV:
......
...@@ -37,6 +37,7 @@ class CardsPanel : public SetWindowPanel { ...@@ -37,6 +37,7 @@ class CardsPanel : public SetWindowPanel {
virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb); virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb);
virtual void onUpdateUI(wxUpdateUIEvent&); virtual void onUpdateUI(wxUpdateUIEvent&);
virtual void onCommand(int id); virtual void onCommand(int id);
virtual void onMenuOpen(wxMenuEvent&);
// --------------------------------------------------- : Actions // --------------------------------------------------- : Actions
......
...@@ -44,6 +44,9 @@ class SetWindowPanel : public wxPanel, public SetView { ...@@ -44,6 +44,9 @@ class SetWindowPanel : public wxPanel, public SetView {
/// Respond to one of those extra menu/tool items /// Respond to one of those extra menu/tool items
virtual void onCommand(int id) {} virtual void onCommand(int id) {}
/// Called before a menu is opened in the parent window
virtual void onMenuOpen(wxMenuEvent&) {}
// --------------------------------------------------- : Actions/Events // --------------------------------------------------- : Actions/Events
/// Should return true if this panel wants to get focus to show an action /// Should return true if this panel wants to get focus to show an action
......
...@@ -813,6 +813,11 @@ void SetWindow::onChildMenu(wxCommandEvent& ev) { ...@@ -813,6 +813,11 @@ void SetWindow::onChildMenu(wxCommandEvent& ev) {
current_panel->onCommand(ev.GetId()); current_panel->onCommand(ev.GetId());
} }
void SetWindow::onMenuOpen(wxMenuEvent& ev) {
wxFrame::OnMenuOpen(ev);
current_panel->onMenuOpen(ev);
}
void SetWindow::onIdle(wxIdleEvent& ev) { void SetWindow::onIdle(wxIdleEvent& ev) {
// Stuff that must be done in the main thread // Stuff that must be done in the main thread
show_update_dialog(this); show_update_dialog(this);
...@@ -856,6 +861,7 @@ BEGIN_EVENT_TABLE(SetWindow, wxFrame) ...@@ -856,6 +861,7 @@ BEGIN_EVENT_TABLE(SetWindow, wxFrame)
EVT_MENU (ID_HELP_INDEX, SetWindow::onHelpIndex) EVT_MENU (ID_HELP_INDEX, SetWindow::onHelpIndex)
EVT_MENU (ID_HELP_WEBSITE, SetWindow::onHelpWebsite) EVT_MENU (ID_HELP_WEBSITE, SetWindow::onHelpWebsite)
EVT_MENU (ID_HELP_ABOUT, SetWindow::onHelpAbout) EVT_MENU (ID_HELP_ABOUT, SetWindow::onHelpAbout)
EVT_MENU_OPEN ( SetWindow::onMenuOpen)
EVT_TOOL_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, SetWindow::onChildMenu) EVT_TOOL_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, SetWindow::onChildMenu)
EVT_COMMAND_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, wxEVT_COMMAND_BUTTON_CLICKED, SetWindow::onChildMenu) EVT_COMMAND_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, wxEVT_COMMAND_BUTTON_CLICKED, SetWindow::onChildMenu)
EVT_COMMAND_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, wxEVT_COMMAND_SPINCTRL_UPDATED, SetWindow::onChildMenu) EVT_COMMAND_RANGE (ID_CHILD_MIN, ID_CHILD_MAX, wxEVT_COMMAND_SPINCTRL_UPDATED, SetWindow::onChildMenu)
......
...@@ -165,6 +165,7 @@ class SetWindow : public wxFrame, public SetView { ...@@ -165,6 +165,7 @@ class SetWindow : public wxFrame, public SetView {
// --------------------------------------------------- : Window events - other // --------------------------------------------------- : Window events - other
void onChildMenu (wxCommandEvent&); void onChildMenu (wxCommandEvent&);
void onMenuOpen (wxMenuEvent&);
void onIdle (wxIdleEvent&); void onIdle (wxIdleEvent&);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment