mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-05 01:20:42 +00:00
Change Find/Replace dialog to have Find Next/Find Previous buttons
* Enter and shift-enter in the find text go forwarwd and backwards respectively. * This replaces the previous system of selecting a direction explicitly and only ever going in that direction when finding.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "FindReplace.h"
|
||||
#include <QKeyEvent>
|
||||
#include <QLineEdit>
|
||||
#include "Widgets/Extended/RDLineEdit.h"
|
||||
#include "ui_FindReplace.h"
|
||||
|
||||
FindReplace::FindReplace(QWidget *parent) : QFrame(parent), ui(new Ui::FindReplace)
|
||||
@@ -37,8 +38,25 @@ FindReplace::FindReplace(QWidget *parent) : QFrame(parent), ui(new Ui::FindRepla
|
||||
setReplaceMode(false);
|
||||
setDirection(FindReplace::Down);
|
||||
|
||||
QObject::connect(ui->findText->lineEdit(), &QLineEdit::returnPressed, this,
|
||||
&FindReplace::on_find_clicked);
|
||||
RDLineEdit *edit = new RDLineEdit(this);
|
||||
ui->findText->setLineEdit(edit);
|
||||
|
||||
QObject::connect(edit, &RDLineEdit::keyPress, [this](QKeyEvent *event) {
|
||||
if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
|
||||
{
|
||||
SearchDirection dir = m_direction;
|
||||
|
||||
if(event->modifiers() & Qt::ShiftModifier)
|
||||
m_direction = SearchDirection::Up;
|
||||
else
|
||||
m_direction = SearchDirection::Down;
|
||||
|
||||
addHistory(ui->findText);
|
||||
emit performFind();
|
||||
|
||||
m_direction = dir;
|
||||
}
|
||||
});
|
||||
QObject::connect(ui->replaceText->lineEdit(), &QLineEdit::returnPressed, this,
|
||||
&FindReplace::on_replace_clicked);
|
||||
}
|
||||
@@ -60,7 +78,7 @@ FindReplace::SearchContext FindReplace::context()
|
||||
|
||||
FindReplace::SearchDirection FindReplace::direction()
|
||||
{
|
||||
return ui->searchUp->isChecked() ? FindReplace::Up : FindReplace::Down;
|
||||
return m_direction;
|
||||
}
|
||||
|
||||
bool FindReplace::matchCase()
|
||||
@@ -108,10 +126,7 @@ void FindReplace::setReplaceMode(bool replacing)
|
||||
|
||||
void FindReplace::setDirection(SearchDirection dir)
|
||||
{
|
||||
if(dir == FindReplace::Up)
|
||||
ui->searchUp->setChecked(true);
|
||||
else
|
||||
ui->searchDown->setChecked(true);
|
||||
m_direction = dir;
|
||||
}
|
||||
|
||||
void FindReplace::takeFocus()
|
||||
@@ -124,19 +139,16 @@ void FindReplace::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if(event->key() == Qt::Key_F3)
|
||||
{
|
||||
SearchDirection dir = direction();
|
||||
SearchDirection dir = m_direction;
|
||||
|
||||
if(event->modifiers() & Qt::ShiftModifier)
|
||||
ui->searchUp->setChecked(true);
|
||||
m_direction = SearchDirection::Up;
|
||||
else
|
||||
ui->searchDown->setChecked(true);
|
||||
m_direction = SearchDirection::Down;
|
||||
|
||||
emit performFind();
|
||||
|
||||
if(dir == FindReplace::Up)
|
||||
ui->searchUp->setChecked(true);
|
||||
else
|
||||
ui->searchDown->setChecked(true);
|
||||
m_direction = dir;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +170,12 @@ void FindReplace::addHistory(QComboBox *combo)
|
||||
combo->setCurrentText(text);
|
||||
}
|
||||
|
||||
void FindReplace::on_findPrev_clicked()
|
||||
{
|
||||
addHistory(ui->findText);
|
||||
emit performFind();
|
||||
}
|
||||
|
||||
void FindReplace::on_find_clicked()
|
||||
{
|
||||
addHistory(ui->findText);
|
||||
|
||||
@@ -78,6 +78,7 @@ signals:
|
||||
|
||||
private slots:
|
||||
// automatic slots
|
||||
void on_findPrev_clicked();
|
||||
void on_find_clicked();
|
||||
void on_findAll_clicked();
|
||||
void on_replace_clicked();
|
||||
@@ -90,5 +91,7 @@ private:
|
||||
|
||||
Ui::FindReplace *ui;
|
||||
|
||||
SearchDirection m_direction;
|
||||
|
||||
void addHistory(QComboBox *combo);
|
||||
};
|
||||
|
||||
@@ -7,10 +7,26 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>321</width>
|
||||
<height>352</height>
|
||||
<height>291</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="7" column="1">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
@@ -81,7 +97,23 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<item row="5" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
@@ -102,34 +134,41 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="2" column="1">
|
||||
<item row="2" column="3">
|
||||
<widget class="QPushButton" name="replaceAll">
|
||||
<property name="text">
|
||||
<string>Replace All</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="replace">
|
||||
<property name="text">
|
||||
<string>Replace</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="find">
|
||||
<property name="text">
|
||||
<string>Find Next</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="1" column="3">
|
||||
<widget class="QPushButton" name="findAll">
|
||||
<property name="text">
|
||||
<string>Find All</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="findPrev">
|
||||
<property name="text">
|
||||
<string>Find Previous</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QPushButton" name="replace">
|
||||
<property name="text">
|
||||
<string>Replace</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -196,74 +235,6 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Direction</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="searchUp">
|
||||
<property name="text">
|
||||
<string>Up</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="searchDown">
|
||||
<property name="text">
|
||||
<string>Down</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="sizePolicy">
|
||||
|
||||
@@ -4098,7 +4098,7 @@ void ShaderViewer::find(bool down)
|
||||
|
||||
FindReplace::SearchContext context = m_FindReplace->context();
|
||||
|
||||
QString findHash = QFormatStr("%1%2%3").arg(find).arg(flags).arg((int)context);
|
||||
QString findHash = QFormatStr("%1%2%3%4").arg(find).arg(flags).arg((int)context).arg(down);
|
||||
|
||||
if(findHash != m_FindState.hash)
|
||||
{
|
||||
@@ -4106,6 +4106,9 @@ void ShaderViewer::find(bool down)
|
||||
m_FindState.start = 0;
|
||||
m_FindState.end = cur->length();
|
||||
m_FindState.offset = cur->currentPos();
|
||||
if(down && cur->selectionStart() == m_FindState.offset &&
|
||||
cur->selectionEnd() - m_FindState.offset == find.length())
|
||||
m_FindState.offset += find.length();
|
||||
}
|
||||
|
||||
int start = m_FindState.start + m_FindState.offset;
|
||||
|
||||
Reference in New Issue
Block a user