diff --git a/WordsIDE/appcore.cpp b/WordsIDE/appcore.cpp index 5a67484..92cd8a6 100644 --- a/WordsIDE/appcore.cpp +++ b/WordsIDE/appcore.cpp @@ -5,8 +5,11 @@ #include "storyboardsourceedit.h" #include "storyvolumesourceedit.h" #include "SensitiveCore.h" +#include "mainwindow.h" #include +#include +#include #include using namespace Core; @@ -14,8 +17,9 @@ using namespace Components; using namespace Parse::Result; using namespace MakeTools; -AppCore::AppCore(QObject *parent) - : QObject(parent), global_config(new Config::XMLConfig(this)), +AppCore::AppCore(MainWindow *win, QObject *parent) + : QObject(parent), views(win), + global_config(new Config::XMLConfig(this)), parse_core(new ParseCore()), make_tool(new StoryTool(parse_core)), framework(new SensitiveCore(make_tool)) @@ -93,3 +97,36 @@ MakeTools::SensitiveCore *AppCore::getFramework() const { return framework; } + +void AppCore::openTextDocument(const QString &src, const QString &name) +{ + if(framework->contains(src)){ + auto ins = framework->queryTextComponent(QFileInfo(src)); + views->contentViewAppend(ins->textView(), name); + return; + } + + auto xfactorys = extensions(QFileInfo(src).suffix()); + VariedTextView *tview = dynamic_cast(xfactorys[0]->newInstance(this)); + + auto doc = parse_core->queryDocument(QFileInfo(src)); + if(doc == nullptr){ + this->make_tool->compile(QFileInfo(src)); + doc = parse_core->queryDocument(QFileInfo(src)); + } + + tview->setSource(this, QFileInfo(src), views); + framework->addPerceptionList(tview); + dynamic_cast(tview)->reload(this->getConfigs(QList() << Scale::Global << Scale::Project)); + + QFile fin(src); + if(!fin.open(QIODevice::ReadOnly | QIODevice::Text)){ + QMessageBox::critical(views, "系统错误", QString("无法打开指定文件:%1(%2)").arg(name, src)); + return; + } + + QTextStream tin(&fin); + tview->textContentReset(tin.readAll()); + + views->contentViewAppend(tview->textView(), name); +} diff --git a/WordsIDE/appcore.h b/WordsIDE/appcore.h index 078b1fe..e185f26 100644 --- a/WordsIDE/appcore.h +++ b/WordsIDE/appcore.h @@ -6,6 +6,8 @@ #include #include +class MainWindow; + namespace MakeTools { class StoryTool; class SensitiveCore; @@ -79,7 +81,7 @@ namespace Core { class AppCore : public QObject { public: - AppCore(QObject *parent = nullptr); + AppCore(MainWindow *win, QObject *parent = nullptr); virtual ~AppCore() = default; void save(); @@ -97,7 +99,11 @@ namespace Core { MakeTools::SensitiveCore *getFramework() const; + + void openTextDocument(const QString &src, const QString &name); + private: + MainWindow *const views; Config::Configration *const global_config; Project::ProjectManager * current_project; QList extensions_list; diff --git a/WordsIDE/mainwindow.cpp b/WordsIDE/mainwindow.cpp index 9545401..7eec62f 100644 --- a/WordsIDE/mainwindow.cpp +++ b/WordsIDE/mainwindow.cpp @@ -319,44 +319,9 @@ MainWindow::MainWindow(QWidget *parent) center_funcs->addTab(current_projects, "欢迎界面"); - connect(project_structure, &ProjectView::activeDocument, - [this](const QString &file_path, const QString &name){ - if(app_core->getFramework()->contains(file_path)){ - auto ins = app_core->getFramework()->queryTextComponent(QFileInfo(file_path)); - center_funcs->setCurrentWidget(ins->textView()); - return; - } - auto xfactorys = app_core->extensions(QFileInfo(file_path).suffix()); - VariedTextView *tview = dynamic_cast(xfactorys[0]->newInstance(app_core)); - - auto doc = app_core->parseCore()->queryDocument(QFileInfo(file_path)); - if(doc == nullptr){ - this->app_core->getMake_tool()->compile(QFileInfo(file_path)); - doc = app_core->parseCore()->queryDocument(QFileInfo(file_path)); - } - - tview->setSource(app_core, QFileInfo(file_path), this); - app_core->getFramework()->addPerceptionList(tview); - dynamic_cast(tview)->reload(app_core->getConfigs(QList() << Scale::Global << Scale::Project)); - - QFile fin(file_path); - if(!fin.open(QIODevice::ReadOnly | QIODevice::Text)){ - QMessageBox::critical(this, "系统错误", QString("无法打开指定文件:%1(%2)").arg(name, file_path)); - return; - } - - QTextStream tin(&fin); - tview->textContentReset(tin.readAll()); - - center_funcs->addTab(tview->textView(), name); - center_funcs->setCurrentWidget(tview->textView()); - }); - app_core->getFramework()->addProcTrigger([this](){ - errors_present->refresh(); - chains_view->refresh(); - units_view->refresh(); - }); + connect(project_structure, &ProjectView::activeDocument, + app_core, &AppCore::openTextDocument); uilayout_load(); @@ -372,6 +337,19 @@ MainWindow::~MainWindow() { } +void MainWindow::contentViewAppend(QWidget *widget, const QString &name) +{ + for(auto idx=0; idxcount(); ++idx){ + if(center_funcs->widget(idx) == widget){ + center_funcs->setCurrentWidget(widget); + } + else { + center_funcs->addTab(widget, name); + center_funcs->setCurrentWidget(widget); + } + } +} + void MainWindow::build_internal(bool all_from_disk) { if(!all_from_disk) diff --git a/WordsIDE/mainwindow.h b/WordsIDE/mainwindow.h index a847d95..65607d6 100644 --- a/WordsIDE/mainwindow.h +++ b/WordsIDE/mainwindow.h @@ -56,6 +56,8 @@ public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); + void contentViewAppend(QWidget *widget, const QString &name); + private: Core::AppCore *const app_core; StatusSyncCore *const sync_kernel;