From 1665dec4e451b42bde5cfda935a64d96a536afaa Mon Sep 17 00:00:00 2001 From: theo-vt Date: Thu, 5 Mar 2026 18:00:49 -0500 Subject: [PATCH] Adress review --- src/App/TransactionDefs.h | 24 ++++++++++++++++++++++++ src/Gui/Application.cpp | 11 +++++++---- src/Gui/Command.cpp | 3 ++- src/Gui/Document.cpp | 14 ++------------ src/Gui/Selection/Selection.cpp | 31 +++---------------------------- src/Gui/Selection/Selection.h | 14 -------------- 6 files changed, 38 insertions(+), 59 deletions(-) diff --git a/src/App/TransactionDefs.h b/src/App/TransactionDefs.h index 8883c0b033..8143a5236c 100644 --- a/src/App/TransactionDefs.h +++ b/src/App/TransactionDefs.h @@ -1,3 +1,27 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/*************************************************************************** + * Copyright (c) 2026 Théo Veilleux-Trinh * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + #ifndef APP_TRANSACTIONDEFS_H_ #define APP_TRANSACTIONDEFS_H_ diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 0fe22dd343..9a2f154941 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1524,11 +1524,14 @@ void Application::unsetEditDocument(Gui::Document* pcDocument) } void Application::unsetEditDocumentIf(const std::function& eval) { - for (auto editDoc : d->editDocuments) { - if (eval(editDoc)) { - unsetEditDocument(editDoc); + std::erase_if(d->editDocuments, [&](Gui::Document* doc) { + if (eval(doc)) { + doc->_resetEdit(); + return true; } - } + return false; + }); + updateActions(); } Gui::MDIView* Application::editViewOfNode(SoNode* node) const { diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 4e76a867c3..0ddb4b0637 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -735,7 +735,8 @@ void Command::resetTransactionID() } bool Command::hasPendingCommand() { - return App::GetApplication().getActiveDocument()->getBookedTransactionID() != 0; + App::Document* doc = App::GetApplication().getActiveDocument(); + return doc && doc->getBookedTransactionID() != App::NullTransaction; } bool Command::_blockCmd = false; diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index ae373f9003..143bf0ce9d 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -286,7 +286,8 @@ struct DocumentP { _editingObject = sobj; _editMode = ModNum; - _editViewProvider = svp; // Helps the viewprovider find the correct in editDocument + _editViewProvider = svp; // Used to resolve start editing (find the document in edit from + // within the viewprovider) _editViewProvider = svp->startEditing(ModNum); if (!_editViewProvider) { _editViewProviderParent = nullptr; @@ -1080,17 +1081,6 @@ void Document::slotDeletedObject(const App::DocumentObject& Obj) }); } - if (d->_editViewProvider == viewProvider || d->_editViewProviderParent == viewProvider) { - _resetEdit(); - } - else if (Application::Instance->editDocument()) { - auto editDoc = Application::Instance->editDocument(); - if (editDoc->d->_editViewProvider == viewProvider - || editDoc->d->_editViewProviderParent == viewProvider) { - Application::Instance->setEditDocument(nullptr); - } - } - handleChildren3D(viewProvider, true); if (viewProvider && viewProvider->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId())) { diff --git a/src/Gui/Selection/Selection.cpp b/src/Gui/Selection/Selection.cpp index 1293699820..061de9a4c9 100644 --- a/src/Gui/Selection/Selection.cpp +++ b/src/Gui/Selection/Selection.cpp @@ -62,34 +62,6 @@ using namespace Gui; using namespace std; namespace sp = std::placeholders; -// TODO-theo-vt remove! -SelectionGateFilterExternal::SelectionGateFilterExternal(const char* docName, const char* objName) -{ - if (docName) { - DocName = docName; - if (objName) { - ObjName = objName; - } - } -} - -bool SelectionGateFilterExternal::allow(App::Document* doc, App::DocumentObject* obj, const char*) -{ - if (!doc || !obj) { - return true; - } - if (!DocName.empty() && doc->getName() != DocName) { - notAllowedReason = "Cannot select external object"; - } - else if (!ObjName.empty() && ObjName == obj->getNameInDocument()) { - notAllowedReason = "Cannot select self"; - } - else { - return true; - } - return false; -} - ////////////////////////////////////////////////////////////////////////////////////////// SelectionObserver::SelectionObserver(bool attach, ResolveMode resolve) @@ -1871,6 +1843,9 @@ void SelectionSingleton::setVisible(VisibleState vis, const char* pDocName) void SelectionSingleton::setSelection(const char* pDocName, const std::vector& sel) { auto context = getSelectionContext(pDocName); + if (!context.info) { + return; + } if (!context.info->pickedList.empty()) { context.info->pickedList.clear(); diff --git a/src/Gui/Selection/Selection.h b/src/Gui/Selection/Selection.h index de6e981cb2..295f55053b 100644 --- a/src/Gui/Selection/Selection.h +++ b/src/Gui/Selection/Selection.h @@ -287,20 +287,6 @@ public: std::string notAllowedReason; }; -/** SelectionGateFilterExternal - * The selection gate disallows any external object - */ -class GuiExport SelectionGateFilterExternal: public SelectionGate -{ -public: - explicit SelectionGateFilterExternal(const char* docName, const char* objName = nullptr); - bool allow(App::Document*, App::DocumentObject*, const char*) override; - -private: - std::string DocName; - std::string ObjName; -}; - /** The Selection class * The selection singleton keeps track of the selection state of * the whole application. It gets messages from all entities which can