QtNovelUI/WordsIDE/DocsManager.h

197 lines
5.3 KiB
C++

#ifndef DOCSMANAGER_H
#define DOCSMANAGER_H
#include "ContentPresent.h"
#include <QHash>
#include <QObject>
#include <StoryTool.h>
namespace MakeTools {
class CompileFeature : public QObject
{
Q_OBJECT
public:
explicit CompileFeature(QObject *parent = nullptr);
virtual ~CompileFeature() = default;
/**
* @brief 获取字符串表示的内容
* @return
*/
virtual QString getText() const = 0;
signals:
/**
* @brief 内容变化
* @param filePath
*/
void dataChanged(const QString &filePath);
};
/**
* @brief 内容编辑和呈现接口
*/
class ContentPresent
{
public:
virtual ~ContentPresent() = default;
enum class Feature{
HighLight = 0x01,
Compile = 0x02,
};
Q_DECLARE_FLAGS(Features, Feature)
virtual Features features() = 0;
/**
* @brief 适配的文件后缀
* @return
*/
virtual QList<QString> suffixes() const = 0;
/**
* @brief 创建新的空文件,允许实际路径名和传入的文件名相对
* @param target
* @param name
* @param suffix
* @return 成功或失败,目标文件相对路径
*/
virtual std::tuple<bool, QString> create(const QDir& target,
const QString &name,
const QString &suffix) = 0;
/**
* @brief 生成一个新实例
* @return
*/
virtual ContentPresent* newInst() const = 0;
/**
* @brief 获取新实例内的widget
* @return
*/
virtual QWidget* widget() const = 0;
/**
* @brief 载入设置和命名
* @param core
* @param name
*/
virtual void applySetting(const QString &name, Core::AppCore *core = nullptr) = 0;
/**
* @brief 获取实例的别名
* @return
*/
virtual QString name() const = 0;
/**
* @brief 使用此实例打开指定的路径文件,冲刷掉所有状态
* @param target_file 指定文件的info
*/
virtual void load(const QFileInfo &target_file) = 0;
/**
* @brief 保存内容到指定路径,默认保存到打开路径
* @param path 指定另存为路径
*/
virtual void saveAs(const QString &path = QString()) = 0;
/**
* @brief 如果完成内容载入,返回相对路径,反之,返回空字符串
* @return
*/
virtual QString relativeTargetPath(const QDir &base) const = 0;
/**
* @brief 完成载入返回绝对路径,反之,返回空字符串
* @return
*/
virtual QString absoluteTargetPath() const = 0;
/**
* @brief 是否处于修改状态
* @return
*/
virtual bool isModified() const = 0;
/**
* @brief 跳转到指定的路径
* @param path
*/
virtual void jumpTo(const QList<QString> &path) = 0;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ContentPresent::Features);
enum class SensitiveType
{
DoNothing,
CompileAtChanged
};
/**
* @brief 自动编译管理框架
*/
// class DocsManager : public QObject
// {
// Q_OBJECT
// public:
// /**
// * @brief 内容自动构建和管理核心
// * @param tool
// */
// DocsManager(StoryTool *tool, Core::AppCore *host, MainWindow *views);
// /**
// * @brief 保存当前所有文档内容
// */
// void saveAll() const;
// void closeAll();
// /**
// * @brief 文档打开状态查询
// * @param target
// * @return
// */
// bool activedContains(const QFileInfo &target) const;
// /**
// * @brief 获取文档内存实例
// * @param child_view
// * @return
// */
// ContentPresent *queryTextComponent(const QWidget *child_view) const;
// /**
// * @brief 获取文档内存实例
// * @param target
// * @return
// */
// ContentPresent *queryTextComponent(const QFileInfo &target) const;
// /**
// * @brief 关闭文档内存实例,关闭之前保存内容
// * @param target
// */
// void closeTextComponent(const QFileInfo &target);
// /**
// * @brief 打开指定路径的文档
// * @param src
// * @param name
// */
// void openTextDocument(const QString &src, const QString &name);
// void addPerceptionList(ContentPresent *ins, SensitiveType type = SensitiveType::CompileAtChanged);
// void addProcTrigger(std::function<void()> exc);
// private:
// Core::AppCore *const host_core;
// MainWindow *const views_holder;
// StoryTool *const make_core;
// QHash<QString, ContentPresent*> sourcecode_map;
// QHash<QString, ContentPresent*> plaintext_map;
// QList<std::function<void()>> trigger_list;
// void recompile(const QString &file_path, const QString &doc_name);
// };
}
#endif // DOCSMANAGER_H