Skip to content

Commit

Permalink
Gui Enhancement: Support for macros in AppUserHome/Macro
Browse files Browse the repository at this point in the history
=====================================================

What?
It was suggested that the macros should be moved to AppUserHome/Macro
http://forum.freecadweb.org/viewtopic.php?f=10&t=13433

Solution:
The solution is backwards compatible in the sense that if you have a running
configuration, updating should not change anything.

For new installations the macro directory will default to AppUserHome/Macro. However
this would break all the installation scripts (probably also ME's plugin manager).

Conflicts:
	src/Mod/Path/Gui/AppPathGuiPy.cpp
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed Jan 11, 2016
1 parent f78a239 commit 7fc7bdc
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/App/Application.cpp
Expand Up @@ -522,6 +522,12 @@ std::string Application::getUserAppDataDir()
return mConfig["UserAppData"];
}

std::string Application::getUserMacroDir()
{
std::string path("Macro/");
return mConfig["UserAppData"] + path;
}

std::string Application::getResourceDir()
{
#ifdef RESOURCEDIR
Expand Down
3 changes: 2 additions & 1 deletion src/App/Application.h
Expand Up @@ -247,6 +247,7 @@ class AppExport Application
static std::string getTempPath();
static std::string getTempFileName(const char* FileName=0);
static std::string getUserAppDataDir();
static std::string getUserMacroDir();
static std::string getResourceDir();
static std::string getHelpDir();
//@}
Expand Down Expand Up @@ -301,7 +302,7 @@ class AppExport Application
static PyObject* sAddExportType (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject* sGetExportType (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject* sGetResourceDir (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject* sGetUserAppDataDir (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject* sGetUserAppDataDir (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject* sGetHomePath (PyObject *self,PyObject *args,PyObject *kwd);

static PyObject* sLoadFile (PyObject *self,PyObject *args,PyObject *kwd);
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/Command.cpp
Expand Up @@ -722,7 +722,7 @@ void MacroCommand::activated(int iMsg)
{
std::string cMacroPath = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/Macro")->GetASCII("MacroPath",
App::Application::getUserAppDataDir().c_str());
App::Application::getUserMacroDir().c_str());

QDir d(QString::fromUtf8(cMacroPath.c_str()));
QFileInfo fi(d, QString::fromUtf8(sScriptName));
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/DlgActionsImp.cpp
Expand Up @@ -62,7 +62,7 @@ DlgCustomActionsImp::DlgCustomActionsImp( QWidget* parent )
// search for all macros
std::string cMacroPath = App::GetApplication().
GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
->GetASCII("MacroPath",App::Application::getUserAppDataDir().c_str());
->GetASCII("MacroPath",App::Application::getUserMacroDir().c_str());

QDir d(QString::fromUtf8(cMacroPath.c_str()), QLatin1String("*.FCMacro *.py"));
actionMacros->insertItems(0, d.entryList());
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/DlgMacroExecuteImp.cpp
Expand Up @@ -79,7 +79,7 @@ DlgMacroExecuteImp::DlgMacroExecuteImp( QWidget* parent, Qt::WindowFlags fl )
this->setupUi(this);
// retrieve the macro path from parameter or use the user data as default
std::string path = getWindowParameter()->GetASCII("MacroPath",
App::Application::getUserAppDataDir().c_str());
App::Application::getUserMacroDir().c_str());
this->macroPath = QString::fromUtf8(path.c_str());
fileChooser->setFileName(this->macroPath);

Expand Down
2 changes: 1 addition & 1 deletion src/Gui/DlgMacroRecordImp.cpp
Expand Up @@ -54,7 +54,7 @@ DlgMacroRecordImp::DlgMacroRecordImp( QWidget* parent, Qt::WindowFlags fl )

// get the macro home path
this->macroPath = QString::fromUtf8(getWindowParameter()->GetASCII("MacroPath",
App::Application::getUserAppDataDir().c_str()).c_str());
App::Application::getUserMacroDir().c_str()).c_str());
this->macroPath = QDir::toNativeSeparators(QDir(this->macroPath).path() + QDir::separator());

// set the edit fields
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/DlgSettingsMacroImp.cpp
Expand Up @@ -39,7 +39,7 @@ DlgSettingsMacroImp::DlgSettingsMacroImp( QWidget* parent )
{
this->setupUi(this);
if (MacroPath->fileName().isEmpty()) {
QDir d(QString::fromUtf8(App::GetApplication().getUserAppDataDir().c_str()));
QDir d(QString::fromUtf8(App::GetApplication().getUserMacroDir().c_str()));
MacroPath->setFileName(d.path());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Gui/PythonConsole.cpp
Expand Up @@ -1196,7 +1196,7 @@ void PythonConsole::onClearConsole()
void PythonConsole::onSaveHistoryAs()
{
QString cMacroPath = QString::fromUtf8(getDefaultParameter()->GetGroup( "Macro" )->
GetASCII("MacroPath",App::Application::getUserAppDataDir().c_str()).c_str());
GetASCII("MacroPath",App::Application::getUserMacroDir().c_str()).c_str());
QString fn = FileDialog::getSaveFileName(this, tr("Save History"), cMacroPath,
QString::fromLatin1("%1 (*.FCMacro *.py)").arg(tr("Macro Files")));
if (!fn.isEmpty()) {
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/Path/Gui/AppPathGuiPy.cpp
Expand Up @@ -63,7 +63,7 @@ static PyObject * open(PyObject *self, PyObject *args)
path += "Mod/Path/PathScripts/";
QDir dir1(QString::fromUtf8(path.c_str()), QString::fromLatin1("*_pre.py"));
std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
->GetASCII("MacroPath",App::Application::getUserAppDataDir().c_str());
->GetASCII("MacroPath",App::Application::getUserMacroDir().c_str());
QDir dir2(QString::fromUtf8(cMacroPath.c_str()), QString::fromLatin1("*_pre.py"));
QFileInfoList list = dir1.entryInfoList();
list << dir2.entryInfoList();
Expand Down Expand Up @@ -124,7 +124,7 @@ static PyObject * importer(PyObject *self, PyObject *args)
path += "Mod/Path/PathScripts/";
QDir dir1(QString::fromUtf8(path.c_str()), QString::fromLatin1("*_pre.py"));
std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
->GetASCII("MacroPath",App::Application::getUserAppDataDir().c_str());
->GetASCII("MacroPath",App::Application::getUserMacroDir().c_str());
QDir dir2(QString::fromUtf8(cMacroPath.c_str()), QString::fromLatin1("*_pre.py"));
QFileInfoList list = dir1.entryInfoList();
list << dir2.entryInfoList();
Expand Down Expand Up @@ -194,7 +194,7 @@ static PyObject * exporter(PyObject *self, PyObject *args)
path += "Mod/Path/PathScripts/";
QDir dir1(QString::fromUtf8(path.c_str()), QString::fromLatin1("*_post.py"));
std::string cMacroPath = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro")
->GetASCII("MacroPath",App::Application::getUserAppDataDir().c_str());
->GetASCII("MacroPath",App::Application::getUserMacroDir().c_str());
QDir dir2(QString::fromUtf8(cMacroPath.c_str()), QString::fromLatin1("*_post.py"));
QFileInfoList list = dir1.entryInfoList();
list << dir2.entryInfoList();
Expand Down

0 comments on commit 7fc7bdc

Please sign in to comment.