#include "srcedit_storyboard.h" #include "keywordshighlighter.h" #include #include #include #include #include using namespace Enhancement; using namespace Core; using namespace Config; using namespace Presents; QString StorySourceEdit::file_suffix = "storyboard"; StorySourceEdit::StorySourceEdit(DocumentsManager *mgr, const Route &p, QObject *parent) : FilePresent(parent), mgr_inst(mgr), path_store(p), edit_square(new QTextEdit) { // words_highlighter->setDocument(this->edit_square->document()); connect(edit_square, &QTextEdit::textChanged, [this](){ emit this->dataChanged(filepath_store); }); } void StorySourceEdit::contexBinding(Core::AppCore *app) { this->core_temp = app; } void StorySourceEdit::renderRepeat() const { // this->words_highlighter->rehighlight(); } 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("参数错误", "传入的文件不存在:" + target_file.absoluteFilePath()); if(!target_file.isFile()) throw new SimpleException("参数错误", "传入参数非文件类型:" + target_file.absoluteFilePath()); filepath_store = target_file.canonicalFilePath(); QFile bin(filepath_store); if(!bin.open(QIODevice::ReadOnly|QIODevice::Text)) throw new SimpleException("参数错误", "指定的文件无法打开:" + target_file.absoluteFilePath()); 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("保存文件参数错误", "指定的文件无法打开:" + path); 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; } bool StorySourceEdit::isModified() const { return true; } void StorySourceEdit::applySetting(const QString &name) { this->name_store = name; } void StorySourceEdit::jumpTo(const QList &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); // } } #include "manager_docs.h" void StorySourceEdit::beforeClose() { mgr_inst->save(); } DocumentsManager *StorySourceEdit::docsManager() const { return mgr_inst; } Route StorySourceEdit::accessPath() const { return path_store; } void StorySourceEditFactory::create(const QFileInfo &target) { QFile base_f(target.canonicalFilePath()); if (!base_f.exists()) { throw new SimpleException("新建错误", "指定路径不合法,文件不存在:" + target.absoluteFilePath()); } if (!base_f.open(QIODevice::WriteOnly | QIODevice::Text)) throw new SimpleException("新建错误", QString("指定文件无法建立:" + target.absoluteFilePath())); base_f.write(" "); base_f.flush(); base_f.close(); }