2 * @file GenericMainMenu.h
3 * Declares the GenericMainMenu class.
8 * Copyright 2012 Joel Baxter
10 * This file is part of MeshTex.
12 * MeshTex is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 2 of the License, or
15 * (at your option) any later version.
17 * MeshTex is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with MeshTex. If not, see <http://www.gnu.org/licenses/>.
26 #if !defined(INCLUDED_GENERICMAINMENU_H)
27 #define INCLUDED_GENERICMAINMENU_H
32 #include "RefCounted.h"
33 #include "GenericDialog.h"
35 #include "generic/callback.h"
36 #include "generic/referencecounted.h"
39 * String used in lists of command tokens or command labels to separate groups
42 #define MENU_SEPARATOR "-"
45 * Framework for a Radiant plugin's main menu. This object handles the menu
46 * logic: what commands exist and how to execute them. The actual menu
47 * display is handled by Radiant.
49 * A subclass should handle creating the command list.
53 class GenericMainMenu : public RefCounted
55 protected: // protected methods
60 virtual ~GenericMainMenu();
63 private: // private methods
65 /// @name Unimplemented to prevent copy/assignment
67 GenericMainMenu(const GenericMainMenu&);
68 const GenericMainMenu& operator=(const GenericMainMenu&);
71 public: // public methods
73 /// @name Service the plugin interface
75 virtual void Dispatch(const char *command);
76 virtual void CommandDialogShow(const std::string& commandString);
77 const std::string& GetCommandList() const;
78 const std::string& GetCommandLabelList() const;
81 protected: // protected types
83 * Function signature for a menu command callback. The callback takes a
84 * string argument (the command token); it has no return value.
86 typedef Callback1<const std::string&, void> CommandCallback;
89 * An instance of this class can be used as a
90 * GenericMainMenu::CommandCallback, in situations where the callback is a
91 * method to be invoked on a target object. When invoking this constructor,
92 * the target object is the constructor argument, and the target object class
93 * and method are template parameters. The target object's method must have
94 * an appropriate signature for CommandCallback: one string argument, void
97 template<typename ObjectClass, void (ObjectClass::*member)(const std::string&)>
98 class CommandCallbackMethod :
99 public MemberCaller1<ObjectClass, const std::string&, member>
105 * @param object The object on which to invoke the callback method.
107 CommandCallbackMethod(ObjectClass& object) :
108 MemberCaller1<ObjectClass, const std::string&, member>(object) {}
111 protected: // protected methods
113 /// @name Command list construction
115 virtual void BeginEntries();
116 virtual void AddSeparator();
117 virtual std::string AddEntry(const char *commandLabel,
119 const CommandCallback& commandCallback);
120 virtual void AddDialogShowEntry(const char *commandLabel,
122 const SmartPointer<GenericDialog>& dialog);
123 virtual void EndEntries();
126 private: // private types
129 * Type for a map between string and reference-counted dialog window.
131 typedef std::map<std::string, SmartPointer<GenericDialog> > DialogMap;
133 private: // private member vars
136 * Semicolon-separated string of command tokens.
138 std::string _menuCommands;
141 * Semicolon-separated string of command labels.
143 std::string _menuCommandLabels;
146 * Associations between command tokens and callbacks.
148 std::map<std::string, CommandCallback> _dispatchMap;
151 * Associations between command tokens and dialog windows.
153 DialogMap _dialogMap;
156 #endif // #if !defined(INCLUDED_GENERICMAINMENU_H)