修改DocumentManager和EditView等机制
This commit is contained in:
parent
a8018c6e54
commit
b87399da16
|
@ -1,3 +0,0 @@
|
|||
#include "ContentPresent.h"
|
||||
|
||||
using namespace Presents;
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef CONTENTPRESENT_H
|
||||
#define CONTENTPRESENT_H
|
||||
|
||||
#include <QString>
|
||||
#include <libConfig.h>
|
||||
#include "appcore.h"
|
||||
|
||||
namespace Presents {
|
||||
|
||||
/**
|
||||
* @brief 允许具有多种显示模式的视图组件
|
||||
*/
|
||||
class ModeView
|
||||
{
|
||||
public:
|
||||
virtual ~ModeView() = default;
|
||||
|
||||
/**
|
||||
* @brief 设置视图显示模式
|
||||
* @param type
|
||||
*/
|
||||
virtual void modeReset(const QString &type) const = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取所有视图模式
|
||||
* @return
|
||||
*/
|
||||
virtual QList<QString> modes() const = 0;
|
||||
virtual QString currentMode() const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // CONTENTPRESENT_H
|
|
@ -1,11 +1,10 @@
|
|||
#ifndef DOCSMANAGER_H
|
||||
#define DOCSMANAGER_H
|
||||
|
||||
#include "ContentPresent.h"
|
||||
|
||||
#include "appcore.h"
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <StoryTool.h>
|
||||
#include <libConfig.h>
|
||||
|
||||
namespace MakeTools {
|
||||
|
||||
|
@ -35,6 +34,8 @@ namespace MakeTools {
|
|||
virtual QString name() const = 0;
|
||||
};
|
||||
|
||||
class EditException : public Config::ParseException {};
|
||||
|
||||
/**
|
||||
* @brief 内容编辑和呈现接口
|
||||
*/
|
||||
|
@ -51,25 +52,6 @@ namespace MakeTools {
|
|||
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 FilePresent *newInst() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 载入设置和命名
|
||||
* @param core
|
||||
|
@ -116,6 +98,41 @@ namespace MakeTools {
|
|||
void dataChanged(const QString &filePath);
|
||||
};
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(FilePresent::Features);
|
||||
}
|
||||
|
||||
class PresentFactory : public QObject {
|
||||
public:
|
||||
virtual ~PresentFactory() = default;
|
||||
|
||||
/**
|
||||
* @brief 在指定路径下创建合法新文件,指定文件一定存在,但内容可能并不合法
|
||||
* @param target 文件路径
|
||||
* @throw EditException 编辑错误
|
||||
*/
|
||||
virtual void create(const QFileInfo &target) = 0;
|
||||
|
||||
/**
|
||||
* @brief 生成一个新Present实例
|
||||
* @return
|
||||
*/
|
||||
virtual FilePresent *newInst(QObject *parent = nullptr) const = 0;
|
||||
};
|
||||
|
||||
template <class PresentType> class TypedPresentFactory : public PresentFactory {
|
||||
public:
|
||||
virtual ~TypedPresentFactory() = default;
|
||||
/**
|
||||
* @brief 插件针对文件类型
|
||||
* @return
|
||||
*/
|
||||
static QString suffix() { return PresentType::file_suffix; }
|
||||
virtual FilePresent *newInst(QObject *parent) const { return new PresentType(parent); }
|
||||
};
|
||||
|
||||
#define DECL_PRESENT(type) \
|
||||
private: \
|
||||
static QString file_suffix; \
|
||||
friend class MakeTools::TypedPresentFactory<type>;
|
||||
|
||||
} // namespace MakeTools
|
||||
|
||||
#endif // DOCSMANAGER_H
|
||||
|
|
|
@ -18,12 +18,11 @@ msvc {
|
|||
}
|
||||
|
||||
SOURCES += \
|
||||
ContentPresent.cpp \
|
||||
DocsManager.cpp \
|
||||
appcore.cpp \
|
||||
command_list.cpp \
|
||||
contentpresenttest.cpp \
|
||||
keywordshighlighter.cpp \
|
||||
# keywordshighlighter.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
manager_docs.cpp \
|
||||
|
@ -39,12 +38,11 @@ SOURCES += \
|
|||
xapp.cpp
|
||||
|
||||
HEADERS += \
|
||||
ContentPresent.h \
|
||||
DocsManager.h \
|
||||
appcore.h \
|
||||
command_list.h \
|
||||
contentpresenttest.h \
|
||||
keywordshighlighter.h \
|
||||
# keywordshighlighter.h \
|
||||
mainwindow.h \
|
||||
manager_docs.h \
|
||||
messagespresent.h \
|
||||
|
|
|
@ -22,7 +22,7 @@ QString NewPackage::name() const
|
|||
void NewPackage::run(Schedule::CommandsDispatcher *core) const
|
||||
{
|
||||
auto vmgr = core->get<DocumentsManager>(NAME(DocumentsManager));
|
||||
vmgr->newPackage(Route::collect(sequence));
|
||||
vmgr->createPackage(Route::collect(sequence));
|
||||
}
|
||||
|
||||
QString NewPackage::toText() const
|
||||
|
@ -46,7 +46,7 @@ QString NewFile::name() const
|
|||
void NewFile::run(Schedule::CommandsDispatcher *core) const
|
||||
{
|
||||
auto vmgr = core->get<DocumentsManager>(NAME(DocumentsManager));
|
||||
vmgr->newFile(Route::collect(group_val), name_val, suffix);
|
||||
vmgr->createFile(Route::collect(group_val), name_val, suffix);
|
||||
}
|
||||
|
||||
QString NewFile::toText() const
|
||||
|
|
|
@ -1,50 +1,49 @@
|
|||
#include "keywordshighlighter.h"
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Parse;
|
||||
using namespace Enhancement;
|
||||
|
||||
KeywordsHighlighter::KeywordsHighlighter(QObject *parent)
|
||||
: QSyntaxHighlighter(parent), parse_core(nullptr)
|
||||
{
|
||||
// KeywordsHighlighter::KeywordsHighlighter(QObject *parent)
|
||||
// : QSyntaxHighlighter(parent), parse_core(nullptr)
|
||||
//{
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
void KeywordsHighlighter::reset(Parse::Result::DocCore *base)
|
||||
{
|
||||
this->parse_core = base;
|
||||
}
|
||||
// void KeywordsHighlighter::reset(Parse::Result::DocCore *base)
|
||||
//{
|
||||
// this->parse_core = base;
|
||||
//}
|
||||
|
||||
void KeywordsHighlighter::highlightBlock(const QString &text)
|
||||
{
|
||||
if(parse_core == nullptr)
|
||||
return;
|
||||
// void KeywordsHighlighter::highlightBlock(const QString &text)
|
||||
//{
|
||||
// if(parse_core == nullptr)
|
||||
// return;
|
||||
|
||||
QTextCharFormat unknowns;
|
||||
unknowns.setForeground(QBrush(Qt::gray));
|
||||
// QTextCharFormat unknowns;
|
||||
// unknowns.setForeground(QBrush(Qt::gray));
|
||||
|
||||
QTextCharFormat generate;
|
||||
generate.setForeground(QBrush(Qt::blue));
|
||||
// QTextCharFormat generate;
|
||||
// generate.setForeground(QBrush(Qt::blue));
|
||||
|
||||
QTextCharFormat error;
|
||||
error.setForeground(QBrush(Qt::red));
|
||||
// QTextCharFormat error;
|
||||
// error.setForeground(QBrush(Qt::red));
|
||||
|
||||
auto block = currentBlock();
|
||||
auto words = parse_core->getWords(block.blockNumber());
|
||||
for(auto &w : words){
|
||||
QList<ErrorMessage> xerrors;
|
||||
// auto block = currentBlock();
|
||||
// auto words = parse_core->getWords(block.blockNumber());
|
||||
// for(auto &w : words){
|
||||
// QList<ErrorMessage> xerrors;
|
||||
|
||||
if(w->host() == parse_core->unknowns()){
|
||||
unknowns.setUnderlineStyle(QTextCharFormat::UnderlineStyle::WaveUnderline);
|
||||
unknowns.setUnderlineColor(QColor(Qt::red));
|
||||
// if(w->host() == parse_core->unknowns()){
|
||||
// unknowns.setUnderlineStyle(QTextCharFormat::UnderlineStyle::WaveUnderline);
|
||||
// unknowns.setUnderlineColor(QColor(Qt::red));
|
||||
|
||||
setFormat(w->column()-1, w->toString().length(), unknowns);
|
||||
}
|
||||
else if(!w->host()->check(xerrors)){
|
||||
setFormat(w->column()-1, w->toString().length(), error);
|
||||
}
|
||||
else{
|
||||
setFormat(w->column()-1, w->toString().length(), generate);
|
||||
}
|
||||
}
|
||||
}
|
||||
// setFormat(w->column()-1, w->toString().length(), unknowns);
|
||||
// }
|
||||
// else if(!w->host()->check(xerrors)){
|
||||
// setFormat(w->column()-1, w->toString().length(), error);
|
||||
// }
|
||||
// else{
|
||||
// setFormat(w->column()-1, w->toString().length(), generate);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <libParse.h>
|
||||
|
||||
namespace Core {
|
||||
class AppCore;
|
||||
|
@ -22,20 +21,20 @@ namespace Enhancement {
|
|||
/**
|
||||
* @brief 词语语法高亮
|
||||
*/
|
||||
class KeywordsHighlighter : public QSyntaxHighlighter
|
||||
{
|
||||
public:
|
||||
KeywordsHighlighter(QObject *parent = nullptr);
|
||||
// class KeywordsHighlighter : public QSyntaxHighlighter
|
||||
// {
|
||||
// public:
|
||||
// KeywordsHighlighter(QObject *parent = nullptr);
|
||||
|
||||
void reset(Parse::Result::DocCore *base);
|
||||
// void reset(Parse::Result::DocCore *base);
|
||||
|
||||
private:
|
||||
Parse::Result::DocCore *parse_core;
|
||||
// private:
|
||||
// Parse::Result::DocCore *parse_core;
|
||||
|
||||
// QSyntaxHighlighter interface
|
||||
protected:
|
||||
virtual void highlightBlock(const QString &text) override;
|
||||
};
|
||||
// // QSyntaxHighlighter interface
|
||||
// protected:
|
||||
// virtual void highlightBlock(const QString &text) override;
|
||||
// };
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -232,13 +232,13 @@ void MainWindow::initial_menubar(QMenuBar *mbar) {
|
|||
XApp::disp_core->postCommand(CompVisible(this, this->errors_present, true));
|
||||
XApp::disp_core->postCommand(Build(false));
|
||||
});
|
||||
sync_kernel->actionCheckSync(msgs, [this]() -> bool { return bottom_funcs->instContains(errors_present); });
|
||||
sync_kernel->actionCheckSync(msgs, [this]() -> bool { return bottom_funcs->contains(errors_present); });
|
||||
}
|
||||
// 脉络统计
|
||||
{
|
||||
auto chain_v = func->addAction("脉络统计", [this](bool v) { XApp::disp_core->postCommand(CompVisible(this, this->chains_view, v)); });
|
||||
chain_v->setCheckable(true);
|
||||
sync_kernel->registerTrigger([this]() -> bool { return right_funcs->instContains(chains_view); },
|
||||
sync_kernel->registerTrigger([this]() -> bool { return right_funcs->contains(chains_view); },
|
||||
[chain_v](bool v) {
|
||||
if (v != chain_v->isChecked())
|
||||
chain_v->setChecked(v);
|
||||
|
@ -248,7 +248,7 @@ void MainWindow::initial_menubar(QMenuBar *mbar) {
|
|||
{
|
||||
auto unit_v = func->addAction("单元统计", [this](bool v) { XApp::disp_core->postCommand(CompVisible(this, this->units_view, v)); });
|
||||
unit_v->setCheckable(true);
|
||||
sync_kernel->registerTrigger([this]() -> bool { return right_funcs->instContains(units_view); },
|
||||
sync_kernel->registerTrigger([this]() -> bool { return right_funcs->contains(units_view); },
|
||||
[unit_v](bool v) {
|
||||
if (v != unit_v->isChecked())
|
||||
unit_v->setChecked(v);
|
||||
|
@ -258,7 +258,7 @@ void MainWindow::initial_menubar(QMenuBar *mbar) {
|
|||
{
|
||||
auto board_v = func->addAction("故事统计", [this](bool v) { XApp::disp_core->postCommand(CompVisible(this, boards_view, v)); });
|
||||
board_v->setCheckable(true);
|
||||
sync_kernel->registerTrigger([this]() -> bool { return right_funcs->instContains(boards_view); },
|
||||
sync_kernel->registerTrigger([this]() -> bool { return right_funcs->contains(boards_view); },
|
||||
[board_v](bool v) {
|
||||
if (v != board_v->isChecked())
|
||||
board_v->setChecked(v);
|
||||
|
@ -268,7 +268,7 @@ void MainWindow::initial_menubar(QMenuBar *mbar) {
|
|||
{
|
||||
auto concept_v = func->addAction("概念统计", [this](bool v) { XApp::disp_core->postCommand(CompVisible(this, concept_view, v)); });
|
||||
concept_v->setCheckable(true);
|
||||
sync_kernel->registerTrigger([this]() -> bool { return right_funcs->instContains(concept_view); },
|
||||
sync_kernel->registerTrigger([this]() -> bool { return right_funcs->contains(concept_view); },
|
||||
[concept_v](bool v) {
|
||||
if (v != concept_v->isChecked())
|
||||
concept_v->setChecked(v);
|
||||
|
@ -278,7 +278,7 @@ void MainWindow::initial_menubar(QMenuBar *mbar) {
|
|||
{
|
||||
auto fragments_v = func->addAction("情节序列", [this](bool v) { XApp::disp_core->postCommand(CompVisible(this, fragments_order, v)); });
|
||||
fragments_v->setCheckable(true);
|
||||
sync_kernel->registerTrigger([this]() -> bool { return right_funcs->instContains(fragments_order); },
|
||||
sync_kernel->registerTrigger([this]() -> bool { return right_funcs->contains(fragments_order); },
|
||||
[fragments_v](bool v) {
|
||||
if (v != fragments_v->isChecked())
|
||||
fragments_v->setChecked(v);
|
||||
|
@ -446,7 +446,7 @@ PresentBase *MainWindow::remove(const Route &unique) {
|
|||
}
|
||||
}
|
||||
|
||||
bool MainWindow::instContains(MakeTools::PresentBase *ins) const { return false; }
|
||||
bool MainWindow::contains(MakeTools::PresentBase *ins) const { return false; }
|
||||
|
||||
QWidget *MainWindow::hostWidget() const { return (QWidget *)this; }
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class MainWindow : public QMainWindow, public Components::PresentHost, public Co
|
|||
virtual bool active(const Core::Route &unique) override;
|
||||
virtual MakeTools::PresentBase *remove(const Core::Route &unique) override;
|
||||
|
||||
virtual bool instContains(MakeTools::PresentBase *ins) const override;
|
||||
virtual bool contains(MakeTools::PresentBase *ins) const override;
|
||||
|
||||
// HostListener interface
|
||||
public:
|
||||
|
|
|
@ -6,75 +6,120 @@ using namespace Components;
|
|||
using namespace Core;
|
||||
using namespace DataModel;
|
||||
|
||||
DocumentsManager::DocumentsManager(AppCore *src,
|
||||
Project::ProjectManager *project,
|
||||
PresentHost *direct_con)
|
||||
: rtcore(src), pjtins(project), present_ui(direct_con) {}
|
||||
DocumentsManager::DocumentsManager(Core::AppCore *src, Project::ProjectManager *project) : rtcore(src), pjtins(project), present_ui(nullptr) {}
|
||||
|
||||
Project::ProjectManager *DocumentsManager::projectManager() const
|
||||
{
|
||||
return pjtins;
|
||||
}
|
||||
void DocumentsManager::setPresent(Components::PresentHost *container) { present_ui = container; }
|
||||
|
||||
void DocumentsManager::newPackage(const Route &link)
|
||||
{
|
||||
pjtins->newPackage(link.links());
|
||||
}
|
||||
Project::ProjectManager *DocumentsManager::projectManager() const { return pjtins; }
|
||||
|
||||
void DocumentsManager::newPackage(const Route &group, const QString &name)
|
||||
{
|
||||
newPackage(group|name);
|
||||
}
|
||||
|
||||
QList<QString> DocumentsManager::fileTypes() const
|
||||
{
|
||||
QList<QString> DocumentsManager::fileTypes() const {
|
||||
QList<QString> all_types;
|
||||
for(auto &it : rtcore->allViews())
|
||||
all_types.append(it->suffixes());
|
||||
|
||||
all_types.removeAll("*");
|
||||
for (auto &it : factory_map.keys())
|
||||
all_types.append(it);
|
||||
return all_types;
|
||||
}
|
||||
|
||||
void DocumentsManager::newFile(const Route &group_path, const QString &name, const QString &suffix)
|
||||
{
|
||||
auto list = rtcore->extensions(suffix);
|
||||
QDir root = pjtins->directory();
|
||||
void DocumentsManager::createPackage(const Core::Route &link) { pjtins->operateAccess()->newPackage(link.links()); }
|
||||
|
||||
auto rst = list.first()->create(root, name, suffix);
|
||||
if(std::get<0>(rst)){
|
||||
auto rpath = root.relativeFilePath(std::get<1>(rst));
|
||||
auto idx = pjtins->appendFile(converter(group_path), name, rpath);
|
||||
openFile(converter(idx));
|
||||
}
|
||||
else{
|
||||
throw new SimpleException("无法创建文件:" + name);
|
||||
void DocumentsManager::createFile(const Core::Route &group_path, const QString &name, const QString &suffix) {
|
||||
auto all_types = fileTypes();
|
||||
if (!all_types.contains(suffix))
|
||||
throw new SimpleException("指定文件类型无法打开:" + suffix);
|
||||
|
||||
auto midx = convertPath(group_path);
|
||||
auto fidx = projectManager()->operateAccess()->newFile(midx, name, suffix);
|
||||
auto fileinfo = projectManager()->queryAccess()->queryInfo(fidx);
|
||||
factory_map[suffix]->create(fileinfo);
|
||||
}
|
||||
|
||||
void DocumentsManager::renameNode(const Core::Route &node_path, const QString &name) {
|
||||
pjtins->operateAccess()->rename(convertPath(node_path), name);
|
||||
|
||||
auto activie_file_nodes = actives();
|
||||
if (activie_file_nodes.contains(node_path)) {
|
||||
auto inst = convertPresent(node_path);
|
||||
inst->applySetting(name, rtcore);
|
||||
doc_openning.remove(node_path);
|
||||
|
||||
auto old_link = node_path.links();
|
||||
auto npath = Core::Route::collect(old_link.mid(0, old_link.size() - 1)) | name;
|
||||
doc_openning[npath] = inst;
|
||||
|
||||
active(npath);
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex DocumentsManager::converter(const Route &path)
|
||||
{
|
||||
void DocumentsManager::deleteNode(const Core::Route &node_path) {
|
||||
auto node_mindex = convertPath(node_path);
|
||||
auto file_nodes = pjtins->queryAccess()->filesGather(node_mindex);
|
||||
auto activie_file_nodes = actives();
|
||||
|
||||
QList<Core::Route> path_buff;
|
||||
for (auto &n : file_nodes) {
|
||||
auto target = convertPath(n);
|
||||
if (activie_file_nodes.contains(target))
|
||||
path_buff << target;
|
||||
}
|
||||
|
||||
closeFile(path_buff);
|
||||
pjtins->operateAccess()->deleteT(node_mindex);
|
||||
}
|
||||
|
||||
void DocumentsManager::openFile(const QList<Route> &doc_paths) {
|
||||
for (auto &it : doc_paths) {
|
||||
auto openning = actives();
|
||||
if (openning.contains(it)) {
|
||||
doc_openning[it]->applySetting(it.links().last(), rtcore);
|
||||
active(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto info = pjtins->queryAccess()->queryInfo(convertPath(it));
|
||||
if (!info.isFile())
|
||||
throw new SimpleException("指向的节点不是文件节点");
|
||||
|
||||
auto view = factory_map[info.suffix()]->newInst(present_ui->hostWidget());
|
||||
doc_openning[it] = view;
|
||||
view->load(info);
|
||||
view->applySetting(it.links().last(), rtcore);
|
||||
present_ui->append(view);
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentsManager::closeFile(const QList<Core::Route> &doc_paths) {
|
||||
auto actives = this->actives();
|
||||
for (auto &idx : doc_paths)
|
||||
if (actives.contains(idx)) {
|
||||
auto inst = convertPresent(idx);
|
||||
inst->saveAs();
|
||||
|
||||
present_ui->remove(inst);
|
||||
delete inst;
|
||||
doc_openning.remove(idx);
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex DocumentsManager::convertPath(const Core::Route &path) {
|
||||
auto path_list = path.links();
|
||||
auto itor_node = pjtins->model()->item(0);
|
||||
while (path_list.size() > 1) {
|
||||
auto item = path_list.takeAt(1);
|
||||
int idx = 0;
|
||||
for(; idx<itor_node->rowCount(); ++idx){
|
||||
if(itor_node->child(idx)->text() == item){
|
||||
for (; idx < itor_node->rowCount(); ++idx) {
|
||||
if (itor_node->child(idx)->text() == item) {
|
||||
itor_node = itor_node->child(idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (idx == itor_node->parent()->rowCount())
|
||||
throw new SimpleException("指定的path非法:/"+ path.links().join("/"));
|
||||
throw new SimpleException("指定的path非法:/" + path.links().join("/"));
|
||||
}
|
||||
return itor_node->index();
|
||||
}
|
||||
|
||||
Route DocumentsManager::converter(const QModelIndex &index)
|
||||
{
|
||||
Route path;
|
||||
Route DocumentsManager::convertPath(const QModelIndex &index) {
|
||||
Core::Route path;
|
||||
auto item = pjtins->model()->itemFromIndex(index);
|
||||
while (item != nullptr) {
|
||||
path.prepend(item->text().trimmed());
|
||||
|
@ -84,184 +129,23 @@ Route DocumentsManager::converter(const QModelIndex &index)
|
|||
return path;
|
||||
}
|
||||
|
||||
void DocumentsManager::removeNode(const Route &node_path)
|
||||
{
|
||||
auto node_mindex = converter(node_path);
|
||||
Route DocumentsManager::convertPresent(MakeTools::FilePresent *ins) const { return doc_openning.key(ins); }
|
||||
|
||||
auto activie_file_nodes = actives();
|
||||
auto file_nodes = pjtins->filesGather(node_mindex);
|
||||
|
||||
QList<Route> path_buff;
|
||||
for(auto &n : file_nodes){
|
||||
auto target = converter(n);
|
||||
if(activie_file_nodes.contains(target))
|
||||
path_buff << target;
|
||||
}
|
||||
|
||||
close(path_buff);
|
||||
pjtins->delete(node_mindex);
|
||||
}
|
||||
|
||||
void DocumentsManager::renameNode(const Route &node_path, const QString &name)
|
||||
{
|
||||
pjtins->rename(converter(node_path), name);
|
||||
|
||||
auto activie_file_nodes = actives();
|
||||
if(activie_file_nodes.contains(node_path)){
|
||||
auto inst = activePresentOf(node_path);
|
||||
inst->applySetting(name, rtcore);
|
||||
present_ui->active(node_path);
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentsManager::openFile(const Route &path_node)
|
||||
{
|
||||
auto info = pjtins->queryInfo(converter(path_node));
|
||||
if(!info.isFile())
|
||||
throw new SimpleException("打开的节点不是文件节点");
|
||||
|
||||
if(actives().contains(path_node)){
|
||||
doc_openning[path_node]->applySetting(path_node.links().last(), rtcore);
|
||||
present_ui->active(path_node);
|
||||
return;
|
||||
}
|
||||
|
||||
auto list = rtcore->extensions(info.suffix());
|
||||
auto nview = list.first()->newInst();
|
||||
nview->load(info);
|
||||
nview->applySetting(path_node.links().last(), rtcore);
|
||||
|
||||
doc_openning[path_node] = nview;
|
||||
present_ui->append(nview, path_node);
|
||||
|
||||
functions_build[nview] = [this, nview](const QString &file_path) {
|
||||
auto nv = dynamic_cast<MakeTools::CompileFeature *>(nview);
|
||||
auto content = nv->getText();
|
||||
rtcore->getMakeCore()->compileSource(file_path, content, nview->name());
|
||||
};
|
||||
|
||||
functions_render[nview] = [nview, this](const QString &) {
|
||||
QObject::disconnect(nview, &MakeTools::FilePresent::dataChanged, nullptr, nullptr);
|
||||
|
||||
auto nv = dynamic_cast<Enhancement::HighlightFeature *>(nview);
|
||||
nv->renderRepeat();
|
||||
|
||||
auto func_build = functions_build[nview];
|
||||
auto func_render = functions_render[nview];
|
||||
QObject::connect(nview, &MakeTools::FilePresent::dataChanged, func_build);
|
||||
QObject::connect(nview, &MakeTools::FilePresent::dataChanged, func_render);
|
||||
};
|
||||
|
||||
auto flags = nview->features();
|
||||
// 编译机制 =========================================
|
||||
if (flags.testFlag(MakeTools::FilePresent::Feature::Compile)) {
|
||||
QObject::connect(nview, &MakeTools::FilePresent::dataChanged, functions_build[nview]);
|
||||
}
|
||||
|
||||
// 高亮机制 =========================================
|
||||
if (flags.testFlag(MakeTools::FilePresent::Feature::HighLight)) {
|
||||
auto nv = dynamic_cast<Enhancement::HighlightFeature *>(nview);
|
||||
nv->contexBinding(rtcore);
|
||||
|
||||
QObject::connect(nview, &MakeTools::FilePresent::dataChanged, functions_render[nview]);
|
||||
}
|
||||
}
|
||||
MakeTools::FilePresent *DocumentsManager::convertPresent(const Core::Route &node_path) { return doc_openning[node_path]; }
|
||||
|
||||
QList<Route> DocumentsManager::actives() const { return doc_openning.keys(); }
|
||||
|
||||
MakeTools::FilePresent *DocumentsManager::activePresentOf(const Route &node_path)
|
||||
{
|
||||
return doc_openning[node_path];
|
||||
void DocumentsManager::active(const Core::Route &node_path) {
|
||||
if (doc_openning.contains(node_path)) {
|
||||
auto inst = convertPresent(node_path);
|
||||
present_ui->active(inst);
|
||||
}
|
||||
}
|
||||
|
||||
void DocumentsManager::save(const QList<Route> &docs_path)
|
||||
{
|
||||
void DocumentsManager::save() {
|
||||
auto actives_paths = this->actives();
|
||||
for(auto &idx_path : docs_path)
|
||||
if(actives_paths.contains(idx_path))
|
||||
activePresentOf(idx_path)->saveAs();
|
||||
for (auto &p : actives_paths)
|
||||
convertPresent(p)->saveAs();
|
||||
}
|
||||
|
||||
void DocumentsManager::close(const QList<Route> &doc_paths)
|
||||
{
|
||||
auto actives = this->actives();
|
||||
for(auto &idx : doc_paths)
|
||||
if(actives.contains(idx)){
|
||||
auto inst = activePresentOf(idx);
|
||||
inst->saveAs();
|
||||
|
||||
present_ui->remove(idx);
|
||||
delete inst;
|
||||
doc_openning.remove(idx);
|
||||
}
|
||||
}
|
||||
|
||||
Route DocumentsManager::pathOf(MakeTools::FilePresent *ins) const
|
||||
{
|
||||
return doc_openning.key(ins);
|
||||
}
|
||||
|
||||
Route DocumentsManager::pathOf(const QModelIndex &p) const
|
||||
{
|
||||
if(!p.isValid())
|
||||
throw new SimpleException("传入非法QModelIndex");
|
||||
|
||||
auto item = projectManager()->model()->itemFromIndex(p);
|
||||
auto proot = projectManager()->model()->item(0);
|
||||
|
||||
Route retv;
|
||||
while(proot != item){
|
||||
retv = retv|item->text();
|
||||
item = item->parent();
|
||||
}
|
||||
|
||||
return retv;
|
||||
}
|
||||
|
||||
void DocumentsManager::build(bool all_from_disk)
|
||||
{
|
||||
if(!all_from_disk)
|
||||
save();
|
||||
|
||||
auto chains = pjtins->filesWithEnds("storychain");
|
||||
for(auto &it : chains){
|
||||
rtcore->getMakeCore()->compile(std::get<1>(it), std::get<0>(it));
|
||||
}
|
||||
|
||||
auto units = pjtins->filesWithEnds("storyunit");
|
||||
for(auto &it : units)
|
||||
rtcore->getMakeCore()->compile(std::get<1>(it), std::get<0>(it));
|
||||
|
||||
auto storys = pjtins->filesWithEnds("storyboard");
|
||||
for(auto &it : storys)
|
||||
rtcore->getMakeCore()->compile(std::get<1>(it), std::get<0>(it));
|
||||
|
||||
auto volumes = pjtins->filesWithEnds("storyvolume");
|
||||
for(auto &it : volumes)
|
||||
rtcore->getMakeCore()->compile(std::get<1>(it), std::get<0>(it));
|
||||
|
||||
auto concepts = pjtins->filesWithEnds("storyconcept");
|
||||
for(auto &it : concepts)
|
||||
rtcore->getMakeCore()->compile(std::get<1>(it), std::get<0>(it));
|
||||
}
|
||||
|
||||
QString DocumentsManager::name() const
|
||||
{
|
||||
return NAME(DocumentsManager);
|
||||
}
|
||||
|
||||
void DocumentsManager::hasBeenAccepted(const Core::Route &key) {}
|
||||
|
||||
void DocumentsManager::hasBeenRemoved(const Core::Route &key) {
|
||||
|
||||
}
|
||||
|
||||
void DocumentsManager::hasBeenClosed(const Core::Route &key) {
|
||||
if (!doc_openning.contains(key))
|
||||
return;
|
||||
|
||||
auto inst = doc_openning[key];
|
||||
inst->widget()->setVisible(false);
|
||||
delete inst;
|
||||
doc_openning.remove(key);
|
||||
}
|
||||
QString DocumentsManager::name() const { return NAME(DocumentsManager); }
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
#include "DocsManager.h"
|
||||
#include "route.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QTreeView>
|
||||
#include <QWidget>
|
||||
#include <libProjectManager.h>
|
||||
#include <commandsdispatcher.h>
|
||||
#include <libProjectManager.h>
|
||||
|
||||
namespace Core {
|
||||
class AppCore;
|
||||
|
@ -19,15 +20,6 @@ namespace MakeTools {
|
|||
|
||||
namespace Components {
|
||||
|
||||
class HostListener {
|
||||
public:
|
||||
virtual ~HostListener() = default;
|
||||
|
||||
virtual void hasBeenAccepted(const Core::Route &key) = 0;
|
||||
virtual void hasBeenRemoved(const Core::Route &key) = 0;
|
||||
virtual void hasBeenClosed(const Core::Route &key) = 0;
|
||||
};
|
||||
|
||||
class PresentHost {
|
||||
public:
|
||||
virtual ~PresentHost() = default;
|
||||
|
@ -42,22 +34,23 @@ namespace Components {
|
|||
* @brief 添加内容展示实例
|
||||
* @param ins
|
||||
*/
|
||||
virtual void append(MakeTools::PresentBase *ins, const Core::Route &key) = 0;
|
||||
virtual void append(MakeTools::PresentBase *ins) = 0;
|
||||
/**
|
||||
* @brief 激活内容展示实例
|
||||
* @param ins
|
||||
*/
|
||||
virtual bool active(const Core::Route &key) = 0;
|
||||
virtual bool active(const MakeTools::PresentBase *ins) = 0;
|
||||
/**
|
||||
* @brief 移除内容展示实例
|
||||
* @param ins
|
||||
*/
|
||||
virtual MakeTools::PresentBase *remove(const Core::Route &key) = 0;
|
||||
|
||||
virtual bool instContains(MakeTools::PresentBase *ins) const = 0;
|
||||
|
||||
virtual void setVisibleState(bool state) = 0;
|
||||
virtual bool visibleState() const = 0;
|
||||
virtual void remove(const MakeTools::PresentBase *ins) = 0;
|
||||
/**
|
||||
* @brief 是否包含指定
|
||||
* @param ins
|
||||
* @return
|
||||
*/
|
||||
virtual bool contains(const MakeTools::PresentBase *ins) const = 0;
|
||||
};
|
||||
|
||||
} // namespace Components
|
||||
|
@ -67,121 +60,135 @@ namespace DataModel {
|
|||
/**
|
||||
* @brief 文档管理器,根据项目配置文件,打开、查询、关闭文档实例
|
||||
*/
|
||||
class DocumentsManager : public Schedule::AccessibleObject, public Components::HostListener {
|
||||
public:
|
||||
DocumentsManager(Core::AppCore *src, Project::ProjectManager *project, Components::PresentHost *direct_con);
|
||||
class DocumentsManager : public Schedule::AccessibleObject {
|
||||
public:
|
||||
DocumentsManager(Core::AppCore *src, Project::ProjectManager *project);
|
||||
virtual ~DocumentsManager() = default;
|
||||
|
||||
Project::ProjectManager* projectManager() const;
|
||||
/**
|
||||
* @brief 设置文档呈现窗口
|
||||
* @param container
|
||||
*/
|
||||
void setPresent(Components::PresentHost *container);
|
||||
|
||||
/**
|
||||
* @brief 提供完整路径创建新包
|
||||
* @param path [/x_name]+
|
||||
* @brief 项目获取管理器
|
||||
* @return 项目管理器实例
|
||||
*/
|
||||
void newPackage(const Core::Route &link);
|
||||
Project::ProjectManager *projectManager() const;
|
||||
|
||||
// ==========================================================
|
||||
/**
|
||||
* @brief 提供父节点Index,创建新包
|
||||
* @param group
|
||||
* @param name
|
||||
* @throw SimpleException
|
||||
* @brief 注册插件类型
|
||||
* @param ins 插件工厂实例
|
||||
*/
|
||||
void newPackage(const Core::Route &group, const QString &name);
|
||||
template <class PresentType> void registPresentType(MakeTools::TypedPresentFactory<PresentType> *ins) {
|
||||
auto suffix = MakeTools::TypedPresentFactory<PresentType>::suffix();
|
||||
factory_map[suffix] = ins;
|
||||
}
|
||||
|
||||
// ==========================================================
|
||||
|
||||
/**
|
||||
* @brief 获取支持的文件类型
|
||||
* @return {txt, storychain, ……}
|
||||
* @return {txt, storyboard, ……}
|
||||
*/
|
||||
QList<QString> fileTypes() const;
|
||||
|
||||
/**
|
||||
* @brief 提供完整路径创建新包
|
||||
* @param link 包路径
|
||||
* @throw SimpleException
|
||||
*/
|
||||
void createPackage(const Core::Route &link);
|
||||
|
||||
/**
|
||||
* @brief 在指定的包节点下,创建指定类型的新文件
|
||||
* @param group 包节点
|
||||
* @param name 文件名称
|
||||
* @param group_path 包路径
|
||||
* @param name 节点名称
|
||||
* @param suffix 通过后缀名,指定文件类型
|
||||
* @throw SimpleException
|
||||
*/
|
||||
void newFile(const Core::Route &group_path, const QString &name, const QString &suffix);
|
||||
|
||||
QModelIndex converter(const Core::Route &path);
|
||||
Core::Route converter(const QModelIndex &index);
|
||||
|
||||
/**
|
||||
* @brief 移除指定节点(必须非根节点)
|
||||
* @param node 文件节点或者包节点
|
||||
* @throw SimpleException
|
||||
*/
|
||||
void removeNode(const Core::Route &node_path);
|
||||
void createFile(const Core::Route &group_path, const QString &name, const QString &suffix);
|
||||
|
||||
/**
|
||||
* @brief 修改指定节点的名称
|
||||
* @param node 节点Index
|
||||
* @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 Core::Route &path_node);
|
||||
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(MakeTools::FilePresent *ins) const;
|
||||
/**
|
||||
* @brief 获取打开的内容展示实例,如果指向未打开的节点或无效文件节点,返回null
|
||||
* @param node_path 节点路径
|
||||
* @return null或打开的展示实例
|
||||
*/
|
||||
MakeTools::FilePresent *convertPresent(const Core::Route &node_path);
|
||||
|
||||
/**
|
||||
* @brief 获取打开的活跃文档
|
||||
* @return
|
||||
*/
|
||||
QList<Core::Route> actives() const;
|
||||
/**
|
||||
* @brief 获取打开的内容展示实例,如果指向未打开的节点或无效文件节点,返回null
|
||||
* @param node
|
||||
* @return null或打开的展示实例
|
||||
*/
|
||||
MakeTools::FilePresent* activePresentOf(const Core::Route &node_path);
|
||||
|
||||
void active(const Core::Route &node_path);
|
||||
|
||||
/**
|
||||
* @brief 保存指定的文档节点集合
|
||||
* @param docs
|
||||
*/
|
||||
void save(const QList<Core::Route> &docs = QList<Core::Route>());
|
||||
|
||||
/**
|
||||
* @brief 关闭定制的文档节点集合
|
||||
* @param docs
|
||||
*/
|
||||
void close(const QList<Core::Route> &doc_paths = QList<Core::Route>());
|
||||
|
||||
|
||||
/**
|
||||
* @brief 查询指定实例(打开的)关联的ModelIndex
|
||||
* @param ins
|
||||
*/
|
||||
Core::Route pathOf(MakeTools::FilePresent *ins) const;
|
||||
Core::Route pathOf(const QModelIndex &p) const;
|
||||
|
||||
/**
|
||||
* @brief 构建所有源代码
|
||||
* @param disk
|
||||
*/
|
||||
void build(bool disk);
|
||||
void save();
|
||||
|
||||
// AccessibleObject interface
|
||||
public:
|
||||
public:
|
||||
virtual QString name() const override;
|
||||
|
||||
// HostListener interface
|
||||
public:
|
||||
virtual void hasBeenAccepted(const Core::Route &key) override;
|
||||
virtual void hasBeenRemoved(const Core::Route &key) override;
|
||||
virtual void hasBeenClosed(const Core::Route &key) override;
|
||||
|
||||
private:
|
||||
private:
|
||||
Core::AppCore *const rtcore;
|
||||
Project::ProjectManager *pjtins;
|
||||
Components::PresentHost *present_ui;
|
||||
|
||||
QHash<QString, MakeTools::PresentFactory *> factory_map;
|
||||
QHash<Core::Route, MakeTools::FilePresent *> doc_openning;
|
||||
QHash<MakeTools::FilePresent *, std::function<void(const QString &)>> functions_build;
|
||||
QHash<MakeTools::FilePresent *, std::function<void(const QString &)>> functions_render;
|
||||
};
|
||||
} // namespace DataModel
|
||||
|
||||
|
|
|
@ -1,37 +1,8 @@
|
|||
#include "messagespresent.h"
|
||||
|
||||
using namespace Components;
|
||||
using namespace Parse;
|
||||
using namespace Parse::Result;
|
||||
|
||||
MessagesPresent::MessagesPresent(MakeTools::StoryTool *tool, QWidget *parent)
|
||||
: QTableView(parent), core_ins(tool), items_present(new QStandardItemModel(this)) {
|
||||
setModel(items_present);
|
||||
}
|
||||
|
||||
void MessagesPresent::refresh() {
|
||||
items_present->clear();
|
||||
|
||||
QList<ErrorMessage> errors;
|
||||
core_ins->checkPass(errors);
|
||||
|
||||
for(auto &err : errors){
|
||||
QList<QStandardItem*> row;
|
||||
row << new QStandardItem(err.Reason);
|
||||
row << new QStandardItem(err.Text);
|
||||
row << new QStandardItem(err.FilePath);
|
||||
row << new QStandardItem(QString("%1").arg(err.CodeRow + 1));
|
||||
row << new QStandardItem(QString("%1").arg(err.CodeCol));
|
||||
|
||||
for(auto &ins : row)
|
||||
ins->setEditable(false);
|
||||
items_present->appendRow(row);
|
||||
}
|
||||
items_present->setHorizontalHeaderLabels(QStringList() << "错误原因"<<"源文本"<<"磁盘路径"<<"代码行"<<"代码列");
|
||||
|
||||
this->resizeColumnsToContents();
|
||||
this->resizeRowsToContents();
|
||||
}
|
||||
MessagesPresent::MessagesPresent(QStandardItemModel *base, QWidget *parent) : QTableView(parent), items_present(base) { setModel(items_present); }
|
||||
|
||||
QWidget *MessagesPresent::widget() const { return (QWidget *)this; }
|
||||
|
||||
|
|
|
@ -2,33 +2,27 @@
|
|||
#define MESSAGEPRESENT_H
|
||||
|
||||
#include "DocsManager.h"
|
||||
#include "StoryTool.h"
|
||||
#include <QStandardItemModel>
|
||||
#include <QTableView>
|
||||
#include <QWidget>
|
||||
#include <libParse.h>
|
||||
|
||||
namespace Components {
|
||||
/**
|
||||
* @brief 显示各种提示信息
|
||||
*/
|
||||
class MessagesPresent : public QTableView, public MakeTools::PresentBase {
|
||||
public:
|
||||
MessagesPresent(MakeTools::StoryTool *tool, QWidget *parent = nullptr);
|
||||
public:
|
||||
MessagesPresent(QStandardItemModel *base, QWidget *parent = nullptr);
|
||||
virtual ~MessagesPresent() = default;
|
||||
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
MakeTools::StoryTool *const core_ins;
|
||||
QStandardItemModel *const items_present;
|
||||
|
||||
// PresentBase interface
|
||||
public:
|
||||
public:
|
||||
virtual QWidget *widget() const override;
|
||||
virtual QString name() const override;
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace Components
|
||||
|
||||
#endif // MESSAGEPRESENT_H
|
||||
|
|
|
@ -254,14 +254,16 @@ void ParseBridge::load_article(const QDomElement &article_elm, QStandardItem *pi
|
|||
|
||||
QStandardItem *ParseBridge::locate_node(QStandardItemModel *model, const QStringList path) {
|
||||
QStandardItem *current_item = nullptr;
|
||||
for (auto n : path) {
|
||||
if (!current_item)
|
||||
current_item = model->findChild<QStandardItem *>(n, Qt::FindChildOption::FindDirectChildrenOnly);
|
||||
else {
|
||||
for (auto &n : path) {
|
||||
if (!current_item) {
|
||||
for (auto idx = 0; idx < model->rowCount(); ++idx) {
|
||||
if (model->item(idx)->text() == n)
|
||||
current_item = model->item(idx);
|
||||
}
|
||||
} else {
|
||||
for (auto idx = 0; idx < current_item->rowCount(); ++idx) {
|
||||
if (current_item->child(idx)->text() == n) {
|
||||
current_item = current_item->child(idx);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ namespace bridge {
|
|||
|
||||
template <class T, int idx> class SupplyItem : public QStandardItem {
|
||||
public:
|
||||
SupplyItem(const T *bitem) : value_store(bitem) { setText(bitem[idx]); }
|
||||
SupplyItem(T *bitem) : value_store(bitem) { setText((*bitem)[idx]); }
|
||||
|
||||
private:
|
||||
const T *const value_store;
|
||||
|
|
|
@ -78,7 +78,7 @@ PresentBase *PresentContainer::remove(const Core::Route &key) {
|
|||
return inst;
|
||||
}
|
||||
|
||||
bool PresentContainer::instContains(MakeTools::PresentBase *ins) const {
|
||||
bool PresentContainer::contains(MakeTools::PresentBase *ins) const {
|
||||
for (auto &insit : items_store) {
|
||||
if (insit == ins)
|
||||
return true;
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Components {
|
|||
virtual void append(MakeTools::PresentBase *ins, const Core::Route &key) override;
|
||||
virtual bool active(const Core::Route &key) override;
|
||||
virtual MakeTools::PresentBase *remove(const Core::Route &key) override;
|
||||
virtual bool instContains(MakeTools::PresentBase *ins) const override;
|
||||
virtual bool contains(MakeTools::PresentBase *ins) const override;
|
||||
virtual void setVisibleState(bool state) override;
|
||||
virtual bool visibleState() const override;
|
||||
|
||||
|
|
|
@ -8,30 +8,34 @@
|
|||
#include <QTextStream>
|
||||
|
||||
using namespace Components;
|
||||
using namespace Parse::Result;
|
||||
using namespace Enhancement;
|
||||
using namespace Core;
|
||||
|
||||
class Impl_EditError : public MakeTools::EditException {
|
||||
public:
|
||||
Impl_EditError(const QString &title, const QString &reason) {
|
||||
this->t = title;
|
||||
this->r = reason;
|
||||
buffer = r.toLocal8Bit();
|
||||
}
|
||||
|
||||
// exception interface
|
||||
public:
|
||||
virtual const char *what() const override { return buffer; }
|
||||
|
||||
DefaultTextEdit:: DefaultTextEdit()
|
||||
:edit_square(new QTextEdit){}
|
||||
// ParseException interface
|
||||
public:
|
||||
virtual QString reason() const override { return r; }
|
||||
virtual QString title() const override { return t; }
|
||||
|
||||
private:
|
||||
QString r, t;
|
||||
QByteArray buffer;
|
||||
};
|
||||
|
||||
void DefaultTextEdit::modeReset(const QString &) const
|
||||
{
|
||||
QString DefaultTextEdit::file_suffix = "txt";
|
||||
|
||||
}
|
||||
|
||||
QList<QString> DefaultTextEdit::modes() const
|
||||
{
|
||||
return QList<QString>() << "文本";
|
||||
}
|
||||
|
||||
QString DefaultTextEdit::currentMode() const
|
||||
{
|
||||
return modes()[0];
|
||||
}
|
||||
DefaultTextEdit::DefaultTextEdit(QObject *parent) : MakeTools::FilePresent(parent), edit_square(new QTextEdit) {}
|
||||
|
||||
void DefaultTextEdit::jumpTo(const QList<QString> &path)
|
||||
{
|
||||
|
@ -43,24 +47,6 @@ MakeTools::FilePresent::Features DefaultTextEdit::features()
|
|||
return Features();
|
||||
}
|
||||
|
||||
std::tuple<bool, QString> DefaultTextEdit::create(const QDir &target, const QString &name, const QString &suffix)
|
||||
{
|
||||
auto x = target.filePath(QString("%1.%2").arg(name, suffix));
|
||||
if(QFileInfo::exists(x))
|
||||
return std::make_tuple(false, x);
|
||||
|
||||
QFile xf(x);
|
||||
if(!xf.open(QIODevice::WriteOnly|QIODevice::Text))
|
||||
throw new std::exception(QString("指定文件无法建立:" + x).toLocal8Bit());
|
||||
|
||||
return std::make_tuple(true, target.relativeFilePath(x));
|
||||
}
|
||||
|
||||
MakeTools::FilePresent * DefaultTextEdit::newInst() const
|
||||
{
|
||||
return new DefaultTextEdit();
|
||||
}
|
||||
|
||||
void DefaultTextEdit::applySetting(const QString &name, Core::AppCore *core)
|
||||
{
|
||||
name_store = name;
|
||||
|
@ -74,12 +60,12 @@ QString DefaultTextEdit::name() const
|
|||
void DefaultTextEdit::load(const QFileInfo &target_file)
|
||||
{
|
||||
if(!target_file.exists())
|
||||
throw new std::exception(QString("指定文件未找到:%1").arg(target_file.absoluteFilePath()).toLocal8Bit());
|
||||
throw new Impl_EditError("解析错误", QString("指定文件未找到:%1").arg(target_file.absoluteFilePath()));
|
||||
|
||||
target_file_path = target_file.canonicalFilePath();
|
||||
QFile bin(target_file_path);
|
||||
if(!bin.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
throw new std::exception(QString("指定文件无法打开:%1").arg(target_file.absoluteFilePath()).toLocal8Bit());
|
||||
throw new Impl_EditError("解析错误", QString("指定文件无法打开:%1").arg(target_file.absoluteFilePath()));
|
||||
|
||||
QTextStream tin(&bin);
|
||||
tin.setCodec("UTF-8");
|
||||
|
@ -110,23 +96,22 @@ QString DefaultTextEdit::relativeTargetPath(const QDir &base) const
|
|||
return base.relativeFilePath(target_file_path);
|
||||
}
|
||||
|
||||
bool DefaultTextEdit::isModified() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool DefaultTextEdit::isModified() const { return true; }
|
||||
|
||||
QList<QString> DefaultTextEdit::suffixes() const
|
||||
{
|
||||
return QStringList() << "txt" << "*";
|
||||
}
|
||||
QString DefaultTextEdit::absoluteTargetPath() const { return target_file_path; }
|
||||
|
||||
QString DefaultTextEdit::absoluteTargetPath() const
|
||||
{
|
||||
return target_file_path;
|
||||
}
|
||||
QWidget *DefaultTextEdit::widget() const { return edit_square; }
|
||||
|
||||
void DefaultTextEditFactory::create(const QFileInfo &target) {
|
||||
QFile base_f(target.canonicalFilePath());
|
||||
if (!base_f.exists()) {
|
||||
throw new Impl_EditError("新建错误", "指定路径不合法,文件不存在:" + target.absoluteFilePath());
|
||||
}
|
||||
|
||||
QWidget * DefaultTextEdit::widget() const
|
||||
{
|
||||
return edit_square;
|
||||
if (!base_f.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
throw new Impl_EditError("新建错误", QString("指定文件无法建立:" + target.absoluteFilePath()));
|
||||
|
||||
base_f.write(" ");
|
||||
base_f.flush();
|
||||
base_f.close();
|
||||
}
|
||||
|
|
|
@ -2,27 +2,22 @@
|
|||
#define SRCEDIT_DEFAULTTEXT_H
|
||||
|
||||
#include "DocsManager.h"
|
||||
#include "ContentPresent.h"
|
||||
#include <QSyntaxHighlighter>
|
||||
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QTextEdit>
|
||||
|
||||
namespace Components {
|
||||
|
||||
/**
|
||||
* @brief Text默认文本编辑视图
|
||||
*/
|
||||
class DefaultTextEdit : public MakeTools::FilePresent, public Presents::ModeView {
|
||||
public:
|
||||
DefaultTextEdit();
|
||||
virtual ~DefaultTextEdit() = default;
|
||||
*/
|
||||
class DefaultTextEdit : public MakeTools::FilePresent {
|
||||
DECL_PRESENT(DefaultTextEdit);
|
||||
|
||||
// ModeView interface
|
||||
public:
|
||||
virtual void modeReset(const QString &) const override;
|
||||
virtual QList<QString> modes() const override;
|
||||
virtual QString currentMode() const override;
|
||||
DefaultTextEdit(QObject *parent);
|
||||
virtual ~DefaultTextEdit() = default;
|
||||
|
||||
private:
|
||||
QTextEdit * edit_square;
|
||||
|
@ -32,21 +27,26 @@ namespace Components {
|
|||
|
||||
// ContentPresent interface
|
||||
public:
|
||||
virtual std::tuple<bool, QString> create(const QDir &target, const QString &name, const QString &suffix) override;
|
||||
virtual QWidget *widget() const override;
|
||||
virtual MakeTools::FilePresent *newInst() const override;
|
||||
virtual void applySetting(const QString &name, Core::AppCore *core) override;
|
||||
virtual QString name() const override;
|
||||
virtual void load(const QFileInfo &target_file) override;
|
||||
virtual void saveAs(const QString &path) override;
|
||||
virtual QString relativeTargetPath(const QDir &base) const override;
|
||||
virtual bool isModified() const override;
|
||||
virtual QList<QString> suffixes() const override;
|
||||
virtual QString absoluteTargetPath() const override;
|
||||
virtual void jumpTo(const QList<QString> &path) override;
|
||||
virtual Features features() override;
|
||||
};
|
||||
}
|
||||
|
||||
class DefaultTextEditFactory : public MakeTools::TypedPresentFactory<DefaultTextEdit> {
|
||||
public:
|
||||
virtual ~DefaultTextEditFactory() = default;
|
||||
|
||||
// PresentFactory interface
|
||||
public:
|
||||
virtual void create(const QFileInfo &target) override;
|
||||
};
|
||||
} // namespace Components
|
||||
|
||||
#endif // SRCEDIT_DEFAULTTEXT_H
|
||||
|
|
|
@ -7,61 +7,47 @@
|
|||
#include <QVBoxLayout>
|
||||
|
||||
using namespace Components;
|
||||
using namespace Parse::Result;
|
||||
using namespace Enhancement;
|
||||
using namespace Core;
|
||||
|
||||
class Impl_EditError2 : public MakeTools::EditException {
|
||||
public:
|
||||
Impl_EditError2(const QString &title, const QString &reason) {
|
||||
this->t = title;
|
||||
this->r = reason;
|
||||
buffer = r.toLocal8Bit();
|
||||
}
|
||||
|
||||
StorySourceEdit::StorySourceEdit()
|
||||
: words_highlighter(new KeywordsHighlighter(this)),
|
||||
edit_square(new QTextEdit)
|
||||
{
|
||||
words_highlighter->setDocument(this->edit_square->document());
|
||||
// exception interface
|
||||
public:
|
||||
virtual const char *what() const override { return buffer; }
|
||||
|
||||
// ParseException interface
|
||||
public:
|
||||
virtual QString reason() const override { return r; }
|
||||
virtual QString title() const override { return t; }
|
||||
|
||||
private:
|
||||
QString r, t;
|
||||
QByteArray buffer;
|
||||
};
|
||||
|
||||
QString StorySourceEdit::file_suffix = "storyboard";
|
||||
|
||||
StorySourceEdit::StorySourceEdit(QObject *parent)
|
||||
: MakeTools::FilePresent(parent),
|
||||
// words_highlighter(new KeywordsHighlighter(this)),
|
||||
edit_square(new QTextEdit) {
|
||||
// words_highlighter->setDocument(this->edit_square->document());
|
||||
connect(edit_square, &QTextEdit::textChanged, [this](){
|
||||
emit this->dataChanged(filepath_store);
|
||||
});
|
||||
}
|
||||
|
||||
void StorySourceEdit::modeReset(const QString &) const{}
|
||||
|
||||
QList<QString> StorySourceEdit::modes() const
|
||||
{
|
||||
return QList<QString>() << "源码";
|
||||
}
|
||||
|
||||
QString StorySourceEdit::currentMode() const
|
||||
{
|
||||
return modes()[0];
|
||||
}
|
||||
|
||||
void StorySourceEdit::contexBinding(Core::AppCore *app) { this->core_temp = app; }
|
||||
|
||||
void StorySourceEdit::renderRepeat() const
|
||||
{
|
||||
this->words_highlighter->rehighlight();
|
||||
}
|
||||
|
||||
QList<QString> StorySourceEdit::suffixes() const
|
||||
{
|
||||
return QList<QString>() << "storyboard";
|
||||
}
|
||||
|
||||
std::tuple<bool, QString> StorySourceEdit::create(const QDir &target, const QString &name, const QString &suffix)
|
||||
{
|
||||
auto path = target.filePath(QString("%1.%2").arg(name, suffix));
|
||||
if(QFileInfo::exists(path))
|
||||
return std::make_tuple(false, path);
|
||||
|
||||
QFile nwf(path);
|
||||
if(!nwf.open(QIODevice::WriteOnly|QIODevice::Text))
|
||||
throw new SimpleException("指定文件无法创建:"+path);
|
||||
|
||||
return std::make_tuple(true, target.relativeFilePath(path));
|
||||
}
|
||||
|
||||
MakeTools::FilePresent *StorySourceEdit::newInst() const
|
||||
{
|
||||
return new StorySourceEdit();
|
||||
void StorySourceEdit::renderRepeat() const {
|
||||
// this->words_highlighter->rehighlight();
|
||||
}
|
||||
|
||||
QWidget *StorySourceEdit::widget() const
|
||||
|
@ -132,22 +118,35 @@ void StorySourceEdit::applySetting(const QString &name, Core::AppCore *core)
|
|||
|
||||
}
|
||||
|
||||
void StorySourceEdit::jumpTo(const QList<QString> &path)
|
||||
{
|
||||
auto fpath = this->absoluteTargetPath();
|
||||
auto core = core_temp->parseCore();
|
||||
if(path.size()){
|
||||
auto storynode = core->queryStoryBoard(path[0]).first();
|
||||
auto first_word = storynode->refered()[0];
|
||||
void StorySourceEdit::jumpTo(const QList<QString> &path) {
|
||||
// auto fpath = this->absoluteTargetPath();
|
||||
// auto core = core_temp->parseCore();
|
||||
// if(path.size()){
|
||||
// auto storynode = core->queryStoryBoard(path[0]).first();
|
||||
// auto first_word = storynode->refered()[0];
|
||||
|
||||
auto textblock = this->edit_square->document()->findBlockByNumber(first_word->row());
|
||||
auto cur = this->edit_square->textCursor();
|
||||
cur.setPosition(textblock.position());
|
||||
this->edit_square->setTextCursor(cur);
|
||||
}
|
||||
// auto textblock = this->edit_square->document()->findBlockByNumber(first_word->row());
|
||||
// auto cur = this->edit_square->textCursor();
|
||||
// cur.setPosition(textblock.position());
|
||||
// this->edit_square->setTextCursor(cur);
|
||||
// }
|
||||
}
|
||||
|
||||
MakeTools::FilePresent::Features StorySourceEdit::features()
|
||||
{
|
||||
return Feature::Compile | Feature::HighLight;
|
||||
}
|
||||
|
||||
void StorySourceEditFactory::create(const QFileInfo &target) {
|
||||
QFile base_f(target.canonicalFilePath());
|
||||
if (!base_f.exists()) {
|
||||
throw new Impl_EditError2("新建错误", "指定路径不合法,文件不存在:" + target.absoluteFilePath());
|
||||
}
|
||||
|
||||
if (!base_f.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
throw new Impl_EditError2("新建错误", QString("指定文件无法建立:" + target.absoluteFilePath()));
|
||||
|
||||
base_f.write(" ");
|
||||
base_f.flush();
|
||||
base_f.close();
|
||||
}
|
||||
|
|
|
@ -8,23 +8,15 @@
|
|||
|
||||
namespace Components {
|
||||
|
||||
class StorySourceEdit : public Presents::ModeView,
|
||||
public MakeTools::CompileFeature,
|
||||
public MakeTools::FilePresent,
|
||||
public Enhancement::HighlightFeature {
|
||||
class StorySourceEdit : public MakeTools::CompileFeature, public MakeTools::FilePresent, public Enhancement::HighlightFeature {
|
||||
DECL_PRESENT(StorySourceEdit);
|
||||
|
||||
public:
|
||||
StorySourceEdit();
|
||||
StorySourceEdit(QObject *parent);
|
||||
virtual ~StorySourceEdit() = default;
|
||||
|
||||
// ModeView interface
|
||||
public:
|
||||
virtual void modeReset(const QString &type) const override;
|
||||
virtual QList<QString> modes() const override;
|
||||
virtual QString currentMode() const override;
|
||||
|
||||
|
||||
private:
|
||||
QSyntaxHighlighter *const words_highlighter;
|
||||
// QSyntaxHighlighter *const words_highlighter;
|
||||
Core::AppCore *core_temp;
|
||||
QString filepath_store;
|
||||
QString name_store;
|
||||
|
@ -32,14 +24,11 @@ namespace Components {
|
|||
|
||||
// HighlightDemand interface
|
||||
public:
|
||||
virtual void contexBinding(Core::AppCore *app) override;
|
||||
virtual void renderRepeat() const override;
|
||||
virtual void contexBinding(Core::AppCore *app) override;
|
||||
virtual void renderRepeat() const override;
|
||||
|
||||
// ContentPresent interface
|
||||
// ContentPresent interface
|
||||
public:
|
||||
virtual QList<QString> suffixes() const override;
|
||||
virtual std::tuple<bool, QString> create(const QDir &target, const QString &name, const QString &suffix) override;
|
||||
virtual MakeTools::FilePresent *newInst() const override;
|
||||
virtual QWidget *widget() const override;
|
||||
virtual QString name() const override;
|
||||
virtual void load(const QFileInfo &target_file) override;
|
||||
|
@ -52,6 +41,14 @@ namespace Components {
|
|||
virtual void jumpTo(const QList<QString> &path) override;
|
||||
virtual Features features() override;
|
||||
};
|
||||
}
|
||||
|
||||
class StorySourceEditFactory : public MakeTools::TypedPresentFactory<StorySourceEdit> {
|
||||
|
||||
// PresentFactory interface
|
||||
public:
|
||||
virtual void create(const QFileInfo &target) override;
|
||||
};
|
||||
|
||||
} // namespace Components
|
||||
|
||||
#endif // SRCEDIT_STORYBOARD_H
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
#include "unnnn.h"
|
||||
|
||||
QString EditView::t = "txt";
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef UNNNN_H
|
||||
#define UNNNN_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
template <class TargetType> class TypeDefine {
|
||||
public:
|
||||
static QString suffix() { return TargetType::t; }
|
||||
};
|
||||
|
||||
class EditView : public TypeDefine<EditView> {
|
||||
public:
|
||||
static QString t;
|
||||
};
|
||||
|
||||
#endif // UNNNN_H
|
Loading…
Reference in New Issue