文档打开操作提升到系统核心
This commit is contained in:
parent
9c9febe9db
commit
45f638dac6
|
@ -5,8 +5,11 @@
|
|||
#include "storyboardsourceedit.h"
|
||||
#include "storyvolumesourceedit.h"
|
||||
#include "SensitiveCore.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QTextStream>
|
||||
#include <StoryTool.h>
|
||||
|
||||
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<VariedTextView*>(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<Core::FileExtension*>(tview)->reload(this->getConfigs(QList<Scale>() << 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);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <libParse.h>
|
||||
#include <libProjectManager.h>
|
||||
|
||||
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<Core::FileExtensionFactory*> extensions_list;
|
||||
|
|
|
@ -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<VariedTextView*>(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<Core::FileExtension*>(tview)->reload(app_core->getConfigs(QList<Scale>() << 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();
|
||||
});
|
||||
app_core, &AppCore::openTextDocument);
|
||||
|
||||
uilayout_load();
|
||||
|
||||
|
@ -372,6 +337,19 @@ MainWindow::~MainWindow()
|
|||
{
|
||||
}
|
||||
|
||||
void MainWindow::contentViewAppend(QWidget *widget, const QString &name)
|
||||
{
|
||||
for(auto idx=0; idx<center_funcs->count(); ++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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue