// SPDX-License-Identifier: LGPL-2.1-or-later /*************************************************************************** * Copyright (c) 2025 Kindred Systems * * * * This file is part of Kindred Create. * * * * 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 GUI_EDITINGCONTEXT_H #define GUI_EDITINGCONTEXT_H #include #include #include #include #include namespace Gui { class Document; class MDIView; class ViewProviderDocumentObject; /// Snapshot of the resolved editing context. struct GuiExport EditingContext { QString id; // e.g. "sketcher.edit", "partdesign.body" QString label; // e.g. "Sketcher: Sketch001" QString color; // Catppuccin Mocha hex, e.g. "#a6e3a1" QStringList toolbars; // toolbar names to ForceAvailable QStringList breadcrumb; // e.g. ["Body", "Sketch001", "[editing]"] QStringList breadcrumbColors; // per-segment color hex values }; /// Definition used when registering a context. struct GuiExport ContextDefinition { QString id; QString labelTemplate; // supports {name} placeholder QString color; QStringList toolbars; int priority = 0; // higher = checked first during resolve /// Return true if this context matches the current application state. std::function match; }; /// Definition for an overlay context (additive, not exclusive). struct GuiExport OverlayDefinition { QString id; QStringList toolbars; /// Return true if the overlay should be active. std::function match; }; /** * Singleton that resolves the current editing context from application state * and drives toolbar visibility and the breadcrumb display. * * Built-in contexts (PartDesign, Sketcher, Assembly, Spreadsheet) are registered * at construction. Third-party modules register via registerContext() / * registerOverlay() from Python or C++. */ class GuiExport EditingContextResolver: public QObject { Q_OBJECT public: static EditingContextResolver* instance(); static void destruct(); void registerContext(const ContextDefinition& def); void unregisterContext(const QString& id); void registerOverlay(const OverlayDefinition& def); void unregisterOverlay(const QString& id); /// Inject additional commands into a context's toolbar. void injectCommands(const QString& contextId, const QString& toolbarName, const QStringList& commands); /// Force a re-resolve (e.g. after workbench switch). void refresh(); EditingContext currentContext() const; Q_SIGNALS: void contextChanged(const EditingContext& ctx); private: EditingContextResolver(); ~EditingContextResolver() override; EditingContext resolve() const; void applyContext(const EditingContext& ctx); QStringList buildBreadcrumb(const EditingContext& ctx) const; QStringList buildBreadcrumbColors(const EditingContext& ctx) const; // Signal handlers void onInEdit(const ViewProviderDocumentObject& vp); void onResetEdit(const ViewProviderDocumentObject& vp); void onActiveDocument(const Document& doc); void onActivateView(const MDIView* view); void registerBuiltinContexts(); struct Private; Private* d; static EditingContextResolver* _instance; }; } // namespace Gui #endif // GUI_EDITINGCONTEXT_H