154 lines
3.8 KiB
C++
154 lines
3.8 KiB
C++
#include "srcedit_storyboard.h"
|
|
#include "keywordshighlighter.h"
|
|
#include <QComboBox>
|
|
#include <QMenu>
|
|
#include <QSpinBox>
|
|
#include <QTextStream>
|
|
#include <QVBoxLayout>
|
|
|
|
using namespace Components;
|
|
using namespace Parse::Result;
|
|
using namespace Enhancement;
|
|
using namespace Core;
|
|
|
|
|
|
StorySourceEdit::StorySourceEdit()
|
|
: 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();
|
|
}
|
|
|
|
QWidget *StorySourceEdit::widget() const
|
|
{
|
|
return edit_square;
|
|
}
|
|
|
|
QString StorySourceEdit::name() const
|
|
{
|
|
return this->name_store;
|
|
}
|
|
|
|
void StorySourceEdit::load(const QFileInfo &target_file)
|
|
{
|
|
if(!target_file.exists())
|
|
throw new SimpleException("参数错误:传入的文件不存在");
|
|
if(!target_file.isFile())
|
|
throw new SimpleException("参数错误:传入参数非文件类型");
|
|
|
|
filepath_store = target_file.absoluteFilePath();
|
|
QFile bin(filepath_store);
|
|
if(!bin.open(QIODevice::ReadOnly|QIODevice::Text))
|
|
throw new SimpleException("参数错误:指定的文件无法打开");
|
|
|
|
QTextStream tin(&bin);
|
|
tin.setCodec("UTF-8");
|
|
this->edit_square->setText(tin.readAll());
|
|
}
|
|
|
|
void StorySourceEdit::saveAs(const QString &path)
|
|
{
|
|
if(!path.isEmpty())
|
|
filepath_store = path;
|
|
|
|
QFile bout(filepath_store);
|
|
if(!bout.open(QIODevice::WriteOnly|QIODevice::Text))
|
|
throw new SimpleException("参数错误:指定的文件无法打开");
|
|
|
|
QTextStream tout(&bout);
|
|
tout.setCodec("UTF-8");
|
|
tout << this->edit_square->toPlainText();
|
|
tout.flush();
|
|
}
|
|
|
|
QString StorySourceEdit::relativeTargetPath(const QDir &base) const
|
|
{
|
|
return base.relativeFilePath(filepath_store);
|
|
}
|
|
|
|
QString StorySourceEdit::absoluteTargetPath() const
|
|
{
|
|
return filepath_store;
|
|
}
|
|
|
|
QString StorySourceEdit::getText() const
|
|
{
|
|
return edit_square->toPlainText();
|
|
}
|
|
|
|
bool StorySourceEdit::isModified() const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void StorySourceEdit::applySetting(const QString &name, Core::AppCore *core)
|
|
{
|
|
this->name_store = name;
|
|
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
MakeTools::FilePresent::Features StorySourceEdit::features()
|
|
{
|
|
return Feature::Compile | Feature::HighLight;
|
|
}
|