diff -r 37f936073cac -r e1ced2523cad src/documentmanager.h --- a/src/documentmanager.h Sun Oct 24 11:33:32 2021 +0300 +++ b/src/documentmanager.h Tue Nov 02 15:43:57 2021 +0200 @@ -26,34 +26,52 @@ public: enum OpenType { + /** + * Document was opened manually by the user + */ ManuallyOpened, + /** + * Document was opened automatically in order to resolve subfile references + */ AutomaticallyOpened, }; DocumentManager(QObject* parent = nullptr); - QString newModel(); - Model* findModelByName(const QString& name); - QString openModel(const QString& path, QTextStream& errorStream, const OpenType openType); + ModelId newModel(); + Model* findDependencyByName(const ModelId modelId, const QString& name); + Model* getModelById(ModelId modelId); + std::optional openModel(const QString& path, QTextStream& errorStream, const OpenType openType); QString makeNewModelName(); - void loadDependenciesForModel(const QString& modelName, + void loadDependenciesForAllModels(const LibraryManager &libraries, QTextStream &errorStream); + void loadDependenciesForModel(const ModelId modelId, const QString& path, const LibraryManager& libraries, QTextStream& errorStream); - void closeDocument(const QString& name); + void closeDocument(const ModelId modelId); + const QString* modelPath(ModelId modelId) const; + void setModelPath( + const ModelId modelId, + const QString& newPath, + const LibraryManager &libraries, + QTextStream &errorStream); + bool saveModel(const ModelId modelId, QTextStream& errors); + std::optional findIdForModel(const Model* model) const; private: - void collectReferences(QSet &referenced, const QString& name, const Model* model); struct ModelInfo { std::unique_ptr model; + QString path; OpenType opentype; + std::map dependencies = {}; }; + struct LoadDepedenciesBag; + int modelIdCounter = 0; int untitledNameCounter = 0; - std::map openModels; - void loadDependenciesForModel(const QString& modelName, - const QString& path, - const LibraryManager& libraries, - QStringList& missing, - QStringList& processed, - QTextStream& errorStream); + std::map openModels; + void loadDependenciesForModel(const ModelId modelId, const QString& path, LoadDepedenciesBag& bag); + void collectReferences(QSet &referenced, const QString& name, const Model* model); + void updateDependencies(ModelInfo* model); + void prune(); + bool isReferencedByAnything(const ModelId modelId) const; }; QString pathToName(const QFileInfo& path);