From f5baef888c25937026ee50001a4fe4293a9f11ee Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 18 Mar 2024 21:17:18 +0100 Subject: [PATCH] Gui: fix several regressions caused by PR #12035 * fix hard crash in MainWindow::_updateActions() if no MDI view exists * in MDIView::buildWindowTitle() use the label of the document because this changes when saving it while the name is immutable * fix const correctness in MDIView::buildWindowTitle() * do not set the modified flag of the main window in MDIView::buildWindowTitle() but in the calling instance * move setting the main window title to Application::viewActivated to reduce code duplication * fix missing application name if FreeCADGui is loaded as Python module --- src/Gui/Application.cpp | 4 ++++ src/Gui/MDIView.cpp | 11 ++--------- src/Gui/MDIView.h | 2 +- src/Gui/MainWindow.cpp | 19 +++++++++++++------ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index a6a2fadd58..4b033b6262 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1260,6 +1260,10 @@ void Application::viewActivated(MDIView* pcView) #endif signalActivateView(pcView); + getMainWindow()->setWindowTitle(pcView->buildWindowTitle()); + if (auto document = pcView->getGuiDocument()) { + getMainWindow()->setWindowModified(document->isModified()); + } // Set the new active document which is taken of the activated view. If, however, // this view is passive we let the currently active document unchanged as we would diff --git a/src/Gui/MDIView.cpp b/src/Gui/MDIView.cpp index 492b219828..2d69285f9c 100644 --- a/src/Gui/MDIView.cpp +++ b/src/Gui/MDIView.cpp @@ -448,18 +448,11 @@ void MDIView::setCurrentViewMode(ViewMode mode) } } -QString MDIView::buildWindowTitle() +QString MDIView::buildWindowTitle() const { QString windowTitle; if (Gui::Document* document = getGuiDocument()) { - if (document->isModified()) { - getMainWindow()->setWindowModified(TRUE); - } - else { - getMainWindow()->setWindowModified(FALSE); - } - - windowTitle.append(QString::fromUtf8(getAppDocument()->getName())); + windowTitle.append(QString::fromStdString(getAppDocument()->Label.getStrValue())); } return windowTitle; diff --git a/src/Gui/MDIView.h b/src/Gui/MDIView.h index a190540b7f..b0002c65c8 100644 --- a/src/Gui/MDIView.h +++ b/src/Gui/MDIView.h @@ -75,7 +75,7 @@ public: virtual void viewAll(); /// build window title - QString buildWindowTitle(); + QString buildWindowTitle() const; /// Message handler bool onMsg(const char* pMsg,const char** ppReturn) override; diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index b56d7bf065..fad007742f 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -1268,9 +1268,8 @@ void MainWindow::removeWindow(Gui::MDIView* view, bool close) void MainWindow::tabChanged(MDIView* view) { - Q_UNUSED(view); + Q_UNUSED(view) updateActions(); - getMainWindow()->setWindowTitle(view->buildWindowTitle()); } void MainWindow::tabCloseRequested(int index) @@ -1665,8 +1664,15 @@ void MainWindow::_updateActions() d->activityTimer->stop(); Application::Instance->commandManager().testActive(); } + d->actionUpdateDelay = 0; - getMainWindow()->setWindowTitle(activeWindow()->buildWindowTitle()); + + if (auto view = activeWindow()) { + setWindowTitle(view->buildWindowTitle()); + if (auto document = view->getGuiDocument()) { + setWindowModified(document->isModified()); + } + } } void MainWindow::updateEditorActions() @@ -2370,7 +2376,6 @@ void MainWindow::changeEvent(QEvent *e) d->activeView = view; Application::Instance->viewActivated(view); } - getMainWindow()->setWindowTitle(view->buildWindowTitle()); } } } @@ -2515,8 +2520,10 @@ QMdiArea *MainWindow::getMdiArea() const void MainWindow::setWindowTitle(const QString& string) { QString title; - QString appname = - QString(static_cast(QCoreApplication::instance())->applicationName()); + QString appname = QCoreApplication::applicationName(); + if (appname.isEmpty()) { + appname = QString::fromLatin1(App::Application::Config()["ExeName"].c_str()); + } // allow to disable version number ParameterGrp::handle hGen = +App::GetApplication().GetParameterGroupByPath(