16 std::shared_ptr<core::ports::storage::IRegistry> registry)
17 : registry_(std::move(registry)) {
21 atomicSave_ = std::move(saveFn);
25 atomicLoad_ = std::move(loadFn);
29 onDeletionImpact_ = std::move(cb);
34 return registry_->getLatest();
40void StorageManager::rememberLatestPath(
const std::string& filePath) {
42 registry_->setLatest(filePath);
47 const std::string previousPath = currentPath_;
48 currentPath_ = filePath;
52 throw std::runtime_error(
"Atomic store load callback not configured");
56 rememberLatestPath(filePath);
59 currentPath_ = previousPath;
65 if (currentPath_.empty()) {
66 throw std::runtime_error(
"No file opened");
69 saveAs(currentPath_, document);
73 const std::string previousPath = currentPath_;
74 currentPath_ = filePath;
78 throw std::runtime_error(
"Atomic store save callback not configured");
82 rememberLatestPath(filePath);
83 if (onDeletionImpact_ && !impact.
empty()) {
84 onDeletionImpact_(impact);
87 currentPath_ = previousPath;
93 std::filesystem::path p(filePath);
94 auto dir = p.parent_path();
95 if (!dir.empty() && !std::filesystem::exists(dir)) {
96 std::filesystem::create_directories(dir);
98 currentPath_ = filePath;
101 (void)atomicLoad_(currentPath_);
104 rememberLatestPath(filePath);
Storage manager: repository factory, atomic save/load and registry handling.
void setAtomicStoreSave(AtomicStoreSave saveFn) override
Configure the atomic save callback.
core::ports::storage::IStorageManager::AtomicStoreLoad AtomicStoreLoad
void save(const core::application::workspace::WorkspaceSessionState &document) override
Save the current application state.
void setDeletionImpactCallback(DeletionImpactCallback cb) override
Configure the deletion impact callback.
void saveAs(const std::string &filePath, const core::application::workspace::WorkspaceSessionState &document) override
Save the current application state to a specific file path.
core::ports::storage::IStorageManager::DeletionImpactCallback DeletionImpactCallback
void createNew(const std::string &filePath) override
Create a new storage target.
std::optional< std::string > loadLatestPath() const override
Load the latest known path.
core::ports::storage::IStorageManager::AtomicStoreSave AtomicStoreSave
core::application::workspace::WorkspaceSessionState loadFrom(const std::string &filePath) override
Load an application state from a file path.
StorageManager(std::shared_ptr< core::ports::storage::IRegistry > registry=nullptr)
Creates a storage manager with an optional latest-path registry backend.
void setAtomicStoreLoad(AtomicStoreLoad loadFn) override
Configure the atomic load callback.
Collects common core includes and aliases for precompiled-header builds.
Lists entity identifiers removed by cascading workspace operations.
bool empty() const noexcept
Reports whether no identifiers were deleted.