Start: Walks the parent tree to close the tab (#22572)

* Start: Walks the parent tree to close the tab

We're currently closing the entire app, it seems a mistake.
Instead, we should look up the widget tree to find the tab
(QMdiSubWindow) and close it instead.

The way I put if we don't find it we don't do anything.
Might be unexpected but at least harmless.

A side effect of this fix is a required drop of constness of
multiple helper methods that call postStart().

* Start: Minor code cleanup and PCH fix

---------

Co-authored-by: Carlos Nihelton <cn@ubuntu.com>
Co-authored-by: Chris Hennes <chennes@gmail.com>
This commit is contained in:
Carlos Nihelton
2025-08-05 21:38:30 -03:00
committed by GitHub
parent 164ecfebac
commit f2fadec102
3 changed files with 23 additions and 17 deletions

View File

@@ -57,6 +57,7 @@
#include <QImageReader>
#include <QLabel>
#include <QListView>
#include <QMdiSubWindow>
#include <QMessageBox>
#include <QModelIndex>
#include <QPainter>

View File

@@ -30,6 +30,7 @@
#include <QGridLayout>
#include <QLabel>
#include <QListView>
#include <QMdiSubWindow>
#include <QMessageBox>
#include <QPushButton>
#include <QScrollArea>
@@ -291,13 +292,13 @@ void StartView::configureCustomFolderListWidget(QListView* customFolderListWidge
}
void StartView::newEmptyFile() const
void StartView::newEmptyFile()
{
Gui::Application::Instance->commandManager().runCommandByName("Std_New");
postStart(PostStartBehavior::switchWorkbench);
}
void StartView::newPartDesignFile() const
void StartView::newPartDesignFile()
{
Gui::Application::Instance->commandManager().runCommandByName("Std_New");
Gui::Application::Instance->activateWorkbench("PartDesignWorkbench");
@@ -305,7 +306,7 @@ void StartView::newPartDesignFile() const
postStart(PostStartBehavior::doNotSwitchWorkbench);
}
void StartView::openExistingFile() const
void StartView::openExistingFile()
{
auto originalDocument = Gui::Application::Instance->activeDocument();
Gui::Application::Instance->commandManager().runCommandByName("Std_Open");
@@ -317,7 +318,7 @@ void StartView::openExistingFile() const
}
}
void StartView::newAssemblyFile() const
void StartView::newAssemblyFile()
{
Gui::Application::Instance->commandManager().runCommandByName("Std_New");
Gui::Application::Instance->activateWorkbench("AssemblyWorkbench");
@@ -326,7 +327,7 @@ void StartView::newAssemblyFile() const
postStart(PostStartBehavior::doNotSwitchWorkbench);
}
void StartView::newDraftFile() const
void StartView::newDraftFile()
{
Gui::Application::Instance->commandManager().runCommandByName("Std_New");
Gui::Application::Instance->activateWorkbench("DraftWorkbench");
@@ -334,7 +335,7 @@ void StartView::newDraftFile() const
postStart(PostStartBehavior::doNotSwitchWorkbench);
}
void StartView::newArchFile() const
void StartView::newArchFile()
{
Gui::Application::Instance->commandManager().runCommandByName("Std_New");
try {
@@ -360,7 +361,7 @@ bool StartView::onHasMsg(const char* pMsg) const
return MDIView::onHasMsg(pMsg);
}
void StartView::postStart(PostStartBehavior behavior) const
void StartView::postStart(PostStartBehavior behavior)
{
auto hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Start");
@@ -376,9 +377,13 @@ void StartView::postStart(PostStartBehavior behavior) const
Gui::Application::Instance->activateWorkbench(wb.c_str());
}
}
auto closeStart = hGrp->GetBool("closeStart", false);
if (closeStart) {
this->window()->close();
if (auto closeStart = hGrp->GetBool("closeStart", false)) {
for (QWidget* w = this; w != nullptr; w = w->parentWidget()) {
if (auto mdiSub = qobject_cast<QMdiSubWindow*>(w)) {
mdiSub->close();
return;
}
}
}
}

View File

@@ -64,12 +64,12 @@ public:
return "StartView";
}
void newEmptyFile() const;
void newPartDesignFile() const;
void openExistingFile() const;
void newAssemblyFile() const;
void newDraftFile() const;
void newArchFile() const;
void newEmptyFile();
void newPartDesignFile();
void openExistingFile();
void newAssemblyFile();
void newDraftFile();
void newArchFile();
bool onHasMsg(const char* pMsg) const override;
@@ -89,7 +89,7 @@ protected:
void configureExamplesListWidget(QListView* examplesListWidget);
void configureCustomFolderListWidget(QListView* customFolderListWidget);
void postStart(PostStartBehavior behavior) const;
void postStart(PostStartBehavior behavior);
void fileCardSelected(const QModelIndex& index);
void showOnStartupChanged(bool checked);