201 lines
5.7 KiB
C++
201 lines
5.7 KiB
C++
#ifndef MANAGER_DOCS_H
|
||
#define MANAGER_DOCS_H
|
||
|
||
#include "DocsManager.h"
|
||
#include "route.h"
|
||
|
||
#include <QList>
|
||
#include <QTreeView>
|
||
#include <QWidget>
|
||
#include <commandsdispatcher.h>
|
||
#include <libProjectManager.h>
|
||
|
||
namespace Presents {
|
||
|
||
class PresentHost {
|
||
public:
|
||
virtual ~PresentHost() = default;
|
||
|
||
/**
|
||
* @brief 承载内容的Widget
|
||
* @return
|
||
*/
|
||
virtual QWidget *hostWidget() const = 0;
|
||
|
||
/**
|
||
* @brief 是否可以放置此视图
|
||
* @param vins
|
||
* @return
|
||
*/
|
||
virtual bool avaliable(Presents::FilePresent *vins) = 0;
|
||
|
||
/**
|
||
* @brief 添加内容展示实例
|
||
* @param ins
|
||
*/
|
||
virtual void append(Presents::FilePresent *ins) = 0;
|
||
/**
|
||
* @brief 激活内容展示实例
|
||
* @param ins
|
||
*/
|
||
virtual bool active(const Presents::FilePresent *ins) = 0;
|
||
/**
|
||
* @brief 移除内容展示实例
|
||
* @param ins
|
||
*/
|
||
virtual void remove(const Presents::FilePresent *ins) = 0;
|
||
/**
|
||
* @brief 是否包含指定
|
||
* @param ins
|
||
* @return
|
||
*/
|
||
virtual bool contains(const Presents::FilePresent *ins) const = 0;
|
||
};
|
||
|
||
} // namespace Presents
|
||
class XApp;
|
||
namespace Core {
|
||
|
||
/**
|
||
* @brief 文档管理器,根据项目配置文件,打开、查询、关闭文档实例
|
||
*/
|
||
class DocumentsManager : public Schedule::AccessibleObject {
|
||
public:
|
||
DocumentsManager(XApp *host);
|
||
virtual ~DocumentsManager() = default;
|
||
|
||
/**
|
||
* @brief 设置文档呈现窗口
|
||
* @param container
|
||
*/
|
||
void appendPresent(Presents::PresentHost *container);
|
||
void removePresent(Presents::PresentHost *container);
|
||
|
||
/**
|
||
* @brief 项目获取管理器
|
||
* @return 项目管理器实例
|
||
*/
|
||
Project::ProjectManager *projectManager() const;
|
||
|
||
/**
|
||
* @brief 初始化内容视图插件
|
||
*/
|
||
void initContentViewPlugins();
|
||
void loadViewConfigWidgets(QTabWidget *stacked);
|
||
|
||
// ==========================================================
|
||
/**
|
||
* @brief 注册插件类型
|
||
* @param ins 插件工厂实例
|
||
*/
|
||
template <class PresentType> void registPresentType(Presents::TypedPresentFactory<PresentType> *ins) {
|
||
auto suffix = Presents::TypedPresentFactory<PresentType>::suffix();
|
||
factory_map[suffix] = ins;
|
||
}
|
||
|
||
// ==========================================================
|
||
|
||
/**
|
||
* @brief 获取支持的文件类型
|
||
* @return {txt, storyboard, ……}
|
||
*/
|
||
QList<QString> fileTypes() const;
|
||
|
||
/**
|
||
* @brief 提供完整路径创建新包
|
||
* @param link 包路径
|
||
* @throw SimpleException
|
||
*/
|
||
void createPackage(const Core::Route &link);
|
||
|
||
/**
|
||
* @brief 在指定的包节点下,创建指定类型的新文件
|
||
* @param group_path 包路径
|
||
* @param name 节点名称
|
||
* @param suffix 通过后缀名,指定文件类型
|
||
* @throw SimpleException
|
||
*/
|
||
void createFile(const Core::Route &group_path, const QString &name, const QString &suffix);
|
||
|
||
/**
|
||
* @brief 修改指定节点的名称
|
||
* @param node_path 节点路径
|
||
* @param name 新名称
|
||
* @throw SimpleException
|
||
*/
|
||
void renameNode(const Core::Route &node_path, const QString &name);
|
||
|
||
/**
|
||
* @brief 移除指定节点(必须非根节点)
|
||
* @param node_path 文件节点或者包节点
|
||
* @throw SimpleException
|
||
*/
|
||
void deleteNode(const Core::Route &node_path);
|
||
|
||
/**
|
||
* @brief 打开文件节点
|
||
* @param path_node
|
||
* @throw SimpleException
|
||
*/
|
||
void openFile(const QList<Core::Route> &doc_paths);
|
||
|
||
/**
|
||
* @brief 关闭定制的文档节点集合
|
||
* @param doc_paths 关闭指定路径下的打开的文档
|
||
*/
|
||
void closeFile(const QList<Core::Route> &doc_paths = QList<Core::Route>());
|
||
|
||
/**
|
||
* @brief 转换路径和索引
|
||
* @param path
|
||
* @return
|
||
*/
|
||
QModelIndex convertPath(const Core::Route &path);
|
||
/**
|
||
* @brief 转换路径和索引
|
||
* @param path
|
||
* @return
|
||
*/
|
||
Core::Route convertPath(const QModelIndex &index);
|
||
/**
|
||
* @brief 获取打开的内容展示实例路径
|
||
* @param ins 打开的实例
|
||
* @return 实例路径
|
||
*/
|
||
Core::Route convertPresent(Presents::FilePresent *ins) const;
|
||
/**
|
||
* @brief 获取打开的内容展示实例,如果指向未打开的节点或无效文件节点,返回null
|
||
* @param node_path 节点路径
|
||
* @return null或打开的展示实例
|
||
*/
|
||
Presents::FilePresent *convertPresent(const Core::Route &node_path);
|
||
|
||
/**
|
||
* @brief 获取打开的活跃文档
|
||
* @return
|
||
*/
|
||
QList<Core::Route> actives() const;
|
||
|
||
void active(const Core::Route &node_path);
|
||
|
||
/**
|
||
* @brief 保存指定的文档节点集合
|
||
* @param docs
|
||
*/
|
||
void save();
|
||
|
||
// AccessibleObject interface
|
||
public:
|
||
virtual QString name() const override;
|
||
|
||
private:
|
||
XApp *const core_inst;
|
||
QList<Presents::PresentHost *> present_ui;
|
||
|
||
QHash<QString, Presents::PresentFactory *> factory_map;
|
||
QHash<Core::Route, Presents::FilePresent *> doc_openning;
|
||
};
|
||
} // namespace Core
|
||
|
||
#endif // MANAGER_DOCS_H
|