From c0051e4ab8c47b19c9dbc394f7e0ffe275a00544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=AE=87=E6=B8=85=E9=9F=B3?= <2422523675@qq.com> Date: Sat, 31 Dec 2022 21:05:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=8C=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E8=81=9A=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DesParser/main.cpp | 9 +- WordsIDE/DocsManager.cpp | 188 ++++++++++++++++++++ WordsIDE/{SensitiveCore.h => DocsManager.h} | 25 ++- WordsIDE/SensitiveCore.cpp | 144 --------------- WordsIDE/SourceEditView.cpp | 2 +- WordsIDE/SourceEditView.h | 2 +- WordsIDE/WordsIDE.pro | 4 +- WordsIDE/appcore.cpp | 49 +---- WordsIDE/appcore.h | 24 ++- WordsIDE/fragmentsorderview.cpp | 6 +- WordsIDE/mainwindow.cpp | 34 ++-- WordsIDE/mainwindow.h | 2 +- WordsIDE/sourcecodeeditor.cpp | 2 +- WordsIDE/storyboardsourceedit.cpp | 2 +- WordsIDE/storychainsourceeditor.cpp | 2 +- WordsIDE/storychainsourceeditor.h | 2 +- WordsIDE/storychainspresent.cpp | 6 +- WordsIDE/storyconceptspresent.cpp | 6 +- WordsIDE/storyunitsourceedit.cpp | 4 +- WordsIDE/storyunitspresent.cpp | 6 +- libParse/StoryTool.cpp | 15 +- libParse/StoryTool.h | 3 +- libParse/libParse.cpp | 93 +++++----- libParse/libParse.h | 11 +- 24 files changed, 335 insertions(+), 306 deletions(-) create mode 100644 WordsIDE/DocsManager.cpp rename WordsIDE/{SensitiveCore.h => DocsManager.h} (80%) delete mode 100644 WordsIDE/SensitiveCore.cpp diff --git a/DesParser/main.cpp b/DesParser/main.cpp index 9c5a6b4..65f0ca3 100644 --- a/DesParser/main.cpp +++ b/DesParser/main.cpp @@ -36,22 +36,21 @@ int main(int argc, char *argv[]) // auto retlist = frame.analysis(&doc, "D:\\Projects\\Cpp\\QtNovelDesc\\DesParser\\example.storyboard"); - ParseCore core; - MakeTools::StoryTool tool(&core); + MakeTools::StoryTool tool; // auto path = "D:\\Projects\\Cpp\\QtNovelDesc\\DesParser\\example.storyvolume"; auto path = "D:\\Projects\\Cpp\\QtNovelDesc\\DesParser\\example.storyunit"; tool.compile(QFileInfo(path), "后台编译"); - auto doc = core.queryDocument(QFileInfo(path)); - auto retlist = core.queryRootNodes(doc); + auto doc = tool.getCore()->queryDocument(QFileInfo(path)); + auto retlist = doc->syntaxNodes(); for (auto x : qAsConst(retlist)) { qDebug().noquote() << x->toString(); } QList errors; if(!tool.checkPass(errors)) - for(auto x : errors) + for(auto &x : errors) qDebug() << QString("%1, %2, %3, %4, %5").arg(x.Reason).arg(x.Text).arg(x.FilePath).arg(x.CodeRow).arg(x.CodeCol); return a.exec(); diff --git a/WordsIDE/DocsManager.cpp b/WordsIDE/DocsManager.cpp new file mode 100644 index 0000000..fea4b51 --- /dev/null +++ b/WordsIDE/DocsManager.cpp @@ -0,0 +1,188 @@ +#include "DocsManager.h" +#include "mainwindow.h" + +#include +#include +#include + +using namespace MakeTools; +using namespace Core; + + +DocsManager::DocsManager(StoryTool *tool, AppCore *host, MainWindow *views) + : host_core(host), views_holder(views), make_core(tool) +{ + +} + +void DocsManager::saveAll() const +{ + for(auto &it : sourcecode_map) + it->save(); + for(auto &it : plaintext_map) + it->save(); +} + +void DocsManager::closeAll() +{ + for(auto &it : sourcecode_map.keys()) + closeTextComponent(QFileInfo(it)); + + for(auto &it : plaintext_map.keys()) + closeTextComponent(QFileInfo(it)); + + host_core->getMakeCore()->getCore()->clear(); +} + +bool DocsManager::contains(const QFileInfo &target) const +{ + for(auto &it : sourcecode_map.keys()) + if(it == target.absoluteFilePath()) + return true; + for(auto &it : plaintext_map.keys()) + if(it == target.absoluteFilePath()) + return true; + + return false; +} + +TextView *DocsManager::queryTextComponent(const QWidget *child_view) const +{ + for(auto ins : sourcecode_map) + if(ins->textView() == child_view) + return ins; + for(auto ins : plaintext_map) + if(ins->textView() == child_view) + return ins; + + return nullptr; +} + +TextView *DocsManager::queryTextComponent(const QFileInfo &target) const +{ + for(auto &it : sourcecode_map.keys()) + if(it == target.absoluteFilePath()) + return sourcecode_map[it]; + for(auto &it : plaintext_map.keys()) + if(it == target.absoluteFilePath()) + return plaintext_map[it]; + + return nullptr; +} + +void DocsManager::closeTextComponent(const QFileInfo &target) +{ + auto key = target.absoluteFilePath(); + + if(sourcecode_map.contains(key)){ + sourcecode_map[key]->save(); + delete sourcecode_map[key]; + sourcecode_map.remove(key); + } + else if(plaintext_map.contains(key)){ + plaintext_map[key]->save(); + delete plaintext_map[key]; + plaintext_map.remove(key); + } +} + +void DocsManager::openTextDocument(const QString &src, const QString &name) +{ + auto xfactorys = host_core->extensions(QFileInfo(src).suffix()); + if(contains(src)){ + auto ins = queryTextComponent(QFileInfo(src)); + + dynamic_cast(ins)->reloadConfigrations(host_core->getConfigs(xfactorys[0]->configs())); + views_holder->contentViewAppend(ins->textView(), name); + return; + } + + make_core->compile(QFileInfo(src), name); + + TextView *tview = dynamic_cast(xfactorys[0]->newInstance(host_core)); + tview->initSource(host_core, QFileInfo(src), name, views_holder); + addPerceptionList(tview); + + dynamic_cast(tview)->resetProcsType(QFileInfo(src).suffix()); + dynamic_cast(tview)->reloadConfigrations(host_core->getConfigs(xfactorys[0]->configs())); + + QFile fin(src); + if(!fin.open(QIODevice::ReadOnly | QIODevice::Text)){ + QMessageBox::critical(views_holder, "系统错误", QString("无法打开指定文件:%1(%2)").arg(name, src)); + return; + } + + QTextStream tin(&fin); + tview->textContentReset(tin.readAll()); + + views_holder->contentViewAppend(tview->textView(), name); +} + +void DocsManager::addPerceptionList(TextView *ins, SensitiveType type) +{ + if(type == SensitiveType::CompileAtChanged){ + connect(ins, &TextView::dataChanged, [ins, this](const QString &path){ + this->recompile(path, ins->docName()); + }); + this->sourcecode_map[ins->absoluteFilePath()] = ins; + } + else{ + this->plaintext_map[ins->absoluteFilePath()] = ins; + } +} + +void DocsManager::addProcTrigger(std::function exc) +{ + this->trigger_list << exc; +} + +void DocsManager::recompile(const QString &file_path, const QString &doc_name) +{ + if(!sourcecode_map.contains(file_path)) + return; + + auto view = this->sourcecode_map[file_path]; + make_core->compileSource(QFileInfo(file_path), view->textContent(), doc_name); + + for(auto &ex : trigger_list) + ex(); +} + +TextView::TextView() + : QObject(nullptr){} + +void TextView::initSource(Core::AppCore *core, const QFileInfo &src, const QString &name, QWidget *parent) +{ + this->doc_name = name; + this->initSource(core, src, parent); +} + +QString TextView::absoluteFilePath() const +{ + return source_x; +} + +void TextView::save() const +{ + QFile bout(absoluteFilePath()); + if(!bout.open(QIODevice::WriteOnly|QIODevice::Text)){ + QMessageBox::critical(nullptr, "系统错误", absoluteFilePath()+"文件无法打开"); + return; + } + + QTextStream tout(&bout); + tout << textContent(); + tout.flush(); +} + +QString TextView::docName() const +{ + return doc_name; +} + +void TextView::initSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent) +{ + this->source_x = src.absoluteFilePath(); + if(parent) + this->setParent(parent); +} diff --git a/WordsIDE/SensitiveCore.h b/WordsIDE/DocsManager.h similarity index 80% rename from WordsIDE/SensitiveCore.h rename to WordsIDE/DocsManager.h index 4403472..79efb23 100644 --- a/WordsIDE/SensitiveCore.h +++ b/WordsIDE/DocsManager.h @@ -1,5 +1,5 @@ -#ifndef SENSITIVECORE_H -#define SENSITIVECORE_H +#ifndef DOCSMANAGER_H +#define DOCSMANAGER_H #include "ContentPresent.h" @@ -20,7 +20,7 @@ namespace MakeTools { void initSource(Core::AppCore *core, const QFileInfo &src, const QString &name, QWidget *parent=nullptr); - QString filePath() const; + QString absoluteFilePath() const; void save() const; virtual void jumpTo(const QList &path) = 0; @@ -50,7 +50,7 @@ namespace MakeTools { /** * @brief 自动编译管理框架 */ - class SensitiveCore : public QObject + class DocsManager : public QObject { Q_OBJECT public: @@ -58,13 +58,15 @@ namespace MakeTools { * @brief 内容自动构建和管理核心 * @param tool */ - SensitiveCore(StoryTool *tool); + DocsManager(StoryTool *tool, Core::AppCore *host, MainWindow *views); /** * @brief 保存当前所有文档内容 */ void saveAll() const; + void closeAll(); + /** * @brief 文档打开状态查询 * @param target @@ -82,17 +84,26 @@ namespace MakeTools { * @param target * @return */ - TextView * queryTextComponent(const QFileInfo &target) const; + TextView *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(TextView *ins, SensitiveType type = SensitiveType::CompileAtChanged); void addProcTrigger(std::function exc); private: + Core::AppCore *const host_core; + MainWindow *const views_holder; StoryTool *const make_core; QHash sourcecode_map; QHash plaintext_map; @@ -102,4 +113,4 @@ namespace MakeTools { }; } -#endif // SENSITIVECORE_H +#endif // DOCSMANAGER_H diff --git a/WordsIDE/SensitiveCore.cpp b/WordsIDE/SensitiveCore.cpp deleted file mode 100644 index 8bc6c27..0000000 --- a/WordsIDE/SensitiveCore.cpp +++ /dev/null @@ -1,144 +0,0 @@ -#include "SensitiveCore.h" - -#include -#include -#include - -using namespace MakeTools; - -SensitiveCore::SensitiveCore(StoryTool *tool) - : make_core(tool) -{ - -} - -void SensitiveCore::saveAll() const -{ - for(auto &it : sourcecode_map) - it->save(); - for(auto &it : plaintext_map) - it->save(); -} - -bool SensitiveCore::contains(const QFileInfo &target) const -{ - for(auto &it : sourcecode_map.keys()) - if(it == target.absoluteFilePath()) - return true; - for(auto &it : plaintext_map.keys()) - if(it == target.absoluteFilePath()) - return true; - - return false; -} - -TextView *SensitiveCore::queryTextComponent(const QWidget *child_view) const -{ - for(auto ins : sourcecode_map) - if(ins->textView() == child_view) - return ins; - for(auto ins : plaintext_map) - if(ins->textView() == child_view) - return ins; - - return nullptr; -} - -TextView *SensitiveCore::queryTextComponent(const QFileInfo &target) const -{ - for(auto &it : sourcecode_map.keys()) - if(it == target.absoluteFilePath()) - return sourcecode_map[it]; - for(auto &it : plaintext_map.keys()) - if(it == target.absoluteFilePath()) - return plaintext_map[it]; - - return nullptr; -} - -void SensitiveCore::closeTextComponent(const QFileInfo &target) -{ - - for(auto &it : sourcecode_map.keys()){ - if(it == target.absoluteFilePath()){ - sourcecode_map[it]->save(); - delete sourcecode_map[it]; - sourcecode_map.remove(it); - } - } - for(auto &it : plaintext_map.keys()) - if(it == target.absoluteFilePath()){ - sourcecode_map[it]->save(); - delete sourcecode_map[it]; - sourcecode_map.remove(it); - } -} - -void SensitiveCore::addPerceptionList(TextView *ins, SensitiveType type) -{ - if(type == SensitiveType::CompileAtChanged){ - connect(ins, &TextView::dataChanged, [ins, this](const QString &path){ - this->recompile(path, ins->docName()); - }); - this->sourcecode_map[ins->filePath()] = ins; - } - else{ - this->plaintext_map[ins->filePath()] = ins; - } -} - -void SensitiveCore::addProcTrigger(std::function exc) -{ - this->trigger_list << exc; -} - -void SensitiveCore::recompile(const QString &file_path, const QString &doc_name) -{ - if(!sourcecode_map.contains(file_path)) - return; - - auto view = this->sourcecode_map[file_path]; - make_core->compileSource(QFileInfo(file_path), view->textContent(), doc_name); - - for(auto &ex : trigger_list) - ex(); -} - -TextView::TextView() - : QObject(nullptr){} - -void TextView::initSource(Core::AppCore *core, const QFileInfo &src, const QString &name, QWidget *parent) -{ - this->doc_name = name; - this->initSource(core, src, parent); -} - -QString TextView::filePath() const -{ - return source_x; -} - -void TextView::save() const -{ - QFile bout(filePath()); - if(!bout.open(QIODevice::WriteOnly|QIODevice::Text)){ - QMessageBox::critical(nullptr, "系统错误", filePath()+"文件无法打开"); - return; - } - - QTextStream tout(&bout); - tout << textContent(); - tout.flush(); -} - -QString TextView::docName() const -{ - return doc_name; -} - -void TextView::initSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent) -{ - this->source_x = src.absoluteFilePath(); - if(parent) - this->setParent(parent); -} diff --git a/WordsIDE/SourceEditView.cpp b/WordsIDE/SourceEditView.cpp index 84ccfdb..541f21b 100644 --- a/WordsIDE/SourceEditView.cpp +++ b/WordsIDE/SourceEditView.cpp @@ -76,7 +76,7 @@ FormattedTextEdit::FormattedTextEdit() { ex_unit = [](QMenu*){}; connect(edit_square, &QTextEdit::textChanged, [this](){ - emit this->dataChanged(this->filePath()); + emit this->dataChanged(this->absoluteFilePath()); }); edit_square->setContextMenuPolicy(Qt::CustomContextMenu); diff --git a/WordsIDE/SourceEditView.h b/WordsIDE/SourceEditView.h index c45cf15..34a6fff 100644 --- a/WordsIDE/SourceEditView.h +++ b/WordsIDE/SourceEditView.h @@ -1,7 +1,7 @@ #ifndef SOURCEEDITVIEW_H #define SOURCEEDITVIEW_H -#include "SensitiveCore.h" +#include "DocsManager.h" #include "ContentPresent.h" #include diff --git a/WordsIDE/WordsIDE.pro b/WordsIDE/WordsIDE.pro index c9febe3..edad0b8 100644 --- a/WordsIDE/WordsIDE.pro +++ b/WordsIDE/WordsIDE.pro @@ -10,7 +10,7 @@ CONFIG += c++11 SOURCES += \ ContentPresent.cpp \ - SensitiveCore.cpp \ + DocsManager.cpp \ SourceEditView.cpp \ appcore.cpp \ fragmentsorderview.cpp \ @@ -32,7 +32,7 @@ SOURCES += \ HEADERS += \ ContentPresent.h \ - SensitiveCore.h \ + DocsManager.h \ SourceEditView.h \ appcore.h \ fragmentsorderview.h \ diff --git a/WordsIDE/appcore.cpp b/WordsIDE/appcore.cpp index 588cc99..de66b81 100644 --- a/WordsIDE/appcore.cpp +++ b/WordsIDE/appcore.cpp @@ -4,7 +4,7 @@ #include "storyunitsourceedit.h" #include "storyboardsourceedit.h" #include "storyvolumesourceedit.h" -#include "SensitiveCore.h" +#include "DocsManager.h" #include "mainwindow.h" #include "sourcecodeeditor.h" @@ -21,9 +21,8 @@ using namespace MakeTools; AppCore::AppCore(MainWindow *win, QObject *parent) : QObject(parent), views_holder(win), global_config(new Config::XMLConfig(this)), - parse_core(new ParseCore()), - make_tool(new StoryTool(parse_core)), - framework(new SensitiveCore(make_tool)) + makes_core(new StoryTool()), + docs_manager(new DocsManager(makes_core, this, win)) { global_config->loadFile(QDir(QApplication::applicationDirPath()).filePath(".software.xml")); extensions_list << new StoryChainSourceEditFactory() @@ -70,7 +69,7 @@ QList AppCore::getConfigs(QList types) const Parse::Result::ParseCore *AppCore::parseCore() const { - return parse_core; + return makes_core->getCore(); } QList AppCore::extensions(const QString &suffix) const @@ -90,46 +89,14 @@ QList AppCore::extensions(const QString &suffix) const return rets; } -MakeTools::StoryTool *AppCore::getMake_tool() const +MakeTools::StoryTool *AppCore::getMakeCore() const { - return make_tool; + return makes_core; } -MakeTools::SensitiveCore *AppCore::getFramework() const +MakeTools::DocsManager *AppCore::getDocsManager() const { - return framework; -} - -void AppCore::openTextDocument(const QString &src, const QString &name) -{ - auto xfactorys = extensions(QFileInfo(src).suffix()); - if(framework->contains(src)){ - auto ins = framework->queryTextComponent(QFileInfo(src)); - - dynamic_cast(ins)->reloadConfigrations(this->getConfigs(xfactorys[0]->configs())); - views_holder->contentViewAppend(ins->textView(), name); - return; - } - - this->make_tool->compile(QFileInfo(src), name); - - TextView *tview = dynamic_cast(xfactorys[0]->newInstance(this)); - tview->initSource(this, QFileInfo(src), name, views_holder); - framework->addPerceptionList(tview); - - dynamic_cast(tview)->resetProcsType(QFileInfo(src).suffix()); - dynamic_cast(tview)->reloadConfigrations(this->getConfigs(xfactorys[0]->configs())); - - QFile fin(src); - if(!fin.open(QIODevice::ReadOnly | QIODevice::Text)){ - QMessageBox::critical(views_holder, "系统错误", QString("无法打开指定文件:%1(%2)").arg(name, src)); - return; - } - - QTextStream tin(&fin); - tview->textContentReset(tin.readAll()); - - views_holder->contentViewAppend(tview->textView(), name); + return docs_manager; } diff --git a/WordsIDE/appcore.h b/WordsIDE/appcore.h index e0295df..84f4182 100644 --- a/WordsIDE/appcore.h +++ b/WordsIDE/appcore.h @@ -10,7 +10,7 @@ class MainWindow; namespace MakeTools { class StoryTool; - class SensitiveCore; + class DocsManager; } namespace Core { @@ -104,14 +104,24 @@ namespace Core { }; + /** + * @brief 软件内核类型 + */ class AppCore : public QObject { public: AppCore(MainWindow *win, QObject *parent = nullptr); virtual ~AppCore() = default; + /** + * @brief 全局保存操作 + */ void save(); + /** + * @brief 全局配置端口 + * @return + */ Config::Configration * globalConfig() const; void setCurrentProject(Project::ProjectManager *project); @@ -121,22 +131,18 @@ namespace Core { QList extensions(const QString &suffix = QString()) const; - MakeTools::StoryTool *getMake_tool() const; + MakeTools::StoryTool *getMakeCore() const; - MakeTools::SensitiveCore *getFramework() const; - - - void openTextDocument(const QString &src, const QString &name); + MakeTools::DocsManager *getDocsManager() const; private: MainWindow *const views_holder; Config::Configration *const global_config; Project::ProjectManager * current_project; QList extensions_list; - Parse::Result::ParseCore *const parse_core; - MakeTools::StoryTool *const make_tool; - MakeTools::SensitiveCore *const framework; + MakeTools::StoryTool *const makes_core; + MakeTools::DocsManager *const docs_manager; }; } diff --git a/WordsIDE/fragmentsorderview.cpp b/WordsIDE/fragmentsorderview.cpp index 313eb4e..a5ef934 100644 --- a/WordsIDE/fragmentsorderview.cpp +++ b/WordsIDE/fragmentsorderview.cpp @@ -1,5 +1,5 @@ #include "fragmentsorderview.h" -#include "SensitiveCore.h" +#include "DocsManager.h" #include #include #include @@ -52,8 +52,8 @@ void FragmentsOrderView::double_click(const QModelIndex &index) auto unit_ins = this->core_ins->parseCore()->queryStoryUnit(path[0]).first(); auto unit_doc = unit_ins->doc(); - this->core_ins->openTextDocument(unit_doc->filePath(), unit_doc->docName()); - auto present = this->core_ins->getFramework()->queryTextComponent(QFileInfo(unit_doc->filePath())); + this->core_ins->getDocsManager()->openTextDocument(unit_doc->filePath(), unit_doc->docName()); + auto present = this->core_ins->getDocsManager()->queryTextComponent(QFileInfo(unit_doc->filePath())); if(path.size()){ present->jumpTo(path); diff --git a/WordsIDE/mainwindow.cpp b/WordsIDE/mainwindow.cpp index c0a679d..2d90960 100644 --- a/WordsIDE/mainwindow.cpp +++ b/WordsIDE/mainwindow.cpp @@ -43,7 +43,7 @@ MainWindow::MainWindow(QWidget *parent) project_structure(new ProjectView(app_core, project_manager, this)), chains_view(new StoryChainsPresent(app_core, this)), units_view(new StoryUnitsPresent(app_core, this)), - errors_present(new MessagePresent(app_core->getMake_tool(), this)), + errors_present(new MessagePresent(app_core->getMakeCore(), this)), boards_view(new StoryBoardsPresent(app_core, this)), concept_view(new StoryConceptsPresent(app_core, this)), fragments_order(new FragmentsOrderView(app_core, this)) @@ -106,7 +106,7 @@ MainWindow::MainWindow(QWidget *parent) sync_kernel->registerActionSync(sav, [this]()->bool{return project_manager->isOpen();}); connect(sav, &QAction::triggered, [this](){ this->project_manager->save(); - app_core->getFramework()->saveAll(); + app_core->getDocsManager()->saveAll(); }); project->addSeparator(); auto opnp = project->addAction("打开项目"); @@ -308,9 +308,7 @@ MainWindow::MainWindow(QWidget *parent) auto build = tool->addAction("编译", [this](){ this->build_internal(); }); - sync_kernel->registerActionSync(build, [this]()->bool{ - return project_manager->isOpen(); - }); + sync_kernel->registerActionSync(build, [this]()->bool{ return project_manager->isOpen(); }); // 窗口菜单 auto window = mbar->addMenu("窗口"); @@ -350,23 +348,23 @@ MainWindow::MainWindow(QWidget *parent) [this](int index){ auto view = center_funcs->widget(index); toggle_widget_visible(false, center_funcs, view); - auto comp = app_core->getFramework()->queryTextComponent(view); + auto comp = app_core->getDocsManager()->queryTextComponent(view); if(comp) - app_core->getFramework()->closeTextComponent(QFileInfo(comp->filePath())); + app_core->getDocsManager()->closeTextComponent(QFileInfo(comp->absoluteFilePath())); }); connect(project_structure, &ProjectView::aboutToBoDelete, [this](QList infos){ for(auto &key : infos){ - auto comp = app_core->getFramework()->queryTextComponent(key); + auto comp = app_core->getDocsManager()->queryTextComponent(key); if(comp){ toggle_widget_visible(false, center_funcs, comp->textView()); - app_core->getFramework()->closeTextComponent(key); + app_core->getDocsManager()->closeTextComponent(key); } } }); - this->app_core->getFramework()->addProcTrigger([this](){ + this->app_core->getDocsManager()->addProcTrigger([this](){ this->chains_view->refresh(); this->units_view->refresh(); this->errors_present->refresh(); @@ -379,7 +377,7 @@ MainWindow::MainWindow(QWidget *parent) center_funcs->addTab(current_projects, "欢迎界面"); connect(project_structure, &ProjectView::activeDocument, - app_core, &AppCore::openTextDocument); + app_core->getDocsManager(), &MakeTools::DocsManager::openTextDocument); uilayout_load(); @@ -410,27 +408,27 @@ void MainWindow::contentViewAppend(QWidget *widget, const QString &name) void MainWindow::build_internal(bool all_from_disk) { if(!all_from_disk) - app_core->getFramework()->saveAll(); + app_core->getDocsManager()->saveAll(); auto chains = project_manager->filesWithEnds("storychain"); for(auto &it : chains) - app_core->getMake_tool()->compile(std::get<0>(it), std::get<1>(it)); + app_core->getMakeCore()->compile(std::get<0>(it), std::get<1>(it)); auto units = project_manager->filesWithEnds("storyunit"); for(auto &it : units) - app_core->getMake_tool()->compile(std::get<0>(it), std::get<1>(it)); + app_core->getMakeCore()->compile(std::get<0>(it), std::get<1>(it)); auto storys = project_manager->filesWithEnds("storyboard"); for(auto &it : storys) - app_core->getMake_tool()->compile(std::get<0>(it), std::get<1>(it)); + app_core->getMakeCore()->compile(std::get<0>(it), std::get<1>(it)); auto volumes = project_manager->filesWithEnds("storyvolume"); for(auto &it : volumes) - app_core->getMake_tool()->compile(std::get<0>(it), std::get<1>(it)); + app_core->getMakeCore()->compile(std::get<0>(it), std::get<1>(it)); auto concepts = project_manager->filesWithEnds("storyconcept"); for(auto &it : concepts) - app_core->getMake_tool()->compile(std::get<0>(it), std::get<1>(it)); + app_core->getMakeCore()->compile(std::get<0>(it), std::get<1>(it)); errors_present->refresh(); chains_view->refresh(); @@ -514,7 +512,7 @@ void MainWindow::closeEvent(QCloseEvent *event) // 关闭事件 if(project_manager->isOpen()){ project_manager->save(); - app_core->getFramework()->saveAll(); + app_core->getDocsManager()->saveAll(); } uilayout_save(); diff --git a/WordsIDE/mainwindow.h b/WordsIDE/mainwindow.h index 4360f87..2eb61d7 100644 --- a/WordsIDE/mainwindow.h +++ b/WordsIDE/mainwindow.h @@ -8,7 +8,7 @@ #include #include #include -#include "SensitiveCore.h" +#include "DocsManager.h" #include "messagepresent.h" #include "storychainspresent.h" #include "storyunitspresent.h" diff --git a/WordsIDE/sourcecodeeditor.cpp b/WordsIDE/sourcecodeeditor.cpp index 1343c9d..f87f7fc 100644 --- a/WordsIDE/sourcecodeeditor.cpp +++ b/WordsIDE/sourcecodeeditor.cpp @@ -23,7 +23,7 @@ SourceCodeEditor::SourceCodeEditor(Core::FileExtensionFactory *factory) void SourceCodeEditor::concept_jump(const QList &path) { - auto fpath = this->filePath(); + auto fpath = this->absoluteFilePath(); auto core = core_ins->parseCore(); if(path.size()){ auto storynode = core->queryStoryConcept(path[0]).first(); diff --git a/WordsIDE/storyboardsourceedit.cpp b/WordsIDE/storyboardsourceedit.cpp index 7acfe3b..b17ae4f 100644 --- a/WordsIDE/storyboardsourceedit.cpp +++ b/WordsIDE/storyboardsourceedit.cpp @@ -70,7 +70,7 @@ void StoryBoardSourceEdit::initSource(Core::AppCore *core, const QFileInfo &src, void StoryBoardSourceEdit::jumpTo(const QList &path) { - auto fpath = this->filePath(); + auto fpath = this->absoluteFilePath(); auto core = core_temp->parseCore(); if(path.size()){ auto storynode = core->queryStoryBoard(path[0]).first(); diff --git a/WordsIDE/storychainsourceeditor.cpp b/WordsIDE/storychainsourceeditor.cpp index 0bf438a..98c77b9 100644 --- a/WordsIDE/storychainsourceeditor.cpp +++ b/WordsIDE/storychainsourceeditor.cpp @@ -79,7 +79,7 @@ void StoryChainSourceEdit::resetProcsType(const QString &suffix) void StoryChainSourceEdit::jumpTo(const QList &path) { - auto fpath = this->filePath(); + auto fpath = this->absoluteFilePath(); auto core = core_ins->parseCore(); if(path.size()){ auto storynode = core->queryStoryChain(path[0]).first(); diff --git a/WordsIDE/storychainsourceeditor.h b/WordsIDE/storychainsourceeditor.h index 57de3ca..8fe9214 100644 --- a/WordsIDE/storychainsourceeditor.h +++ b/WordsIDE/storychainsourceeditor.h @@ -2,7 +2,7 @@ #define STORYCHAINSOURCEEDITOR_H #include "ContentPresent.h" -#include "SensitiveCore.h" +#include "DocsManager.h" #include "SourceEditView.h" #include diff --git a/WordsIDE/storychainspresent.cpp b/WordsIDE/storychainspresent.cpp index 6f444a5..9cfa8c5 100644 --- a/WordsIDE/storychainspresent.cpp +++ b/WordsIDE/storychainspresent.cpp @@ -1,5 +1,5 @@ #include "storychainspresent.h" -#include "SensitiveCore.h" +#include "DocsManager.h" #include #include @@ -93,8 +93,8 @@ void StoryChainsPresent::click_to(const QModelIndex &curr) auto chain_ins = this->core_ins->parseCore()->queryStoryChain(path[0]).first(); auto chain_doc = chain_ins->doc(); - this->core_ins->openTextDocument(chain_doc->filePath(), chain_doc->docName()); - auto present = this->core_ins->getFramework()->queryTextComponent(QFileInfo(chain_doc->filePath())); + this->core_ins->getDocsManager()->openTextDocument(chain_doc->filePath(), chain_doc->docName()); + auto present = this->core_ins->getDocsManager()->queryTextComponent(QFileInfo(chain_doc->filePath())); if(path.size()){ present->jumpTo(path); diff --git a/WordsIDE/storyconceptspresent.cpp b/WordsIDE/storyconceptspresent.cpp index ea26366..380c621 100644 --- a/WordsIDE/storyconceptspresent.cpp +++ b/WordsIDE/storyconceptspresent.cpp @@ -1,5 +1,5 @@ #include "storyconceptspresent.h" -#include "SensitiveCore.h" +#include "DocsManager.h" #include "opstream.h" #include @@ -101,8 +101,8 @@ void StoryConceptsPresent::click_to(const QModelIndex &curr) auto unit_ins = this->core_ins->parseCore()->queryStoryConcept(path[0]).first(); auto chain_doc = unit_ins->doc(); - this->core_ins->openTextDocument(chain_doc->filePath(), chain_doc->docName()); - auto present = this->core_ins->getFramework()->queryTextComponent(QFileInfo(chain_doc->filePath())); + this->core_ins->getDocsManager()->openTextDocument(chain_doc->filePath(), chain_doc->docName()); + auto present = this->core_ins->getDocsManager()->queryTextComponent(QFileInfo(chain_doc->filePath())); if(path.size()){ present->jumpTo(path); diff --git a/WordsIDE/storyunitsourceedit.cpp b/WordsIDE/storyunitsourceedit.cpp index 5d20f71..8c3d661 100644 --- a/WordsIDE/storyunitsourceedit.cpp +++ b/WordsIDE/storyunitsourceedit.cpp @@ -91,7 +91,7 @@ void StoryUnitSourceEdit::cursor_contex_query() refers_model->setHorizontalHeaderLabels(QStringList() << "故事" << "内容"); auto cursor = edit_square->textCursor(); - auto doc = this->core_ins->parseCore()->queryDocument(QFileInfo(filePath())); + auto doc = this->core_ins->parseCore()->queryDocument(QFileInfo(absoluteFilePath())); auto words = doc->getWords(cursor.block().blockNumber()); QList frags; @@ -172,7 +172,7 @@ void StoryUnitSourceEdit::present_refersed_tips(const QString &unit, const QStri void StoryUnitSourceEdit::jumpTo(const QList &path) { - auto fpath = this->filePath(); + auto fpath = this->absoluteFilePath(); auto core = core_ins->parseCore(); if(path.size()){ auto storynode = core->queryStoryUnit(path[0]).first(); diff --git a/WordsIDE/storyunitspresent.cpp b/WordsIDE/storyunitspresent.cpp index fb0726b..6798797 100644 --- a/WordsIDE/storyunitspresent.cpp +++ b/WordsIDE/storyunitspresent.cpp @@ -1,5 +1,5 @@ #include "storyunitspresent.h" -#include "SensitiveCore.h" +#include "DocsManager.h" #include #include @@ -93,8 +93,8 @@ void StoryUnitsPresent::click_to(const QModelIndex &curr) auto unit_ins = this->core_ins->parseCore()->queryStoryUnit(path[0]).first(); auto chain_doc = unit_ins->doc(); - this->core_ins->openTextDocument(chain_doc->filePath(), chain_doc->docName()); - auto present = this->core_ins->getFramework()->queryTextComponent(QFileInfo(chain_doc->filePath())); + this->core_ins->getDocsManager()->openTextDocument(chain_doc->filePath(), chain_doc->docName()); + auto present = this->core_ins->getDocsManager()->queryTextComponent(QFileInfo(chain_doc->filePath())); if(path.size()){ present->jumpTo(path); diff --git a/libParse/StoryTool.cpp b/libParse/StoryTool.cpp index 08823ba..7388fed 100644 --- a/libParse/StoryTool.cpp +++ b/libParse/StoryTool.cpp @@ -11,8 +11,8 @@ using namespace Parse; using namespace Parse::Result; using namespace CheckTools; -StoryTool::StoryTool(Parse::Result::ParseCore *core) - : parse_core(core), fragment_check(new FragmentsCheck(core)){} +StoryTool::StoryTool() + : parse_core(new ParseCore()), fragment_check(new FragmentsCheck(parse_core)){} QList StoryTool::compile(const QFileInfo &file, const QString &doc_name) { @@ -59,7 +59,7 @@ QList StoryTool::compile(const QFileInfo &file, const QString &doc_name if(doc_core){ parse_core->registerDoc(doc_core); for(auto n : results) - parse_core->registerNode(doc_core, n); + doc_core->append(n); } return QList(); } @@ -109,7 +109,7 @@ QList StoryTool::compileSource(const QFileInfo &_file, const QString &s if(doc_core){ parse_core->registerDoc(doc_core); for(auto n : results) - parse_core->registerNode(doc_core, n); + doc_core->append(n); } return QList(); } @@ -129,13 +129,18 @@ bool StoryTool::checkPass(QList &errors) errors << error; } - for(auto &n : this->parse_core->queryRootNodes(d)) + for(auto &n : d->syntaxNodes()) error_check(n, errors); } fragment_check->check(errors); return errors.size() == 0; } +ParseCore *StoryTool::getCore() const +{ + return parse_core; +} + bool StoryTool::error_check(Parse::Result::DesNode * node, QList &err_out) { node->check(err_out); diff --git a/libParse/StoryTool.h b/libParse/StoryTool.h index 717e12e..10af100 100644 --- a/libParse/StoryTool.h +++ b/libParse/StoryTool.h @@ -14,12 +14,13 @@ namespace MakeTools { class LIBPARSE_EXPORT StoryTool { public: - StoryTool(Parse::Result::ParseCore *core); + StoryTool(); QList compile(const QFileInfo &file, const QString &doc_name); QList compileSource(const QFileInfo &file, const QString &src, const QString &doc_name); bool checkPass(QList &errors); + Parse::Result::ParseCore *getCore() const; private: Parse::Result::ParseCore *const parse_core; diff --git a/libParse/libParse.cpp b/libParse/libParse.cpp index 93d9c2d..509a1d1 100644 --- a/libParse/libParse.cpp +++ b/libParse/libParse.cpp @@ -109,46 +109,18 @@ ParseCore::ParseCore() void ParseCore::registerDoc(DocCore *ins) { - if(!nodes_map.contains(ins)) - nodes_map[ins] = new QList(); -} - -void ParseCore::registerNode(DocCore *doc, DesNode *node) -{ - if(!nodes_map.contains(doc)) - nodes_map[doc] = new QList(); - - nodes_map[doc]->append(node); -} - -void ParseCore::clearNodes(DocCore *ins) -{ - if(!nodes_map.contains(ins)) - return; - - auto c = nodes_map[ins]; - for(auto &i : *c) - delete i; - - c->clear(); + if(!doc_nodes.contains(ins)) + doc_nodes << ins; } QList ParseCore::allDocuments() const { - return nodes_map.keys(); -} - -QList ParseCore::queryRootNodes(DocCore *doc) const -{ - if(!nodes_map.contains(doc)) - return QList(); - - return *nodes_map[doc]; + return doc_nodes; } DocCore *ParseCore::queryDocument(const QFileInfo &file_src) const { - for(auto &d : nodes_map.keys()){ + for(auto &d : doc_nodes){ auto anchor_file = d->filePath(); if(anchor_file == file_src.absoluteFilePath()) return d; @@ -159,17 +131,27 @@ DocCore *ParseCore::queryDocument(const QFileInfo &file_src) const void ParseCore::deleteDocument(DocCore *ins) { ins->clear(); - nodes_map.remove(ins); + doc_nodes.removeAll(ins); delete ins; } +void ParseCore::clear() +{ + for(auto &ins : doc_nodes) { + ins->clear(); + delete ins; + } + + doc_nodes.clear(); +} + QList ParseCore::allStoryChains() const { QList retlist; - auto keys = nodes_map.keys(); - for(auto &k : keys) + + for(auto &k : doc_nodes) if(k->docType() == DocType::STORYCHAIN) - for(auto &n : *nodes_map[k]) + for(auto &n : k->syntaxNodes()) if(n->typeValue()==NODE_STORYCHAIN) retlist << n; @@ -201,10 +183,10 @@ QList ParseCore::queryStoryPoint(DesNode *chain, const QString QList ParseCore::allStoryUnits() const { QList retlist; - auto keys = nodes_map.keys(); - for(auto &k : keys) + + for(auto &k : doc_nodes) if(k->docType() == DocType::STORYUNIT) - for(auto &n : *nodes_map[k]){ + for(auto &n : k->syntaxNodes()){ if(n->typeValue()==NODE_STORYUNIT) retlist << n; } @@ -264,10 +246,9 @@ QList ParseCore::allStoryBoards() const { QList retlist; - auto keys = nodes_map.keys(); - for(auto &k : keys) + for(auto &k : doc_nodes) if(k->docType() == DocType::STORYBOARD) - for(auto &n : *nodes_map[k]){ + for(auto &n : k->syntaxNodes()){ if(n->typeValue() == NODE_STORYBOARD) retlist << n; } @@ -300,9 +281,10 @@ QList ParseCore::queryStoryFragmentRefer(DesNode *unit, const QString QList ParseCore::allStoryConcept() const { QList rets; - for(auto &it : nodes_map.keys()){ + + for(auto &it : doc_nodes){ if(it->docType() == DocType::STORYCONCEPTS) - for(auto n : *nodes_map[it]) + for(auto n : it->syntaxNodes()) if(n->typeValue() == NODE_STORYCONCEPT) rets << n; } @@ -336,9 +318,10 @@ QList ParseCore::queryStoryStrongPoint(DesNode *concept, const QStrin QList ParseCore::queryStoryDepiction(const QString &name) const { QList retlist; - for(auto &it : nodes_map.keys()) { + + for(auto &it : doc_nodes) { if(it->docType() == DocType::STORYOUTLINES) - for(auto &n : *nodes_map[it]) + for(auto &n : it->syntaxNodes()) if(n->typeValue() == NODE_STORYDEPICTION && static_cast(n)->name()[0] == name) retlist << n; @@ -419,9 +402,12 @@ void DocCore::clear() { for(auto &it : words_store) delete it; - words_store.clear(); - core()->clearNodes(this); + + for(auto &it : root_nodes) + delete it; + root_nodes.clear(); + static_cast(unknown_host)->xClear(); } @@ -446,3 +432,14 @@ QList DocCore::getWords(int row, int col) const return list; } + +int DocCore::append(DesNode *ins) +{ + this->root_nodes.append(ins); + return 0; +} + +QList DocCore::syntaxNodes() const +{ + return this->root_nodes; +} diff --git a/libParse/libParse.h b/libParse/libParse.h index dcc4800..23301cc 100644 --- a/libParse/libParse.h +++ b/libParse/libParse.h @@ -276,6 +276,9 @@ namespace Parse */ QList getWords(int row, int col=-1) const; + int append(DesNode *ins); + QList syntaxNodes() const; + private: Result::DesNode *const unknown_host; ParseCore *const core_store; @@ -284,6 +287,7 @@ namespace Parse DocType type_store; QList words_store; + QList root_nodes; }; /** @@ -292,20 +296,16 @@ namespace Parse class LIBPARSE_EXPORT ParseCore { private: - QHash*> nodes_map; + QList doc_nodes; public: explicit ParseCore(); virtual ~ParseCore() = default; virtual void registerDoc(DocCore *ins); - virtual void registerNode(DocCore *doc, DesNode *node); - virtual void clearNodes(DocCore *ins); virtual QList allDocuments() const; - virtual QList queryRootNodes(DocCore *doc) const; - /** * 获取文档内存实例,如果不存在指定实例,返回nullptr. * @@ -314,6 +314,7 @@ namespace Parse */ virtual Result::DocCore* queryDocument(const QFileInfo &file_src) const; virtual void deleteDocument(Result::DocCore *ins); + virtual void clear(); virtual QList allStoryChains() const; virtual QList queryStoryChain(const QString & name) const;