Implement double clicking to go to find-all results. Closes #2277

This commit is contained in:
baldurk
2021-07-20 16:59:11 +01:00
parent a88bc9dd7d
commit 71bbc53759
2 changed files with 50 additions and 6 deletions
+46 -6
View File
@@ -131,6 +131,9 @@ ShaderViewer::ShaderViewer(ICaptureContext &ctx, QWidget *parent)
ui->docking->setToolWindowProperties(
m_FindResults, ToolWindowManager::HideOnClose | ToolWindowManager::DisallowFloatWindow);
QObject::connect(m_FindResults, &ScintillaEdit::doubleClick, this,
&ShaderViewer::resultsDoubleClick);
{
m_DisassemblyView =
MakeEditor(lit("scintillaDisassem"), QString(),
@@ -1202,6 +1205,15 @@ ScintillaEdit *ShaderViewer::MakeEditor(const QString &name, const QString &text
ret->indicSetAlpha(INDICATOR_FINDRESULT, 50);
ret->indicSetOutlineAlpha(INDICATOR_FINDRESULT, 80);
QColor highlightColor = palette().color(QPalette::Highlight).toRgb();
ret->indicSetFore(
INDICATOR_FINDALLHIGHLIGHT,
SCINTILLA_COLOUR(highlightColor.red(), highlightColor.green(), highlightColor.blue()));
ret->indicSetStyle(INDICATOR_FINDALLHIGHLIGHT, INDIC_FULLBOX);
ret->indicSetAlpha(INDICATOR_FINDALLHIGHLIGHT, 120);
ret->indicSetOutlineAlpha(INDICATOR_FINDALLHIGHLIGHT, 180);
ConfigureSyntax(ret, lang);
ret->setTabWidth(4);
@@ -5251,8 +5263,13 @@ void ShaderViewer::performFindAll()
QList<QPair<int, int>> resultList;
m_FindAllResults.clear();
QByteArray findUtf8 = find.toUtf8();
if(findUtf8.isEmpty())
return;
for(ScintillaEdit *s : scintillas)
{
sptr_t start = 0;
@@ -5261,9 +5278,6 @@ void ShaderViewer::performFindAll()
s->setIndicatorCurrent(INDICATOR_FINDRESULT);
s->indicatorClearRange(start, end);
if(findUtf8.isEmpty())
continue;
QPair<int, int> result;
do
@@ -5288,6 +5302,8 @@ void ShaderViewer::performFindAll()
resultList.push_back(
qMakePair(result.first - lineStart + startPos, result.second - lineStart + startPos));
m_FindAllResults.push_back({s, result.first});
}
start = result.second;
@@ -5295,14 +5311,14 @@ void ShaderViewer::performFindAll()
} while(result.first >= 0);
}
if(findUtf8.isEmpty())
return;
results += tr("Matching lines: %1").arg(resultList.count());
m_FindResults->setReadOnly(false);
m_FindResults->setText(results.toUtf8().data());
m_FindResults->setIndicatorCurrent(INDICATOR_FINDALLHIGHLIGHT);
m_FindResults->indicatorClearRange(0, m_FindResults->length());
m_FindResults->setIndicatorCurrent(INDICATOR_FINDRESULT);
for(QPair<int, int> r : resultList)
@@ -5324,6 +5340,30 @@ void ShaderViewer::performFindAll()
}
}
void ShaderViewer::resultsDoubleClick(int position, int line)
{
if(line >= 1 && line - 1 < m_FindAllResults.count())
{
m_FindResults->setIndicatorCurrent(INDICATOR_FINDALLHIGHLIGHT);
m_FindResults->indicatorClearRange(0, m_FindResults->length());
sptr_t start = m_FindResults->positionFromLine(line);
sptr_t length = m_FindResults->lineLength(line);
m_FindResults->indicatorFillRange(start, length);
m_FindResults->setSelection(position, position);
ScintillaEdit *s = m_FindAllResults[line - 1].first;
int resultPos = m_FindAllResults[line - 1].second;
ToolWindowManager::raiseToolWindow(s);
s->activateWindow();
s->QWidget::setFocus();
s->clearSelections();
s->setSelection(resultPos, resultPos);
s->scrollCaret();
}
}
void ShaderViewer::performReplace()
{
ScintillaEdit *cur = currentScintilla();
+4
View File
@@ -160,6 +160,7 @@ private slots:
void watch_keyPress(QKeyEvent *event);
void performFind();
void performFindAll();
void resultsDoubleClick(int position, int line);
void performReplace();
void performReplaceAll();
@@ -290,6 +291,8 @@ private:
rdcarray<BoundResourceArray> m_ReadWriteResources;
QList<int> m_Breakpoints;
QList<QPair<ScintillaEdit *, int>> m_FindAllResults;
static const int CURRENT_MARKER = 0;
static const int BREAKPOINT_MARKER = 2;
static const int FINISHED_MARKER = 4;
@@ -299,6 +302,7 @@ private:
static const int INDICATOR_FINDRESULT = 0;
static const int INDICATOR_REGHIGHLIGHT = 1;
static const int INDICATOR_FINDALLHIGHLIGHT = 2;
QString targetName(const ShaderProcessingTool &disasm);