fix: 修复设置无法重置的问题;一些增强和修复;

This commit is contained in:
寂静的羽夏 2025-05-10 21:07:41 +08:00
parent 066ab5375b
commit 57bd7b7c61
19 changed files with 1136 additions and 979 deletions

View File

@ -704,27 +704,31 @@ void QHexDocument::beginMarco(const QString &text) {
void QHexDocument::endMarco() { m_undostack->endMacro(); }
void QHexDocument::Insert(QHexCursor *cursor, qsizetype offset, uchar b,
bool QHexDocument::Insert(QHexCursor *cursor, qsizetype offset, uchar b,
int nibbleindex) {
this->Insert(cursor, offset, QByteArray(1, char(b)), nibbleindex);
return this->Insert(cursor, offset, QByteArray(1, char(b)), nibbleindex);
}
void QHexDocument::Replace(QHexCursor *cursor, qsizetype offset, uchar b,
bool QHexDocument::Replace(QHexCursor *cursor, qsizetype offset, uchar b,
int nibbleindex) {
this->Replace(cursor, offset, QByteArray(1, char(b)), nibbleindex);
return this->Replace(cursor, offset, QByteArray(1, char(b)), nibbleindex);
}
void QHexDocument::Insert(QHexCursor *cursor, qsizetype offset,
bool QHexDocument::Insert(QHexCursor *cursor, qsizetype offset,
const QByteArray &data, int nibbleindex) {
if (m_keepsize || m_readonly || m_islocked)
return;
if (m_keepsize || m_readonly || m_islocked) {
return false;
}
auto cmd = MakeInsert(nullptr, cursor, offset, data, nibbleindex);
if (cmd) {
m_undostack->push(cmd);
} else {
return false;
}
emit documentChanged();
return true;
}
void QHexDocument::Append(QHexCursor *cursor, uchar b, int nibbleindex) {
@ -742,15 +746,19 @@ void QHexDocument::Append(QHexCursor *cursor, const QByteArray &data,
emit documentChanged();
}
void QHexDocument::Replace(QHexCursor *cursor, qsizetype offset,
bool QHexDocument::Replace(QHexCursor *cursor, qsizetype offset,
const QByteArray &data, int nibbleindex) {
if (m_readonly || m_islocked)
return;
if (m_readonly || m_islocked) {
return false;
}
auto cmd = MakeReplace(nullptr, cursor, offset, data, nibbleindex);
if (cmd) {
m_undostack->push(cmd);
} else {
return false;
}
emit documentChanged();
return true;
}
bool QHexDocument::Remove(QHexCursor *cursor, qsizetype offset, qsizetype len,

View File

@ -148,14 +148,14 @@ public slots:
void beginMarco(const QString &text);
void endMarco();
void Insert(QHexCursor *cursor, qsizetype offset, uchar b, int nibbleindex);
void Insert(QHexCursor *cursor, qsizetype offset, const QByteArray &data,
bool Insert(QHexCursor *cursor, qsizetype offset, uchar b, int nibbleindex);
bool Insert(QHexCursor *cursor, qsizetype offset, const QByteArray &data,
int nibbleindex);
void Append(QHexCursor *cursor, uchar b, int nibbleindex);
void Append(QHexCursor *cursor, const QByteArray &data, int nibbleindex);
void Replace(QHexCursor *cursor, qsizetype offset, uchar b,
bool Replace(QHexCursor *cursor, qsizetype offset, uchar b,
int nibbleindex);
void Replace(QHexCursor *cursor, qsizetype offset, const QByteArray &data,
bool Replace(QHexCursor *cursor, qsizetype offset, const QByteArray &data,
int nibbleindex = 0);
bool Remove(QHexCursor *cursor, qsizetype offset, qsizetype len,
int nibbleindex = 0);

View File

@ -355,7 +355,7 @@ qsizetype QHexView::findPrevious(qsizetype begin, const QByteArray &ba) {
bool QHexView::RemoveSelection(int nibbleindex) {
if (!m_cursor->hasSelection())
return false;
return true;
auto total = m_cursor->selectionCount();
m_document->beginMarco(QStringLiteral("RemoveSelection"));
@ -375,7 +375,7 @@ bool QHexView::RemoveSelection(int nibbleindex) {
bool QHexView::removeSelection() {
if (!m_cursor->hasSelection())
return false;
return true;
// We essure selections are ordered by desending
// by selection-start, so it's safe to remove
@ -417,7 +417,7 @@ QByteArrayList QHexView::selectedBytes() const {
return res;
}
void QHexView::paste(bool hex) {
bool QHexView::paste(bool hex) {
QClipboard *c = qApp->clipboard();
QByteArray data;
@ -426,19 +426,28 @@ void QHexView::paste(bool hex) {
} else {
auto d = c->mimeData();
data = d->data(QStringLiteral("application/octet-stream"));
if (data.isEmpty()) {
data = d->text().toUtf8();
}
}
if (data.isEmpty())
return;
if (data.isEmpty()) {
return true;
}
this->removeSelection();
auto ret = this->removeSelection();
if (!ret) {
return false;
}
auto pos = m_cursor->position().offset();
if (!m_document->isKeepSize()) {
m_document->insert(pos, data);
bool ret = m_document->insert(pos, data);
m_cursor->moveTo(pos + data.length()); // added by wingsummer
} else
m_document->replace(pos, data);
return ret;
} else {
return m_document->replace(pos, data);
}
}
bool QHexView::Cut(bool hex, int nibbleindex) {
@ -457,7 +466,7 @@ bool QHexView::Cut(bool hex, int nibbleindex) {
}
}
void QHexView::Paste(bool hex, int nibbleindex) {
bool QHexView::Paste(bool hex, int nibbleindex) {
QClipboard *c = qApp->clipboard();
QByteArray data;
@ -466,19 +475,27 @@ void QHexView::Paste(bool hex, int nibbleindex) {
} else {
auto d = c->mimeData();
data = d->data(QStringLiteral("application/octet-stream"));
if (data.isEmpty()) {
data = d->text().toUtf8();
}
}
if (data.isEmpty())
return;
if (data.isEmpty()) {
return true;
}
this->RemoveSelection(nibbleindex);
auto ret = this->RemoveSelection(nibbleindex);
if (!ret) {
return false;
}
auto pos = m_cursor->position().offset();
if (m_cursor->insertionMode() == QHexCursor::InsertionMode::InsertMode) {
m_document->Insert(m_cursor, pos, data, nibbleindex);
auto ret = m_document->Insert(m_cursor, pos, data, nibbleindex);
m_cursor->moveTo(pos + data.length()); // added by wingsummer
return ret;
} else {
m_document->Replace(m_cursor, pos, data, nibbleindex);
return m_document->Replace(m_cursor, pos, data, nibbleindex);
}
}

View File

@ -135,10 +135,10 @@ public:
bool cut(bool hex);
bool copy(bool hex = false);
void paste(bool hex = false);
bool paste(bool hex = false);
bool Cut(bool hex = false, int nibbleindex = 0);
void Paste(bool hex = false, int nibbleindex = 0);
bool Paste(bool hex = false, int nibbleindex = 0);
void Replace(qsizetype offset, uchar b, int nibbleindex);
void Replace(qsizetype offset, const QByteArray &data, int nibbleindex = 0);

@ -1 +1 @@
Subproject commit e5cef2dcf126037ffdc57a5aaf6a3b1d3f4c70ae
Subproject commit 3a5bb0d8bc45b6150ed4a7513b0712b0a5954a74

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -126,7 +126,7 @@ void AsCompletion::applyClassNodes(QList<CodeInfoTip> &nodes) {
for (auto &item : n) {
if (item.type == CodeInfoTip::Type::Class) {
for (auto &c : item.children) {
if (c.type == CodeInfoTip::Type::Function) {
if (c.type == CodeInfoTip::Type::ClsFunction) {
if (!c.addinfo.contains(CodeInfoTip::RetType)) {
continue;
}
@ -361,6 +361,8 @@ bool AsCompletion::processTrigger(const QString &trigger,
processTrigger(*DOT_TRIGGER, content.left(etoken.pos));
setCompletionPrefix(prefix);
return true;
} else if (etoken.content == QByteArrayLiteral(")")) {
// ignore
} else {
applyEmptyNsNode(nodes, docNodes);
}
@ -370,48 +372,60 @@ bool AsCompletion::processTrigger(const QString &trigger,
}
if (trigger == *DOT_TRIGGER) {
// member type guessing ? basic match is enough. (>n<)
auto isBasicType = [](const QString &type) {
static QStringList basicType{
"int", "int8", "int16", "int32", "int64",
"uint", "uint8", "uint16", "uint32", "uint64",
"float", "double", "byte"};
if (etoken.type == asTC_IDENTIFIER) {
// member type guessing ? basic match is enough. (>n<)
auto isBasicType = [](const QByteArray &type) {
static QByteArrayList basicType{
"int", "int8", "int16", "int32", "int64",
"uint", "uint8", "uint16", "uint32", "uint64",
"float", "double", "byte"};
return basicType.contains(type);
};
return basicType.contains(type);
};
auto clsNodes = parser.classNodes();
auto clsNodes = parser.classNodes();
// filter the type we can use to auto-complete in docNodes
for (auto &item : docNodes) {
if (item.type == CodeInfoTip::Type::Class) {
auto name = item.nameSpace;
if (name.isEmpty()) {
name = item.name;
} else {
name += QStringLiteral("::") + item.name;
// filter the type we can use to auto-complete in docNodes
for (auto &item : docNodes) {
if (item.type == CodeInfoTip::Type::Class) {
auto name = item.nameSpace;
if (name.isEmpty()) {
name = item.name;
} else {
name += QStringLiteral("::") + item.name;
}
clsNodes.insert(name, item.children);
}
clsNodes.insert(name, item.children);
// a typedef can only be used to define an alias
// for primitive types, so NO NEED for auto-completing
}
// a typedef can only be used to define an alias
// for primitive types, so NO NEED for auto-completing
}
tokens.removeLast();
auto ns = getNamespace(tokens);
for (auto &item : docNodes) {
if (etoken.content == item.name && ns == item.nameSpace) {
auto retType = item.addinfo.value(CodeInfoTip::RetType);
tokens.removeLast();
auto ns = getNamespace(tokens);
for (auto &item : docNodes) {
if (etoken.content == item.name && ns == item.nameSpace) {
auto retType = item.addinfo.value(CodeInfoTip::RetType);
auto decl = engine->GetTypeInfoByDecl(retType.toUtf8());
if (decl) {
QByteArray type = decl->GetNamespace();
if (type.isEmpty()) {
type = decl->GetName();
} else {
type +=
(QByteArrayLiteral("::") + decl->GetName());
}
// auto type inference is not supported.
// PRs will be welcomed !!!
if (isBasicType(retType)) {
popup()->hide();
return false;
// auto type inference is not supported.
// PRs will be welcomed !!!
if (isBasicType(type)) {
popup()->hide();
return false;
}
nodes.append(clsNodes.value(type));
break;
}
}
nodes.append(clsNodes.value(retType));
break;
}
}

View File

@ -33,12 +33,24 @@
_setUnsavedEditor.setFlag(flag, false); \
}
#define WRITE_CONFIG_EDITOR_RESET(config, flag, dvalue) \
do { \
WRITE_CONFIG(config, dvalue); \
_setUnsavedEditor.setFlag(flag, false); \
} while (0);
#define WRITE_CONFIG_CONSOLE_SET(config, flag, dvalue) \
if (this->_setUnsavedConsole.testFlag(flag)) { \
WRITE_CONFIG(config, dvalue); \
_setUnsavedConsole.setFlag(flag, false); \
}
#define WRITE_CONFIG_CONSOLE_RESET(config, flag, dvalue) \
do { \
WRITE_CONFIG(config, dvalue); \
_setUnsavedConsole.setFlag(flag, false); \
} while (0);
Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_FONT, ("codeedit.font"))
Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_FONT_SIZE, ("codeedit.fontsize"))
Q_GLOBAL_STATIC_WITH_ARGS(QString, CODEEDIT_THEME, ("codeedit.theme"))
@ -200,56 +212,59 @@ void ScriptSettings::save(SETTINGS cat) {
}
void ScriptSettings::reset(SETTINGS cat) {
__reset(cat);
load();
}
void ScriptSettings::__reset(SETTINGS cat) {
HANDLE_CONFIG;
if (cat.testFlag(SETTING::EDITOR)) {
WRITE_CONFIG_EDITOR_SET(CODEEDIT_FONT, SETTING_ITEM::FONT,
_defaultFont.defaultFamily());
WRITE_CONFIG_EDITOR_SET(CODEEDIT_FONT_SIZE, SETTING_ITEM::FONT_SIZE,
10);
WRITE_CONFIG_EDITOR_SET(CODEEDIT_THEME, SETTING_ITEM::THEME, {});
WRITE_CONFIG_EDITOR_SET(CODEEDIT_TABS_WIDTH, SETTING_ITEM::TAB_WIDTH,
4);
WRITE_CONFIG_EDITOR_SET(CODEEDIT_INDENTATION, SETTING_ITEM::INDENTATION,
0);
WRITE_CONFIG_EDITOR_SET(CODEEDIT_MATCH_BRACES,
SETTING_ITEM::MATCH_BRACES, true);
WRITE_CONFIG_EDITOR_SET(CODEEDIT_WORD_WRAP, SETTING_ITEM::WORD_WRAP,
false);
WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_LINENUMBER,
SETTING_ITEM::SHOW_LINENUMBER, true);
WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_FOLDING,
SETTING_ITEM::SHOW_FOLDING, true);
WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_INDENTGUIDES,
SETTING_ITEM::SHOW_INDENTGUIDES, true);
WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_LONGLINEEDGE,
SETTING_ITEM::SHOW_LONGLINEEDGE, false);
WRITE_CONFIG_EDITOR_SET(CODEEDIT_SHOW_WHITESPACE,
SETTING_ITEM::SHOW_WHITESPACE, false);
WRITE_CONFIG_EDITOR_SET(CODEEDIT_AUTO_CLOSE_CHAR,
SETTING_ITEM::AUTO_CLOSE_CHAR, true);
WRITE_CONFIG_EDITOR_SET(CODEEDIT_AUTO_IDEN, SETTING_ITEM::AUTO_IDEN,
true);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_FONT, SETTING_ITEM::FONT,
_defaultFont.defaultFamily());
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_FONT_SIZE, SETTING_ITEM::FONT_SIZE,
10);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_THEME, SETTING_ITEM::THEME, {});
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_TABS_WIDTH, SETTING_ITEM::TAB_WIDTH,
4);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_INDENTATION,
SETTING_ITEM::INDENTATION, 0);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_MATCH_BRACES,
SETTING_ITEM::MATCH_BRACES, true);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_WORD_WRAP, SETTING_ITEM::WORD_WRAP,
false);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_SHOW_LINENUMBER,
SETTING_ITEM::SHOW_LINENUMBER, true);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_SHOW_FOLDING,
SETTING_ITEM::SHOW_FOLDING, true);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_SHOW_INDENTGUIDES,
SETTING_ITEM::SHOW_INDENTGUIDES, true);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_SHOW_LONGLINEEDGE,
SETTING_ITEM::SHOW_LONGLINEEDGE, false);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_SHOW_WHITESPACE,
SETTING_ITEM::SHOW_WHITESPACE, false);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_AUTO_CLOSE_CHAR,
SETTING_ITEM::AUTO_CLOSE_CHAR, true);
WRITE_CONFIG_EDITOR_RESET(CODEEDIT_AUTO_IDEN, SETTING_ITEM::AUTO_IDEN,
true);
}
if (cat.testFlag(SETTING::CONSOLE)) {
WRITE_CONFIG_CONSOLE_SET(CONSOLE_FONT, SETTING_ITEM::FONT,
_defaultFont.defaultFamily());
WRITE_CONFIG_CONSOLE_SET(CONSOLE_FONT_SIZE, SETTING_ITEM::FONT_SIZE,
10);
WRITE_CONFIG_CONSOLE_SET(CONSOLE_THEME, SETTING_ITEM::THEME, {});
WRITE_CONFIG_CONSOLE_SET(CONSOLE_TABS_WIDTH, SETTING_ITEM::TAB_WIDTH,
4);
WRITE_CONFIG_CONSOLE_SET(CONSOLE_INDENTATION, SETTING_ITEM::INDENTATION,
0);
WRITE_CONFIG_CONSOLE_SET(CONSOLE_MATCH_BRACES,
SETTING_ITEM::MATCH_BRACES, true);
WRITE_CONFIG_CONSOLE_SET(CONSOLE_SHOW_WHITESPACE,
SETTING_ITEM::SHOW_WHITESPACE, false);
WRITE_CONFIG_CONSOLE_SET(CONSOLE_AUTO_CLOSE_CHAR,
SETTING_ITEM::AUTO_CLOSE_CHAR, true);
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_FONT, SETTING_ITEM::FONT,
_defaultFont.defaultFamily());
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_FONT_SIZE, SETTING_ITEM::FONT_SIZE,
10);
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_THEME, SETTING_ITEM::THEME, {});
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_TABS_WIDTH, SETTING_ITEM::TAB_WIDTH,
4);
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_INDENTATION,
SETTING_ITEM::INDENTATION, 0);
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_MATCH_BRACES,
SETTING_ITEM::MATCH_BRACES, true);
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_SHOW_WHITESPACE,
SETTING_ITEM::SHOW_WHITESPACE, false);
WRITE_CONFIG_CONSOLE_RESET(CONSOLE_AUTO_CLOSE_CHAR,
SETTING_ITEM::AUTO_CLOSE_CHAR, true);
}
load();
}
ScriptSettings::ScriptSettings() : QObject() {

View File

@ -57,6 +57,8 @@ public:
void save(SETTINGS cat = SETTING::ALL);
void reset(SETTINGS cat = SETTING::ALL);
void __reset(SETTINGS cat);
public:
QString editorFontFamily() const;
void setEditorFontFamily(const QString &newEditorFontFamily);

View File

@ -31,6 +31,12 @@
_setUnsaved.setFlag(SettingManager::SETTING_ITEM::config, false); \
}
#define WRITE_CONFIG_RESET(config, dvalue) \
do { \
WRITE_CONFIG(config, dvalue); \
_setUnsaved.setFlag(SettingManager::SETTING_ITEM::config, false); \
} while (0);
Q_GLOBAL_STATIC_WITH_ARGS(QString, DOCK_LAYOUT, ("dock.layout"))
Q_GLOBAL_STATIC_WITH_ARGS(QString, SCRIPT_DOCK_LAYOUT, ("script.layout"))
Q_GLOBAL_STATIC_WITH_ARGS(QString, APP_LASTUSED_PATH, ("app.lastusedpath"))
@ -423,45 +429,49 @@ void SettingManager::save(SETTINGS cat) {
}
void SettingManager::reset(SETTINGS cat) {
__reset(cat);
load();
}
void SettingManager::__reset(SETTINGS cat) {
HANDLE_CONFIG;
if (cat.testFlag(SETTING::APP)) {
WRITE_CONFIG_SET(SKIN_THEME, 0);
WRITE_CONFIG_SET(APP_LANGUAGE, QString());
WRITE_CONFIG_SET(APP_FONTFAMILY, _defaultFont.family());
WRITE_CONFIG_SET(APP_FONTSIZE, _defaultFont.pointSize());
WRITE_CONFIG_SET(APP_WINDOWSIZE, Qt::WindowMaximized);
WRITE_CONFIG_RESET(SKIN_THEME, 0);
WRITE_CONFIG_RESET(APP_LANGUAGE, QString());
WRITE_CONFIG_RESET(APP_FONTFAMILY, _defaultFont.family());
WRITE_CONFIG_RESET(APP_FONTSIZE, _defaultFont.pointSize());
WRITE_CONFIG_RESET(APP_WINDOWSIZE, Qt::WindowMaximized);
}
if (cat.testFlag(SETTING::PLUGIN)) {
WRITE_CONFIG_SET(PLUGIN_ENABLE, true);
WRITE_CONFIG_SET(PLUGIN_ENABLE_ROOT, false);
WRITE_CONFIG_RESET(PLUGIN_ENABLE, true);
WRITE_CONFIG_RESET(PLUGIN_ENABLE_ROOT, false);
}
if (cat.testFlag(SETTING::EDITOR)) {
WRITE_CONFIG_SET(EDITOR_FONTSIZE, _defaultFont.pointSize());
WRITE_CONFIG_SET(EDITOR_SHOW_ADDR, true);
WRITE_CONFIG_SET(EDITOR_SHOW_COL, true);
WRITE_CONFIG_SET(EDITOR_SHOW_TEXT, true);
WRITE_CONFIG_SET(EDITOR_FIND_MAXCOUNT, 100);
WRITE_CONFIG_SET(EDITOR_COPY_LIMIT, 100);
WRITE_CONFIG_SET(EDITOR_DECSTRLIMIT, 10);
WRITE_CONFIG_RESET(EDITOR_FONTSIZE, _defaultFont.pointSize());
WRITE_CONFIG_RESET(EDITOR_SHOW_ADDR, true);
WRITE_CONFIG_RESET(EDITOR_SHOW_COL, true);
WRITE_CONFIG_RESET(EDITOR_SHOW_TEXT, true);
WRITE_CONFIG_RESET(EDITOR_FIND_MAXCOUNT, 100);
WRITE_CONFIG_RESET(EDITOR_COPY_LIMIT, 100);
WRITE_CONFIG_RESET(EDITOR_DECSTRLIMIT, 10);
}
if (cat.testFlag(SETTING::SCRIPT)) {
WRITE_CONFIG_SET(SCRIPT_ENABLE, true);
WRITE_CONFIG_SET(SCRIPT_TIMEOUT, 10);
WRITE_CONFIG_SET(SCRIPT_ALLOW_USRSCRIPT_INROOT, false);
WRITE_CONFIG_SET(SCRIPT_USRHIDECATS, QStringList());
WRITE_CONFIG_SET(SCRIPT_SYSHIDECATS, QStringList());
WRITE_CONFIG_RESET(SCRIPT_ENABLE, true);
WRITE_CONFIG_RESET(SCRIPT_TIMEOUT, 10);
WRITE_CONFIG_RESET(SCRIPT_ALLOW_USRSCRIPT_INROOT, false);
WRITE_CONFIG_RESET(SCRIPT_USRHIDECATS, QStringList());
WRITE_CONFIG_RESET(SCRIPT_SYSHIDECATS, QStringList());
}
if (cat.testFlag(SETTING::OTHER)) {
WRITE_CONFIG_SET(OTHER_USESYS_FILEDIALOG, true);
WRITE_CONFIG_RESET(OTHER_USESYS_FILEDIALOG, true);
#ifdef WINGHEX_USE_FRAMELESS
WRITE_CONFIG_SET(OTHER_USE_NATIVE_TITLEBAR, false);
WRITE_CONFIG_RESET(OTHER_USE_NATIVE_TITLEBAR, false);
#endif
WRITE_CONFIG_SET(OTHER_DONT_USE_SPLASH, false);
WRITE_CONFIG_SET(OTHER_CHECK_UPDATE, false);
WRITE_CONFIG_SET(OTHER_LOG_LEVEL, Logger::defaultLevel());
WRITE_CONFIG_SET(OTHER_LOG_COUNT, 20);
WRITE_CONFIG_RESET(OTHER_DONT_USE_SPLASH, false);
WRITE_CONFIG_RESET(OTHER_CHECK_UPDATE, false);
WRITE_CONFIG_RESET(OTHER_LOG_LEVEL, Logger::defaultLevel());
WRITE_CONFIG_RESET(OTHER_LOG_COUNT, 20);
}
load();
}
qsizetype SettingManager::decodeStrlimit() const { return m_decodeStrlimit; }

View File

@ -119,6 +119,8 @@ public:
void save(SETTINGS cat = SETTING::ALL);
void reset(SETTINGS cat);
void __reset(SETTINGS cat);
QList<RecentFileManager::RecentInfo> recentHexFiles() const;
void
setRecentFiles(const QList<RecentFileManager::RecentInfo> &newRecentFiles);

View File

@ -104,11 +104,20 @@ void CodeEdit::onCompletion(const QModelIndex &index) {
if (selfdata.type == CodeInfoTip::Type::Function ||
selfdata.type == CodeInfoTip::Type::ClsFunction) {
auto args = selfdata.addinfo.value(CodeInfoTip::Args);
auto cursor = textCursor();
cursor.insertText(QStringLiteral("()"));
if (!args.isEmpty()) {
cursor.movePosition(QTextCursor::Left);
setTextCursor(cursor);
auto cur = textCursor();
cur.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
auto ch = cur.selectedText();
if (ch.isEmpty() || ch.front().isSpace()) {
auto cursor = textCursor();
cursor.insertText(QStringLiteral("()"));
if (!args.isEmpty()) {
cursor.movePosition(QTextCursor::Left);
setTextCursor(cursor);
}
} else {
auto cursor = textCursor();
cursor.insertText(QStringLiteral("("));
}
}
}

View File

@ -389,11 +389,20 @@ void ScriptingConsole::onCompletion(const QModelIndex &index) {
if (selfdata.type == CodeInfoTip::Type::Function ||
selfdata.type == CodeInfoTip::Type::ClsFunction) {
auto args = selfdata.addinfo.value(CodeInfoTip::Args);
auto cursor = textCursor();
cursor.insertText(QStringLiteral("()"));
if (!args.isEmpty()) {
cursor.movePosition(QTextCursor::Left);
setTextCursor(cursor);
auto cur = textCursor();
cur.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
auto ch = cur.selectedText();
if (ch.isEmpty() || ch.front().isSpace()) {
auto cursor = textCursor();
cursor.insertText(QStringLiteral("()"));
if (!args.isEmpty()) {
cursor.movePosition(QTextCursor::Left);
setTextCursor(cursor);
}
} else {
auto cursor = textCursor();
cursor.insertText(QStringLiteral("("));
}
}
}
@ -407,7 +416,12 @@ void ScriptingConsole::paste() {
const QString text = clipboard->text();
if (!text.isEmpty()) {
if (text.indexOf('\n') < 0) {
replaceCommandLine(text);
if (isCursorInEditZone()) {
auto cursor = this->textCursor();
cursor.insertText(text);
} else {
replaceCommandLine(text);
}
} else {
auto ret = WingMessageBox::question(
nullptr, tr("MultiCodeCanNotUndo"), text);
@ -452,30 +466,37 @@ QString ScriptingConsole::currentCodes() const {
void ScriptingConsole::contextMenuEvent(QContextMenuEvent *event) {
QMenu menu(this);
menu.addAction(QIcon(QStringLiteral(":/qeditor/copy.png")), tr("Copy"),
QKeySequence(QKeySequence::Copy), this,
&ScriptingConsole::copy);
menu.addAction(QIcon(QStringLiteral(":/qeditor/cut.png")), tr("Cut"),
QKeySequence(QKeySequence::Cut), this,
&ScriptingConsole::cut);
menu.addAction(QIcon(QStringLiteral(":/qeditor/paste.png")), tr("Paste"),
QKeySequence(QKeySequence::Paste), this,
&ScriptingConsole::paste);
auto a = menu.addAction(QIcon(QStringLiteral(":/qeditor/copy.png")),
tr("Copy"), QKeySequence(QKeySequence::Copy), this,
&ScriptingConsole::copy);
a->setShortcutContext(Qt::WidgetShortcut);
a = menu.addAction(QIcon(QStringLiteral(":/qeditor/cut.png")), tr("Cut"),
QKeySequence(QKeySequence::Cut), this,
&ScriptingConsole::cut);
a->setShortcutContext(Qt::WidgetShortcut);
a = menu.addAction(QIcon(QStringLiteral(":/qeditor/paste.png")),
tr("Paste"), QKeySequence(QKeySequence::Paste), this,
&ScriptingConsole::paste);
a->setShortcutContext(Qt::WidgetShortcut);
if (_isTerminal) {
menu.addAction(ICONRES(QStringLiteral("del")), tr("Clear"),
QKeySequence(Qt::ControlModifier | Qt::Key_L), this,
&ScriptingConsole::clearConsole);
a = menu.addAction(ICONRES(QStringLiteral("del")), tr("Clear"),
QKeySequence(Qt::ControlModifier | Qt::Key_L), this,
&ScriptingConsole::clearConsole);
a->setShortcutContext(Qt::WidgetShortcut);
menu.addSeparator();
menu.addAction(ICONRES(QStringLiteral("dbgstop")), tr("AbortScript"),
QKeySequence(Qt::ControlModifier | Qt::Key_Q), []() {
ScriptMachine::instance().abortScript(
ScriptMachine::Background);
});
a = menu.addAction(ICONRES(QStringLiteral("dbgstop")),
tr("AbortScript"),
QKeySequence(Qt::ControlModifier | Qt::Key_Q), []() {
ScriptMachine::instance().abortScript(
ScriptMachine::Background);
});
a->setShortcutContext(Qt::WidgetShortcut);
} else {
menu.addAction(ICONRES(QStringLiteral("del")), tr("Clear"),
QKeySequence(Qt::ControlModifier | Qt::Key_L), this,
&ScriptingConsole::clear);
a = menu.addAction(ICONRES(QStringLiteral("del")), tr("Clear"),
QKeySequence(Qt::ControlModifier | Qt::Key_L), this,
&ScriptingConsole::clear);
a->setShortcutContext(Qt::WidgetShortcut);
}
menu.exec(event->globalPos());

View File

@ -607,11 +607,13 @@ ads::CDockAreaWidget *MainWindow::buildUpLogDock(ads::CDockManager *dock,
m_logbrowser->setOpenExternalLinks(true);
m_logbrowser->setUndoRedoEnabled(false);
m_logbrowser->addAction(newAction(
auto a = newAction(
ICONRES("copy"), tr("Copy"), [=]() { m_logbrowser->copy(); },
QKeySequence::Copy));
QKeySequence::Copy);
a->setShortcutContext(Qt::WidgetShortcut);
m_logbrowser->addAction(a);
auto a = new QAction(this);
a = new QAction(this);
a->setSeparator(true);
m_logbrowser->addAction(a);
@ -1009,18 +1011,17 @@ MainWindow::buildUpDecodingStrShowDock(ads::CDockManager *dock,
tr("DecodeText") + QStringLiteral(" (ASCII)"),
m_txtDecode);
auto menu = m_txtDecode->createStandardContextMenu();
menu->addSeparator();
auto a = new QAction(tr("Encoding"), this);
auto a = newAction(
ICONRES("copy"), tr("Copy"), [=]() { m_logbrowser->copy(); },
QKeySequence::Copy);
a->setShortcutContext(Qt::WidgetShortcut);
m_txtDecode->addAction(a);
a = new QAction(tr("Encoding"), this);
a->setIcon(ICONRES(QStringLiteral("encoding")));
connect(a, &QAction::triggered, this, &MainWindow::on_encoding);
menu->addAction(a);
m_txtDecode->addAction(a);
m_txtDecode->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_txtDecode, &QTextBrowser::customContextMenuRequested, this,
[=](const QPoint &pos) {
menu->popup(m_txtDecode->viewport()->mapToGlobal(pos));
});
m_txtDecode->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(m_txtDecode, &QTextBrowser::windowTitleChanged, dw,
&QDockWidget::setWindowTitle);
@ -1066,13 +1067,16 @@ MainWindow::buildUpScriptBgOutputDock(ads::CDockManager *dock,
auto a = newAction(
ICONRES(QStringLiteral("mStr")), tr("SelectAll"),
[this]() { m_bgScriptOutput->selectAll(); }, QKeySequence::SelectAll);
a->setShortcutContext(Qt::WidgetShortcut);
m_bgScriptOutput->addAction(a);
a = newAction(
ICONRES(QStringLiteral("copy")), tr("Copy"),
[this]() { m_bgScriptOutput->copy(); }, QKeySequence::Copy);
a->setShortcutContext(Qt::WidgetShortcut);
m_bgScriptOutput->addAction(a);
a = newAction(ICONRES(QStringLiteral("del")), tr("Clear"),
[this]() { m_bgScriptOutput->clear(); });
a->setShortcutContext(Qt::WidgetShortcut);
m_bgScriptOutput->addAction(a);
a = new QAction(this);
a->setSeparator(true);
@ -1083,6 +1087,7 @@ MainWindow::buildUpScriptBgOutputDock(ads::CDockManager *dock,
ScriptMachine::instance().abortScript(ScriptMachine::Background);
},
QKeySequence(Qt::ControlModifier | Qt::Key_Q));
a->setShortcutContext(Qt::WidgetShortcut);
m_bgScriptOutput->addAction(a);
m_bgScriptOutput->setContextMenuPolicy(Qt::ActionsContextMenu);
@ -2077,7 +2082,10 @@ void MainWindow::on_pastefile() {
if (hexeditor == nullptr) {
return;
}
hexeditor->Paste();
if (!hexeditor->Paste()) {
Toast::toast(this, NAMEICONRES(QStringLiteral("paste")),
tr("PasteFailedNote"));
}
}
void MainWindow::on_delete() {

View File

@ -113,21 +113,26 @@ void SettingDialog::on_buttonBox_clicked(QAbstractButton *button) {
page->apply();
}
} else if (button == btnbox->button(QDialogButtonBox::RestoreDefaults)) {
for (auto &page : m_pages) {
page->reset();
auto index = ui->listWidget->currentRow();
if (index >= 0) {
m_pages.at(index)->reset();
}
toastTakeEffectReboot();
} else if (button == btnbox->button(QDialogButtonBox::Reset)) {
auto res = WingMessageBox::warning(
this, qAppName(),
tr("This will reset all settings. Are you sure to continue?"),
QMessageBox::Yes | QMessageBox::No);
if (res == QMessageBox::No)
if (res == QMessageBox::No) {
return;
}
for (auto &page : m_pages) {
page->reset();
}
toastTakeEffectReboot();
} else if (button == btnbox->button(QDialogButtonBox::Cancel)) {
for (auto &page : m_pages) {
page->cancel();

View File

@ -71,7 +71,7 @@ public:
Map_t::iterator it = stringCache.find(strv);
if (it == stringCache.end()) {
// ret = asERROR;
// TODO: I don't know why invalid string pointer passed to it
// I don't know why invalid string pointer passed to it
// just ignore it.
} else {
it->second--;
@ -311,19 +311,6 @@ static int StringCmp(const QString &a, const QString &b) {
return cmp;
}
// This function returns the index of the first position where the substring
// exists in the input string. If the substring doesn't exist in the input
// string -1 is returned.
//
// AngelScript signature:
// int string::findFirst(const string &in sub, uint start = 0) const
static int StringFindFirst(const QString &sub, asUINT start,
const QString &str) {
// We don't register the method directly because the argument types change
// between 32bit and 64bit platforms
return (int)str.indexOf(sub, start);
}
// This function returns the index of the first position where the one of the
// bytes in substring exists in the input string. If the characters in the
// substring doesn't exist in the input string -1 is returned.
@ -498,6 +485,82 @@ static CScriptArray *stringSplit(const QString &sep, bool skipEmpty,
"array<string>");
}
static QString fromAscii(CScriptArray *array) {
return QString::fromLatin1(
reinterpret_cast<const char *>(array->GetBuffer()), array->GetSize());
}
static CScriptArray *toAsciiArray(const QString &s) {
return byteArrayWrapperFunction([s]() { return s.toLatin1(); });
}
static QString fromUtf8(CScriptArray *array) {
return QString::fromUtf8(reinterpret_cast<const char *>(array->GetBuffer()),
array->GetSize());
}
static CScriptArray *toUtf8Array(const QString &s) {
return byteArrayWrapperFunction([s]() { return s.toUtf8(); });
}
static QString fromUtf16(CScriptArray *array) {
return QString::fromUtf16(
reinterpret_cast<const char16_t *>(array->GetBuffer()),
array->GetSize() / sizeof(char16_t));
}
static CScriptArray *toUtf16Array(const QString &s) {
return byteArrayWrapperFunction([s]() {
auto data = s.utf16();
return QByteArray(reinterpret_cast<const char *>(data),
s.size() * sizeof(char16_t));
});
}
static QString fromUcs4(CScriptArray *array) {
return QString::fromUcs4(
reinterpret_cast<const char32_t *>(array->GetBuffer()),
array->GetSize() / sizeof(char32_t));
}
static CScriptArray *toUcs4Array(const QString &s) {
return byteArrayWrapperFunction([s]() { return s.toUcs4(); });
}
static QString fromRawData(CScriptArray *array) {
auto total = array->GetSize();
QString buffer;
buffer.reserve(total);
for (asUINT i = 0; i < total; ++i) {
auto ch = reinterpret_cast<const QChar *>(array->At(i));
buffer.append(*ch);
}
return buffer;
}
static void appendStr(const QString &str, QString &s) { s.append(str); }
static void appendCh(const QChar &ch, QString &s) { s.append(ch); }
static void prependStr(const QString &str, QString &s) { s.prepend(str); }
static void prependCh(const QChar &ch, QString &s) { s.prepend(ch); }
static CScriptArray *toRawData(const QString &s) {
return retarrayWrapperFunction(
[s]() {
QList<QChar> data;
data.reserve(s.length());
for (auto &ch : s) {
data.append(ch);
}
return data;
},
"array<char>");
}
//=================================================
static void ConstructChar(QChar *thisPointer) { new (thisPointer) QChar(); }
@ -669,34 +732,18 @@ void RegisterQString_Native(asIScriptEngine *engine) {
Q_UNUSED(r);
#endif
// The string length can be accessed through methods or through virtual
// property
#if AS_USE_ACCESSORS != 1
r = engine->RegisterObjectMethod("string", "uint length() const",
asFUNCTION(StringLength),
asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
#endif
r = engine->RegisterObjectMethod("string", "void resize(uint)",
asFUNCTION(StringResize),
asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
#if AS_USE_ACCESSORS == 1
// Don't register these if STL names is used, as they conflict with the
// method size()
r = engine->RegisterObjectMethod(
"string", "uint get_length() const property", asFUNCTION(StringLength),
asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string", "void set_length(uint) property",
asFUNCTION(StringResize),
asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
#endif
// Need to use a wrapper on Mac OS X 10.7/XCode 4.3 and CLang/LLVM,
// otherwise the linker fails
// r = engine->RegisterObjectMethod("string", "bool isEmpty() const",
@ -851,19 +898,39 @@ void RegisterQString_Native(asIScriptEngine *engine) {
#endif
// Utilities
r = engine->RegisterObjectMethod(
"string", "void append(const string &in str)", asFUNCTION(appendStr),
asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string", "void append(const char &in ch)",
asFUNCTION(appendCh),
asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "void prepend(const string &in str)", asFUNCTION(prependStr),
asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "void prepend(const char &in ch)", asFUNCTION(prependCh),
asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "string substr(uint start = 0, int count = -1) const",
asFUNCTION(StringSubString), asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "int findFirst(const string &in, uint start = 0) const",
asFUNCTION(StringFindFirst), asCALL_CDECL_OBJLAST);
"string", "int findFirstOf(const string &in, uint start = 0) const",
asFUNCTION(StringFindFirstOf), asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "int findFirstOf(const string &in, uint start = 0) const",
asFUNCTION(StringFindFirstOf), asCALL_CDECL_OBJLAST);
"string", "int findLastOf(const string &in, uint start = 0) const",
asFUNCTION(StringFindLastOf), asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
@ -878,12 +945,6 @@ void RegisterQString_Native(asIScriptEngine *engine) {
Q_ASSERT(r >= 0);
Q_UNUSED(r);
/* These following things are not avaliable for generic call
* because it needs a lot of wrapper to do
* while WingHexExplorer only needs native call
* (by wingsummer)
* PULL REQUESTS ARE WELCOMED IF YOU WANT TO ADD GENERIC CALL
*/
r = engine->RegisterObjectMethod(
"string",
"int compare(const string &in val, bool caseSensitive = true) const",
@ -933,6 +994,33 @@ void RegisterQString_Native(asIScriptEngine *engine) {
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "array<uint8>@ toAsciiArray() const",
asFUNCTION(toAsciiArray), asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "array<uint8>@ toUtf8Array() const", asFUNCTION(toUtf8Array),
asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "array<uint8>@ toUtf16Array() const",
asFUNCTION(toUtf16Array), asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "array<uint8>@ toUcs4Array() const", asFUNCTION(toUcs4Array),
asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string", "array<char>@ toRawData() const",
asFUNCTION(toRawData),
asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
// Global functions
r = engine->SetDefaultNamespace("string");
Q_ASSERT(r >= 0);
Q_UNUSED(r);
@ -970,6 +1058,33 @@ void RegisterQString_Native(asIScriptEngine *engine) {
asFUNCTION(parseFloat), asCALL_CDECL);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string fromAscii(const array<uint8> &in array)", asFUNCTION(fromAscii),
asCALL_CDECL);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string fromUtf8(const array<uint8> &in array)", asFUNCTION(fromUtf8),
asCALL_CDECL);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string fromUtf16(const array<uint8> &in array)", asFUNCTION(fromUtf16),
asCALL_CDECL);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string fromUcs4(const array<uint8> &in array)", asFUNCTION(fromUcs4),
asCALL_CDECL);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string fromRawData(const array<char> &in array)",
asFUNCTION(fromRawData), asCALL_CDECL);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
engine->SetDefaultNamespace("");
}
@ -1044,82 +1159,6 @@ static void StringResizeGeneric(asIScriptGeneric *gen) {
self->resize(*static_cast<asUINT *>(gen->GetAddressOfArg(0)));
}
static void StringInsert_Generic(asIScriptGeneric *gen) {
QString *self = static_cast<QString *>(gen->GetObject());
asUINT pos = gen->GetArgDWord(0);
QString *other = reinterpret_cast<QString *>(gen->GetArgAddress(1));
StringInsert(pos, *other, *self);
}
static void StringErase_Generic(asIScriptGeneric *gen) {
QString *self = static_cast<QString *>(gen->GetObject());
asUINT pos = gen->GetArgDWord(0);
int count = int(gen->GetArgDWord(1));
StringErase(pos, count, *self);
}
static void StringFindFirst_Generic(asIScriptGeneric *gen) {
QString *find = reinterpret_cast<QString *>(gen->GetArgAddress(0));
asUINT start = gen->GetArgDWord(1);
QString *self = reinterpret_cast<QString *>(gen->GetObject());
*reinterpret_cast<int *>(gen->GetAddressOfReturnLocation()) =
StringFindFirst(*find, start, *self);
}
static void StringFindFirstOf_Generic(asIScriptGeneric *gen) {
QString *find = reinterpret_cast<QString *>(gen->GetArgAddress(0));
asUINT start = gen->GetArgDWord(1);
QString *self = reinterpret_cast<QString *>(gen->GetObject());
*reinterpret_cast<int *>(gen->GetAddressOfReturnLocation()) =
StringFindFirstOf(*find, start, *self);
}
static void StringFindLastOf_Generic(asIScriptGeneric *gen) {
QString *find = reinterpret_cast<QString *>(gen->GetArgAddress(0));
asUINT start = gen->GetArgDWord(1);
QString *self = reinterpret_cast<QString *>(gen->GetObject());
*reinterpret_cast<int *>(gen->GetAddressOfReturnLocation()) =
StringFindLastOf(*find, start, *self);
}
static void formatInt_Generic(asIScriptGeneric *gen) {
asINT64 val = gen->GetArgQWord(0);
QString *options = reinterpret_cast<QString *>(gen->GetArgAddress(1));
new (gen->GetAddressOfReturnLocation()) QString(formatInt(val, *options));
}
static void formatUInt_Generic(asIScriptGeneric *gen) {
asQWORD val = gen->GetArgQWord(0);
QString *options = reinterpret_cast<QString *>(gen->GetArgAddress(1));
new (gen->GetAddressOfReturnLocation()) QString(formatUInt(val, *options));
}
static void formatFloat_Generic(asIScriptGeneric *gen) {
double val = gen->GetArgDouble(0);
QString *options = reinterpret_cast<QString *>(gen->GetArgAddress(1));
new (gen->GetAddressOfReturnLocation()) QString(formatFloat(val, *options));
}
static void parseInt_Generic(asIScriptGeneric *gen) {
QString *str = reinterpret_cast<QString *>(gen->GetArgAddress(0));
asUINT base = gen->GetArgDWord(1);
asUINT *byteCount = reinterpret_cast<asUINT *>(gen->GetArgAddress(2));
gen->SetReturnQWord(parseInt(*str, base, byteCount));
}
static void parseUInt_Generic(asIScriptGeneric *gen) {
QString *str = reinterpret_cast<QString *>(gen->GetArgAddress(0));
asUINT base = gen->GetArgDWord(1);
bool *ok = reinterpret_cast<bool *>(gen->GetArgAddress(2));
gen->SetReturnQWord(parseUInt(*str, base, ok));
}
static void parseFloat_Generic(asIScriptGeneric *gen) {
QString *str = reinterpret_cast<QString *>(gen->GetArgAddress(0));
bool *ok = reinterpret_cast<bool *>(gen->GetArgAddress(1));
gen->SetReturnDouble(parseFloat(*str, ok));
}
static void StringCharAtGeneric(asIScriptGeneric *gen) {
asDWORD index = gen->GetArgDWord(0);
QString *self = static_cast<QString *>(gen->GetObject());
@ -1277,17 +1316,6 @@ static void AddBool2StringGeneric(asIScriptGeneric *gen) {
}
#endif
static void StringSubString_Generic(asIScriptGeneric *gen) {
// Get the arguments
QString *str = (QString *)gen->GetObject();
asUINT start = *(int *)gen->GetAddressOfArg(0);
int count = *(int *)gen->GetAddressOfArg(1);
// Return the substring
new (gen->GetAddressOfReturnLocation())
QString(StringSubString(start, count, *str));
}
void RegisterQString_Generic(asIScriptEngine *engine) {
int r = 0;
Q_UNUSED(r);
@ -1348,13 +1376,12 @@ void RegisterQString_Generic(asIScriptEngine *engine) {
Q_UNUSED(r);
// Register the object methods
#if AS_USE_ACCESSORS != 1
r = engine->RegisterObjectMethod("string", "uint length() const",
asFUNCTION(StringLengthGeneric),
asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
#endif
r = engine->RegisterObjectMethod("string", "void resize(uint)",
asFUNCTION(StringResizeGeneric),
asCALL_GENERIC);
@ -1487,67 +1514,50 @@ void RegisterQString_Generic(asIScriptEngine *engine) {
Q_UNUSED(r);
#endif
r = engine->RegisterObjectMethod(
"string", "string substr(uint start = 0, int count = -1) const",
asFUNCTION(StringSubString_Generic), asCALL_GENERIC);
// Utilities
r = engine->RegisterObjectMethod("string",
"void append(const string &in str)",
WRAP_FN(appendStr), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string", "void append(const char &in ch)",
WRAP_FN(appendCh), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string",
"void prepend(const string &in str)",
WRAP_FN(prependStr), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string",
"void prepend(const char &in ch)",
WRAP_FN(prependCh), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "int findFirst(const string &in, uint start = 0) const",
asFUNCTION(StringFindFirst_Generic), asCALL_GENERIC);
"string", "string substr(uint start = 0, int count = -1) const",
WRAP_FN(StringSubString), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "int findFirstOf(const string &in, uint start = 0) const",
asFUNCTION(StringFindFirstOf_Generic), asCALL_GENERIC);
WRAP_FN(StringFindFirstOf), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "int findLastOf(const string &in, int start = -1) const",
asFUNCTION(StringFindLastOf_Generic), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "void insert(uint pos, const string &in other)",
asFUNCTION(StringInsert_Generic), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string", "void erase(uint pos, int count = -1)",
asFUNCTION(StringErase_Generic), asCALL_GENERIC);
"string", "int findLastOf(const string &in, uint start = 0) const",
WRAP_FN(StringFindLastOf), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string formatInt(int64 val, const string &in options = \"\")",
asFUNCTION(formatInt_Generic), asCALL_GENERIC);
r = engine->RegisterObjectMethod(
"string", "void insert(uint pos, const string &in other)",
WRAP_FN(StringInsert), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string formatUInt(uint64 val, const string &in options = \"\")",
asFUNCTION(formatUInt_Generic), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string formatFloat(double val, const string &in options = \"\")",
asFUNCTION(formatFloat_Generic), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction("int64 parseInt(const string &in, uint "
"base = 10, bool &out ok = false)",
asFUNCTION(parseInt_Generic),
asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction("uint64 parseUInt(const string &in, "
"uint base = 10, bool &out ok = false)",
asFUNCTION(parseUInt_Generic),
asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"double parseFloat(const string &in, bool &out ok = false)",
WRAP_FN(parseFloat_Generic), asCALL_GENERIC);
r = engine->RegisterObjectMethod("string",
"void erase(uint pos, int count = -1)",
WRAP_FN(StringErase), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
@ -1582,7 +1592,8 @@ void RegisterQString_Generic(asIScriptEngine *engine) {
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string", "string simplified()",
WRAP_FN(stringSimplified), asCALL_GENERIC);
asFUNCTION(stringSimplified),
asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
@ -1599,6 +1610,32 @@ void RegisterQString_Generic(asIScriptEngine *engine) {
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string",
"array<uint8>@ toAsciiArray() const",
WRAP_FN(toAsciiArray), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string",
"array<uint8>@ toUtf8Array() const",
WRAP_FN(toUtf8Array), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string",
"array<uint8>@ toUtf16Array() const",
WRAP_FN(toUtf16Array), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string",
"array<uint8>@ toUcs4Array() const",
WRAP_FN(toUcs4Array), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod("string", "array<char>@ toRawData() const",
WRAP_FN(toRawData), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
// Global functions
r = engine->SetDefaultNamespace("string");
Q_ASSERT(r >= 0);
Q_UNUSED(r);
@ -1636,6 +1673,34 @@ void RegisterQString_Generic(asIScriptEngine *engine) {
WRAP_FN(parseFloat), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string fromAscii(const array<uint8> &in array)", WRAP_FN(fromAscii),
asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string fromUtf8(const array<uint8> &in array)", WRAP_FN(fromUtf8),
asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string fromUtf16(const array<uint8> &in array)", WRAP_FN(fromUtf16),
asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string fromUcs4(const array<uint8> &in array)", WRAP_FN(fromUcs4),
asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterGlobalFunction(
"string fromRawData(const array<char> &in array)", WRAP_FN(fromRawData),
asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
engine->SetDefaultNamespace("");
}
void RegisterQString(asIScriptEngine *engine) {
@ -1725,19 +1790,6 @@ void RegisterQStringUtils(asIScriptEngine *engine) {
engine->SetDefaultNamespace("");
}
// This function returns the index of the first position where the substring
// exists in the input string. If the substring doesn't exist in the input
// string -1 is returned.
//
// AngelScript signature:
// int string::findFirst(const regex::exp &in exp, uint start = 0) const
static int StringFindFirstReg(const QRegularExpression &exp, asUINT start,
const QString &str) {
// We don't register the method directly because the argument types change
// between 32bit and 64bit platforms
return (int)str.indexOf(exp, start);
}
// This function returns the index of the first position where the one of the
// bytes in substring exists in the input string. If the characters in the
// substring doesn't exist in the input string -1 is returned.
@ -1789,12 +1841,6 @@ void RegisterQStringRegExSupport(asIScriptEngine *engine) {
Q_UNUSED(r);
if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY")) {
r = engine->RegisterObjectMethod(
"string",
"int findFirst(const regex::exp &in, uint start = 0) const",
WRAP_FN(StringFindFirstReg), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string",
"int findFirstOf(const regex::exp &in, uint start = 0) const",
@ -1819,14 +1865,7 @@ void RegisterQStringRegExSupport(asIScriptEngine *engine) {
WRAP_FN(stringSplitReg), asCALL_GENERIC);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
} else {
r = engine->RegisterObjectMethod(
"string",
"int findFirst(const regex::exp &in, uint start = 0) const",
asFUNCTION(StringFindFirstReg), asCALL_CDECL_OBJLAST);
Q_ASSERT(r >= 0);
Q_UNUSED(r);
r = engine->RegisterObjectMethod(
"string",
"int findFirstOf(const regex::exp &in, uint start = 0) const",

View File

@ -27,12 +27,6 @@
// Compilation settings
//
// Some prefer to use property accessors to get/set the length of the string
// This option registers the accessors instead of the method length()
#ifndef AS_USE_ACCESSORS
#define AS_USE_ACCESSORS 0
#endif
// This option disables the implicit operators with primitives
#ifndef AS_NO_IMPL_OPS_WITH_STRING_AND_PRIMITIVE
#define AS_NO_IMPL_OPS_WITH_STRING_AND_PRIMITIVE 0

View File

@ -47,7 +47,8 @@ void RegisterScriptRegex(asIScriptEngine *engine) {
r = engine->RegisterObjectBehaviour(
"exp", asBEHAVE_CONSTRUCT,
"void f(string &in, PatternOptions = PatternOptions::NoPatternOption)",
"void f(const string &in, PatternOptions = "
"regex::PatternOptions::NoPatternOption)",
asFUNCTIONPR(
[](void *memory, const QString &r, Angel::PatternOptions op) {
new (memory) QRegularExpression(
@ -169,7 +170,7 @@ void RegisterScriptRegex(asIScriptEngine *engine) {
// QRegularExpression...
r = engine->RegisterObjectMethod(
"exp", "void setPattern(string &in)",
"exp", "void setPattern(const string &in)",
asMETHODPR(QRegularExpression, setPattern, (const QString &), void),
asCALL_THISCALL);
Q_ASSERT(r >= 0);