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.
This commit is contained in:
Abdullah Tahiri 2015-12-24 18:43:48 +01:00 committed by wmayer
parent 3d551450a2
commit 8a3958ced5
3 changed files with 37 additions and 9 deletions

View File

@ -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 );
}
}
}

View File

@ -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

View File

@ -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; i<d.count(); i++ )
actionMacros->insertItem(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; i<d.count(); i++ ) {
actionMacros->insertItem(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