Gui: Add helper function Command::getActiveDocument() to get active App document
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user