feat: 可视化组件脚本支持鼠标单击和双击事件响应;代码填充支持关键字;
This commit is contained in:
parent
557311c85f
commit
5bd8a870d1
|
@ -46,16 +46,13 @@
|
||||||
QList<qsizetype> QHexDocument::getLineBookmarksPos(qsizetype line) {
|
QList<qsizetype> QHexDocument::getLineBookmarksPos(qsizetype line) {
|
||||||
QList<qsizetype> pos;
|
QList<qsizetype> pos;
|
||||||
auto begin = m_hexlinewidth * line;
|
auto begin = m_hexlinewidth * line;
|
||||||
auto end = m_hexlinewidth + begin;
|
auto end = m_hexlinewidth + begin - 1;
|
||||||
|
|
||||||
auto lbound = _bookmarks.lowerBound(begin);
|
auto lbound = _bookmarks.lowerBound(begin);
|
||||||
auto ubound = _bookmarks.upperBound(end);
|
auto ubound = _bookmarks.upperBound(end);
|
||||||
|
|
||||||
for (auto p = lbound; p != ubound; ++p) {
|
for (auto p = lbound; p != ubound; ++p) {
|
||||||
auto off = p.key();
|
pos.append(p.key());
|
||||||
if (off >= begin && off < end) {
|
|
||||||
pos.append(off);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
|
@ -63,19 +60,12 @@ QList<qsizetype> QHexDocument::getLineBookmarksPos(qsizetype line) {
|
||||||
|
|
||||||
bool QHexDocument::lineHasBookMark(qsizetype line) {
|
bool QHexDocument::lineHasBookMark(qsizetype line) {
|
||||||
auto begin = m_hexlinewidth * line;
|
auto begin = m_hexlinewidth * line;
|
||||||
auto end = m_hexlinewidth + begin;
|
auto end = m_hexlinewidth + begin - 1;
|
||||||
|
|
||||||
auto lbound = _bookmarks.lowerBound(begin);
|
auto lbound = _bookmarks.lowerBound(begin);
|
||||||
auto ubound = _bookmarks.upperBound(end);
|
auto ubound = _bookmarks.upperBound(end);
|
||||||
|
|
||||||
for (auto p = lbound; p != ubound; ++p) {
|
return lbound != ubound;
|
||||||
auto off = p.key();
|
|
||||||
if (off >= begin && off < end) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QHexDocument::addUndoCommand(QUndoCommand *command) {
|
void QHexDocument::addUndoCommand(QUndoCommand *command) {
|
||||||
|
|
|
@ -267,7 +267,8 @@ set(CLASS_SRC
|
||||||
src/class/dockcomponentsfactory.h
|
src/class/dockcomponentsfactory.h
|
||||||
src/class/dockcomponentsfactory.cpp
|
src/class/dockcomponentsfactory.cpp
|
||||||
src/class/diffutil.h
|
src/class/diffutil.h
|
||||||
src/class/diffutil.cpp)
|
src/class/diffutil.cpp
|
||||||
|
src/class/clickcallback.h)
|
||||||
|
|
||||||
set(INTERNAL_PLG_SRC
|
set(INTERNAL_PLG_SRC
|
||||||
src/class/wingangelapi.h src/class/wingangelapi.cpp
|
src/class/wingangelapi.h src/class/wingangelapi.cpp
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.7 KiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -220,8 +220,6 @@ void AsCompletion::complete(const QDocumentCursor &c, const QString &trigger) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto &_headerNodes = parser.headerNodes();
|
|
||||||
|
|
||||||
if (etoken.content.length() >= trigWordLen()) {
|
if (etoken.content.length() >= trigWordLen()) {
|
||||||
// completion for a.b.c or a::b.c or a::b::c.d or ::a::b.c
|
// completion for a.b.c or a::b.c or a::b::c.d or ::a::b.c
|
||||||
if (trigger == *DBL_COLON_TRIGGER) {
|
if (trigger == *DBL_COLON_TRIGGER) {
|
||||||
|
@ -284,6 +282,7 @@ void AsCompletion::complete(const QDocumentCursor &c, const QString &trigger) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodes.append(parser.keywordNode());
|
||||||
auto cur = c;
|
auto cur = c;
|
||||||
cur.movePosition(trigger.length());
|
cur.movePosition(trigger.length());
|
||||||
pPopup->setCursor(cur);
|
pPopup->setCursor(cur);
|
||||||
|
@ -311,10 +310,10 @@ void AsCompletion::applyEmptyNsNode(QList<QCodeNode *> &nodes) {
|
||||||
nodes = _emptyNsNodes;
|
nodes = _emptyNsNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsCompletion::parse(const QDocumentCursor &c) {
|
// void AsCompletion::parse(const QDocumentCursor &c) {
|
||||||
auto codes = c.document()->text();
|
// auto codes = c.document()->text();
|
||||||
// asBuilder builder;
|
// // asBuilder builder;
|
||||||
}
|
// }
|
||||||
|
|
||||||
QList<QCodeNode *> AsCompletion::lookupNamespace(const QByteArrayList &ns) {
|
QList<QCodeNode *> AsCompletion::lookupNamespace(const QByteArrayList &ns) {
|
||||||
QList<QCodeNode *> nodes;
|
QList<QCodeNode *> nodes;
|
||||||
|
|
|
@ -50,7 +50,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
void applyEmptyNsNode(QList<QCodeNode *> &nodes);
|
void applyEmptyNsNode(QList<QCodeNode *> &nodes);
|
||||||
|
|
||||||
void parse(const QDocumentCursor &c);
|
// void parse(const QDocumentCursor &c);
|
||||||
|
|
||||||
QList<QCodeNode *> lookupNamespace(const QByteArrayList &ns);
|
QList<QCodeNode *> lookupNamespace(const QByteArrayList &ns);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
#ifndef CLICKCALLBACK_H
|
||||||
|
#define CLICKCALLBACK_H
|
||||||
|
|
||||||
|
#include "angelscript.h"
|
||||||
|
#include "plugin/iwingplugin.h"
|
||||||
|
|
||||||
|
class ClickCallBack {
|
||||||
|
public:
|
||||||
|
ClickCallBack() {}
|
||||||
|
|
||||||
|
ClickCallBack(const WingHex::WingPlugin::DataVisual::ClickedCallBack &b)
|
||||||
|
: _call(b) {}
|
||||||
|
|
||||||
|
explicit ClickCallBack(asIScriptEngine *engine, asIScriptFunction *func)
|
||||||
|
: _engine(engine), _func(func) {
|
||||||
|
if (_engine && _func) {
|
||||||
|
_func->AddRef();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~ClickCallBack() {
|
||||||
|
if (_func) {
|
||||||
|
_func->Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
ClickCallBack &
|
||||||
|
operator=(const WingHex::WingPlugin::DataVisual::ClickedCallBack &_Right) {
|
||||||
|
*this = ClickCallBack(_Right);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClickCallBack &
|
||||||
|
operator=(WingHex::WingPlugin::DataVisual::ClickedCallBack &&_Right) {
|
||||||
|
*this = ClickCallBack(_Right);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit operator bool() const noexcept {
|
||||||
|
return _call || (_engine && _func);
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator()(const QModelIndex &index) {
|
||||||
|
if (_call) {
|
||||||
|
_call(index);
|
||||||
|
} else {
|
||||||
|
if (_engine && _func) {
|
||||||
|
auto ctx = _engine->CreateContext();
|
||||||
|
if (ctx) {
|
||||||
|
auto r = ctx->Prepare(_func);
|
||||||
|
if (r >= 0) {
|
||||||
|
auto idx = index;
|
||||||
|
ctx->SetArgObject(0, &idx);
|
||||||
|
ctx->Execute();
|
||||||
|
}
|
||||||
|
ctx->Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
WingHex::WingPlugin::DataVisual::ClickedCallBack _call;
|
||||||
|
asIScriptEngine *_engine = nullptr;
|
||||||
|
asIScriptFunction *_func = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CLICKCALLBACK_H
|
|
@ -86,50 +86,63 @@ Logger &Logger::instance() {
|
||||||
|
|
||||||
Logger::Level Logger::logLevel() const { return _level; }
|
Logger::Level Logger::logLevel() const { return _level; }
|
||||||
|
|
||||||
void Logger::_log(const QString &message) { emit instance().log(message); }
|
void Logger::logPrint(const QString &message) { emit instance().log(message); }
|
||||||
|
|
||||||
void Logger::newLine() { _log({}); }
|
void Logger::newLine() { logPrint({}); }
|
||||||
|
|
||||||
void Logger::trace(const QString &message) {
|
void Logger::trace(const QString &message) {
|
||||||
if (instance()._level >= q5TRACE) {
|
if (instance()._level >= q5TRACE) {
|
||||||
QString str = message;
|
QString str = message;
|
||||||
emit instance().log(tr("[Trace]") + str.replace("\n", "<br />"));
|
emit instance().log(packDebugStr(tr("[Trace]") + str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::warning(const QString &message) {
|
void Logger::warning(const QString &message) {
|
||||||
if (instance()._level >= q2WARN) {
|
if (instance()._level >= q2WARN) {
|
||||||
QString str = message;
|
QString str = message;
|
||||||
emit instance().log(
|
emit instance().log(packWarnStr(tr("[Warn]") + str));
|
||||||
WARNLOG(tr("[Warn]") + str.replace("\n", "<br />")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::info(const QString &message) {
|
void Logger::info(const QString &message) {
|
||||||
if (instance()._level >= q3INFO) {
|
if (instance()._level >= q3INFO) {
|
||||||
QString str = message;
|
QString str = message;
|
||||||
emit instance().log(
|
emit instance().log(packInfoStr(tr("[Info]") + str));
|
||||||
INFOLOG(tr("[Info]") + str.replace("\n", "<br />")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::debug(const QString &message) {
|
void Logger::debug(const QString &message) {
|
||||||
if (instance()._level >= q4DEBUG) {
|
if (instance()._level >= q4DEBUG) {
|
||||||
QString str = message;
|
QString str = message;
|
||||||
emit instance().log(tr("[Debug]") + str.replace("\n", "<br />"));
|
emit instance().log(packDebugStr(tr("[Debug]") + str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::critical(const QString &message) {
|
void Logger::critical(const QString &message) {
|
||||||
if (instance()._level >= q0FATAL) {
|
if (instance()._level >= q0FATAL) {
|
||||||
QString str = message;
|
QString str = message;
|
||||||
emit instance().log(
|
emit instance().log(packErrorStr(tr("[Error]") + str));
|
||||||
ERRLOG(tr("[Error]") + str.replace("\n", "<br />")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::setLogLevel(Level level) { _level = level; }
|
void Logger::setLogLevel(Level level) { _level = level; }
|
||||||
|
|
||||||
|
QString Logger::packInfoStr(QString msg) {
|
||||||
|
return INFOLOG(msg.replace("\n", "<br />"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Logger::packDebugStr(QString msg) {
|
||||||
|
return msg.replace("\n", "<br />");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Logger::packErrorStr(QString msg) {
|
||||||
|
return ERRLOG(msg.replace("\n", "<br />"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Logger::packWarnStr(QString msg) {
|
||||||
|
return WARNLOG(msg.replace("\n", "<br />"));
|
||||||
|
}
|
||||||
|
|
||||||
QString Logger::getString(Level level) {
|
QString Logger::getString(Level level) {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case q0FATAL:
|
case q0FATAL:
|
||||||
|
|
|
@ -62,16 +62,20 @@ public slots:
|
||||||
static void info(const QString &message);
|
static void info(const QString &message);
|
||||||
static void debug(const QString &message);
|
static void debug(const QString &message);
|
||||||
static void critical(const QString &message);
|
static void critical(const QString &message);
|
||||||
|
static void logPrint(const QString &message);
|
||||||
|
|
||||||
void setLogLevel(Level level);
|
void setLogLevel(Level level);
|
||||||
|
|
||||||
|
static QString packInfoStr(QString msg);
|
||||||
|
static QString packDebugStr(QString msg);
|
||||||
|
static QString packErrorStr(QString msg);
|
||||||
|
static QString packWarnStr(QString msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Logger(QObject *parent = nullptr);
|
explicit Logger(QObject *parent = nullptr);
|
||||||
|
|
||||||
virtual ~Logger();
|
virtual ~Logger();
|
||||||
|
|
||||||
static void _log(const QString &message);
|
|
||||||
|
|
||||||
Q_DISABLE_COPY_MOVE(Logger)
|
Q_DISABLE_COPY_MOVE(Logger)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -31,6 +31,29 @@ QAsParser::QAsParser(asIScriptEngine *engine)
|
||||||
addEnumCompletion(engine);
|
addEnumCompletion(engine);
|
||||||
_buffer.clear();
|
_buffer.clear();
|
||||||
_buffer.squeeze();
|
_buffer.squeeze();
|
||||||
|
|
||||||
|
// generate keyword completion
|
||||||
|
_keywordNode = new QCodeNode;
|
||||||
|
_keywordNode->setNodeType(QCodeNode::Group);
|
||||||
|
QStringList kws{
|
||||||
|
"const", "in", "inout", "out", "auto", "public",
|
||||||
|
"protected", "private", "void", "int8", "int16", "int",
|
||||||
|
"int64", "uint8", "uint16", "uint", "uint64", "float",
|
||||||
|
"double", "bool", "enum", "string", "array", "any",
|
||||||
|
"for", "while", "do", "if", "else", "switch",
|
||||||
|
"break", "continue", "try", "catch", "throw", "abstract",
|
||||||
|
"delete", "cast", "class", "final", "property", "external",
|
||||||
|
"function", "interface", "shared", "this", "explicit", "override",
|
||||||
|
"namespace", "get", "set", "super", "mixin", "false",
|
||||||
|
"true", "null", "typename", "return", "typedef", "funcdef",
|
||||||
|
"from", "import", "not", "xor", "or", "is"};
|
||||||
|
for (auto &k : kws) {
|
||||||
|
auto knode = new QCodeNode;
|
||||||
|
knode->setParent(_keywordNode);
|
||||||
|
knode->setNodeType(QCodeNode::KeyWord);
|
||||||
|
knode->setRole(QCodeNode::Name, k.toUtf8());
|
||||||
|
_keywordNode->children().append(knode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QAsParser::~QAsParser() {
|
QAsParser::~QAsParser() {
|
||||||
|
@ -38,6 +61,7 @@ QAsParser::~QAsParser() {
|
||||||
_headerNodes.clear();
|
_headerNodes.clear();
|
||||||
qDeleteAll(_nodes);
|
qDeleteAll(_nodes);
|
||||||
_nodes.clear();
|
_nodes.clear();
|
||||||
|
delete _keywordNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray QAsParser::getFnParamDeclString(asIScriptFunction *fn,
|
QByteArray QAsParser::getFnParamDeclString(asIScriptFunction *fn,
|
||||||
|
@ -162,10 +186,10 @@ QByteArray QAsParser::getFnRetTypeString(asIScriptFunction *fn,
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QAsParser::parse(qsizetype offset, const QString &code,
|
// bool QAsParser::parse(qsizetype offset, const QString &code,
|
||||||
const QString §ion) {
|
// const QString §ion) {
|
||||||
return ProcessScriptSection(code.toUtf8(), code.length(), section, 0);
|
// return ProcessScriptSection(code.toUtf8(), code.length(), section, 0);
|
||||||
}
|
// }
|
||||||
|
|
||||||
const QList<QCodeNode *> &QAsParser::headerNodes() const {
|
const QList<QCodeNode *> &QAsParser::headerNodes() const {
|
||||||
return _headerNodes;
|
return _headerNodes;
|
||||||
|
@ -410,4 +434,6 @@ QCodeNode *QAsParser::newEnumCodeNode(const EnumInfo &info) {
|
||||||
return enode;
|
return enode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QCodeNode *QAsParser::keywordNode() const { return _keywordNode; }
|
||||||
|
|
||||||
QList<QCodeNode *> QAsParser::codeNodes() const { return _nodes; }
|
QList<QCodeNode *> QAsParser::codeNodes() const { return _nodes; }
|
||||||
|
|
|
@ -72,12 +72,15 @@ private:
|
||||||
QByteArray getFnRetTypeString(asIScriptFunction *fn, bool includeNamespace);
|
QByteArray getFnRetTypeString(asIScriptFunction *fn, bool includeNamespace);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool parse(qsizetype offset, const QString &code, const QString §ion);
|
// bool parse(qsizetype offset, const QString &code, const QString
|
||||||
|
// §ion);
|
||||||
|
|
||||||
QList<QCodeNode *> codeNodes() const;
|
QList<QCodeNode *> codeNodes() const;
|
||||||
|
|
||||||
const QList<QCodeNode *> &headerNodes() const;
|
const QList<QCodeNode *> &headerNodes() const;
|
||||||
|
|
||||||
|
QCodeNode *keywordNode() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addGlobalFunctionCompletion(asIScriptEngine *engine);
|
void addGlobalFunctionCompletion(asIScriptEngine *engine);
|
||||||
void addEnumCompletion(asIScriptEngine *engine);
|
void addEnumCompletion(asIScriptEngine *engine);
|
||||||
|
@ -96,6 +99,7 @@ private:
|
||||||
|
|
||||||
QHash<QString, QCodeNode *> _buffer;
|
QHash<QString, QCodeNode *> _buffer;
|
||||||
QList<QCodeNode *> _headerNodes;
|
QList<QCodeNode *> _headerNodes;
|
||||||
|
QCodeNode *_keywordNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !_QCPP_PARSER_H_
|
#endif // !_QCPP_PARSER_H_
|
||||||
|
|
|
@ -52,6 +52,7 @@ static QIcon icon(int cacheIndex) {
|
||||||
(*q_icon_cache)[ICON_CLASS] = getIcon(QStringLiteral("CVclass"));
|
(*q_icon_cache)[ICON_CLASS] = getIcon(QStringLiteral("CVclass"));
|
||||||
|
|
||||||
// q_icon_cache[ICON_STRUCT] = QIcon(":/completion/CVstruct.png");
|
// q_icon_cache[ICON_STRUCT] = QIcon(":/completion/CVstruct.png");
|
||||||
|
(*q_icon_cache)[ICON_KEYWORD] = getIcon(QStringLiteral("CVKeyword"));
|
||||||
|
|
||||||
(*q_icon_cache)[ICON_TYPEDEF] = getIcon(QStringLiteral("CVtypedef"));
|
(*q_icon_cache)[ICON_TYPEDEF] = getIcon(QStringLiteral("CVtypedef"));
|
||||||
|
|
||||||
|
@ -366,6 +367,9 @@ QVariant QCodeNode::data(int r) const {
|
||||||
// case Struct:
|
// case Struct:
|
||||||
// return icon(ICON_STRUCT);
|
// return icon(ICON_STRUCT);
|
||||||
|
|
||||||
|
case KeyWord:
|
||||||
|
return icon(ICON_KEYWORD);
|
||||||
|
|
||||||
case Enum:
|
case Enum:
|
||||||
return icon(ICON_ENUM);
|
return icon(ICON_ENUM);
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "scriptmachine.h"
|
#include "scriptmachine.h"
|
||||||
|
|
||||||
|
#include "AngelScript/sdk/add_on/autowrapper/aswrappedcall.h"
|
||||||
#include "AngelScript/sdk/add_on/scriptany/scriptany.h"
|
#include "AngelScript/sdk/add_on/scriptany/scriptany.h"
|
||||||
#include "AngelScript/sdk/add_on/scriptarray/scriptarray.h"
|
#include "AngelScript/sdk/add_on/scriptarray/scriptarray.h"
|
||||||
#include "AngelScript/sdk/add_on/scriptdictionary/scriptdictionary.h"
|
#include "AngelScript/sdk/add_on/scriptdictionary/scriptdictionary.h"
|
||||||
|
@ -49,7 +50,7 @@ ScriptMachine::~ScriptMachine() {
|
||||||
|
|
||||||
bool ScriptMachine::inited() { return _engine != nullptr; }
|
bool ScriptMachine::inited() { return _engine != nullptr; }
|
||||||
|
|
||||||
bool ScriptMachine::isRunning() const { return _ctxMgr->isRunning(); }
|
bool ScriptMachine::isRunning() const { return _debugger->getEngine(); }
|
||||||
|
|
||||||
bool ScriptMachine::configureEngine(asIScriptEngine *engine) {
|
bool ScriptMachine::configureEngine(asIScriptEngine *engine) {
|
||||||
if (engine == nullptr) {
|
if (engine == nullptr) {
|
||||||
|
@ -1609,7 +1610,71 @@ void ScriptMachine::registerEngineAddon(asIScriptEngine *engine) {
|
||||||
RegisterScriptHandle(engine);
|
RegisterScriptHandle(engine);
|
||||||
RegisterColor(engine);
|
RegisterColor(engine);
|
||||||
RegisterScriptJson(engine);
|
RegisterScriptJson(engine);
|
||||||
RegisterExceptionRoutines(engine);
|
registerExceptionRoutines(engine);
|
||||||
|
registerEngineAssert(engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptMachine::registerEngineAssert(asIScriptEngine *engine) {
|
||||||
|
int r;
|
||||||
|
|
||||||
|
// The string type must be available
|
||||||
|
Q_ASSERT(engine->GetTypeInfoByDecl("string"));
|
||||||
|
|
||||||
|
if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") == 0) {
|
||||||
|
r = engine->RegisterGlobalFunction("void assert(bool expression)",
|
||||||
|
asFUNCTION(scriptAssert),
|
||||||
|
asCALL_CDECL);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterGlobalFunction(
|
||||||
|
"void assert_x(bool expression, const string &in msg)",
|
||||||
|
asFUNCTION(scriptAssert_X), asCALL_CDECL);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
} else {
|
||||||
|
r = engine->RegisterGlobalFunction("void assert(bool expression)",
|
||||||
|
WRAP_FN(scriptAssert),
|
||||||
|
asCALL_GENERIC);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterGlobalFunction(
|
||||||
|
"void assert_x(bool expression, const string &in msg)",
|
||||||
|
WRAP_FN(scriptAssert_X), asCALL_GENERIC);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptMachine::scriptAssert(bool b) {
|
||||||
|
auto ctx = asGetActiveContext();
|
||||||
|
if (ctx) {
|
||||||
|
if (!b) {
|
||||||
|
QString buffer = tr("Assert failed");
|
||||||
|
ctx->SetException(buffer.toUtf8(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptMachine::scriptAssert_X(bool b, const QString &msg) {
|
||||||
|
auto ctx = asGetActiveContext();
|
||||||
|
if (ctx) {
|
||||||
|
if (!b) {
|
||||||
|
auto m = msg;
|
||||||
|
if (m.isEmpty()) {
|
||||||
|
m = tr("Assert failed");
|
||||||
|
}
|
||||||
|
ctx->SetException(m.toUtf8(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptMachine::scriptThrow(const QString &msg) {
|
||||||
|
asIScriptContext *ctx = asGetActiveContext();
|
||||||
|
if (ctx) {
|
||||||
|
ctx->SetException(msg.toUtf8());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptMachine::isDebugMode() const {
|
bool ScriptMachine::isDebugMode() const {
|
||||||
|
@ -1750,3 +1815,49 @@ bool ScriptMachine::executeCode(const QString &code) {
|
||||||
|
|
||||||
return r >= 0;
|
return r >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ScriptMachine::scriptGetExceptionInfo() {
|
||||||
|
asIScriptContext *ctx = asGetActiveContext();
|
||||||
|
if (!ctx)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
const char *msg = ctx->GetExceptionString();
|
||||||
|
if (msg == 0)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return QString(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptMachine::registerExceptionRoutines(asIScriptEngine *engine) {
|
||||||
|
int r;
|
||||||
|
|
||||||
|
// The string type must be available
|
||||||
|
Q_ASSERT(engine->GetTypeInfoByDecl("string"));
|
||||||
|
|
||||||
|
if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") == 0) {
|
||||||
|
r = engine->RegisterGlobalFunction("void throw(const string &in)",
|
||||||
|
asFUNCTION(scriptThrow),
|
||||||
|
asCALL_CDECL);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterGlobalFunction("string getExceptionInfo()",
|
||||||
|
asFUNCTION(scriptGetExceptionInfo),
|
||||||
|
asCALL_CDECL);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
r = engine->RegisterGlobalFunction("void throw(const string &in)",
|
||||||
|
WRAP_FN(scriptThrow),
|
||||||
|
asCALL_GENERIC);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterGlobalFunction("string getExceptionInfo()",
|
||||||
|
WRAP_FN(scriptGetExceptionInfo),
|
||||||
|
asCALL_GENERIC);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -95,7 +95,19 @@ public:
|
||||||
void setInsteadFoundDisabled(bool newInsteadFoundDisabled);
|
void setInsteadFoundDisabled(bool newInsteadFoundDisabled);
|
||||||
|
|
||||||
static void registerEngineAddon(asIScriptEngine *engine);
|
static void registerEngineAddon(asIScriptEngine *engine);
|
||||||
|
static void registerEngineAssert(asIScriptEngine *engine);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void scriptAssert(bool b);
|
||||||
|
static void scriptAssert_X(bool b, const QString &msg);
|
||||||
|
|
||||||
|
static void scriptThrow(const QString &msg);
|
||||||
|
|
||||||
|
static QString scriptGetExceptionInfo();
|
||||||
|
|
||||||
|
static void registerExceptionRoutines(asIScriptEngine *engine);
|
||||||
|
|
||||||
|
public:
|
||||||
// debug or release?
|
// debug or release?
|
||||||
bool isDebugMode() const;
|
bool isDebugMode() const;
|
||||||
void setDebugMode(bool isDbg);
|
void setDebugMode(bool isDbg);
|
||||||
|
|
|
@ -150,21 +150,19 @@ void WingAngelAPI::registerScriptFns(const QString &ns,
|
||||||
|
|
||||||
void WingAngelAPI::installAPI(ScriptMachine *machine) {
|
void WingAngelAPI::installAPI(ScriptMachine *machine) {
|
||||||
Q_ASSERT(machine);
|
Q_ASSERT(machine);
|
||||||
|
|
||||||
auto engine = machine->engine();
|
auto engine = machine->engine();
|
||||||
auto stringTypeID = machine->typeInfo(ScriptMachine::tString)->GetTypeId();
|
|
||||||
|
|
||||||
installBasicTypes(engine);
|
installBasicTypes(engine);
|
||||||
installExtAPI(engine);
|
installExtAPI(engine);
|
||||||
installLogAPI(engine);
|
installLogAPI(engine);
|
||||||
installMsgboxAPI(engine);
|
installMsgboxAPI(engine);
|
||||||
installInputboxAPI(engine, stringTypeID);
|
installInputboxAPI(engine);
|
||||||
installFileDialogAPI(engine);
|
installFileDialogAPI(engine);
|
||||||
installColorDialogAPI(engine);
|
installColorDialogAPI(engine);
|
||||||
|
|
||||||
installHexReaderAPI(engine);
|
installHexReaderAPI(engine);
|
||||||
installHexControllerAPI(engine);
|
installHexControllerAPI(engine);
|
||||||
installDataVisualAPI(engine, stringTypeID);
|
installDataVisualAPI(engine);
|
||||||
|
|
||||||
installScriptEnums(engine);
|
installScriptEnums(engine);
|
||||||
installScriptFns(engine);
|
installScriptFns(engine);
|
||||||
|
@ -192,6 +190,85 @@ void WingAngelAPI::installBasicTypes(asIScriptEngine *engine) {
|
||||||
|
|
||||||
engine->SetDefaultNamespace("");
|
engine->SetDefaultNamespace("");
|
||||||
|
|
||||||
|
// QModelIndex
|
||||||
|
r = engine->RegisterObjectType("ModelIndex", sizeof(QModelIndex),
|
||||||
|
asOBJ_VALUE | asOBJ_POD |
|
||||||
|
asGetTypeTraits<QModelIndex>());
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterObjectMethod("ModelIndex", "ModelIndex parent() const",
|
||||||
|
asMETHOD(QModelIndex, parent),
|
||||||
|
asCALL_THISCALL);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterObjectMethod("ModelIndex", "int row() const",
|
||||||
|
asMETHOD(QModelIndex, row),
|
||||||
|
asCALL_THISCALL);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterObjectMethod("ModelIndex", "int column() const",
|
||||||
|
asMETHOD(QModelIndex, column),
|
||||||
|
asCALL_THISCALL);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
// extension function for data, we dont want to register QVariant to it
|
||||||
|
r = engine->RegisterObjectMethod("ModelIndex", "string dataString() const",
|
||||||
|
asFUNCTION(QModelIndex_dataString),
|
||||||
|
asCALL_CDECL_OBJFIRST);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterObjectMethod("ModelIndex", "char dataChar() const",
|
||||||
|
asFUNCTION(QModelIndex_dataChar),
|
||||||
|
asCALL_CDECL_OBJFIRST);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterObjectMethod("ModelIndex", "uint dataUInt() const",
|
||||||
|
asFUNCTION(QModelIndex_dataUInt),
|
||||||
|
asCALL_CDECL_OBJFIRST);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterObjectMethod("ModelIndex", "int dataInt() const",
|
||||||
|
asFUNCTION(QModelIndex_dataInt),
|
||||||
|
asCALL_CDECL_OBJFIRST);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterObjectMethod("ModelIndex", "int64 dataLongLong() const",
|
||||||
|
asFUNCTION(QModelIndex_dataLongLong),
|
||||||
|
asCALL_CDECL_OBJFIRST);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterObjectMethod(
|
||||||
|
"ModelIndex", "uint64 dataULongLong() const",
|
||||||
|
asFUNCTION(QModelIndex_dataULongLong), asCALL_CDECL_OBJFIRST);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterObjectMethod("ModelIndex", "float dataFloat() const",
|
||||||
|
asFUNCTION(QModelIndex_dataFloat),
|
||||||
|
asCALL_CDECL_OBJFIRST);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterObjectMethod("ModelIndex", "double dataDouble() const",
|
||||||
|
asFUNCTION(QModelIndex_dataDouble),
|
||||||
|
asCALL_CDECL_OBJFIRST);
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
|
r = engine->RegisterFuncdef(
|
||||||
|
"void ClickCallBack(const ModelIndex &in index)");
|
||||||
|
Q_ASSERT(r >= 0);
|
||||||
|
Q_UNUSED(r);
|
||||||
|
|
||||||
installHexBaseType(engine);
|
installHexBaseType(engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +389,7 @@ void WingAngelAPI::installMsgboxAPI(asIScriptEngine *engine) {
|
||||||
engine->SetDefaultNamespace("");
|
engine->SetDefaultNamespace("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void WingAngelAPI::installInputboxAPI(asIScriptEngine *engine, int stringID) {
|
void WingAngelAPI::installInputboxAPI(asIScriptEngine *engine) {
|
||||||
int r = engine->SetDefaultNamespace("inputbox");
|
int r = engine->SetDefaultNamespace("inputbox");
|
||||||
Q_ASSERT(r >= 0);
|
Q_ASSERT(r >= 0);
|
||||||
Q_UNUSED(r);
|
Q_UNUSED(r);
|
||||||
|
@ -373,11 +450,10 @@ void WingAngelAPI::installInputboxAPI(asIScriptEngine *engine, int stringID) {
|
||||||
registerAPI<QString(const QString &, const QString &, const CScriptArray &,
|
registerAPI<QString(const QString &, const QString &, const CScriptArray &,
|
||||||
int, bool, bool *, Qt::InputMethodHints)>(
|
int, bool, bool *, Qt::InputMethodHints)>(
|
||||||
engine,
|
engine,
|
||||||
std::bind(&WingAngelAPI::_InputBox_getItem, this, stringID,
|
std::bind(&WingAngelAPI::_InputBox_getItem, this, std::placeholders::_1,
|
||||||
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_2, std::placeholders::_3,
|
||||||
std::placeholders::_3, std::placeholders::_4,
|
std::placeholders::_4, std::placeholders::_5,
|
||||||
std::placeholders::_5, std::placeholders::_6,
|
std::placeholders::_6, std::placeholders::_7),
|
||||||
std::placeholders::_7),
|
|
||||||
"string getItem(const string &in title, const string &in label, "
|
"string getItem(const string &in title, const string &in label, "
|
||||||
"const string[] &in items, int current = 0, "
|
"const string[] &in items, int current = 0, "
|
||||||
"bool editable = true, bool &out ok = false, "
|
"bool editable = true, bool &out ok = false, "
|
||||||
|
@ -1186,7 +1262,7 @@ void WingAngelAPI::installHexControllerAPI(asIScriptEngine *engine) {
|
||||||
engine->SetDefaultNamespace("");
|
engine->SetDefaultNamespace("");
|
||||||
}
|
}
|
||||||
|
|
||||||
void WingAngelAPI::installDataVisualAPI(asIScriptEngine *engine, int stringID) {
|
void WingAngelAPI::installDataVisualAPI(asIScriptEngine *engine) {
|
||||||
int r = engine->SetDefaultNamespace("visual");
|
int r = engine->SetDefaultNamespace("visual");
|
||||||
Q_ASSERT(r >= 0);
|
Q_ASSERT(r >= 0);
|
||||||
Q_UNUSED(r);
|
Q_UNUSED(r);
|
||||||
|
@ -1199,28 +1275,35 @@ void WingAngelAPI::installDataVisualAPI(asIScriptEngine *engine, int stringID) {
|
||||||
std::placeholders::_1, std::placeholders::_2),
|
std::placeholders::_1, std::placeholders::_2),
|
||||||
"bool updateText(string &in data, string &in title=\"\")");
|
"bool updateText(string &in data, string &in title=\"\")");
|
||||||
|
|
||||||
registerAPI<bool(const CScriptArray &, const QString &)>(
|
registerAPI<bool(const CScriptArray &, const QString &, asIScriptFunction *,
|
||||||
|
asIScriptFunction *)>(
|
||||||
engine,
|
engine,
|
||||||
std::bind(&WingAngelAPI::_DataVisual_updateTextList, this, stringID,
|
std::bind(&WingAngelAPI::_DataVisual_updateTextList, this,
|
||||||
std::placeholders::_1, std::placeholders::_2),
|
|
||||||
"bool updateTextList(string[] &in data, string &in title=\"\")");
|
|
||||||
|
|
||||||
registerAPI<bool(const QString &, const QString &)>(
|
|
||||||
engine,
|
|
||||||
std::bind(&WingHex::WingPlugin::DataVisual::updateTextTree, datavis,
|
|
||||||
std::placeholders::_1, std::placeholders::_2,
|
|
||||||
WingHex::WingPlugin::DataVisual::ClickedCallBack(),
|
|
||||||
WingHex::WingPlugin::DataVisual::DoubleClickedCallBack()),
|
|
||||||
"bool updateTextTree(string &in json, string &in title=\"\")");
|
|
||||||
|
|
||||||
registerAPI<bool(const QString &, const CScriptArray &,
|
|
||||||
const CScriptArray &, const QString &)>(
|
|
||||||
engine,
|
|
||||||
std::bind(&WingAngelAPI::_DataVisual_updateTextTable, this, stringID,
|
|
||||||
std::placeholders::_1, std::placeholders::_2,
|
std::placeholders::_1, std::placeholders::_2,
|
||||||
std::placeholders::_3, std::placeholders::_4),
|
std::placeholders::_3, std::placeholders::_4),
|
||||||
|
"bool updateTextList(string[] &in data, string &in title=\"\", "
|
||||||
|
"ClickCallBack @clickfn = null, ClickCallBack @dblclick = null)");
|
||||||
|
|
||||||
|
registerAPI<bool(const QString &, const QString &, asIScriptFunction *,
|
||||||
|
asIScriptFunction *)>(
|
||||||
|
engine,
|
||||||
|
std::bind(&WingAngelAPI::_DataVisual_updateTextTree, this,
|
||||||
|
std::placeholders::_1, std::placeholders::_2,
|
||||||
|
std::placeholders::_3, std::placeholders::_4),
|
||||||
|
"bool updateTextTree(string &in json, string &in title=\"\", "
|
||||||
|
"ClickCallBack @clickfn = null, ClickCallBack @dblclick = null)");
|
||||||
|
|
||||||
|
registerAPI<bool(const QString &, const CScriptArray &,
|
||||||
|
const CScriptArray &, const QString &, asIScriptFunction *,
|
||||||
|
asIScriptFunction *)>(
|
||||||
|
engine,
|
||||||
|
std::bind(&WingAngelAPI::_DataVisual_updateTextTable, this,
|
||||||
|
std::placeholders::_1, std::placeholders::_2,
|
||||||
|
std::placeholders::_3, std::placeholders::_4,
|
||||||
|
std::placeholders::_5, std::placeholders::_6),
|
||||||
"bool updateTextTable(string &in json, string[] &in headers, "
|
"bool updateTextTable(string &in json, string[] &in headers, "
|
||||||
"string[] &in headerNames = {}, string &in title=\"\")");
|
"string[] &in headerNames = {}, string &in title=\"\", "
|
||||||
|
"ClickCallBack @clickfn = null, ClickCallBack @dblclick = null)");
|
||||||
|
|
||||||
engine->SetDefaultNamespace("");
|
engine->SetDefaultNamespace("");
|
||||||
}
|
}
|
||||||
|
@ -1992,6 +2075,38 @@ void WingAngelAPI::script_unsafe_call(asIScriptGeneric *gen) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString WingAngelAPI::QModelIndex_dataString(const QModelIndex &idx) {
|
||||||
|
return idx.data().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString WingAngelAPI::QModelIndex_dataChar(const QModelIndex &idx) {
|
||||||
|
return idx.data().toChar();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint WingAngelAPI::QModelIndex_dataUInt(const QModelIndex &idx) {
|
||||||
|
return idx.data().toUInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
int WingAngelAPI::QModelIndex_dataInt(const QModelIndex &idx) {
|
||||||
|
return idx.data().toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
qlonglong WingAngelAPI::QModelIndex_dataLongLong(const QModelIndex &idx) {
|
||||||
|
return idx.data().toLongLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
qlonglong WingAngelAPI::QModelIndex_dataULongLong(const QModelIndex &idx) {
|
||||||
|
return idx.data().toULongLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
float WingAngelAPI::QModelIndex_dataFloat(const QModelIndex &idx) {
|
||||||
|
return idx.data().toFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
double WingAngelAPI::QModelIndex_dataDouble(const QModelIndex &idx) {
|
||||||
|
return idx.data().toDouble();
|
||||||
|
}
|
||||||
|
|
||||||
bool WingAngelAPI::execScriptCode(const WingHex::SenderInfo &sender,
|
bool WingAngelAPI::execScriptCode(const WingHex::SenderInfo &sender,
|
||||||
const QString &code) {
|
const QString &code) {
|
||||||
if (code.isEmpty()) {
|
if (code.isEmpty()) {
|
||||||
|
@ -2176,20 +2291,29 @@ void WingAngelAPI::cleanUpHandles(const QVector<int> &handles) {
|
||||||
_handles = handles;
|
_handles = handles;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString WingAngelAPI::_InputBox_getItem(int stringID, const QString &title,
|
QString WingAngelAPI::_InputBox_getItem(const QString &title,
|
||||||
const QString &label,
|
const QString &label,
|
||||||
const CScriptArray &items, int current,
|
const CScriptArray &items, int current,
|
||||||
bool editable, bool *ok,
|
bool editable, bool *ok,
|
||||||
Qt::InputMethodHints inputMethodHints) {
|
Qt::InputMethodHints inputMethodHints) {
|
||||||
bool o = false;
|
asIScriptContext *ctx = asGetActiveContext();
|
||||||
auto ret = cArray2QStringList(items, stringID, &o);
|
if (ctx) {
|
||||||
if (o) {
|
auto engine = ctx->GetEngine();
|
||||||
return WingInputDialog::getItem(nullptr, title, label, ret, current,
|
Q_ASSERT(engine);
|
||||||
editable, ok, inputMethodHints);
|
auto stringID = engine->GetTypeIdByDecl("string");
|
||||||
} else {
|
Q_ASSERT(stringID >= 0);
|
||||||
*ok = false;
|
|
||||||
return {};
|
bool o = false;
|
||||||
|
auto ret = cArray2QStringList(items, stringID, &o);
|
||||||
|
if (o) {
|
||||||
|
return WingInputDialog::getItem(nullptr, title, label, ret, current,
|
||||||
|
editable, ok, inputMethodHints);
|
||||||
|
} else {
|
||||||
|
*ok = false;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
CScriptArray *WingAngelAPI::_FileDialog_getOpenFileNames(
|
CScriptArray *WingAngelAPI::_FileDialog_getOpenFileNames(
|
||||||
|
@ -2394,40 +2518,82 @@ bool WingAngelAPI::_HexController_appendBytes(const CScriptArray &ba) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return emit controller.appendBytes(bab);
|
return emit controller.appendBytes(bab);
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WingAngelAPI::_DataVisual_updateTextList(int stringID,
|
bool WingAngelAPI::_DataVisual_updateTextList(const CScriptArray &data,
|
||||||
const CScriptArray &data,
|
const QString &title,
|
||||||
const QString &title) {
|
asIScriptFunction *click,
|
||||||
bool o = false;
|
asIScriptFunction *dblclick) {
|
||||||
auto ret = cArray2QStringList(data, stringID, &o);
|
asIScriptContext *ctx = asGetActiveContext();
|
||||||
if (o) {
|
if (ctx) {
|
||||||
return emit visual.updateTextList(ret, title);
|
auto engine = ctx->GetEngine();
|
||||||
} else {
|
Q_ASSERT(engine);
|
||||||
return false;
|
auto stringID = engine->GetTypeIdByDecl("string");
|
||||||
|
Q_ASSERT(stringID >= 0);
|
||||||
|
|
||||||
|
// we dont call visual.updateTextList
|
||||||
|
bool o = false;
|
||||||
|
auto ret = cArray2QStringList(data, stringID, &o);
|
||||||
|
if (o) {
|
||||||
|
ClickCallBack c(engine, click);
|
||||||
|
ClickCallBack dblc(engine, dblclick);
|
||||||
|
|
||||||
|
return PluginSystem::instance().updateTextList_API(ret, title, c,
|
||||||
|
dblc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WingAngelAPI::_DataVisual_updateTextTable(int stringID,
|
bool WingAngelAPI::_DataVisual_updateTextTree(const QString &json,
|
||||||
const QString &json,
|
const QString &title,
|
||||||
|
asIScriptFunction *click,
|
||||||
|
asIScriptFunction *dblclick) {
|
||||||
|
asIScriptContext *ctx = asGetActiveContext();
|
||||||
|
if (ctx) {
|
||||||
|
auto engine = ctx->GetEngine();
|
||||||
|
Q_ASSERT(engine);
|
||||||
|
|
||||||
|
// we dont call visual.updateTextTree
|
||||||
|
ClickCallBack c(engine, click);
|
||||||
|
ClickCallBack dblc(engine, dblclick);
|
||||||
|
|
||||||
|
return PluginSystem::instance().updateTextTree_API(json, title, c,
|
||||||
|
dblc);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WingAngelAPI::_DataVisual_updateTextTable(const QString &json,
|
||||||
const CScriptArray &headers,
|
const CScriptArray &headers,
|
||||||
const CScriptArray &headerNames,
|
const CScriptArray &headerNames,
|
||||||
const QString &title) {
|
const QString &title,
|
||||||
bool o = false;
|
asIScriptFunction *click,
|
||||||
auto h = cArray2QStringList(headers, stringID, &o);
|
asIScriptFunction *dblclick) {
|
||||||
if (o) {
|
asIScriptContext *ctx = asGetActiveContext();
|
||||||
auto hn = cArray2QStringList(headerNames, stringID, &o);
|
if (ctx) {
|
||||||
|
auto engine = ctx->GetEngine();
|
||||||
|
Q_ASSERT(engine);
|
||||||
|
auto stringID = engine->GetTypeIdByDecl("string");
|
||||||
|
Q_ASSERT(stringID >= 0);
|
||||||
|
|
||||||
|
// we dont call visual.updateTextTable
|
||||||
|
bool o = false;
|
||||||
|
auto h = cArray2QStringList(headers, stringID, &o);
|
||||||
if (o) {
|
if (o) {
|
||||||
return emit visual.updateTextTable(json, h, hn, title);
|
auto hn = cArray2QStringList(headerNames, stringID, &o);
|
||||||
} else {
|
if (o) {
|
||||||
return false;
|
ClickCallBack c(engine, click);
|
||||||
|
ClickCallBack dblc(engine, dblclick);
|
||||||
|
|
||||||
|
return PluginSystem::instance().updateTextTable_API(
|
||||||
|
json, h, hn, title, c, dblc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WingAngelAPI::setBindingConsole(ScriptingConsole *console) {
|
void WingAngelAPI::setBindingConsole(ScriptingConsole *console) {
|
||||||
|
|
|
@ -70,6 +70,7 @@ public:
|
||||||
void installBasicTypes(asIScriptEngine *engine);
|
void installBasicTypes(asIScriptEngine *engine);
|
||||||
|
|
||||||
void setBindingConsole(ScriptingConsole *console);
|
void setBindingConsole(ScriptingConsole *console);
|
||||||
|
void unBindConsole();
|
||||||
|
|
||||||
static QString qvariantCastASString(const QMetaType::Type &id);
|
static QString qvariantCastASString(const QMetaType::Type &id);
|
||||||
|
|
||||||
|
@ -89,13 +90,13 @@ private:
|
||||||
void installLogAPI(asIScriptEngine *engine);
|
void installLogAPI(asIScriptEngine *engine);
|
||||||
void installExtAPI(asIScriptEngine *engine);
|
void installExtAPI(asIScriptEngine *engine);
|
||||||
void installMsgboxAPI(asIScriptEngine *engine);
|
void installMsgboxAPI(asIScriptEngine *engine);
|
||||||
void installInputboxAPI(asIScriptEngine *engine, int stringID);
|
void installInputboxAPI(asIScriptEngine *engine);
|
||||||
void installFileDialogAPI(asIScriptEngine *engine);
|
void installFileDialogAPI(asIScriptEngine *engine);
|
||||||
void installColorDialogAPI(asIScriptEngine *engine);
|
void installColorDialogAPI(asIScriptEngine *engine);
|
||||||
void installHexBaseType(asIScriptEngine *engine);
|
void installHexBaseType(asIScriptEngine *engine);
|
||||||
void installHexReaderAPI(asIScriptEngine *engine);
|
void installHexReaderAPI(asIScriptEngine *engine);
|
||||||
void installHexControllerAPI(asIScriptEngine *engine);
|
void installHexControllerAPI(asIScriptEngine *engine);
|
||||||
void installDataVisualAPI(asIScriptEngine *engine, int stringID);
|
void installDataVisualAPI(asIScriptEngine *engine);
|
||||||
void installScriptFns(asIScriptEngine *engine);
|
void installScriptFns(asIScriptEngine *engine);
|
||||||
void installScriptUnSafeFns(asIScriptEngine *engine);
|
void installScriptUnSafeFns(asIScriptEngine *engine);
|
||||||
void installScriptEnums(asIScriptEngine *engine);
|
void installScriptEnums(asIScriptEngine *engine);
|
||||||
|
@ -155,6 +156,16 @@ private:
|
||||||
|
|
||||||
static void script_unsafe_call(asIScriptGeneric *gen);
|
static void script_unsafe_call(asIScriptGeneric *gen);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static QString QModelIndex_dataString(const QModelIndex &idx);
|
||||||
|
static QString QModelIndex_dataChar(const QModelIndex &idx);
|
||||||
|
static uint QModelIndex_dataUInt(const QModelIndex &idx);
|
||||||
|
static int QModelIndex_dataInt(const QModelIndex &idx);
|
||||||
|
static qlonglong QModelIndex_dataLongLong(const QModelIndex &idx);
|
||||||
|
static qlonglong QModelIndex_dataULongLong(const QModelIndex &idx);
|
||||||
|
static float QModelIndex_dataFloat(const QModelIndex &idx);
|
||||||
|
static double QModelIndex_dataDouble(const QModelIndex &idx);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WING_SERVICE bool execScriptCode(const WingHex::SenderInfo &sender,
|
WING_SERVICE bool execScriptCode(const WingHex::SenderInfo &sender,
|
||||||
const QString &code);
|
const QString &code);
|
||||||
|
@ -192,9 +203,9 @@ private:
|
||||||
void cleanUpHandles(const QVector<int> &handles);
|
void cleanUpHandles(const QVector<int> &handles);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString _InputBox_getItem(int stringID, const QString &title,
|
QString _InputBox_getItem(const QString &title, const QString &label,
|
||||||
const QString &label, const CScriptArray &items,
|
const CScriptArray &items, int current,
|
||||||
int current, bool editable, bool *ok,
|
bool editable, bool *ok,
|
||||||
Qt::InputMethodHints inputMethodHints);
|
Qt::InputMethodHints inputMethodHints);
|
||||||
|
|
||||||
CScriptArray *_FileDialog_getOpenFileNames(const QString &caption,
|
CScriptArray *_FileDialog_getOpenFileNames(const QString &caption,
|
||||||
|
@ -229,13 +240,22 @@ private:
|
||||||
|
|
||||||
bool _HexController_appendBytes(const CScriptArray &ba);
|
bool _HexController_appendBytes(const CScriptArray &ba);
|
||||||
|
|
||||||
bool _DataVisual_updateTextList(int stringID, const CScriptArray &data,
|
private:
|
||||||
const QString &title);
|
bool _DataVisual_updateTextList(const CScriptArray &data,
|
||||||
|
const QString &title,
|
||||||
|
asIScriptFunction *click,
|
||||||
|
asIScriptFunction *dblclick);
|
||||||
|
|
||||||
bool _DataVisual_updateTextTable(int stringID, const QString &json,
|
bool _DataVisual_updateTextTree(const QString &json, const QString &title,
|
||||||
|
asIScriptFunction *click,
|
||||||
|
asIScriptFunction *dblclick);
|
||||||
|
|
||||||
|
bool _DataVisual_updateTextTable(const QString &json,
|
||||||
const CScriptArray &headers,
|
const CScriptArray &headers,
|
||||||
const CScriptArray &headerNames,
|
const CScriptArray &headerNames,
|
||||||
const QString &title);
|
const QString &title,
|
||||||
|
asIScriptFunction *click,
|
||||||
|
asIScriptFunction *dblclick);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::any> _fnbuffer;
|
std::vector<std::any> _fnbuffer;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "scriptingconsole.h"
|
#include "scriptingconsole.h"
|
||||||
|
#include "class/logger.h"
|
||||||
#include "class/scriptconsolemachine.h"
|
#include "class/scriptconsolemachine.h"
|
||||||
#include "qregularexpression.h"
|
#include "qregularexpression.h"
|
||||||
|
|
||||||
|
@ -51,25 +52,48 @@ void ScriptingConsole::init() {
|
||||||
connect(_sp, &ScriptConsoleMachine::onOutput, this,
|
connect(_sp, &ScriptConsoleMachine::onOutput, this,
|
||||||
[=](ScriptConsoleMachine::MessageType type,
|
[=](ScriptConsoleMachine::MessageType type,
|
||||||
const ScriptConsoleMachine::MessageInfo &message) {
|
const ScriptConsoleMachine::MessageInfo &message) {
|
||||||
switch (type) {
|
// If running ouput in the console,
|
||||||
case ScriptMachine::MessageType::Info:
|
// otherwise logging.
|
||||||
stdOut(tr("[Info]") + message.message);
|
if (_sp->isRunning()) {
|
||||||
_s << Qt::flush;
|
switch (type) {
|
||||||
newLine();
|
case ScriptMachine::MessageType::Info:
|
||||||
break;
|
stdOut(tr("[Info]") + message.message);
|
||||||
case ScriptMachine::MessageType::Warn:
|
_s << Qt::flush;
|
||||||
stdWarn(tr("[Warn]") + message.message);
|
newLine();
|
||||||
_s << Qt::flush;
|
break;
|
||||||
newLine();
|
case ScriptMachine::MessageType::Warn:
|
||||||
break;
|
stdWarn(tr("[Warn]") + message.message);
|
||||||
case ScriptMachine::MessageType::Error:
|
_s << Qt::flush;
|
||||||
stdErr(tr("[Error]") + message.message);
|
newLine();
|
||||||
_s << Qt::flush;
|
break;
|
||||||
newLine();
|
case ScriptMachine::MessageType::Error:
|
||||||
break;
|
stdErr(tr("[Error]") + message.message);
|
||||||
case ScriptMachine::MessageType::Print:
|
_s << Qt::flush;
|
||||||
stdOut(message.message);
|
newLine();
|
||||||
break;
|
break;
|
||||||
|
case ScriptMachine::MessageType::Print:
|
||||||
|
stdOut(message.message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (type) {
|
||||||
|
case ScriptMachine::MessageType::Info:
|
||||||
|
Logger::logPrint(Logger::packInfoStr(
|
||||||
|
packUpLoggingStr(message.message)));
|
||||||
|
break;
|
||||||
|
case ScriptMachine::MessageType::Warn:
|
||||||
|
Logger::logPrint(Logger::packWarnStr(
|
||||||
|
packUpLoggingStr(message.message)));
|
||||||
|
break;
|
||||||
|
case ScriptMachine::MessageType::Error:
|
||||||
|
Logger::logPrint(Logger::packErrorStr(
|
||||||
|
packUpLoggingStr(message.message)));
|
||||||
|
break;
|
||||||
|
case ScriptMachine::MessageType::Print:
|
||||||
|
Logger::logPrint(Logger::packDebugStr(
|
||||||
|
packUpLoggingStr(message.message)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -155,6 +179,10 @@ QString ScriptingConsole::getInput() {
|
||||||
return instr;
|
return instr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ScriptingConsole::packUpLoggingStr(const QString &message) {
|
||||||
|
return tr("[Console]") + message;
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptingConsole::keyPressEvent(QKeyEvent *e) {
|
void ScriptingConsole::keyPressEvent(QKeyEvent *e) {
|
||||||
if (e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_L) {
|
if (e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_L) {
|
||||||
clearConsole();
|
clearConsole();
|
||||||
|
|
|
@ -58,6 +58,8 @@ private:
|
||||||
|
|
||||||
QString getInput();
|
QString getInput();
|
||||||
|
|
||||||
|
QString packUpLoggingStr(const QString &message);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *e) override;
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "QWingRibbon/ribbontabcontent.h"
|
#include "QWingRibbon/ribbontabcontent.h"
|
||||||
#include "Qt-Advanced-Docking-System/src/DockManager.h"
|
#include "Qt-Advanced-Docking-System/src/DockManager.h"
|
||||||
#include "Qt-Advanced-Docking-System/src/DockWidget.h"
|
#include "Qt-Advanced-Docking-System/src/DockWidget.h"
|
||||||
|
#include "class/clickcallback.h"
|
||||||
#include "class/recentfilemanager.h"
|
#include "class/recentfilemanager.h"
|
||||||
#include "class/scriptmanager.h"
|
#include "class/scriptmanager.h"
|
||||||
#include "class/wingprogressdialog.h"
|
#include "class/wingprogressdialog.h"
|
||||||
|
@ -61,9 +62,8 @@ class MainWindow : public FramelessMainWindow {
|
||||||
|
|
||||||
friend class PluginSystem;
|
friend class PluginSystem;
|
||||||
|
|
||||||
using ClickedCallBack = WingHex::WingPlugin::DataVisual::ClickedCallBack;
|
using ClickedCallBack = ClickCallBack;
|
||||||
using DblClickedCallBack =
|
using DblClickedCallBack = ClickCallBack;
|
||||||
WingHex::WingPlugin::DataVisual::DoubleClickedCallBack;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(SplashDialog *splash);
|
explicit MainWindow(SplashDialog *splash);
|
||||||
|
|
|
@ -1392,6 +1392,77 @@ void PluginSystem::registerPluginPages(IWingPluginBase *p) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PluginSystem::updateTextList_API(const QStringList &data,
|
||||||
|
const QString &title,
|
||||||
|
const ClickCallBack &click,
|
||||||
|
const ClickCallBack &dblclick) {
|
||||||
|
auto oldmodel = _win->m_infolist->model();
|
||||||
|
if (oldmodel) {
|
||||||
|
oldmodel->deleteLater();
|
||||||
|
}
|
||||||
|
_win->m_infolist->setProperty("__TITLE__", title);
|
||||||
|
auto model = new QStringListModel(data);
|
||||||
|
_win->m_infolist->setModel(model);
|
||||||
|
_win->m_infoclickfn = click;
|
||||||
|
_win->m_infodblclickfn = dblclick;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PluginSystem::updateTextTree_API(const QString &json, const QString &title,
|
||||||
|
const ClickCallBack &click,
|
||||||
|
const ClickCallBack &dblclick) {
|
||||||
|
auto oldmodel = _win->m_infotree->model();
|
||||||
|
if (oldmodel) {
|
||||||
|
oldmodel->deleteLater();
|
||||||
|
}
|
||||||
|
_win->m_infotree->setProperty("__TITLE__", title);
|
||||||
|
auto model = new QJsonModel;
|
||||||
|
if (model->loadJson(json.toUtf8())) {
|
||||||
|
_win->m_infotree->setModel(model);
|
||||||
|
_win->m_infotreeclickfn = click;
|
||||||
|
_win->m_infotreedblclickfn = dblclick;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PluginSystem::updateTextTable_API(const QString &json,
|
||||||
|
const QStringList &headers,
|
||||||
|
const QStringList &headerNames,
|
||||||
|
const QString &title,
|
||||||
|
const ClickCallBack &click,
|
||||||
|
const ClickCallBack &dblclick) {
|
||||||
|
auto oldmodel = _win->m_infotable->model();
|
||||||
|
if (oldmodel) {
|
||||||
|
oldmodel->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonTableModel::Header header;
|
||||||
|
if (headers.size() > headerNames.size()) {
|
||||||
|
for (auto &name : headers) {
|
||||||
|
QJsonTableModel::Heading heading;
|
||||||
|
heading["index"] = name;
|
||||||
|
heading["title"] = name;
|
||||||
|
header.append(heading);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
auto np = headerNames.cbegin();
|
||||||
|
for (auto p = headers.cbegin(); p != headers.cend(); ++p, ++np) {
|
||||||
|
QJsonTableModel::Heading heading;
|
||||||
|
heading["index"] = *p;
|
||||||
|
heading["title"] = *np;
|
||||||
|
header.append(heading);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_win->m_infotable->setProperty("__TITLE__", title);
|
||||||
|
auto model = new QJsonTableModel(header);
|
||||||
|
model->setJson(QJsonDocument::fromJson(json.toUtf8()));
|
||||||
|
_win->m_infotable->setModel(model);
|
||||||
|
_win->m_infotableclickfn = click;
|
||||||
|
_win->m_infotabledblclickfn = dblclick;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void PluginSystem::connectInterface(IWingPlugin *plg) {
|
void PluginSystem::connectInterface(IWingPlugin *plg) {
|
||||||
connectReaderInterface(plg);
|
connectReaderInterface(plg);
|
||||||
connectControllerInterface(plg);
|
connectControllerInterface(plg);
|
||||||
|
@ -2829,16 +2900,7 @@ void PluginSystem::connectUIInterface(IWingPlugin *plg) {
|
||||||
WingHex::WingPlugin::DataVisual::ClickedCallBack clicked,
|
WingHex::WingPlugin::DataVisual::ClickedCallBack clicked,
|
||||||
WingHex::WingPlugin::DataVisual::DoubleClickedCallBack dblClicked)
|
WingHex::WingPlugin::DataVisual::DoubleClickedCallBack dblClicked)
|
||||||
-> bool {
|
-> bool {
|
||||||
auto oldmodel = _win->m_infolist->model();
|
return updateTextList_API(data, title, clicked, dblClicked);
|
||||||
if (oldmodel) {
|
|
||||||
oldmodel->deleteLater();
|
|
||||||
}
|
|
||||||
_win->m_infolist->setProperty("__TITLE__", title);
|
|
||||||
auto model = new QStringListModel(data);
|
|
||||||
_win->m_infolist->setModel(model);
|
|
||||||
_win->m_infoclickfn = clicked;
|
|
||||||
_win->m_infodblclickfn = dblClicked;
|
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
connect(
|
connect(
|
||||||
visual, &WingPlugin::DataVisual::updateTextListByModel, _win,
|
visual, &WingPlugin::DataVisual::updateTextListByModel, _win,
|
||||||
|
@ -2865,19 +2927,7 @@ void PluginSystem::connectUIInterface(IWingPlugin *plg) {
|
||||||
WingHex::WingPlugin::DataVisual::ClickedCallBack clicked,
|
WingHex::WingPlugin::DataVisual::ClickedCallBack clicked,
|
||||||
WingHex::WingPlugin::DataVisual::DoubleClickedCallBack dblClicked)
|
WingHex::WingPlugin::DataVisual::DoubleClickedCallBack dblClicked)
|
||||||
-> bool {
|
-> bool {
|
||||||
auto oldmodel = _win->m_infotree->model();
|
return updateTextTree_API(json, title, clicked, dblClicked);
|
||||||
if (oldmodel) {
|
|
||||||
oldmodel->deleteLater();
|
|
||||||
}
|
|
||||||
_win->m_infotree->setProperty("__TITLE__", title);
|
|
||||||
auto model = new QJsonModel;
|
|
||||||
if (model->loadJson(json.toUtf8())) {
|
|
||||||
_win->m_infotree->setModel(model);
|
|
||||||
_win->m_infotreeclickfn = clicked;
|
|
||||||
_win->m_infotreedblclickfn = dblClicked;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
connect(
|
connect(
|
||||||
visual, &WingPlugin::DataVisual::updateTextTreeByModel, _win,
|
visual, &WingPlugin::DataVisual::updateTextTreeByModel, _win,
|
||||||
|
@ -2905,36 +2955,8 @@ void PluginSystem::connectUIInterface(IWingPlugin *plg) {
|
||||||
WingHex::WingPlugin::DataVisual::ClickedCallBack clicked,
|
WingHex::WingPlugin::DataVisual::ClickedCallBack clicked,
|
||||||
WingHex::WingPlugin::DataVisual::DoubleClickedCallBack dblClicked)
|
WingHex::WingPlugin::DataVisual::DoubleClickedCallBack dblClicked)
|
||||||
-> bool {
|
-> bool {
|
||||||
auto oldmodel = _win->m_infotable->model();
|
return updateTextTable_API(json, headers, headerNames, title,
|
||||||
if (oldmodel) {
|
clicked, dblClicked);
|
||||||
oldmodel->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonTableModel::Header header;
|
|
||||||
if (headers.size() > headerNames.size()) {
|
|
||||||
for (auto &name : headers) {
|
|
||||||
QJsonTableModel::Heading heading;
|
|
||||||
heading["index"] = name;
|
|
||||||
heading["title"] = name;
|
|
||||||
header.append(heading);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
auto np = headerNames.cbegin();
|
|
||||||
for (auto p = headers.cbegin(); p != headers.cend();
|
|
||||||
++p, ++np) {
|
|
||||||
QJsonTableModel::Heading heading;
|
|
||||||
heading["index"] = *p;
|
|
||||||
heading["title"] = *np;
|
|
||||||
header.append(heading);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_win->m_infotable->setProperty("__TITLE__", title);
|
|
||||||
auto model = new QJsonTableModel(header);
|
|
||||||
model->setJson(QJsonDocument::fromJson(json.toUtf8()));
|
|
||||||
_win->m_infotable->setModel(model);
|
|
||||||
_win->m_infotableclickfn = clicked;
|
|
||||||
_win->m_infotabledblclickfn = dblClicked;
|
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
connect(
|
connect(
|
||||||
visual, &WingPlugin::DataVisual::updateTextTableByModel, _win,
|
visual, &WingPlugin::DataVisual::updateTextTableByModel, _win,
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include "class/clickcallback.h"
|
||||||
#include "class/wingangelapi.h"
|
#include "class/wingangelapi.h"
|
||||||
#include "control/editorview.h"
|
#include "control/editorview.h"
|
||||||
#include "plugin/iwingdevice.h"
|
#include "plugin/iwingdevice.h"
|
||||||
|
@ -257,6 +258,18 @@ private:
|
||||||
void registerPluginDockWidgets(IWingPluginBase *p);
|
void registerPluginDockWidgets(IWingPluginBase *p);
|
||||||
void registerPluginPages(IWingPluginBase *p);
|
void registerPluginPages(IWingPluginBase *p);
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool updateTextList_API(const QStringList &data, const QString &title,
|
||||||
|
const ClickCallBack &click,
|
||||||
|
const ClickCallBack &dblclick);
|
||||||
|
bool updateTextTree_API(const QString &json, const QString &title,
|
||||||
|
const ClickCallBack &click,
|
||||||
|
const ClickCallBack &dblclick);
|
||||||
|
bool updateTextTable_API(const QString &json, const QStringList &headers,
|
||||||
|
const QStringList &headerNames,
|
||||||
|
const QString &title, const ClickCallBack &click,
|
||||||
|
const ClickCallBack &dblclick);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T readBasicTypeContent(IWingPlugin *plg, qsizetype offset) {
|
T readBasicTypeContent(IWingPlugin *plg, qsizetype offset) {
|
||||||
|
|
|
@ -46,8 +46,6 @@ QDocumentSwapTextCommand::QDocumentSwapTextCommand(const QString &text,
|
||||||
}
|
}
|
||||||
|
|
||||||
auto cursor = doc->editCursor();
|
auto cursor = doc->editCursor();
|
||||||
_line = cursor->lineNumber();
|
|
||||||
_column = cursor->columnNumber();
|
|
||||||
setTargetCursor(cursor->handle());
|
setTargetCursor(cursor->handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,6 @@ private:
|
||||||
QList<QDocumentLineHandle *> _handles;
|
QList<QDocumentLineHandle *> _handles;
|
||||||
QList<QDocumentLineHandle *> _oldhandles;
|
QList<QDocumentLineHandle *> _oldhandles;
|
||||||
QVector<DiffUtil::DiffEntry> diffs;
|
QVector<DiffUtil::DiffEntry> diffs;
|
||||||
|
|
||||||
int _line, _column;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QDOCUMENTSWAPTEXTCOMMAND_H
|
#endif // QDOCUMENTSWAPTEXTCOMMAND_H
|
||||||
|
|
Loading…
Reference in New Issue