feat: 增加自选类方法代码填充;修复编辑超大文件编辑结果不对的问题;

This commit is contained in:
寂静的羽夏 2025-02-08 21:18:55 +08:00
parent 5bd8a870d1
commit 46a884b8e4
13 changed files with 845 additions and 744 deletions

View File

@ -1103,7 +1103,7 @@ bool QHexView::processTextInput(QHexCursor *cur, QKeyEvent *e) {
return true;
}
uchar ch = uchar(m_document->at(int(cur->position().offset())));
uchar ch = uchar(m_document->at(cur->position().offset()));
if (cur->currentNibble()) // X0
val = uchar((ch & 0x0F) | (val << 4));

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -107,9 +107,11 @@ void AsCompletion::complete(const QDocumentCursor &c, const QString &trigger) {
}
auto code = txt.mid(off, c.columnNumber() - off).toUtf8();
auto len = code.length();
if (len < trigWordLen()) {
QList<QCodeNode *> nodes;
if (len < trigWordLen() && trigger != *DOT_TRIGGER) {
emit onFunctionTip(this, {});
pPopup->hide();
return;
@ -170,7 +172,6 @@ void AsCompletion::complete(const QDocumentCursor &c, const QString &trigger) {
};
QByteArray fn;
QList<QCodeNode *> nodes;
QFlags<QCodeCompletionWidget::FilterFlag> filter(
QCodeCompletionWidget::FilterFlag::Public |
@ -220,7 +221,9 @@ void AsCompletion::complete(const QDocumentCursor &c, const QString &trigger) {
return;
}
if (etoken.content.length() >= trigWordLen()) {
if (trigger == *DOT_TRIGGER) {
nodes = parser.classNodes();
} else if (etoken.content.length() >= trigWordLen()) {
// completion for a.b.c or a::b.c or a::b::c.d or ::a::b.c
if (trigger == *DBL_COLON_TRIGGER) {
auto ns = getNamespace(tokens);
@ -282,7 +285,6 @@ void AsCompletion::complete(const QDocumentCursor &c, const QString &trigger) {
}
}
nodes.append(parser.keywordNode());
auto cur = c;
cur.movePosition(trigger.length());
pPopup->setCursor(cur);
@ -305,6 +307,7 @@ void AsCompletion::applyEmptyNsNode(QList<QCodeNode *> &nodes) {
break;
}
}
_emptyNsNodes.append(parser.keywordNode());
}
nodes = _emptyNsNodes;

View File

@ -59,8 +59,6 @@ typedef int (*PRAGMACALLBACK_t)(const QByteArray &pragmaText,
AsPreprocesser *builder,
const QString &sectionname, void *userParam);
#include "class/qascodeparser.h"
// Helper class for loading and pre-processing script files to
// support include directives declarations

View File

@ -62,6 +62,8 @@ QAsParser::~QAsParser() {
qDeleteAll(_nodes);
_nodes.clear();
delete _keywordNode;
qDeleteAll(_classNodes);
_classNodes.clear();
}
QByteArray QAsParser::getFnParamDeclString(asIScriptFunction *fn,
@ -348,21 +350,28 @@ void QAsParser::addClassCompletion(asIScriptEngine *engine) {
_maps[ns] << cls;
}
for (auto p = _maps.keyValueBegin(); p != _maps.keyValueEnd(); p++) {
auto node = getNewHeadNodePointer(p->first);
if (p->first.isEmpty()) {
node->setNodeType(QCodeNode::Group);
} else {
node->setNodeType(QCodeNode::Namespace);
}
auto applyClsNode = [](const QList<ClassInfo> &clsinfos,
bool isComplete) -> QList<QCodeNode *> {
QList<QCodeNode *> ret;
for (auto &cls : p->second) {
auto clsnode = new QCodeNode;
for (auto &cls : clsinfos) {
QCodeNode *clsnode = new QCodeNode;
clsnode->setNodeType(QCodeNode::Class);
clsnode->setRole(QCodeNode::Name, cls.name);
clsnode->attach(node);
for (auto &m : cls.methods) {
if (isComplete) {
if (m.fnName == cls.name) {
continue;
}
if (m.fnName.startsWith('~')) {
continue;
}
if (m.fnName.startsWith("op")) {
continue;
}
}
auto node = newFnCodeNode(m);
node->attach(clsnode);
}
@ -386,7 +395,25 @@ void QAsParser::addClassCompletion(asIScriptEngine *engine) {
node->setParent(clsnode);
clsnode->children().append(node);
}
ret.append(clsnode);
}
return ret;
};
for (auto p = _maps.keyValueBegin(); p != _maps.keyValueEnd(); p++) {
auto node = getNewHeadNodePointer(p->first);
if (p->first.isEmpty()) {
node->setNodeType(QCodeNode::Group);
} else {
node->setNodeType(QCodeNode::Namespace);
}
auto nodes = applyClsNode(p->second, false);
for (auto &n : nodes) {
n->attach(node);
}
_classNodes.append(applyClsNode(p->second, true));
}
}
@ -434,6 +461,8 @@ QCodeNode *QAsParser::newEnumCodeNode(const EnumInfo &info) {
return enode;
}
QList<QCodeNode *> QAsParser::classNodes() const { return _classNodes; }
QCodeNode *QAsParser::keywordNode() const { return _keywordNode; }
QList<QCodeNode *> QAsParser::codeNodes() const { return _nodes; }

View File

@ -81,6 +81,8 @@ public:
QCodeNode *keywordNode() const;
QList<QCodeNode *> classNodes() const;
private:
void addGlobalFunctionCompletion(asIScriptEngine *engine);
void addEnumCompletion(asIScriptEngine *engine);
@ -89,9 +91,9 @@ private:
QCodeNode *getNewHeadNodePointer(const QByteArray &name);
private:
QCodeNode *newFnCodeNode(const FnInfo &info);
static QCodeNode *newFnCodeNode(const FnInfo &info);
QCodeNode *newEnumCodeNode(const EnumInfo &info);
static QCodeNode *newEnumCodeNode(const EnumInfo &info);
private:
asIScriptEngine *_engine;
@ -99,6 +101,7 @@ private:
QHash<QString, QCodeNode *> _buffer;
QList<QCodeNode *> _headerNodes;
QList<QCodeNode *> _classNodes;
QCodeNode *_keywordNode;
};

View File

@ -226,8 +226,9 @@ void QCodeCompletionWidget::complete(const QModelIndex &index) {
static QRegularExpression re("(\\bconst\\s*)?(=\\s*0)?$");
txt.remove(re);
QStringView view(txt);
if (prefix.length() &&
prefix.compare(txt.left(prefix.length()), Qt::CaseInsensitive) == 0) {
prefix.compare(view.left(prefix.length()), Qt::CaseInsensitive) == 0) {
if (_cur.isValid()) {
_cur.movePosition(prefix.length(),
QDocumentCursor::PreviousCharacter,
@ -472,9 +473,22 @@ QVariant QCodeCompletionModel::data(const QModelIndex &index, int role) const {
QCodeNode *n = m_visibles.at(row);
int type = n->type();
if ((role == Qt::DisplayRole) && (type == QCodeNode::Enumerator))
return n->parent()->data(role).toString() +
"::" + n->data(role).toString();
if (role == Qt::DisplayRole) {
if (type == QCodeNode::Enumerator) {
return n->parent()->data(role).toString() +
"::" + n->data(role).toString();
}
if (type == QCodeNode::Function || type == QCodeNode::Variable) {
auto p = n->parent();
if (p) {
if (p->type() == QCodeNode::Class) {
return p->role(QCodeNode::Name) + QStringLiteral("::") +
n->data(role).toString();
}
}
}
}
if (role == Qt::UserRole)
role = Qt::DisplayRole;

View File

@ -293,6 +293,11 @@ MainWindow::MainWindow(SplashDialog *splash) : FramelessMainWindow() {
splash->setInfoText(tr("SetupDockingLayout"));
_defaultLayout = m_dock->saveState();
m_leftViewArea = nullptr;
m_rightViewArea = nullptr;
m_topViewArea = nullptr;
m_bottomViewArea = nullptr;
m_dock->restoreState(set.dockLayout());
m_lastusedpath = set.lastUsedPath();
@ -422,6 +427,38 @@ void MainWindow::buildUpDockSystem(QWidget *container) {
}
updateEditModeEnabled();
});
connect(m_dock, &CDockManager::stateRestored, this, [this]() {
// no allowing floating widgets
QList<CDockWidget *> _dws;
for (auto &dw : m_dock->dockWidgetsMap()) {
if (dw->dockAreaWidget() == nullptr) {
_dws.append(dw);
}
}
if (_dws.isEmpty()) {
return;
}
auto replaceDW = [this](CDockWidget *dw,
CDockAreaWidget *darea) -> CDockAreaWidget * {
m_dock->blockSignals(true);
m_dock->removeDockWidget(dw);
auto area =
m_dock->addDockWidget(ads::BottomDockWidgetArea, dw, darea);
m_dock->blockSignals(false);
dw->toggleView(false);
return area;
};
auto darea = m_dock->centralWidget()->dockAreaWidget();
auto dw = _dws.takeFirst();
darea = replaceDW(dw, darea);
for (auto &dw : _dws) {
replaceDW(dw, darea);
}
});
qApp->processEvents();
@ -1062,6 +1099,7 @@ MainWindow::buildUpVisualDataDock(ads::CDockManager *dock,
newAction(QStringLiteral("del"), tr("ClearResult"), [this]() {
auto model = m_infolist->model();
model->removeRows(0, model->rowCount());
m_infolist->setProperty("__TITLE__", {});
}));
auto ar = dock->addDockWidget(area, dw, areaw);
@ -1134,6 +1172,7 @@ MainWindow::buildUpVisualDataDock(ads::CDockManager *dock,
newAction(QStringLiteral("del"), tr("ClearResult"), [this]() {
auto model = m_infotree->model();
model->removeRows(0, model->rowCount());
m_infotree->setProperty("__TITLE__", {});
}));
dock->addDockWidget(CenterDockWidgetArea, dw, ar);
@ -1176,6 +1215,7 @@ MainWindow::buildUpVisualDataDock(ads::CDockManager *dock,
newAction(QStringLiteral("del"), tr("ClearResult"), [this]() {
auto model = m_infotable->model();
model->removeRows(0, model->rowCount());
m_infotable->setProperty("__TITLE__", {});
}));
dock->addDockWidget(CenterDockWidgetArea, dw, ar);
@ -1209,8 +1249,11 @@ MainWindow::buildUpVisualDataDock(ads::CDockManager *dock,
Toast::toast(this, NAMEICONRES(QStringLiteral("save")),
tr("SaveSuccessfully"));
}));
menu->addAction(newAction(QStringLiteral("del"), tr("ClearResult"),
[this]() { m_infotxt->clear(); }));
menu->addAction(
newAction(QStringLiteral("del"), tr("ClearResult"), [this]() {
m_infotxt->clear();
m_infotxt->setProperty("__TITLE__", {});
}));
connect(m_infotxt, &QTextBrowser::customContextMenuRequested, this,
[=](const QPoint &pos) {
menu->popup(m_infotxt->viewport()->mapToGlobal(pos));

View File

@ -632,6 +632,7 @@ private:
QHash<SettingPage *, bool> m_settingPages;
QList<PluginPage *> m_plgPages;
// these variables will be invalid after restoring state
ads::CDockAreaWidget *m_leftViewArea = nullptr;
ads::CDockAreaWidget *m_rightViewArea = nullptr; // 该值使用时必不为空
ads::CDockAreaWidget *m_topViewArea = nullptr;

View File

@ -334,10 +334,15 @@ void PluginSystem::cleanUpEditorViewHandle(EditorView *view) {
bool PluginSystem::closeEditor(IWingPlugin *plg, int handle, bool force) {
if (handle >= 0) {
auto &handles = m_plgviewMap[plg];
auto r = std::find_if(handles.begin(), handles.end(),
[handle](const PluginFileContext &d) {
return equalCompareHandle(d.fid, handle);
});
auto r = std::find_if(
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
handles.cbegin(), handles.cend(),
#else
handles.begin(), handles.end(),
#endif
[handle](const PluginFileContext &d) {
return equalCompareHandle(d.fid, handle);
});
if (r == handles.end()) {
return false;
}
@ -366,10 +371,15 @@ bool PluginSystem::closeHandle(IWingPlugin *plg, int handle) {
return false;
}
auto &handles = m_plgviewMap[plg];
auto r = std::find_if(handles.begin(), handles.end(),
[handle](const PluginFileContext &d) {
return equalCompareHandle(d.fid, handle);
});
auto r = std::find_if(
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
handles.cbegin(), handles.cend(),
#else
handles.begin(), handles.end(),
#endif
[handle](const PluginFileContext &d) {
return equalCompareHandle(d.fid, handle);
});
if (r == handles.end()) {
return false;
}

View File

@ -2259,7 +2259,7 @@ QHeaderView::section::horizontal
border-left: transparent;
}
QHeaderView[showSortIndicator="true"]::section::horizontal
QHeaderView::section::horizontal
{
/* Same as the width of the arrow subcontrols below. */
padding-right: 0.8em;
@ -2281,7 +2281,7 @@ QHeaderView::section::vertical::only-one:hover
border: 0.04em solid #3daee9;
}
QHeaderView[showSortIndicator="true"]::down-arrow
QHeaderView::down-arrow
{
image: url(:/dark/down_arrow.svg);
/**
@ -2304,7 +2304,7 @@ QHeaderView[showSortIndicator="true"]::down-arrow
padding-left: -0.8em;
}
QHeaderView[showSortIndicator="true"]::up-arrow
QHeaderView::up-arrow
{
image: url(:/dark/up_arrow.svg);
subcontrol-origin: content;

View File

@ -2259,7 +2259,7 @@ QHeaderView::section::horizontal
border-left: transparent;
}
QHeaderView[showSortIndicator="true"]::section::horizontal
QHeaderView::section::horizontal
{
/* Same as the width of the arrow subcontrols below. */
padding-right: 0.8em;
@ -2281,7 +2281,7 @@ QHeaderView::section::vertical::only-one:hover
border: 0.04em solid rgba(51, 164, 223, 0.5);
}
QHeaderView[showSortIndicator="true"]::down-arrow
QHeaderView::down-arrow
{
image: url(:/light/down_arrow.svg);
/**
@ -2304,7 +2304,7 @@ QHeaderView[showSortIndicator="true"]::down-arrow
padding-left: -0.8em;
}
QHeaderView[showSortIndicator="true"]::up-arrow
QHeaderView::up-arrow
{
image: url(:/light/up_arrow.svg);
subcontrol-origin: content;