Gui: Add helper function Command::getActiveDocument() to get active App document

This commit is contained in:
wmayer
2025-05-05 15:55:45 +02:00
committed by Ladislav Michl
parent 439cb2122e
commit c6c356e389
2 changed files with 12 additions and 12 deletions

View File

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

View File

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