Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/menumanager' into u…
Browse files Browse the repository at this point in the history
…imodule
  • Loading branch information
codereader committed Jan 5, 2017
2 parents 01a5d04 + 29d5d39 commit e6bbc35
Show file tree
Hide file tree
Showing 30 changed files with 1,381 additions and 789 deletions.
6 changes: 2 additions & 4 deletions include/ifiltermenu.h
Expand Up @@ -12,10 +12,7 @@ namespace ui
* A class representing a Filters submenu, with a proper
* getWidget() method for packing it into a parent container.
*
* Upon construction, the menu will be registered in the
* global MenuManager. The destructor will remove it from there,
* so the client needs to prevent this class from getting
* out of scope too soon.
* It's the caller's responsibility to delete the object.
*
* Use the GlobalUIManager() interface to acquire
* a new instance of this filter menu.
Expand All @@ -28,6 +25,7 @@ class IFilterMenu
// Constructs and returns the widget of a full filters menu
// including submenu and the items. This can be packed into an
// existing menu bar or toolitem right away.
// Caller is responsible of deleting the menu!
virtual wxMenu* getMenuWidget() = 0;
};
typedef std::shared_ptr<IFilterMenu> IFilterMenuPtr;
Expand Down
26 changes: 9 additions & 17 deletions include/iuimanager.h
Expand Up @@ -5,8 +5,8 @@

// Forward declarations
class wxWindow;
class wxObject;
class wxToolBar;
class wxMenuBar;

class IColourSchemeManager {
public:
Expand All @@ -32,22 +32,17 @@ namespace ui
};
} // namespace ui

/** greebo: Implementation documentation: see MenuManager.h.
*/
class IMenuManager
{
public:
/** Destructor
*/
virtual ~IMenuManager() {}

/** greebo: Retrieves the menuitem widget specified by the path.
*
* Example: get("main/file/open") delivers the widget for the "Open..." command.
*
* @returns: the widget, or NULL, if no the path hasn't been found.
/**
* Returns the constructed menu bar, ready for packing into a parent container.
*/
virtual wxObject* get(const std::string& path) = 0;
virtual wxMenuBar* getMenuBar(const std::string& name) = 0;

/** greebo: Shows/hides the menuitem under the given path.
*
Expand All @@ -64,11 +59,8 @@ class IMenuManager
* @caption: the display string of the menu item (incl. mnemonic)
* @icon: the icon filename (can be empty)
* @eventname: the event name (e.g. "ToggleShowSizeInfo")
*
* @returns: the menu item wxObject, which might be a wxMenuItem, or
* a wxMenu or wxMenuBar pointer.
*/
virtual wxObject* add(const std::string& insertPath,
virtual void add(const std::string& insertPath,
const std::string& name,
ui::eMenuItemType type,
const std::string& caption,
Expand All @@ -82,17 +74,17 @@ class IMenuManager
* @caption: the display string including mnemonic
* @icon: the image file name relative to "bitmaps/", can be empty.
* @eventName: the event name this item is associated with (can be empty).
*
* @returns: the menu item wxObject, which might be a wxMenuItem, or
* a wxMenu or wxMenuBar pointer.
*/
virtual wxObject* insert(const std::string& insertPath,
virtual void insert(const std::string& insertPath,
const std::string& name,
ui::eMenuItemType type,
const std::string& caption,
const std::string& icon,
const std::string& eventName) = 0;

// Returns true if the given path exists
virtual bool exists(const std::string& path) = 0;

/**
* Removes an entire path from the menus.
*/
Expand Down
8 changes: 8 additions & 0 deletions libs/wxutil/menu/PopupMenu.cpp
Expand Up @@ -84,4 +84,12 @@ void PopupMenu::_onItemClick(wxCommandEvent& ev)
}
}

void PopupMenu::foreachMenuItem(const std::function<void(const ui::IMenuItemPtr&)>& functor)
{
for (const ui::IMenuItemPtr& item : _menuItems)
{
functor(item);
}
}

} // namespace
3 changes: 3 additions & 0 deletions libs/wxutil/menu/PopupMenu.h
Expand Up @@ -77,6 +77,9 @@ class PopupMenu :
* displayed.
*/
virtual void show(wxWindow* parent);

protected:
virtual void foreachMenuItem(const std::function<void(const ui::IMenuItemPtr&)>& functor);
};
typedef std::shared_ptr<PopupMenu> PopupMenuPtr;

Expand Down
7 changes: 5 additions & 2 deletions libs/wxutil/preview/RenderPreview.cpp
Expand Up @@ -48,7 +48,8 @@ RenderPreview::RenderPreview(wxWindow* parent, bool enableAnimation) :
_timer(this),
_previewWidth(0),
_previewHeight(0),
_filtersMenu(GlobalUIManager().createFilterMenu())
_filtersMenu(GlobalUIManager().createFilterMenu()),
_filterTool(nullptr)
{
Connect(wxEVT_TIMER, wxTimerEventHandler(RenderPreview::_onFrame), NULL, this);

Expand Down Expand Up @@ -96,6 +97,8 @@ void RenderPreview::setupToolbars(bool enableAnimation)
wxToolBarToolBase* filterTool = filterToolbar->AddTool(wxID_ANY, _("Filters"),
wxArtProvider::GetBitmap(GlobalUIManager().ArtIdPrefix() + "iconFilter16.png"),
_("Filters"), wxITEM_DROPDOWN);

// By setting it as dropdown menu the toolitem will take ownership and delete the menu on destruction
filterToolbar->SetDropdownMenu(filterTool->GetId(), filterSubmenu);

filterToolbar->Realize();
Expand Down Expand Up @@ -134,7 +137,7 @@ void RenderPreview::connectToolbarSignals()

RenderPreview::~RenderPreview()
{
_timer.Stop();
_timer.Stop();
}

void RenderPreview::updateActiveRenderModeButton()
Expand Down
3 changes: 3 additions & 0 deletions libs/wxutil/preview/RenderPreview.h
Expand Up @@ -16,6 +16,8 @@
#include "render/SceneRenderWalker.h"
#include "render/NopVolumeTest.h"

class wxToolBarToolBase;

namespace wxutil
{

Expand Down Expand Up @@ -117,6 +119,7 @@ class RenderPreview :

// The filters menu
ui::IFilterMenuPtr _filtersMenu;
wxToolBarToolBase* _filterTool;

protected:
const scene::GraphPtr& getScene();
Expand Down
56 changes: 26 additions & 30 deletions plugins/uimanager/FilterMenu.cpp
@@ -1,60 +1,56 @@
#include "FilterMenu.h"

#include "iuimanager.h"
#include "string/convert.h"
#include "i18n.h"
#include "ieventmanager.h"
#include <wx/menu.h>

#include "wxutil/menu/IconTextMenuItem.h"

namespace ui
{

namespace
{
// These are used for the general-purpose Filter Menu:
const char* const FILTERS_MENU_BAR = "filters";
const char* const FILTERS_MENU_FOLDER = "allfilters";
const char* const FILTERS_MENU_CAPTION = N_("_Filters");

const char* const MENU_ICON = "iconFilter16.png";
}

std::size_t FilterMenu::_counter = 0;

FilterMenu::FilterMenu()
FilterMenu::FilterMenu() :
_menu(new wxutil::PopupMenu)
{
IMenuManager& menuManager = GlobalUIManager().getMenuManager();

// Create a unique name for the menu
_path = FILTERS_MENU_BAR + string::to_string(_counter++);

// Menu not yet constructed, do it now
_menu = dynamic_cast<wxMenu*>(menuManager.add("", _path,
menuFolder, _(FILTERS_MENU_CAPTION), "", ""));
assert(_menu != NULL);

_targetPath = _path;

// Visit the filters in the FilterSystem to populate the menu
GlobalFilterSystem().forEachFilter(*this);
}

FilterMenu::~FilterMenu()
{
GlobalUIManager().getMenuManager().remove(_path);
for (auto i : _filterItems)
{
IEventPtr event = GlobalEventManager().findEvent(i.first);

if (event)
{
event->disconnectMenuItem(i.second);
}
}

_menu = nullptr;
}

// Visitor function
void FilterMenu::visit(const std::string& filterName)
{
// Get the menu manager
IMenuManager& menuManager = GlobalUIManager().getMenuManager();
wxMenuItem* item = _menu->Append(new wxutil::IconTextMenuItem(filterName, MENU_ICON));
item->SetCheckable(true);

std::string eventName = GlobalFilterSystem().getFilterEventName(filterName);

// Create the menu item
menuManager.add(_targetPath, _targetPath + "_" + filterName,
menuItem, filterName,
MENU_ICON, eventName);
IEventPtr event = GlobalEventManager().findEvent(eventName);

if (event)
{
event->connectMenuItem(item);
}

_filterItems.insert(std::make_pair(eventName, item));
}

wxMenu* FilterMenu::getMenuWidget()
Expand Down
17 changes: 6 additions & 11 deletions plugins/uimanager/FilterMenu.h
@@ -1,7 +1,9 @@
#pragma once

#include <map>
#include "ifiltermenu.h"
#include "ifilter.h"
#include "wxutil/menu/PopupMenu.h"

namespace ui
{
Expand All @@ -10,26 +12,19 @@ namespace ui
* registers the relevant menuitems on demand.
*
* Construct a FiltersMenu instance to generate a new Filter Menu which
* can be packed into a parent container widget using the GtkWidget* operator.
* can be packed into a parent container widget using the getMenuWidget().
*/
class FilterMenu :
public IFilterMenu,
public IFilterVisitor
{
private:
wxMenu* _menu;
std::map<std::string, wxMenuItem*> _filterItems;

// Static counter to create unique menu bar widgets
static std::size_t _counter;

// The path of this menu
std::string _path;

// The target path used for population
std::string _targetPath;
wxutil::PopupMenu* _menu;

public:
// Constructs the filters submenu including menu bar
// Constructs the filter items
FilterMenu();

~FilterMenu();
Expand Down
12 changes: 8 additions & 4 deletions plugins/uimanager/Makefile.am
Expand Up @@ -15,19 +15,23 @@ uimanager_la_LIBADD = $(top_builddir)/libs/wxutil/libwxutil.la \
$(top_builddir)/libs/math/libmath.la \
$(top_builddir)/libs/scene/libscenegraph.la \
$(top_builddir)/libs/xmlutil/libxmlutil.la
uimanager_la_SOURCES = MenuItem.cpp \
GroupDialog.cpp \
uimanager_la_SOURCES = GroupDialog.cpp \
animationpreview/MD5AnimationChooser.cpp \
animationpreview/MD5AnimationViewer.cpp \
animationpreview/AnimationPreview.cpp \
colourscheme/ColourScheme.cpp \
colourscheme/ColourSchemeEditor.cpp \
colourscheme/ColourSchemeManager.cpp \
menu/MenuBar.cpp \
menu/MenuElement.cpp \
menu/MenuFolder.cpp \
menu/MenuItem.cpp \
menu/MenuManager.cpp \
menu/MenuSeparator.cpp \
SoundChooser.cpp \
SoundShaderPreview.cpp \
StatusBarManager.cpp \
DialogManager.cpp \
ToolbarManager.cpp \
UIManager.cpp \
FilterMenu.cpp \
MenuManager.cpp
FilterMenu.cpp

0 comments on commit e6bbc35

Please sign in to comment.