From 8a3958ced5a3d6e548535fa5b8f0299e20fd416e Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Thu, 24 Dec 2015 18:43:48 +0100 Subject: [PATCH] Gui: Extension of CommandMacro for system-wide macros ===================================================== What? Extension of the CommandMacro constructor to take an additional optional argument to indicate that the macro is located in the system-wide directory, and shall be executed accordingly. --- src/Gui/Command.cpp | 27 +++++++++++++++++++++------ src/Gui/Command.h | 3 ++- src/Gui/DlgActionsImp.cpp | 16 ++++++++++++++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 7b2d6a0e9..a3c563a37 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -701,11 +701,11 @@ void Command::updateAction(int) /* TRANSLATOR Gui::MacroCommand */ -MacroCommand::MacroCommand(const char* name) +MacroCommand::MacroCommand(const char* name, bool system) #if defined (_MSC_VER) - : Command( _strdup(name) ) + : Command( _strdup(name) ), systemMacro(system) #else - : Command( strdup(name) ) + : Command( strdup(name) ), systemMacro(system) #endif { sGroup = QT_TR_NOOP("Macros"); @@ -720,11 +720,22 @@ MacroCommand::~MacroCommand() void MacroCommand::activated(int iMsg) { - std::string cMacroPath = App::GetApplication().GetParameterGroupByPath + QDir d; + + if(!systemMacro) { + std::string cMacroPath; + + cMacroPath = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/Macro")->GetASCII("MacroPath", App::Application::getUserMacroDir().c_str()); - - QDir d(QString::fromUtf8(cMacroPath.c_str())); + + d = QDir(QString::fromUtf8(cMacroPath.c_str())); + } + else { + QString dirstr = QString::fromUtf8(App::GetApplication().getHomePath()) + QString::fromUtf8("Macro"); + d = QDir(dirstr); + } + QFileInfo fi(d, QString::fromUtf8(sScriptName)); if (!fi.exists()) { QMessageBox::critical(Gui::getMainWindow(), @@ -795,6 +806,9 @@ void MacroCommand::load() if ((*it)->GetASCII("Pixmap", "nix") != "nix") macro->setPixmap ( (*it)->GetASCII( "Pixmap" ).c_str() ); macro->setAccel ( (*it)->GetASCII( "Accel",0 ).c_str() ); + + macro->systemMacro = (*it)->GetBool("System", false); + Application::Instance->commandManager().addCommand( macro ); } } @@ -817,6 +831,7 @@ void MacroCommand::save() hMacro->SetASCII( "Statustip", macro->getStatusTip () ); hMacro->SetASCII( "Pixmap", macro->getPixmap () ); hMacro->SetASCII( "Accel", macro->getAccel () ); + hMacro->SetBool( "System", macro->systemMacro ); } } } diff --git a/src/Gui/Command.h b/src/Gui/Command.h index f9c20fa6d..36e9f3a17 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -431,7 +431,7 @@ protected: class MacroCommand: public Command { public: - MacroCommand(const char* name); + MacroCommand(const char* name, bool system = false); virtual ~MacroCommand(); protected: @@ -467,6 +467,7 @@ public: protected: const char* sScriptName; + bool systemMacro; }; /** The CommandManager class diff --git a/src/Gui/DlgActionsImp.cpp b/src/Gui/DlgActionsImp.cpp index a3ec0d797..4f200ec89 100644 --- a/src/Gui/DlgActionsImp.cpp +++ b/src/Gui/DlgActionsImp.cpp @@ -65,7 +65,19 @@ DlgCustomActionsImp::DlgCustomActionsImp( QWidget* parent ) ->GetASCII("MacroPath",App::Application::getUserMacroDir().c_str()); QDir d(QString::fromUtf8(cMacroPath.c_str()), QLatin1String("*.FCMacro *.py")); - actionMacros->insertItems(0, d.entryList()); + + for (unsigned int i=0; iinsertItem(0,d[i],QVariant(false)); + + QString systemMacroDirStr = QString::fromUtf8(App::GetApplication().getHomePath()) + QString::fromUtf8("Macro"); + + d = QDir(systemMacroDirStr, QLatin1String("*.FCMacro *.py")); + + if(d.exists()) { + for (unsigned int i=0; iinsertItem(0,d[i],QVariant(true)); + } + } QStringList labels; labels << tr("Icons") << tr("Macros"); actionListWidget->setHeaderLabels(labels); @@ -228,7 +240,7 @@ void DlgCustomActionsImp::on_buttonAddAction_clicked() // search for the command in the manager QByteArray actionName = newActionName().toLatin1(); CommandManager& rclMan = Application::Instance->commandManager(); - MacroCommand* macro = new MacroCommand(actionName); + MacroCommand* macro = new MacroCommand(actionName, actionMacros->itemData(actionMacros->currentIndex()).toBool()); rclMan.addCommand( macro ); // add new action