Code::Blocks  SVN r11506
Public Member Functions | Protected Attributes | List of all members
MenuItemsManager Class Reference

Manager for wxMenuItem pointers. More...

#include <menuitemsmanager.h>

Collaboration diagram for MenuItemsManager:

Public Member Functions

 MenuItemsManager (bool autoClearOnDestroy=true)
 
virtual ~MenuItemsManager ()
 
virtual int CreateFromString (const wxString &menuPath, int id)
 Create menu path from string. More...
 
virtual wxMenuItemAdd (wxMenu *parent, int id, const wxString &caption, const wxString &helptext)
 Add a menu item. More...
 
virtual wxMenuItemInsert (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
 

Detailed Description

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.

Author
Yiannis Mandravellos

Definition at line 28 of file menuitemsmanager.h.

Constructor & Destructor Documentation

◆ MenuItemsManager()

MenuItemsManager::MenuItemsManager ( bool  autoClearOnDestroy = true)

Definition at line 24 of file menuitemsmanager.cpp.

◆ ~MenuItemsManager()

MenuItemsManager::~MenuItemsManager ( )
virtual

Definition at line 30 of file menuitemsmanager.cpp.

References Clear(), m_AutoClearOnDestroy, and m_MenuItems.

Member Function Documentation

◆ Add()

wxMenuItem * MenuItemsManager::Add ( wxMenu parent,
int  id,
const wxString caption,
const wxString helptext 
)
virtual

Add a menu item.

Parameters
parentThe menu to append the menu item to
idThe menu item ID (use wxID_SEPARATOR for adding a separator)
captionThe caption for the new menu item
helptextThe help text for the new menu item
Returns
The new menu item or NULL for failure.

Definition at line 48 of file menuitemsmanager.cpp.

References wxMenu::Append(), and m_MenuItems.

Referenced by ToolsManager::BuildToolsMenu().

◆ Clear()

void MenuItemsManager::Clear ( )
virtual

◆ CreateFromString()

int MenuItemsManager::CreateFromString ( const wxString menuPath,
int  id 
)
virtual

Create menu path from string.

Parameters
menuPathThe 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.
idThe menu item ID (use wxID_SEPARATOR for adding a separator)
Returns
The id of the newly created menu or the id of the old, same menu entry or NULL for failure.

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().

◆ Insert()

wxMenuItem * MenuItemsManager::Insert ( wxMenu parent,
int  index,
int  id,
const wxString caption,
const wxString helptext 
)
virtual

Insert a menu item.

Parameters
parentThe menu to insert the menu item to
indexThe index where to insert the menu item
idThe menu item ID (use wxID_SEPARATOR for adding a separator)
captionThe caption for the new menu item
helptextThe help text for the new menu item
Returns
The new menu item or NULL for failure.

Definition at line 67 of file menuitemsmanager.cpp.

References wxMenu::Insert(), and m_MenuItems.

Referenced by CreateFromString().

Member Data Documentation

◆ m_AutoClearOnDestroy

bool MenuItemsManager::m_AutoClearOnDestroy
protected

Definition at line 41 of file menuitemsmanager.h.

Referenced by ~MenuItemsManager().

◆ m_MenuItems

MenuItemsList MenuItemsManager::m_MenuItems
protected

Definition at line 40 of file menuitemsmanager.h.

Referenced by Add(), Clear(), Insert(), and ~MenuItemsManager().


The documentation for this class was generated from the following files: