diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 976b9fa6e..0b1dbe27d 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -672,6 +672,10 @@ void Command::languageChange() } } +void Command::updateAction(int) +{ +} + //=========================================================================== // MacroCommand //=========================================================================== @@ -1049,3 +1053,20 @@ void CommandManager::testActive(void) } } +void CommandManager::addCommandMode(const char* sContext, const char* sName) +{ + _sCommandModes[sContext].push_back(sName); +} + +void CommandManager::updateCommands(const char* sContext, int mode) +{ + std::map >::iterator it = _sCommandModes.find(sContext); + if (it != _sCommandModes.end()) { + for (std::list::iterator jt = it->second.begin(); jt != it->second.end(); ++jt) { + Command* cmd = getCommandByName(jt->c_str()); + if (cmd) { + cmd->updateAction(mode); + } + } + } +} diff --git a/src/Gui/Command.h b/src/Gui/Command.h index 5a436ea32..7f51acd51 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -84,9 +84,12 @@ public: protected: /// Creates the used Action when adding to a widget. The default implementation does nothing. virtual Action * createAction(void); + public: /// Reassigns QAction stuff after the language has changed. virtual void languageChange() = 0; + /// Updates the QAction with respect to the passed mode. + virtual void updateAction(int mode) = 0; /// The C++ class name is needed as context for the translation framework virtual const char* className() const = 0; //@} @@ -219,6 +222,8 @@ public: static bool isActiveObjectValid(void); /// Translate command void languageChange(); + /// Updates the QAction with respect to the passed mode. + void updateAction(int mode); //@} /** @name Helper methods for issuing commands to the Python interpreter */ @@ -464,14 +469,19 @@ public: */ void runCommandByName (const char* sName) const; - /// method is OBSOLET use GetModuleCommands() or GetAllCommands() + /// method is OBSOLETE use GetModuleCommands() or GetAllCommands() const std::map& getCommands() const { return _sCommands; } /// get frequently called by the AppWnd to check the commands are active. void testActive(void); + + void addCommandMode(const char* sContext, const char* sName); + void updateCommands(const char* sContext, int mode); + private: /// Destroys all commands in the manager and empties the list. void clearCommands(); - std::map _sCommands; + std::map _sCommands; + std::map > _sCommandModes; }; } // namespace Gui @@ -544,6 +554,24 @@ protected: \ virtual Gui::Action * createAction(void);\ }; +/** The Command Macro Standard + isActive() + updateAction() + * This macro makes it easier to define a new command. + * The parameters are the class name + * @author Werner Mayer + */ +#define DEF_STD_CMD_AU(X) class X : public Gui::Command \ +{\ +public:\ + X();\ + virtual ~X(){}\ + virtual void updateAction(int mode); \ + virtual const char* className() const\ + { return #X; }\ +protected: \ + virtual void activated(int iMsg);\ + virtual bool isActive(void);\ +}; + /** The Command Macro Standard + isActive() + createAction() * + languageChange() * This macro makes it easier to define a new command. @@ -564,6 +592,27 @@ protected: \ virtual Gui::Action * createAction(void);\ }; +/** The Command Macro Standard + isActive() + createAction() + * + languageChange() + updateAction() + * This macro makes it easier to define a new command. + * The parameters are the class name + * @author Werner Mayer + */ +#define DEF_STD_CMD_ACLU(X) class X : public Gui::Command \ +{\ +public:\ + X();\ + virtual ~X(){}\ + virtual void languageChange(); \ + virtual void updateAction(int mode); \ + virtual const char* className() const\ + { return #X; }\ +protected: \ + virtual void activated(int iMsg);\ + virtual bool isActive(void);\ + virtual Gui::Action * createAction(void);\ +}; + /** The Command Macro view * This macro makes it easier to define a new command for the 3D View * It activate the command only when a 3DView is active.