QtNovelUI/WordsIDE/DocsManager.h

183 lines
4.8 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 {
2023-02-26 14:44:00 +00:00
2022-11-17 08:26:05 +00:00
/**
2023-02-26 14:44:00 +00:00
* @brief
2022-11-17 08:26:05 +00:00
*/
2023-02-26 14:44:00 +00:00
class ContentPresent : public QObject
2022-11-17 08:26:05 +00:00
{
Q_OBJECT
public:
2023-02-26 14:44:00 +00:00
explicit ContentPresent(QObject *parent = nullptr);
virtual ~ContentPresent() = default;
/**
* @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;
2023-02-26 14:44:00 +00:00
/**
* @brief
* @return
*/
virtual QString absulateTargetPath() const = 0;
/**
* @brief
* @return
*/
virtual QString getText() const = 0;
2022-11-17 08:26:05 +00:00
2023-02-26 14:44:00 +00:00
/**
* @brief
* @return
*/
virtual bool isModified() const = 0;
2022-11-17 08:26:05 +00:00
2023-02-26 14:44:00 +00:00
/**
* @brief
* @param path
*/
virtual void jumpTo(const QList<QString> &path) = 0;
2022-11-17 08:26:05 +00:00
signals:
2023-02-26 14:44:00 +00:00
/**
* @brief
* @param filePath
*/
2022-11-17 08:26:05 +00:00
void dataChanged(const QString &filePath);
};
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
*/
2023-02-26 14:44:00 +00:00
bool activedContains(const QFileInfo &target) const;
2022-12-31 05:40:18 +00:00
/**
* @brief
* @param child_view
* @return
*/
2023-02-26 14:44:00 +00:00
ContentPresent *queryTextComponent(const QWidget *child_view) const;
2022-12-31 05:40:18 +00:00
/**
* @brief
* @param target
* @return
*/
2023-02-26 14:44:00 +00:00
ContentPresent *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);
2023-02-26 14:44:00 +00:00
void addPerceptionList(ContentPresent *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;
2023-02-26 14:44:00 +00:00
QHash<QString, ContentPresent*> sourcecode_map;
QHash<QString, ContentPresent*> 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