移除了分类型特化源码编辑视图
This commit is contained in:
parent
0566da9f72
commit
0d583e648f
|
@ -34,10 +34,6 @@ SOURCES += \
|
|||
route.cpp \
|
||||
srcedit_defaulttext.cpp \
|
||||
srcedit_storyboard.cpp \
|
||||
srcedit_storychain.cpp \
|
||||
srcedit_storyconcept.cpp \
|
||||
srcedit_storyunit.cpp \
|
||||
srcedit_storyvolume.cpp \
|
||||
tools.cpp \
|
||||
welcomepanel.cpp \
|
||||
xapp.cpp
|
||||
|
@ -59,10 +55,6 @@ HEADERS += \
|
|||
route.h \
|
||||
srcedit_defaulttext.h \
|
||||
srcedit_storyboard.h \
|
||||
srcedit_storychain.h \
|
||||
srcedit_storyconcept.h \
|
||||
srcedit_storyunit.h \
|
||||
srcedit_storyvolume.h \
|
||||
tools.h \
|
||||
welcomepanel.h \
|
||||
xapp.h
|
||||
|
|
|
@ -24,7 +24,7 @@ AppCore::AppCore(QObject *parent) : QObject(parent), global_config(new Config::X
|
|||
|
||||
auto ins0 = new StorychainSourceEdit();
|
||||
auto ins1 = new StoryunitSourceEdit();
|
||||
auto ins2 = new StoryboardSourceEdit();
|
||||
auto ins2 = new StorySourceEdit();
|
||||
auto ins3 = new StoryvolumeSourceEdit();
|
||||
auto ins4 = new StoryconceptSourceEdit();
|
||||
registerHighlightType(ins0);
|
||||
|
|
|
@ -12,7 +12,7 @@ using namespace Enhancement;
|
|||
using namespace Core;
|
||||
|
||||
|
||||
StoryboardSourceEdit::StoryboardSourceEdit()
|
||||
StorySourceEdit::StorySourceEdit()
|
||||
: words_highlighter(new KeywordsHighlighter(this)),
|
||||
edit_square(new QTextEdit)
|
||||
{
|
||||
|
@ -22,31 +22,31 @@ StoryboardSourceEdit::StoryboardSourceEdit()
|
|||
});
|
||||
}
|
||||
|
||||
void StoryboardSourceEdit::modeReset(const QString &) const{}
|
||||
void StorySourceEdit::modeReset(const QString &) const{}
|
||||
|
||||
QList<QString> StoryboardSourceEdit::modes() const
|
||||
QList<QString> StorySourceEdit::modes() const
|
||||
{
|
||||
return QList<QString>() << "源码";
|
||||
}
|
||||
|
||||
QString StoryboardSourceEdit::currentMode() const
|
||||
QString StorySourceEdit::currentMode() const
|
||||
{
|
||||
return modes()[0];
|
||||
}
|
||||
|
||||
void StoryboardSourceEdit::contexBinding(Core::AppCore *app) { this->core_temp = app; }
|
||||
void StorySourceEdit::contexBinding(Core::AppCore *app) { this->core_temp = app; }
|
||||
|
||||
void StoryboardSourceEdit::renderRepeat() const
|
||||
void StorySourceEdit::renderRepeat() const
|
||||
{
|
||||
this->words_highlighter->rehighlight();
|
||||
}
|
||||
|
||||
QList<QString> StoryboardSourceEdit::suffixes() const
|
||||
QList<QString> StorySourceEdit::suffixes() const
|
||||
{
|
||||
return QList<QString>() << "storyboard";
|
||||
}
|
||||
|
||||
std::tuple<bool, QString> StoryboardSourceEdit::create(const QDir &target, const QString &name, const QString &suffix)
|
||||
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))
|
||||
|
@ -59,22 +59,22 @@ std::tuple<bool, QString> StoryboardSourceEdit::create(const QDir &target, const
|
|||
return std::make_tuple(true, target.relativeFilePath(path));
|
||||
}
|
||||
|
||||
MakeTools::FilePresent *StoryboardSourceEdit::newInst() const
|
||||
MakeTools::FilePresent *StorySourceEdit::newInst() const
|
||||
{
|
||||
return new StoryboardSourceEdit();
|
||||
return new StorySourceEdit();
|
||||
}
|
||||
|
||||
QWidget *StoryboardSourceEdit::widget() const
|
||||
QWidget *StorySourceEdit::widget() const
|
||||
{
|
||||
return edit_square;
|
||||
}
|
||||
|
||||
QString StoryboardSourceEdit::name() const
|
||||
QString StorySourceEdit::name() const
|
||||
{
|
||||
return this->name_store;
|
||||
}
|
||||
|
||||
void StoryboardSourceEdit::load(const QFileInfo &target_file)
|
||||
void StorySourceEdit::load(const QFileInfo &target_file)
|
||||
{
|
||||
if(!target_file.exists())
|
||||
throw new SimpleException("参数错误:传入的文件不存在");
|
||||
|
@ -91,7 +91,7 @@ void StoryboardSourceEdit::load(const QFileInfo &target_file)
|
|||
this->edit_square->setText(tin.readAll());
|
||||
}
|
||||
|
||||
void StoryboardSourceEdit::saveAs(const QString &path)
|
||||
void StorySourceEdit::saveAs(const QString &path)
|
||||
{
|
||||
if(!path.isEmpty())
|
||||
filepath_store = path;
|
||||
|
@ -106,33 +106,33 @@ void StoryboardSourceEdit::saveAs(const QString &path)
|
|||
tout.flush();
|
||||
}
|
||||
|
||||
QString StoryboardSourceEdit::relativeTargetPath(const QDir &base) const
|
||||
QString StorySourceEdit::relativeTargetPath(const QDir &base) const
|
||||
{
|
||||
return base.relativeFilePath(filepath_store);
|
||||
}
|
||||
|
||||
QString StoryboardSourceEdit::absoluteTargetPath() const
|
||||
QString StorySourceEdit::absoluteTargetPath() const
|
||||
{
|
||||
return filepath_store;
|
||||
}
|
||||
|
||||
QString StoryboardSourceEdit::getText() const
|
||||
QString StorySourceEdit::getText() const
|
||||
{
|
||||
return edit_square->toPlainText();
|
||||
}
|
||||
|
||||
bool StoryboardSourceEdit::isModified() const
|
||||
bool StorySourceEdit::isModified() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void StoryboardSourceEdit::applySetting(const QString &name, Core::AppCore *core)
|
||||
void StorySourceEdit::applySetting(const QString &name, Core::AppCore *core)
|
||||
{
|
||||
this->name_store = name;
|
||||
|
||||
}
|
||||
|
||||
void StoryboardSourceEdit::jumpTo(const QList<QString> &path)
|
||||
void StorySourceEdit::jumpTo(const QList<QString> &path)
|
||||
{
|
||||
auto fpath = this->absoluteTargetPath();
|
||||
auto core = core_temp->parseCore();
|
||||
|
@ -147,7 +147,7 @@ void StoryboardSourceEdit::jumpTo(const QList<QString> &path)
|
|||
}
|
||||
}
|
||||
|
||||
MakeTools::FilePresent::Features StoryboardSourceEdit::features()
|
||||
MakeTools::FilePresent::Features StorySourceEdit::features()
|
||||
{
|
||||
return Feature::Compile | Feature::HighLight;
|
||||
}
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
|
||||
namespace Components {
|
||||
|
||||
class StoryboardSourceEdit : public Presents::ModeView, public MakeTools::CompileFeature,
|
||||
public MakeTools::FilePresent, public Enhancement::HighlightFeature
|
||||
{
|
||||
class StorySourceEdit : public Presents::ModeView,
|
||||
public MakeTools::CompileFeature,
|
||||
public MakeTools::FilePresent,
|
||||
public Enhancement::HighlightFeature {
|
||||
public:
|
||||
StoryboardSourceEdit();
|
||||
virtual ~StoryboardSourceEdit() = default;
|
||||
StorySourceEdit();
|
||||
virtual ~StorySourceEdit() = default;
|
||||
|
||||
// ModeView interface
|
||||
public:
|
||||
|
|
|
@ -1,178 +0,0 @@
|
|||
#include "srcedit_storychain.h"
|
||||
#include "keywordshighlighter.h"
|
||||
#include <QMenu>
|
||||
#include <QDebug>
|
||||
#include <QVBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QSpinBox>
|
||||
|
||||
using namespace Enhancement;
|
||||
using namespace Parse::Result;
|
||||
using namespace Core;
|
||||
using namespace Components;
|
||||
|
||||
StorychainSourceEdit::StorychainSourceEdit()
|
||||
: highter_ins(new KeywordsHighlighter(this)), edit_square(new QTextEdit)
|
||||
{
|
||||
connect(edit_square, &QTextEdit::textChanged, [this](){
|
||||
emit this->dataChanged(filepath_store);
|
||||
});
|
||||
highter_ins->setDocument(edit_square->document());
|
||||
}
|
||||
|
||||
void StorychainSourceEdit::contexBinding(AppCore *app) { app_core = app; }
|
||||
|
||||
void StorychainSourceEdit::renderRepeat() const
|
||||
{
|
||||
highter_ins->rehighlight();
|
||||
}
|
||||
|
||||
void StorychainSourceEdit::modeReset(const QString &) const{}
|
||||
|
||||
QList<QString> StorychainSourceEdit::modes() const
|
||||
{
|
||||
return QList<QString>() << "源码";
|
||||
}
|
||||
|
||||
QString StorychainSourceEdit::currentMode() const
|
||||
{
|
||||
return modes()[0];
|
||||
}
|
||||
|
||||
QList<QString> StorychainSourceEdit::suffixes() const
|
||||
{
|
||||
return QList<QString>() << "storychain";
|
||||
}
|
||||
|
||||
std::tuple<bool, QString> StorychainSourceEdit::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("指定文件");
|
||||
|
||||
return std::make_tuple(true, target.relativeFilePath(path));
|
||||
}
|
||||
|
||||
MakeTools::FilePresent *StorychainSourceEdit::newInst() const
|
||||
{
|
||||
return new StorychainSourceEdit();
|
||||
}
|
||||
|
||||
QWidget *StorychainSourceEdit::widget() const
|
||||
{
|
||||
return edit_square;
|
||||
}
|
||||
|
||||
void StorychainSourceEdit::applySetting(const QString &name, Core::AppCore *core)
|
||||
{
|
||||
this->name_store = name;
|
||||
}
|
||||
|
||||
QString StorychainSourceEdit::name() const
|
||||
{
|
||||
return name_store;
|
||||
}
|
||||
|
||||
void StorychainSourceEdit::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 StorychainSourceEdit::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 StorychainSourceEdit::relativeTargetPath(const QDir &base) const
|
||||
{
|
||||
return base.relativeFilePath(filepath_store);
|
||||
}
|
||||
|
||||
QString StorychainSourceEdit::absoluteTargetPath() const
|
||||
{
|
||||
return filepath_store;
|
||||
}
|
||||
|
||||
QString StorychainSourceEdit::getText() const
|
||||
{
|
||||
return edit_square->toPlainText();
|
||||
}
|
||||
|
||||
bool StorychainSourceEdit::isModified() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void StorychainSourceEdit::jumpTo(const QList<QString> &path)
|
||||
{
|
||||
auto fpath = this->absoluteTargetPath();
|
||||
auto core = app_core->parseCore();
|
||||
if(path.size()){
|
||||
auto storynode = core->queryStoryChain(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());
|
||||
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
||||
this->edit_square->setTextCursor(cur);
|
||||
|
||||
if(path.size() > 1){
|
||||
auto storypoint = core->queryStoryPoint(storynode, path[1]).first();
|
||||
first_word = storypoint->refered()[0];
|
||||
|
||||
auto textblock = this->edit_square->document()->findBlockByNumber(first_word->row());
|
||||
cur.setPosition(textblock.position());
|
||||
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
||||
this->edit_square->setTextCursor(cur);
|
||||
}
|
||||
}
|
||||
|
||||
this->widget()->setFocus();
|
||||
}
|
||||
|
||||
MakeTools::FilePresent::Features StorychainSourceEdit::features()
|
||||
{
|
||||
return Feature::Compile | Feature::HighLight;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
#ifndef SRCEDIT_STORYCHAIN_H
|
||||
#define SRCEDIT_STORYCHAIN_H
|
||||
|
||||
#include "ContentPresent.h"
|
||||
#include "DocsManager.h"
|
||||
#include "srcedit_defaulttext.h"
|
||||
#include "keywordshighlighter.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QSyntaxHighlighter>
|
||||
|
||||
namespace Components {
|
||||
|
||||
/**
|
||||
* @brief Storychain详情属性展示
|
||||
*/
|
||||
class StorychainSourceEdit : public Presents::ModeView, public MakeTools::CompileFeature,
|
||||
public MakeTools::FilePresent, public Enhancement::HighlightFeature
|
||||
{
|
||||
public:
|
||||
StorychainSourceEdit();
|
||||
virtual ~StorychainSourceEdit() = default;
|
||||
|
||||
private:
|
||||
QSyntaxHighlighter *const highter_ins;
|
||||
Core::AppCore *app_core;
|
||||
QTextEdit *edit_square;
|
||||
QString name_store;
|
||||
QString filepath_store;
|
||||
|
||||
// HighlightDemand interface
|
||||
public:
|
||||
virtual void contexBinding(Core::AppCore *app) override;
|
||||
virtual void renderRepeat() const override;
|
||||
|
||||
// ModeView interface
|
||||
public:
|
||||
virtual void modeReset(const QString &) const override;
|
||||
virtual QList<QString> modes() const override;
|
||||
virtual QString currentMode() const override;
|
||||
|
||||
// ContentPresent interface
|
||||
public:
|
||||
virtual QList<QString> suffixes() const override;
|
||||
virtual std::tuple<bool, QString> create(const QDir &target, const QString &name, const QString &suffix) override;
|
||||
virtual MakeTools::FilePresent *newInst() const override;
|
||||
virtual QWidget *widget() const override;
|
||||
virtual void applySetting(const QString &name, Core::AppCore *core) override;
|
||||
virtual QString name() const override;
|
||||
virtual void load(const QFileInfo &target_file) override;
|
||||
virtual void saveAs(const QString &path) override;
|
||||
virtual QString relativeTargetPath(const QDir &base) const override;
|
||||
virtual QString absoluteTargetPath() const override;
|
||||
virtual QString getText() const override;
|
||||
virtual bool isModified() const override;
|
||||
virtual void jumpTo(const QList<QString> &path) override;
|
||||
virtual Features features() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // SRCEDIT_STORYCHAIN_H
|
|
@ -1,171 +0,0 @@
|
|||
#include "srcedit_storyconcept.h"
|
||||
#include "keywordshighlighter.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QMenu>
|
||||
#include <QSpinBox>
|
||||
#include <QTextStream>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
using namespace Components;
|
||||
using namespace Enhancement;
|
||||
|
||||
StoryconceptSourceEdit::StoryconceptSourceEdit()
|
||||
: highlighter_ins(new KeywordsHighlighter(this)),
|
||||
edit_square(new QTextEdit)
|
||||
{
|
||||
highlighter_ins->setDocument(this->edit_square->document());
|
||||
connect(edit_square, &QTextEdit::textChanged, [this](){
|
||||
emit this->dataChanged(filepath_store);
|
||||
});
|
||||
}
|
||||
|
||||
void StoryconceptSourceEdit::concept_jump(const QList<QString> &path)
|
||||
{
|
||||
auto fpath = this->absoluteTargetPath();
|
||||
auto core = core_ins->parseCore();
|
||||
if(path.size()){
|
||||
auto storynode = core->queryStoryConcept(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());
|
||||
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
||||
this->edit_square->setTextCursor(cur);
|
||||
|
||||
if(path.size() > 1){
|
||||
auto storypoint = core->queryStoryStrongPoint(storynode, path[1]).first();
|
||||
first_word = storypoint->refered()[0];
|
||||
|
||||
auto textblock = this->edit_square->document()->findBlockByNumber(first_word->row());
|
||||
cur.setPosition(textblock.position());
|
||||
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
||||
this->edit_square->setTextCursor(cur);
|
||||
}
|
||||
}
|
||||
|
||||
edit_square->setFocus();
|
||||
}
|
||||
|
||||
void StoryconceptSourceEdit::modeReset(const QString &type) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QList<QString> StoryconceptSourceEdit::modes() const
|
||||
{
|
||||
return QList<QString>() << "源码编辑";
|
||||
}
|
||||
|
||||
QString StoryconceptSourceEdit::currentMode() const
|
||||
{
|
||||
return "源码编辑";
|
||||
}
|
||||
|
||||
void StoryconceptSourceEdit::contexBinding(Core::AppCore *app) { this->core_ins = app; }
|
||||
|
||||
void StoryconceptSourceEdit::renderRepeat() const
|
||||
{
|
||||
this->highlighter_ins->rehighlight();
|
||||
}
|
||||
|
||||
QList<QString> StoryconceptSourceEdit::suffixes() const
|
||||
{
|
||||
return QList<QString>() << "storyconcept";
|
||||
}
|
||||
|
||||
std::tuple<bool, QString> StoryconceptSourceEdit::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 *StoryconceptSourceEdit::newInst() const
|
||||
{
|
||||
return new StoryconceptSourceEdit();
|
||||
}
|
||||
|
||||
QWidget *StoryconceptSourceEdit::widget() const
|
||||
{
|
||||
return edit_square;
|
||||
}
|
||||
|
||||
QString StoryconceptSourceEdit::name() const
|
||||
{
|
||||
return this->name_store;
|
||||
}
|
||||
|
||||
void StoryconceptSourceEdit::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 StoryconceptSourceEdit::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 StoryconceptSourceEdit::relativeTargetPath(const QDir &base) const
|
||||
{
|
||||
return base.relativeFilePath(filepath_store);
|
||||
}
|
||||
|
||||
QString StoryconceptSourceEdit::absoluteTargetPath() const
|
||||
{
|
||||
return filepath_store;
|
||||
}
|
||||
|
||||
QString StoryconceptSourceEdit::getText() const
|
||||
{
|
||||
return edit_square->toPlainText();
|
||||
}
|
||||
|
||||
bool StoryconceptSourceEdit::isModified() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void StoryconceptSourceEdit::applySetting(const QString &name, Core::AppCore *core)
|
||||
{
|
||||
this->name_store = name;
|
||||
|
||||
}
|
||||
|
||||
MakeTools::FilePresent::Features StoryconceptSourceEdit::features()
|
||||
{
|
||||
return Feature::Compile | Feature::HighLight;
|
||||
}
|
||||
void StoryconceptSourceEdit::jumpTo(const QList<QString> &path)
|
||||
{
|
||||
concept_jump(path);
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
#ifndef SRCEDIT_STORYCONCEPT_H
|
||||
#define SRCEDIT_STORYCONCEPT_H
|
||||
|
||||
#include "srcedit_defaulttext.h"
|
||||
#include "appcore.h"
|
||||
#include "keywordshighlighter.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace Components {
|
||||
|
||||
class StoryconceptSourceEdit : public Presents::ModeView, public MakeTools::CompileFeature,
|
||||
public MakeTools::FilePresent, public Enhancement::HighlightFeature
|
||||
{
|
||||
public:
|
||||
StoryconceptSourceEdit();
|
||||
virtual ~StoryconceptSourceEdit() = default;
|
||||
|
||||
private:
|
||||
QSyntaxHighlighter *const highlighter_ins;
|
||||
QTextEdit *edit_square;
|
||||
Core::AppCore *core_ins;
|
||||
QString name_store;
|
||||
QString filepath_store;
|
||||
|
||||
|
||||
void concept_jump(const QList<QString> &path);
|
||||
|
||||
// ModeView interface
|
||||
public:
|
||||
virtual void modeReset(const QString &type) const override;
|
||||
virtual QList<QString> modes() const override;
|
||||
virtual QString currentMode() const override;
|
||||
|
||||
// HighlightDemand interface
|
||||
public:
|
||||
virtual void contexBinding(Core::AppCore *app) override;
|
||||
virtual void renderRepeat() const override;
|
||||
|
||||
// ContentPresent interface
|
||||
public:
|
||||
virtual QList<QString> suffixes() const override;
|
||||
virtual std::tuple<bool, QString> create(const QDir &target, const QString &name, const QString &suffix) override;
|
||||
virtual MakeTools::FilePresent *newInst() const override;
|
||||
virtual QWidget *widget() const override;
|
||||
virtual QString name() const override;
|
||||
virtual void load(const QFileInfo &target_file) override;
|
||||
virtual void saveAs(const QString &path) override;
|
||||
virtual QString relativeTargetPath(const QDir &base) const override;
|
||||
virtual QString absoluteTargetPath() const override;
|
||||
virtual QString getText() const override;
|
||||
virtual bool isModified() const override;
|
||||
virtual void jumpTo(const QList<QString> &path) override;
|
||||
virtual void applySetting(const QString &name, Core::AppCore *core) override;
|
||||
virtual Features features() override;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // SRCEDIT_STORYCONCEPT_H
|
|
@ -1,274 +0,0 @@
|
|||
#include "srcedit_storyunit.h"
|
||||
#include "keywordshighlighter.h"
|
||||
#include <QComboBox>
|
||||
#include <QMenu>
|
||||
#include <QSpinBox>
|
||||
#include <QSplitter>
|
||||
#include <QVBoxLayout>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Parse::Result;
|
||||
using namespace Components;
|
||||
using namespace Enhancement;
|
||||
|
||||
StoryunitSourceEdit::StoryunitSourceEdit()
|
||||
: edit_square(new QTextEdit),
|
||||
refers_descriptions(new QTableView()),
|
||||
refers_model(new QStandardItemModel()),
|
||||
split(new QSplitter()),
|
||||
words_highlighter(new KeywordsHighlighter(this))
|
||||
{
|
||||
words_highlighter->setDocument(this->edit_square->document());
|
||||
refers_descriptions->setModel(refers_model);
|
||||
|
||||
connect(this->edit_square, &QTextEdit::textChanged, [this](){
|
||||
emit this->dataChanged(filepath_store);
|
||||
});
|
||||
|
||||
split->addWidget(edit_square);
|
||||
split->addWidget(this->refers_descriptions);
|
||||
}
|
||||
|
||||
StoryunitSourceEdit::~StoryunitSourceEdit()
|
||||
{
|
||||
delete this->refers_descriptions;
|
||||
|
||||
split->deleteLater();
|
||||
}
|
||||
|
||||
void StoryunitSourceEdit::modeReset(const QString &) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QList<QString> StoryunitSourceEdit::modes() const
|
||||
{
|
||||
return QList<QString>() << "源码";
|
||||
}
|
||||
|
||||
QString StoryunitSourceEdit::currentMode() const
|
||||
{
|
||||
return modes()[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
void StoryunitSourceEdit::cursor_contex_query()
|
||||
{
|
||||
refers_model->clear();
|
||||
refers_model->setHorizontalHeaderLabels(QStringList() << "故事" << "内容");
|
||||
|
||||
auto cursor = edit_square->textCursor();
|
||||
auto doc = this->core_ins->parseCore()->queryDocument(QFileInfo(this->absoluteTargetPath()));
|
||||
auto words = doc->getWords(cursor.block().blockNumber());
|
||||
|
||||
QList<DesNode*> frags;
|
||||
for (auto &w : words) {
|
||||
QHash<uint, Parse::Result::DesNode*> nodes;
|
||||
|
||||
auto xhost = w->host();
|
||||
while (xhost != nullptr){
|
||||
nodes[xhost->typeValue()] = xhost;
|
||||
xhost = xhost->parent();
|
||||
}
|
||||
|
||||
if(!nodes.contains(NODE_STORYFRAGMENT))
|
||||
continue;
|
||||
|
||||
xhost = nodes[NODE_STORYFRAGMENT];
|
||||
if(!frags.contains(xhost))
|
||||
frags << xhost;
|
||||
}
|
||||
|
||||
auto less_equal_than = [](std::pair<uint, uint> a, std::pair<uint, uint> b)->bool{
|
||||
if(a.first < b.first)
|
||||
return true;
|
||||
else if(a.first == b.first)
|
||||
return a.second <= b.second;
|
||||
return false;
|
||||
};
|
||||
for(auto &x : frags){
|
||||
auto first = x->refered().first();
|
||||
auto last = x->refered().last();
|
||||
|
||||
auto tcursor = std::make_pair(cursor.block().blockNumber(), cursor.positionInBlock());
|
||||
auto fcursor = std::make_pair(first->row(), first->column());
|
||||
auto lcursor = std::make_pair(last->row(), last->column()+last->length());
|
||||
|
||||
if(less_equal_than(fcursor, tcursor) && less_equal_than(tcursor, lcursor))
|
||||
{
|
||||
auto name = static_cast<NamedNode*>(x)->name();
|
||||
present_refersed_tips(name[1], name[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StoryunitSourceEdit::present_refersed_tips(const QString &unit, const QString &frag)
|
||||
{
|
||||
QHash<QString, DesNode*> nodes;
|
||||
|
||||
auto storys = core_ins->parseCore()->allStoryBoards();
|
||||
for (auto &s : storys) {
|
||||
auto xins = static_cast<NamedNode*>(s);
|
||||
auto refs_x = s->children();
|
||||
for(auto &ref : refs_x)
|
||||
if(ref->typeValue() == NODE_FRAGMENTREFERENCE){
|
||||
auto nm_ref = static_cast<NamedNode*>(ref);
|
||||
|
||||
if(nm_ref->name()[0] == frag && nm_ref->name()[1] == unit){
|
||||
nodes[xins->name()[0]] = ref;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(auto &nm : nodes.keys())
|
||||
{
|
||||
QList<QStandardItem*> row;
|
||||
row << new QStandardItem(nm);
|
||||
row.last()->setEditable(false);
|
||||
row << new QStandardItem(nodes[nm]->toString());
|
||||
row.last()->setEditable(false);
|
||||
|
||||
refers_model->appendRow(row);
|
||||
}
|
||||
|
||||
refers_descriptions->resizeColumnsToContents();
|
||||
refers_descriptions->resizeRowsToContents();
|
||||
}
|
||||
|
||||
void StoryunitSourceEdit::contexBinding(Core::AppCore *app) {
|
||||
this->core_ins = app;
|
||||
|
||||
connect(edit_square, &QTextEdit::cursorPositionChanged, this, &StoryunitSourceEdit::cursor_contex_query);
|
||||
}
|
||||
|
||||
void StoryunitSourceEdit::renderRepeat() const
|
||||
{
|
||||
this->words_highlighter->rehighlight();
|
||||
}
|
||||
|
||||
QList<QString> StoryunitSourceEdit::suffixes() const
|
||||
{
|
||||
return QList<QString>() << "storyunit";
|
||||
}
|
||||
|
||||
std::tuple<bool, QString> StoryunitSourceEdit::create(const QDir &target, const QString &name, const QString &suffix)
|
||||
{
|
||||
auto filepath = target.filePath(QString("%1.%2").arg(name, suffix));
|
||||
if(QFileInfo::exists(filepath))
|
||||
return std::make_tuple(false, filepath);
|
||||
|
||||
QFile nf(filepath);
|
||||
if(!nf.open(QIODevice::WriteOnly|QIODevice::Text))
|
||||
throw new SimpleException("新建文件错误:指定文件无法创建:"+filepath);
|
||||
|
||||
return std::make_tuple(true, filepath);
|
||||
}
|
||||
|
||||
MakeTools::FilePresent *StoryunitSourceEdit::newInst() const
|
||||
{
|
||||
return new StoryunitSourceEdit();
|
||||
}
|
||||
|
||||
void StoryunitSourceEdit::applySetting(const QString &name, Core::AppCore *core)
|
||||
{
|
||||
this->name_store = name;
|
||||
}
|
||||
|
||||
QString StoryunitSourceEdit::name() const
|
||||
{
|
||||
return name_store;
|
||||
}
|
||||
|
||||
void StoryunitSourceEdit::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.absoluteFilePath();
|
||||
|
||||
QFile bin(filepath_store);
|
||||
if(!bin.open(QIODevice::ReadOnly|QIODevice::Text))
|
||||
throw new SimpleException("文件打开:指定的文件无法打开:"+filepath_store);
|
||||
QTextStream tin(&bin);
|
||||
tin.setCodec("UTF-8");
|
||||
this->edit_square->setText(tin.readAll());
|
||||
}
|
||||
|
||||
void StoryunitSourceEdit::saveAs(const QString &path)
|
||||
{
|
||||
if(!path.isEmpty())
|
||||
filepath_store = path;
|
||||
|
||||
QFile bout(filepath_store);
|
||||
if(!bout.open(QIODevice::WriteOnly|QIODevice::Text))
|
||||
throw new SimpleException("保存出错:无法写出到指定文件:"+filepath_store);
|
||||
QTextStream tout(&bout);
|
||||
tout.setCodec("UTF-8");
|
||||
tout << this->edit_square->toPlainText();
|
||||
tout.flush();
|
||||
}
|
||||
|
||||
QString StoryunitSourceEdit::relativeTargetPath(const QDir &base) const
|
||||
{
|
||||
return base.relativeFilePath(filepath_store);
|
||||
}
|
||||
|
||||
QString StoryunitSourceEdit::absoluteTargetPath() const
|
||||
{
|
||||
return filepath_store;
|
||||
}
|
||||
|
||||
QString StoryunitSourceEdit::getText() const
|
||||
{
|
||||
return edit_square->toPlainText();
|
||||
}
|
||||
|
||||
bool StoryunitSourceEdit::isModified() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void StoryunitSourceEdit::jumpTo(const QList<QString> &path)
|
||||
{
|
||||
auto fpath = this->absoluteTargetPath();
|
||||
auto core = core_ins->parseCore();
|
||||
if(path.size()){
|
||||
auto storynode = core->queryStoryUnit(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());
|
||||
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
||||
this->edit_square->setTextCursor(cur);
|
||||
|
||||
if(path.size() > 1){
|
||||
auto storypoint = core->queryStoryFragment(storynode, path[1]).first();
|
||||
first_word = storypoint->refered()[0];
|
||||
|
||||
auto textblock = this->edit_square->document()->findBlockByNumber(first_word->row());
|
||||
cur.setPosition(textblock.position());
|
||||
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
||||
this->edit_square->setTextCursor(cur);
|
||||
}
|
||||
}
|
||||
|
||||
edit_square->setFocus();
|
||||
}
|
||||
|
||||
|
||||
QWidget *StoryunitSourceEdit::widget() const
|
||||
{
|
||||
return split;
|
||||
}
|
||||
|
||||
MakeTools::FilePresent::Features StoryunitSourceEdit::features()
|
||||
{
|
||||
return Feature::Compile | Feature::HighLight;
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
#ifndef SRCEDIT_STORYUNIT_H
|
||||
#define SRCEDIT_STORYUNIT_H
|
||||
|
||||
#include "srcedit_defaulttext.h"
|
||||
#include "keywordshighlighter.h"
|
||||
|
||||
#include <QSplitter>
|
||||
#include <QTableView>
|
||||
|
||||
namespace Components {
|
||||
|
||||
class StoryunitSourceEdit : public MakeTools::FilePresent, public MakeTools::CompileFeature,
|
||||
public Presents::ModeView, public Enhancement::HighlightFeature
|
||||
{
|
||||
public:
|
||||
StoryunitSourceEdit();
|
||||
virtual ~StoryunitSourceEdit();
|
||||
|
||||
// ModeView interface
|
||||
public:
|
||||
virtual void modeReset(const QString &type) const override;
|
||||
virtual QList<QString> modes() const override;
|
||||
virtual QString currentMode() const override;
|
||||
|
||||
private:
|
||||
QTextEdit *edit_square;
|
||||
QTableView *const refers_descriptions;
|
||||
QStandardItemModel *const refers_model;
|
||||
QSplitter *const split;
|
||||
QSyntaxHighlighter *const words_highlighter;
|
||||
QString name_store;
|
||||
QString filepath_store;
|
||||
Core::AppCore *core_ins;
|
||||
|
||||
void cursor_contex_query();
|
||||
void present_refersed_tips(const QString &unit, const QString &frag);
|
||||
|
||||
// HighlightDemand interface
|
||||
public:
|
||||
virtual void contexBinding(Core::AppCore *app) override;
|
||||
virtual void renderRepeat() const override;
|
||||
|
||||
// ContentPresent interface
|
||||
public:
|
||||
virtual QList<QString> suffixes() const override;
|
||||
virtual std::tuple<bool, QString> create(const QDir &target, const QString &name, const QString &suffix) override;
|
||||
virtual MakeTools::FilePresent *newInst() const override;
|
||||
virtual void applySetting(const QString &name, Core::AppCore *core) override;
|
||||
virtual QString name() const override;
|
||||
virtual void load(const QFileInfo &target_file) override;
|
||||
virtual void saveAs(const QString &path) override;
|
||||
virtual QString relativeTargetPath(const QDir &base) const override;
|
||||
virtual QString absoluteTargetPath() const override;
|
||||
virtual QString getText() const override;
|
||||
virtual bool isModified() const override;
|
||||
virtual void jumpTo(const QList<QString> &path) override;
|
||||
virtual QWidget *widget() const override;
|
||||
virtual Features features() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // SRCEDIT_STORYUNIT_H
|
|
@ -1,145 +0,0 @@
|
|||
#include "srcedit_storyvolume.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;
|
||||
|
||||
|
||||
|
||||
StoryvolumeSourceEdit::StoryvolumeSourceEdit()
|
||||
: 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 StoryvolumeSourceEdit::modeReset(const QString &) const{}
|
||||
|
||||
QList<QString> StoryvolumeSourceEdit::modes() const
|
||||
{
|
||||
return QList<QString>() << "源码";
|
||||
}
|
||||
|
||||
QString StoryvolumeSourceEdit::currentMode() const
|
||||
{
|
||||
return modes()[0];
|
||||
}
|
||||
|
||||
QString StoryvolumeSourceEdit::name() const
|
||||
{
|
||||
return name_store;
|
||||
}
|
||||
|
||||
void StoryvolumeSourceEdit::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 StoryvolumeSourceEdit::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 StoryvolumeSourceEdit::relativeTargetPath(const QDir &base) const
|
||||
{
|
||||
return base.relativeFilePath(filepath_store);
|
||||
}
|
||||
|
||||
QString StoryvolumeSourceEdit::absoluteTargetPath() const
|
||||
{
|
||||
return filepath_store;
|
||||
}
|
||||
|
||||
QString StoryvolumeSourceEdit::getText() const
|
||||
{
|
||||
return edit_square->toPlainText();
|
||||
}
|
||||
|
||||
bool StoryvolumeSourceEdit::isModified() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void StoryvolumeSourceEdit::applySetting(const QString &name, Core::AppCore *core)
|
||||
{
|
||||
this->name_store = name;
|
||||
|
||||
}
|
||||
|
||||
MakeTools::FilePresent::Features StoryvolumeSourceEdit::features()
|
||||
{
|
||||
return Feature::Compile | Feature::HighLight;
|
||||
}
|
||||
|
||||
void StoryvolumeSourceEdit::renderRepeat() const
|
||||
{
|
||||
this->words_highlighter->rehighlight();
|
||||
}
|
||||
|
||||
QList<QString> StoryvolumeSourceEdit::suffixes() const
|
||||
{
|
||||
return QList<QString>() << "storyvolume";
|
||||
}
|
||||
|
||||
std::tuple<bool, QString> StoryvolumeSourceEdit::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 *StoryvolumeSourceEdit::newInst() const
|
||||
{
|
||||
return new StoryvolumeSourceEdit();
|
||||
}
|
||||
|
||||
QWidget *StoryvolumeSourceEdit::widget() const
|
||||
{
|
||||
return edit_square;
|
||||
}
|
||||
|
||||
void StoryvolumeSourceEdit::jumpTo(const QList<QString> &path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void StoryvolumeSourceEdit::contexBinding(Core::AppCore *app) { core_ins = app; }
|
|
@ -1,56 +0,0 @@
|
|||
#ifndef SRCEDIT_STORYVOLUME_H
|
||||
#define SRCEDIT_STORYVOLUME_H
|
||||
|
||||
#include "srcedit_defaulttext.h"
|
||||
#include "keywordshighlighter.h"
|
||||
|
||||
|
||||
namespace Components {
|
||||
class StoryvolumeSourceEdit : public Presents::ModeView, public MakeTools::CompileFeature,
|
||||
public MakeTools::FilePresent, public Enhancement::HighlightFeature
|
||||
{
|
||||
public:
|
||||
StoryvolumeSourceEdit();
|
||||
virtual ~StoryvolumeSourceEdit() = default;
|
||||
|
||||
|
||||
// ModeView interface
|
||||
public:
|
||||
virtual void modeReset(const QString &type) const override;
|
||||
virtual QList<QString> modes() const override;
|
||||
virtual QString currentMode() const override;
|
||||
|
||||
|
||||
private:
|
||||
QSyntaxHighlighter *const words_highlighter;
|
||||
QString name_store;
|
||||
QString filepath_store;
|
||||
Core::AppCore *core_ins;
|
||||
QTextEdit *edit_square;
|
||||
|
||||
|
||||
// HighlightDemand interface
|
||||
public:
|
||||
virtual void contexBinding(Core::AppCore *app) override;
|
||||
virtual void renderRepeat() const override;
|
||||
|
||||
// ContentPresent interface
|
||||
public:
|
||||
virtual QList<QString> suffixes() const override;
|
||||
virtual std::tuple<bool, QString> create(const QDir &target, const QString &name, const QString &suffix) override;
|
||||
virtual MakeTools::FilePresent *newInst() const override;
|
||||
virtual QWidget *widget() const override;
|
||||
virtual QString name() const override;
|
||||
virtual void load(const QFileInfo &target_file) override;
|
||||
virtual void saveAs(const QString &path) override;
|
||||
virtual QString relativeTargetPath(const QDir &base) const override;
|
||||
virtual QString absoluteTargetPath() const override;
|
||||
virtual QString getText() const override;
|
||||
virtual bool isModified() const override;
|
||||
virtual void jumpTo(const QList<QString> &path) override;
|
||||
virtual void applySetting(const QString &name, Core::AppCore *core) override;
|
||||
virtual Features features() override;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // SRCEDIT_STORYVOLUME_H
|
Loading…
Reference in New Issue