From c6c356e389f6e3fe7fbd9340fb8a219c152df402 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 5 May 2025 15:55:45 +0200 Subject: [PATCH] Gui: Add helper function Command::getActiveDocument() to get active App document --- src/Gui/Command.cpp | 22 ++++++++++------------ src/Gui/Command.h | 2 ++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index c7a830945c..a3ddb24cd8 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -294,6 +294,12 @@ Application *Command::getGuiApplication() return Application::Instance; } +App::Document* Command::getActiveDocument() const +{ + Gui::Document* doc = getActiveGuiDocument(); + return doc ? doc->getDocument() : nullptr; +} + Gui::Document* Command::getActiveGuiDocument() const { return getGuiApplication()->activeDocument(); @@ -304,22 +310,14 @@ App::Document* Command::getDocument(const char* Name) const if (Name) { return App::GetApplication().getDocument(Name); } - else { - Gui::Document * pcDoc = getGuiApplication()->activeDocument(); - if (pcDoc) - return pcDoc->getDocument(); - else - return nullptr; - } + + return getActiveDocument(); } App::DocumentObject* Command::getObject(const char* Name) const { - App::Document*pDoc = getDocument(); - if (pDoc) - return pDoc->getObject(Name); - else - return nullptr; + App::Document* pDoc = getDocument(); + return pDoc ? pDoc->getObject(Name) : nullptr; } int Command::_busy; diff --git a/src/Gui/Command.h b/src/Gui/Command.h index db158d0596..ca644a9fba 100644 --- a/src/Gui/Command.h +++ b/src/Gui/Command.h @@ -379,6 +379,8 @@ public: static Application* getGuiApplication(); /// Get a reference to the selection static Gui::SelectionSingleton& getSelection(); + /// Get pointer to the active app document + App::Document* getActiveDocument() const; /// Get pointer to the active gui document Gui::Document* getActiveGuiDocument() const; /** Get pointer to the named or active App document