diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index d94d5198d0..76d43fb475 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1256,8 +1256,14 @@ bool Application::activateWorkbench(const char* name) // now get the newly activated workbench Workbench* newWb = WorkbenchManager::instance()->active(); - if (newWb) + if (newWb) { + if (!Instance->d->startingUp) { + std::string name = newWb->name(); + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> + SetASCII("LastModule", name.c_str()); + } newWb->activated(); + } } catch (Py::Exception&) { Base::PyException e; // extract the Python error text @@ -2021,15 +2027,26 @@ void Application::runApplication(void) // Activate the correct workbench std::string start = App::Application::Config()["StartWorkbench"]; Base::Console().Log("Init: Activating default workbench %s\n", start.c_str()); - start = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> + std::string autoload = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> GetASCII("AutoloadModule", start.c_str()); + if ("$LastModule" == autoload) { + start = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> + GetASCII("LastModule", start.c_str()); + } else { + start = autoload; + } // if the auto workbench is not visible then force to use the default workbech // and replace the wrong entry in the parameters QStringList wb = app.workbenches(); if (!wb.contains(QString::fromLatin1(start.c_str()))) { start = App::Application::Config()["StartWorkbench"]; - App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> - SetASCII("AutoloadModule", start.c_str()); + if ("$LastModule" == autoload) { + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> + SetASCII("LastModule", start.c_str()); + } else { + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> + SetASCII("AutoloadModule", start.c_str()); + } } // Call this before showing the main window because otherwise: diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp index 7350ad9fbe..881589b4d6 100644 --- a/src/Gui/DlgGeneralImp.cpp +++ b/src/Gui/DlgGeneralImp.cpp @@ -65,6 +65,16 @@ DlgGeneralImp::DlgGeneralImp( QWidget* parent ) menuText[text] = *it; } + { // add special workbench to selection + QPixmap px = Application::Instance->workbenchIcon(QString::fromLatin1("NoneWorkbench")); + QString key = QString::fromLatin1(""); + QString value = QString::fromLatin1("$LastModule"); + if (px.isNull()) + ui->AutoloadModuleCombo->addItem(key, QVariant(value)); + else + ui->AutoloadModuleCombo->addItem(px, key, QVariant(value)); + } + for (QMap::Iterator it = menuText.begin(); it != menuText.end(); ++it) { QPixmap px = Application::Instance->workbenchIcon(it.value()); if (px.isNull()) diff --git a/src/Main/FreeCADGuiPy.cpp b/src/Main/FreeCADGuiPy.cpp index 547c190f4a..43efa5714d 100644 --- a/src/Main/FreeCADGuiPy.cpp +++ b/src/Main/FreeCADGuiPy.cpp @@ -298,15 +298,26 @@ QWidget* setupMainWindow() // Activate the correct workbench std::string start = App::Application::Config()["StartWorkbench"]; Base::Console().Log("Init: Activating default workbench %s\n", start.c_str()); - start = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> + std::string autoload = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> GetASCII("AutoloadModule", start.c_str()); + if ("$LastModule" == autoload) { + start = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> + GetASCII("LastModule", start.c_str()); + } else { + start = autoload; + } // if the auto workbench is not visible then force to use the default workbech // and replace the wrong entry in the parameters QStringList wb = Gui::Application::Instance->workbenches(); if (!wb.contains(QString::fromLatin1(start.c_str()))) { start = App::Application::Config()["StartWorkbench"]; - App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> - SetASCII("AutoloadModule", start.c_str()); + if ("$LastModule" == autoload) { + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> + SetASCII("LastModule", start.c_str()); + } else { + App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")-> + SetASCII("AutoloadModule", start.c_str()); + } } Gui::Application::Instance->activateWorkbench(start.c_str()); diff --git a/src/Mod/Start/Gui/DlgStartPreferencesImp.cpp b/src/Mod/Start/Gui/DlgStartPreferencesImp.cpp index d9e4ea5911..ab9cff0a02 100644 --- a/src/Mod/Start/Gui/DlgStartPreferencesImp.cpp +++ b/src/Mod/Start/Gui/DlgStartPreferencesImp.cpp @@ -54,6 +54,16 @@ DlgStartPreferencesImp::DlgStartPreferencesImp( QWidget* parent ) menuText[text] = *it; } + { // add special workbench to selection + QPixmap px = Gui::Application::Instance->workbenchIcon(QString::fromLatin1("NoneWorkbench")); + QString key = QString::fromLatin1(""); + QString value = QString::fromLatin1("$LastModule"); + if (px.isNull()) + AutoloadModuleCombo->addItem(key, QVariant(value)); + else + AutoloadModuleCombo->addItem(px, key, QVariant(value)); + } + for (QMap::Iterator it = menuText.begin(); it != menuText.end(); ++it) { QPixmap px = Gui::Application::Instance->workbenchIcon(it.value()); if (px.isNull()) diff --git a/src/Mod/Start/StartPage/StartPage.py b/src/Mod/Start/StartPage/StartPage.py index 3f63056cfb..76e94c3a5c 100644 --- a/src/Mod/Start/StartPage/StartPage.py +++ b/src/Mod/Start/StartPage/StartPage.py @@ -567,6 +567,8 @@ def postStart(): # switch workbench wb = param.GetString("AutoloadModule","") + if "$LastModule" == wb: + wb = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General").GetString("LastModule","") if wb: # don't switch workbenches if we are not in Start anymore if FreeCADGui.activeWorkbench() and (FreeCADGui.activeWorkbench().name() == "StartWorkbench"):