Code::Blocks
SVN r11506
|
Manager for wxMenuItem pointers. More...
#include <menuitemsmanager.h>
Public Member Functions | |
MenuItemsManager (bool autoClearOnDestroy=true) | |
virtual | ~MenuItemsManager () |
virtual int | CreateFromString (const wxString &menuPath, int id) |
Create menu path from string. More... | |
virtual wxMenuItem * | Add (wxMenu *parent, int id, const wxString &caption, const wxString &helptext) |
Add a menu item. More... | |
virtual wxMenuItem * | Insert (wxMenu *parent, int index, int id, const wxString &caption, const wxString &helptext) |
Insert a menu item. More... | |
virtual void | Clear () |
Clear all managed menu items. More... | |
Protected Attributes | |
MenuItemsList | m_MenuItems |
bool | m_AutoClearOnDestroy |
Manager for wxMenuItem pointers.
This class manages an array of wxMenuItem pointers. Usually used by classes that need to create menu items in the app and, at some point, remove them without messing with other menu items, created by other classes. Useful for plugins.
To use it, add a MenuItemsManager variable in your class and then use MenuItemsManager::Add() to add menu items to a menu (instead of wxMenu::Append). When you no longer want those menu items, call MenuItemsManager::Clear(). That's it.
Definition at line 28 of file menuitemsmanager.h.
MenuItemsManager::MenuItemsManager | ( | bool | autoClearOnDestroy = true | ) |
Definition at line 24 of file menuitemsmanager.cpp.
|
virtual |
Definition at line 30 of file menuitemsmanager.cpp.
References Clear(), m_AutoClearOnDestroy, and m_MenuItems.
|
virtual |
Add a menu item.
parent | The menu to append the menu item to |
id | The menu item ID (use wxID_SEPARATOR for adding a separator) |
caption | The caption for the new menu item |
helptext | The help text for the new menu item |
Definition at line 48 of file menuitemsmanager.cpp.
References wxMenu::Append(), and m_MenuItems.
Referenced by ToolsManager::BuildToolsMenu().
|
virtual |
Clear all managed menu items.
Definition at line 79 of file menuitemsmanager.cpp.
References wxMenu::Delete(), wxMenuItem::GetMenu(), wxMenu::GetMenuItemCount(), wxMenuItem::GetSubMenu(), and m_MenuItems.
Referenced by ToolsManager::BuildToolsMenu(), ScriptingManager::UnRegisterAllScriptMenus(), ~MenuItemsManager(), and ToolsManager::~ToolsManager().
|
virtual |
Create menu path from string.
menuPath | The full menu path. This can be separated by slashes (/) to create submenus (e.g. "MyScripts/ASubMenu/MyItem"). If the last part of the string ("MyItem" in the example) starts with a dash (-) (e.g. "-MyItem") then a menu separator is prepended before the actual menu item. |
id | The menu item ID (use wxID_SEPARATOR for adding a separator) |
Definition at line 105 of file menuitemsmanager.cpp.
References _T, wxMenu::FindChildItem(), wxMenu::FindItem(), wxMenuBar::FindMenu(), Manager::Get(), Manager::GetAppFrame(), wxString::GetChar(), wxMenuBar::GetMenu(), wxMenuBar::GetMenuCount(), wxMenu::GetMenuItemCount(), wxMenuItem::GetSubMenu(), wxMenu::Insert(), wxMenuBar::Insert(), Insert(), wxString::IsEmpty(), wxString::Length(), wxString::Mid(), wxString::Remove(), wxString::StartsWith(), wxString::ToULong(), wxEmptyString, wxID_SEPARATOR, wxITEM_NORMAL, and wxNOT_FOUND.
Referenced by ScriptBindings::ScriptPluginWrapper::CreateMenu(), and ScriptingManager::RegisterScriptMenu().
|
virtual |
Insert a menu item.
parent | The menu to insert the menu item to |
index | The index where to insert the menu item |
id | The menu item ID (use wxID_SEPARATOR for adding a separator) |
caption | The caption for the new menu item |
helptext | The help text for the new menu item |
Definition at line 67 of file menuitemsmanager.cpp.
References wxMenu::Insert(), and m_MenuItems.
Referenced by CreateFromString().
|
protected |
Definition at line 41 of file menuitemsmanager.h.
Referenced by ~MenuItemsManager().
|
protected |
Definition at line 40 of file menuitemsmanager.h.
Referenced by Add(), Clear(), Insert(), and ~MenuItemsManager().