Files
create/src/Gui/OriginManager.h
forbes 87a0af0b0f phase 1: copy Kindred-only files onto upstream/main (FreeCAD 1.2.0-dev)
Wholesale copy of all Kindred Create additions that don't conflict with
upstream FreeCAD code:

- kindred-icons/ (1444 Catppuccin Mocha SVG icon overrides)
- src/Mod/Create/ (Kindred Create workbench)
- src/Gui/ Kindred source files (FileOrigin, OriginManager,
  OriginSelectorWidget, CommandOrigin, BreadcrumbToolBar, EditingContext)
- src/Gui/Icons/ (Kindred branding and silo icons)
- src/Gui/PreferencePacks/KindredCreate/
- src/Gui/Stylesheets/ (KindredCreate.qss, images_dark-light/)
- package/ (rattler-build recipe)
- docs/ (architecture, guides, specifications)
- .gitea/ (CI workflows, issue templates)
- mods/silo, mods/ztools submodules
- .gitmodules (Kindred submodule URLs)
- resources/ (kindred-create.desktop, kindred-create.xml)
- banner-logo-light.png, CONTRIBUTING.md
2026-02-13 14:03:58 -06:00

185 lines
6.0 KiB
C++

/***************************************************************************
* Copyright (c) 2025 Kindred Systems *
* *
* 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 GUI_ORIGINMANAGER_H
#define GUI_ORIGINMANAGER_H
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <FCGlobal.h>
#include <fastsignals/signal.h>
namespace App {
class Document;
}
namespace Gui {
class FileOrigin;
/**
* @brief Singleton manager for document origins
*
* OriginManager tracks all registered FileOrigin instances and maintains
* the current origin selection. It provides lookup methods and signals
* for UI updates.
*
* The manager always has at least one origin: the local filesystem origin,
* which is created automatically on initialization.
*/
class GuiExport OriginManager
{
public:
/** Get the singleton instance */
static OriginManager* instance();
/** Destroy the singleton instance */
static void destruct();
///@name Origin Registration
//@{
/**
* Register an origin with the manager.
* The manager takes ownership of the origin.
* @param origin The origin to register
* @return true if successfully registered (ID not already in use)
*/
bool registerOrigin(FileOrigin* origin);
/**
* Unregister and delete an origin.
* Cannot unregister the built-in "local" origin.
* @param id The origin ID to unregister
* @return true if successfully unregistered
*/
bool unregisterOrigin(const std::string& id);
/**
* Get all registered origin IDs.
* @return Vector of origin ID strings
*/
std::vector<std::string> originIds() const;
/**
* Get origin by ID.
* @param id The origin ID
* @return The origin or nullptr if not found
*/
FileOrigin* getOrigin(const std::string& id) const;
//@}
///@name Current Origin Selection
//@{
/**
* Get the currently selected origin.
* @return The current origin (never nullptr)
*/
FileOrigin* currentOrigin() const;
/**
* Get the current origin ID.
* @return The current origin's ID
*/
std::string currentOriginId() const;
/**
* Set the current origin by ID.
* @param id The origin ID to select
* @return true if origin was found and selected
*/
bool setCurrentOrigin(const std::string& id);
//@}
///@name Document Origin Resolution
//@{
/**
* Find which origin owns a document.
* Iterates through all origins to find one that claims ownership
* based on document properties.
* @param doc The document to check
* @return The owning origin or nullptr if unowned
*/
FileOrigin* findOwningOrigin(App::Document* doc) const;
/**
* Get the origin associated with a document.
* First checks explicit association, then uses findOwningOrigin().
* @param doc The document to check
* @return The document's origin or nullptr if unknown
*/
FileOrigin* originForDocument(App::Document* doc) const;
/**
* Associate a document with an origin.
* @param doc The document
* @param origin The origin to associate (nullptr to clear)
*/
void setDocumentOrigin(App::Document* doc, FileOrigin* origin);
/**
* Clear document origin association (called when document closes).
* @param doc The document being closed
*/
void clearDocumentOrigin(App::Document* doc);
/**
* Get the appropriate origin for a new document.
* Returns the current origin.
* @return The origin to use for new documents
*/
FileOrigin* originForNewDocument() const;
//@}
///@name Signals
//@{
/** Emitted when an origin is registered */
fastsignals::signal<void(const std::string&)> signalOriginRegistered;
/** Emitted when an origin is unregistered */
fastsignals::signal<void(const std::string&)> signalOriginUnregistered;
/** Emitted when current origin changes */
fastsignals::signal<void(const std::string&)> signalCurrentOriginChanged;
/** Emitted when a document's origin association changes */
fastsignals::signal<void(App::Document*, const std::string&)> signalDocumentOriginChanged;
//@}
protected:
OriginManager();
~OriginManager();
private:
void loadPreferences();
void savePreferences();
void ensureLocalOrigin();
static OriginManager* _instance;
std::map<std::string, std::unique_ptr<FileOrigin>> _origins;
std::string _currentOriginId;
// Document-to-origin associations (doc -> origin ID)
mutable std::map<App::Document*, std::string> _documentOrigins;
};
} // namespace Gui
#endif // GUI_ORIGINMANAGER_H