Skip to content

Commit

Permalink
Fix #4482, second attempt. Construct menus in idle event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Feb 9, 2017
1 parent c5a3a4e commit c61af5c
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/version.h
Expand Up @@ -2,7 +2,7 @@
#include <config.h>
#define RADIANT_VERSION PACKAGE_VERSION
#else
#define RADIANT_VERSION "2.2.1"
#define RADIANT_VERSION "2.2.2pre1"
#endif

#define RADIANT_APPNAME "DarkRadiant"
Expand Down
49 changes: 47 additions & 2 deletions plugins/uimanager/menu/MenuBar.cpp
Expand Up @@ -14,6 +14,12 @@ MenuBar::MenuBar() :
_menuBar(nullptr)
{}

MenuBar::~MenuBar()
{
// When destroyed, make sure to unsubscribe from any idle events
setNeedsRefresh(false);
}

wxMenuBar* MenuBar::getMenuBar()
{
if (_menuBar == nullptr)
Expand All @@ -24,9 +30,29 @@ wxMenuBar* MenuBar::getMenuBar()
return _menuBar;
}

void MenuBar::ensureMenusConstructed()
bool MenuBar::isConstructed()
{
construct();
return _menuBar != nullptr;
}

void MenuBar::setNeedsRefresh(bool needsRefresh)
{
MenuElement::setNeedsRefresh(needsRefresh);

// Let's get notified on idle events
if (_menuBar == nullptr || _menuBar->GetFrame() == nullptr)
{
return;
}

if (needsRefresh)
{
_menuBar->GetFrame()->Connect(wxEVT_IDLE, wxIdleEventHandler(MenuBar::onIdle), nullptr, this);
}
else
{
_menuBar->GetFrame()->Disconnect(wxEVT_IDLE, wxIdleEventHandler(MenuBar::onIdle), nullptr, this);
}
}

void MenuBar::construct()
Expand Down Expand Up @@ -97,4 +123,23 @@ void MenuBar::onMenuOpen(wxMenuEvent& ev)
}
}

void MenuBar::onIdle(wxIdleEvent& ev)
{
if (!needsRefresh())
{
ev.Skip();
return;
}

// Unsubscribe from idle events
setNeedsRefresh(false);

construct();

if (_menuBar != nullptr && _menuBar->GetFrame() != nullptr)
{
_menuBar->Refresh();
}
}

}
12 changes: 9 additions & 3 deletions plugins/uimanager/menu/MenuBar.h
Expand Up @@ -2,23 +2,28 @@

#include "MenuElement.h"
#include <wx/menu.h>
#include <wx/event.h>

namespace ui
{

class MenuBar :
public MenuElement
public MenuElement,
public wxEvtHandler
{
private:
wxMenuBar* _menuBar;

public:
MenuBar();

~MenuBar();

virtual wxMenuBar* getMenuBar();

// Makes sure this menubar and all child menus are constructed
void ensureMenusConstructed();
bool isConstructed();

virtual void setNeedsRefresh(bool needsRefresh) override;

protected:
virtual void construct() override;
Expand All @@ -27,6 +32,7 @@ class MenuBar :
private:
MenuElementPtr findMenu(wxMenu* menu);
void onMenuOpen(wxMenuEvent& ev);
void onIdle(wxIdleEvent& ev);
};

}
Expand Down
2 changes: 1 addition & 1 deletion plugins/uimanager/menu/MenuElement.h
Expand Up @@ -106,7 +106,7 @@ class MenuElement :
void setEvent(const std::string& eventName);

bool needsRefresh();
void setNeedsRefresh(bool needsRefresh);
virtual void setNeedsRefresh(bool needsRefresh);

// Tries to (recursively) locate the MenuElement by looking up the path
MenuElementPtr find(const std::string& menuPath);
Expand Down
6 changes: 2 additions & 4 deletions plugins/uimanager/menu/MenuManager.cpp
Expand Up @@ -187,15 +187,13 @@ void MenuManager::handleElementAdded(const MenuElementPtr& element)
parentMenu->setNeedsRefresh(true);
}

#if 0
// When inserting a new menu in a menubar, make sure it is constructed
if (element->getParent() &&
std::dynamic_pointer_cast<MenuBar>(element->getParent()) &&
std::static_pointer_cast<MenuBar>(element->getParent())->getMenuBar() != nullptr)
std::static_pointer_cast<MenuBar>(element->getParent())->isConstructed())
{
std::static_pointer_cast<MenuBar>(element->getParent())->ensureMenusConstructed();
std::static_pointer_cast<MenuBar>(element->getParent())->setNeedsRefresh(true);
}
#endif
}

void MenuManager::handleElementRemoved(const MenuElementPtr& element)
Expand Down
2 changes: 1 addition & 1 deletion plugins/uimanager/menu/MenuManager.h
Expand Up @@ -80,7 +80,7 @@ class MenuManager :
void loadFromRegistry();

/**
* Clears all references to GtkWidgets etc.
* Clears all references to widgets etc.
*/
void clear();

Expand Down
6 changes: 3 additions & 3 deletions tools/innosetup/darkradiant.iss
Expand Up @@ -3,15 +3,15 @@

[Setup]
AppName=DarkRadiant
AppVerName=DarkRadiant 2.2.1 x86
AppVerName=DarkRadiant 2.2.2pre1 x86
AppPublisher=The Dark Mod
AppPublisherURL=http://www.thedarkmod.com
AppSupportURL=http://www.thedarkmod.com
AppUpdatesURL=http://www.thedarkmod.com
DefaultDirName={pf}\DarkRadiant
DefaultGroupName=DarkRadiant 2.2.1 x86
DefaultGroupName=DarkRadiant 2.2.2pre1 x86
OutputDir=.
OutputBaseFilename=darkradiant-2.2.1-x86
OutputBaseFilename=darkradiant-2.2.2pre1-x86
Compression=lzma
SolidCompression=yes
;ArchitecturesAllowed=x64
Expand Down
6 changes: 3 additions & 3 deletions tools/innosetup/darkradiant.x64.iss
Expand Up @@ -3,15 +3,15 @@

[Setup]
AppName=DarkRadiant
AppVerName=DarkRadiant 2.2.1 x64
AppVerName=DarkRadiant 2.2.2pre1 x64
AppPublisher=The Dark Mod
AppPublisherURL=http://www.thedarkmod.com
AppSupportURL=http://www.thedarkmod.com
AppUpdatesURL=http://www.thedarkmod.com
DefaultDirName={pf}\DarkRadiant
DefaultGroupName=DarkRadiant 2.2.1 x64
DefaultGroupName=DarkRadiant 2.2.2pre1 x64
OutputDir=.
OutputBaseFilename=darkradiant-2.2.1-x64
OutputBaseFilename=darkradiant-2.2.2pre1-x64
Compression=lzma
SolidCompression=yes
ArchitecturesAllowed=x64
Expand Down

0 comments on commit c61af5c

Please sign in to comment.