137 lines
3.7 KiB
C++
137 lines
3.7 KiB
C++
#include "appcore.h"
|
|
#include "xmlconfig.h"
|
|
#include "storychainsourceeditor.h"
|
|
#include "storyunitsourceedit.h"
|
|
#include "storyboardsourceedit.h"
|
|
#include "storyvolumesourceedit.h"
|
|
#include "SensitiveCore.h"
|
|
#include "mainwindow.h"
|
|
#include "sourcecodeeditor.h"
|
|
|
|
#include <QApplication>
|
|
#include <QMessageBox>
|
|
#include <QTextStream>
|
|
#include <StoryTool.h>
|
|
|
|
using namespace Core;
|
|
using namespace Components;
|
|
using namespace Parse::Result;
|
|
using namespace MakeTools;
|
|
|
|
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))
|
|
{
|
|
global_config->loadFile(QDir(QApplication::applicationDirPath()).filePath(".software.xml"));
|
|
extensions_list << new StoryChainSourceEditFactory()
|
|
<< new StoryUnitSourceEditFactory
|
|
<< new StoryBoardSourceEditFactory()
|
|
<< new StoryVolumeSourceEditFactory()
|
|
<< new TextContentEditFactory()
|
|
<< new SourceCodeEditorFactory();
|
|
}
|
|
|
|
void AppCore::save()
|
|
{
|
|
global_config->save();
|
|
}
|
|
|
|
Config::Configration *AppCore::globalConfig() const
|
|
{
|
|
return global_config;
|
|
}
|
|
|
|
void AppCore::setCurrentProject(Project::ProjectManager *project)
|
|
{
|
|
this->current_project = project;
|
|
}
|
|
|
|
Project::ProjectManager *AppCore::currentProject() const
|
|
{
|
|
return this->current_project;
|
|
}
|
|
|
|
QList<Config::Configration *> AppCore::getConfigs(QList<Scale> types) const
|
|
{
|
|
QList<Config::Configration*> rets;
|
|
|
|
for(auto &x : types){
|
|
if(x == Scale::Global)
|
|
rets << global_config;
|
|
if(x == Scale::Project && current_project->isOpen())
|
|
rets << current_project->configraions();
|
|
}
|
|
|
|
return rets;
|
|
}
|
|
|
|
Parse::Result::ParseCore *AppCore::parseCore() const
|
|
{
|
|
return parse_core;
|
|
}
|
|
|
|
QList<FileExtensionFactory *> AppCore::extensions(const QString &suffix) const
|
|
{
|
|
if(suffix.isEmpty())
|
|
return this->extensions_list;
|
|
|
|
QList<FileExtensionFactory*> rets;
|
|
for(auto &ext : extensions_list)
|
|
if(ext->suffixPeers().contains(suffix))
|
|
rets << ext;
|
|
|
|
for(auto &ext : extensions_list)
|
|
if(ext->suffixPeers().contains("*"))
|
|
rets << ext;
|
|
|
|
return rets;
|
|
}
|
|
|
|
MakeTools::StoryTool *AppCore::getMake_tool() const
|
|
{
|
|
return make_tool;
|
|
}
|
|
|
|
MakeTools::SensitiveCore *AppCore::getFramework() 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<Extension*>(ins)->resetProcsType(QFileInfo(src).suffix());
|
|
dynamic_cast<Core::Extension*>(ins)->reload(this->getConfigs(xfactorys[0]->configs()));
|
|
views->contentViewAppend(ins->textView(), name);
|
|
return;
|
|
}
|
|
|
|
VariedTextView *tview = dynamic_cast<VariedTextView*>(xfactorys[0]->newInstance(this));
|
|
dynamic_cast<Extension*>(tview)->resetProcsType(QFileInfo(src).suffix());
|
|
dynamic_cast<Core::Extension*>(tview)->reload(this->getConfigs(xfactorys[0]->configs()));
|
|
|
|
this->make_tool->compile(QFileInfo(src), name);
|
|
tview->setSource(this, QFileInfo(src), name, views);
|
|
framework->addPerceptionList(tview);
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
|