QtNovelUI/WordsIDE/DocsManager.h

117 lines
3.0 KiB
C
Raw Normal View History

2022-12-31 13:05:58 +00:00
#ifndef DOCSMANAGER_H
#define DOCSMANAGER_H
2022-11-17 08:26:05 +00:00
#include "ContentPresent.h"
2022-11-17 08:26:05 +00:00
#include <QHash>
#include <QObject>
#include <StoryTool.h>
namespace MakeTools {
/**
* @brief
*/
class TextView : public QObject
2022-11-17 08:26:05 +00:00
{
Q_OBJECT
public:
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;
virtual void jumpTo(const QList<QString> &path) = 0;
2022-11-17 08:26:05 +00:00
virtual QString docName() const;
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);
protected:
2022-11-29 03:47:12 +00:00
virtual void initSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent=nullptr);
2022-11-17 08:26:05 +00:00
private:
2022-11-29 03:47:12 +00:00
QString source_x;
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
*/
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
*/
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);
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;
QHash<QString, TextView*> sourcecode_map;
QHash<QString, TextView*> plaintext_map;
2022-11-17 08:26:05 +00:00
QList<std::function<void()>> trigger_list;
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