From ca83354bf9f8818dd6c18a2169725b21c7986ff3 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 28 Mar 2021 20:04:31 +0200 Subject: [PATCH] Gui: [skip ci] refactor Command::invoke --- src/Gui/Command.cpp | 57 ++++++++++++++++++++++++++++----------------- src/Gui/Command.h | 3 +++ 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 03120743da..88b6a02888 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -375,65 +375,78 @@ void Command::setupCheckable(int iMsg) { void Command::invoke(int i, TriggerSource trigger) { CommandTrigger cmdTrigger(_trigger,trigger); - if(displayText.empty()) { + if (displayText.empty()) { displayText = getMenuText(); boost::replace_all(displayText,"&",""); - if(displayText.empty()) + if (displayText.empty()) displayText = getName(); } - // Because Transaction now captures ViewObject changes, auto named - // transaction is disabled here to avoid too many unnecessary transactions. - // - // App::AutoTransaction committer((eType&NoTransaction)?0:displayText.c_str(),true); - App::AutoTransaction committer(0,true); - // Do not query _pcAction since it isn't created necessarily #ifdef FC_LOGUSERACTION Base::Console().Log("CmdG: %s\n",sName); #endif - // set the application module type for the macro - getGuiApplication()->macroManager()->setModule(sAppModule); + + _invoke(i, bCanLog && !_busy); +} + +void Command::_invoke(int id, bool disablelog) +{ try { - std::unique_ptr disabler; - if(bCanLog && !_busy) - disabler.reset(new LogDisabler); + // Because Transaction now captures ViewObject changes, auto named + // transaction is disabled here to avoid too many unnecessary transactions. + // + App::AutoTransaction committer(nullptr, true); + + // set the application module type for the macro + getGuiApplication()->macroManager()->setModule(sAppModule); + + std::unique_ptr logdisabler; + if (disablelog) + logdisabler.reset(new LogDisabler); + // check if it really works NOW (could be a delay between click deactivation of the button) if (isActive()) { auto manager = getGuiApplication()->macroManager(); auto editDoc = getGuiApplication()->editDocument(); - if(!disabler) - activated( i ); + + if (!logdisabler) { + activated(id); + } else { - Gui::SelectionLogDisabler disabler; + Gui::SelectionLogDisabler seldisabler; auto lines = manager->getLines(); std::ostringstream ss; ss << "### Begin command " << sName; // Add a pending line to mark the start of a command PendingLine pending(MacroManager::Cmt, ss.str().c_str()); - activated( i ); ss.str(""); - if(manager->getLines() == lines) { + + activated(id); + + if (manager->getLines() == lines) { // This command does not record any lines, lets do it for - // him. The above LogDisabler is to prevent nested command + // it. The above LogDisabler is to prevent nested command // logging, i.e. we only auto log the first invoking // command. // Cancel the above pending line first pending.cancel(); - ss << "Gui.runCommand('" << sName << "'," << i << ')'; + ss << "Gui.runCommand('" << sName << "'," << id << ')'; manager->addLine(MacroManager::Gui, ss.str().c_str()); - }else{ + } + else { // In case the command has any output to the console, lets // mark the end of the command here ss << "### End command " << sName; manager->addLine(MacroManager::Cmt, ss.str().c_str()); } } + getMainWindow()->updateActions(); // If this command starts an editing, let the transaction persist - if(!editDoc && getGuiApplication()->editDocument()) + if (!editDoc && getGuiApplication()->editDocument()) committer.setEnable(false); } } diff --git a/src/Gui/Command.h b/src/Gui/Command.h index c3c76fc39c..c3f7a2c982 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -584,6 +584,9 @@ public: }; friend class LogDisabler; +private: + void _invoke(int, bool disablelog); + protected: enum CmdType { AlterDoc = 1, /**< Command change the Document */