2022-12-31 13:05:58 +00:00
|
|
|
|
#ifndef DOCSMANAGER_H
|
|
|
|
|
#define DOCSMANAGER_H
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
#include "ContentPresent.h"
|
|
|
|
|
|
2022-11-17 08:26:05 +00:00
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <StoryTool.h>
|
|
|
|
|
|
|
|
|
|
namespace MakeTools {
|
|
|
|
|
/**
|
|
|
|
|
* @brief 变化的文本视图
|
|
|
|
|
*/
|
2022-12-31 05:26:58 +00:00
|
|
|
|
class TextView : public QObject
|
2022-11-17 08:26:05 +00:00
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2022-12-31 05:26:58 +00:00
|
|
|
|
explicit TextView();
|
|
|
|
|
virtual ~TextView() = default;
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-11-29 03:47:12 +00:00
|
|
|
|
void initSource(Core::AppCore *core, const QFileInfo &src, const QString &name, QWidget *parent=nullptr);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-12-31 13:05:58 +00:00
|
|
|
|
QString absoluteFilePath() const;
|
2022-11-17 08:26:05 +00:00
|
|
|
|
void save() const;
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
virtual void jumpTo(const QList<QString> &path) = 0;
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-11-22 06:15:36 +00:00
|
|
|
|
virtual QString docName() const;
|
2022-11-22 03:42:48 +00:00
|
|
|
|
virtual QWidget* textView() const = 0;
|
|
|
|
|
virtual QString textContent() const = 0;
|
2022-11-17 08:26:05 +00:00
|
|
|
|
virtual void textContentReset(const QString &value) = 0;
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void dataChanged(const QString &filePath);
|
|
|
|
|
|
2022-11-22 06:15:36 +00:00
|
|
|
|
protected:
|
2022-11-29 03:47:12 +00:00
|
|
|
|
virtual void initSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent=nullptr);
|
2022-11-22 06:15:36 +00:00
|
|
|
|
|
2022-11-17 08:26:05 +00:00
|
|
|
|
private:
|
2022-11-29 03:47:12 +00:00
|
|
|
|
QString source_x;
|
2022-11-22 06:15:36 +00:00
|
|
|
|
QString doc_name;
|
2022-11-17 08:26:05 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class SensitiveType
|
|
|
|
|
{
|
|
|
|
|
DoNothing,
|
|
|
|
|
CompileAtChanged
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 自动编译管理框架
|
|
|
|
|
*/
|
2022-12-31 13:05:58 +00:00
|
|
|
|
class DocsManager : public QObject
|
2022-11-17 08:26:05 +00:00
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2022-12-31 05:40:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 内容自动构建和管理核心
|
|
|
|
|
* @param tool
|
|
|
|
|
*/
|
2022-12-31 13:05:58 +00:00
|
|
|
|
DocsManager(StoryTool *tool, Core::AppCore *host, MainWindow *views);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-12-31 05:40:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 保存当前所有文档内容
|
|
|
|
|
*/
|
2022-11-17 08:26:05 +00:00
|
|
|
|
void saveAll() const;
|
|
|
|
|
|
2022-12-31 13:05:58 +00:00
|
|
|
|
void closeAll();
|
|
|
|
|
|
2022-12-31 05:40:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 文档打开状态查询
|
|
|
|
|
* @param target
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-11-17 08:26:05 +00:00
|
|
|
|
bool contains(const QFileInfo &target) const;
|
2022-12-31 05:40:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 获取文档内存实例
|
|
|
|
|
* @param child_view
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-12-31 05:26:58 +00:00
|
|
|
|
TextView *queryTextComponent(const QWidget *child_view) const;
|
2022-12-31 05:40:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 获取文档内存实例
|
|
|
|
|
* @param target
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
2022-12-31 13:05:58 +00:00
|
|
|
|
TextView *queryTextComponent(const QFileInfo &target) const;
|
2022-12-31 05:40:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 关闭文档内存实例,关闭之前保存内容
|
|
|
|
|
* @param target
|
|
|
|
|
*/
|
2022-11-22 03:42:48 +00:00
|
|
|
|
void closeTextComponent(const QFileInfo &target);
|
2022-11-17 08:52:37 +00:00
|
|
|
|
|
2022-12-31 13:05:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 打开指定路径的文档
|
|
|
|
|
* @param src
|
|
|
|
|
* @param name
|
|
|
|
|
*/
|
|
|
|
|
void openTextDocument(const QString &src, const QString &name);
|
|
|
|
|
|
2022-12-31 05:26:58 +00:00
|
|
|
|
void addPerceptionList(TextView *ins, SensitiveType type = SensitiveType::CompileAtChanged);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
void addProcTrigger(std::function<void()> exc);
|
|
|
|
|
|
|
|
|
|
private:
|
2022-12-31 13:05:58 +00:00
|
|
|
|
Core::AppCore *const host_core;
|
|
|
|
|
MainWindow *const views_holder;
|
2022-11-17 08:26:05 +00:00
|
|
|
|
StoryTool *const make_core;
|
2022-12-31 05:26:58 +00:00
|
|
|
|
QHash<QString, TextView*> sourcecode_map;
|
|
|
|
|
QHash<QString, TextView*> plaintext_map;
|
2022-11-17 08:26:05 +00:00
|
|
|
|
QList<std::function<void()>> trigger_list;
|
|
|
|
|
|
2022-11-22 06:15:36 +00:00
|
|
|
|
void recompile(const QString &file_path, const QString &doc_name);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-31 13:05:58 +00:00
|
|
|
|
#endif // DOCSMANAGER_H
|