diff --git a/src/Gui/FileOriginPython.cpp b/src/Gui/FileOriginPython.cpp index b5e7c2719d..1011dfeb6c 100644 --- a/src/Gui/FileOriginPython.cpp +++ b/src/Gui/FileOriginPython.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -41,7 +42,7 @@ void FileOriginPython::addOrigin(const Py::Object& obj) { // Check if already registered if (findOrigin(obj)) { - Base::Console().Warning("FileOriginPython: Origin already registered\n"); + Base::Console().warning("FileOriginPython: Origin already registered\n"); return; } @@ -50,7 +51,7 @@ void FileOriginPython::addOrigin(const Py::Object& obj) // Cache the ID immediately for registration origin->_cachedId = origin->callStringMethod("id"); if (origin->_cachedId.empty()) { - Base::Console().Error("FileOriginPython: Origin must have non-empty id()\n"); + Base::Console().error("FileOriginPython: Origin must have non-empty id()\n"); delete origin; return; } @@ -117,7 +118,7 @@ Py::Object FileOriginPython::callMethod(const char* method, const Py::Tuple& arg } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return Py::None(); } @@ -139,7 +140,7 @@ bool FileOriginPython::callBoolMethod(const char* method, bool defaultValue) con } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return defaultValue; } @@ -158,7 +159,7 @@ std::string FileOriginPython::callStringMethod(const char* method, const std::st } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return defaultValue; } @@ -210,7 +211,7 @@ OriginType FileOriginPython::type() const } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return OriginType::Custom; } @@ -265,7 +266,7 @@ ConnectionState FileOriginPython::connectionState() const } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return ConnectionState::Connected; } @@ -297,7 +298,7 @@ std::string FileOriginPython::documentIdentity(App::Document* doc) const } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return {}; } @@ -318,7 +319,7 @@ std::string FileOriginPython::documentDisplayId(App::Document* doc) const } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return documentIdentity(doc); } @@ -342,7 +343,7 @@ bool FileOriginPython::ownsDocument(App::Document* doc) const } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return false; } @@ -366,7 +367,7 @@ bool FileOriginPython::syncProperties(App::Document* doc) } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return true; } @@ -391,7 +392,7 @@ App::Document* FileOriginPython::newDocument(const std::string& name) } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return nullptr; } @@ -414,7 +415,7 @@ App::Document* FileOriginPython::openDocument(const std::string& identity) } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return nullptr; } @@ -438,7 +439,7 @@ bool FileOriginPython::saveDocument(App::Document* doc) } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return false; } @@ -463,7 +464,7 @@ bool FileOriginPython::saveDocumentAs(App::Document* doc, const std::string& new } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return false; } @@ -488,7 +489,7 @@ bool FileOriginPython::commitDocument(App::Document* doc) } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return false; } @@ -512,7 +513,7 @@ bool FileOriginPython::pullDocument(App::Document* doc) } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return false; } @@ -536,7 +537,7 @@ bool FileOriginPython::pushDocument(App::Document* doc) } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } return false; } @@ -554,7 +555,7 @@ void FileOriginPython::showInfo(App::Document* doc) } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } } @@ -571,8 +572,53 @@ void FileOriginPython::showBOM(App::Document* doc) } catch (Py::Exception&) { Base::PyException e; - e.ReportException(); + e.reportException(); } } +App::Document* FileOriginPython::openDocumentInteractive() +{ + Base::PyGILStateLocker lock; + try { + if (_inst.hasAttr("openDocumentInteractive")) { + Py::Callable func(_inst.getAttr("openDocumentInteractive")); + Py::Object result = func.apply(Py::Tuple()); + if (!result.isNone()) { + if (PyObject_TypeCheck(result.ptr(), &(App::DocumentPy::Type))) { + return static_cast(result.ptr())->getDocumentPtr(); + } + } + } + } + catch (Py::Exception&) { + Base::PyException e; + e.reportException(); + } + return nullptr; +} + +bool FileOriginPython::saveDocumentAsInteractive(App::Document* doc) +{ + Base::PyGILStateLocker lock; + try { + if (_inst.hasAttr("saveDocumentAsInteractive")) { + Py::Callable func(_inst.getAttr("saveDocumentAsInteractive")); + Py::Tuple args(1); + args.setItem(0, getDocPyObject(doc)); + Py::Object result = func.apply(args); + if (result.isBoolean()) { + return Py::Boolean(result); + } + if (result.isNumeric()) { + return Py::Long(result) != 0; + } + } + } + catch (Py::Exception&) { + Base::PyException e; + e.reportException(); + } + return false; +} + } // namespace Gui diff --git a/src/Gui/FileOriginPython.h b/src/Gui/FileOriginPython.h index 1348e9022d..f3ca11cd65 100644 --- a/src/Gui/FileOriginPython.h +++ b/src/Gui/FileOriginPython.h @@ -115,8 +115,10 @@ public: App::Document* newDocument(const std::string& name = "") override; App::Document* openDocument(const std::string& identity) override; + App::Document* openDocumentInteractive() override; bool saveDocument(App::Document* doc) override; bool saveDocumentAs(App::Document* doc, const std::string& newIdentity) override; + bool saveDocumentAsInteractive(App::Document* doc) override; bool commitDocument(App::Document* doc) override; bool pullDocument(App::Document* doc) override; diff --git a/src/Gui/OriginManager.cpp b/src/Gui/OriginManager.cpp index 28add9234b..2f40bb8126 100644 --- a/src/Gui/OriginManager.cpp +++ b/src/Gui/OriginManager.cpp @@ -111,14 +111,14 @@ bool OriginManager::registerOrigin(FileOrigin* origin) std::string originId = origin->id(); if (originId.empty()) { - Base::Console().Warning("OriginManager: Cannot register origin with empty ID\n"); + Base::Console().warning("OriginManager: Cannot register origin with empty ID\n"); delete origin; return false; } // Check if ID already in use if (_origins.find(originId) != _origins.end()) { - Base::Console().Warning("OriginManager: Origin '%s' already registered\n", originId.c_str()); + Base::Console().warning("OriginManager: Origin '%s' already registered\n", originId.c_str()); delete origin; return false; } @@ -134,7 +134,7 @@ bool OriginManager::unregisterOrigin(const std::string& id) { // Cannot unregister the built-in local origin if (id == LOCAL_ORIGIN_ID) { - Base::Console().Warning("OriginManager: Cannot unregister built-in local origin\n"); + Base::Console().warning("OriginManager: Cannot unregister built-in local origin\n"); return false; }