Added <last> as an option to the workbench selection.

This commit is contained in:
Markus Lampert
2019-10-18 22:05:55 -07:00
committed by Yorik van Havre
parent 813b529f5c
commit c6c761b812
5 changed files with 57 additions and 7 deletions

View File

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

View File

@@ -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("<last>");
QString value = QString::fromLatin1("$LastModule");
if (px.isNull())
ui->AutoloadModuleCombo->addItem(key, QVariant(value));
else
ui->AutoloadModuleCombo->addItem(px, key, QVariant(value));
}
for (QMap<QString, QString>::Iterator it = menuText.begin(); it != menuText.end(); ++it) {
QPixmap px = Application::Instance->workbenchIcon(it.value());
if (px.isNull())

View File

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

View File

@@ -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("<last>");
QString value = QString::fromLatin1("$LastModule");
if (px.isNull())
AutoloadModuleCombo->addItem(key, QVariant(value));
else
AutoloadModuleCombo->addItem(px, key, QVariant(value));
}
for (QMap<QString, QString>::Iterator it = menuText.begin(); it != menuText.end(); ++it) {
QPixmap px = Gui::Application::Instance->workbenchIcon(it.value());
if (px.isNull())

View File

@@ -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"):