mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Search bar improvements
New button and key sequence (ESC) to close the search bar. Clear selection (by not avoiding the search) when the text to search is deleted, as expected by @pamtbaau at #1220.
This commit is contained in:
@@ -1737,6 +1737,7 @@ unsigned int MainWindow::openSqlTab(bool resetCounter)
|
||||
ui->tabSqlAreas->setCurrentIndex(index);
|
||||
w->setFindFrameVisibility(ui->actionSqlFind->isChecked());
|
||||
w->getEditor()->setFocus();
|
||||
connect(w, SIGNAL(findFrameVisibilityChanged(bool)), ui->actionSqlFind, SLOT(setChecked(bool)));
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QShortcut>
|
||||
|
||||
SqlExecutionArea::SqlExecutionArea(DBBrowserDB& _db, QWidget* parent) :
|
||||
QWidget(parent),
|
||||
@@ -25,11 +26,15 @@ SqlExecutionArea::SqlExecutionArea(DBBrowserDB& _db, QWidget* parent) :
|
||||
|
||||
ui->findFrame->hide();
|
||||
|
||||
QShortcut* shortcutHideFind = new QShortcut(QKeySequence("ESC"), ui->findLineEdit);
|
||||
connect(shortcutHideFind, SIGNAL(activated()), this, SLOT(hideFindFrame()));
|
||||
|
||||
connect(ui->findLineEdit, SIGNAL(textChanged(const QString &)),
|
||||
this, SLOT(findLineEdit_textChanged(const QString &)));
|
||||
connect(ui->previousToolButton, SIGNAL(clicked()), this, SLOT(findPrevious()));
|
||||
connect(ui->nextToolButton, SIGNAL(clicked()), this, SLOT(findNext()));
|
||||
connect(ui->findLineEdit, SIGNAL(returnPressed()), this, SLOT(findNext()));
|
||||
connect(ui->hideFindButton, SIGNAL(clicked()), this, SLOT(hideFindFrame()));
|
||||
|
||||
// Load settings
|
||||
reloadSettings();
|
||||
@@ -152,7 +157,7 @@ void SqlExecutionArea::find(QString expr, bool forward)
|
||||
forward);
|
||||
|
||||
// Set reddish background when not found
|
||||
if (found)
|
||||
if (found || expr == "")
|
||||
ui->findLineEdit->setStyleSheet("");
|
||||
else
|
||||
ui->findLineEdit->setStyleSheet("color: white; background-color: rgb(255, 102, 102)");
|
||||
@@ -174,26 +179,26 @@ void SqlExecutionArea::findLineEdit_textChanged(const QString &)
|
||||
// When the text changes, perform an incremental search from cursor
|
||||
// position, or from begin of the selection position.
|
||||
|
||||
// Reset reddish background when the user has deleted the input,
|
||||
// otherwise search the text forward.
|
||||
if (ui->findLineEdit->text() == "")
|
||||
ui->findLineEdit->setStyleSheet("");
|
||||
else {
|
||||
// For incremental search while typing we need to start from the
|
||||
// begining of the current selection, otherwise we'd jump to the
|
||||
// next occurrence
|
||||
if (ui->editEditor->hasSelectedText()) {
|
||||
int lineFrom;
|
||||
int indexFrom;
|
||||
int lineTo;
|
||||
int indexTo;
|
||||
ui->editEditor->getSelection(&lineFrom, &indexFrom, &lineTo, &indexTo);
|
||||
ui->editEditor->setCursorPosition(lineFrom, indexFrom);
|
||||
}
|
||||
|
||||
find(ui->findLineEdit->text(), true);
|
||||
|
||||
// For incremental search while typing we need to start from the
|
||||
// begining of the current selection, otherwise we'd jump to the
|
||||
// next occurrence
|
||||
if (ui->editEditor->hasSelectedText()) {
|
||||
int lineFrom;
|
||||
int indexFrom;
|
||||
int lineTo;
|
||||
int indexTo;
|
||||
ui->editEditor->getSelection(&lineFrom, &indexFrom, &lineTo, &indexTo);
|
||||
ui->editEditor->setCursorPosition(lineFrom, indexFrom);
|
||||
}
|
||||
|
||||
find(ui->findLineEdit->text(), true);
|
||||
}
|
||||
|
||||
void SqlExecutionArea::hideFindFrame()
|
||||
{
|
||||
ui->editEditor->setFocus();
|
||||
ui->findFrame->hide();
|
||||
emit findFrameVisibilityChanged(false);
|
||||
}
|
||||
|
||||
void SqlExecutionArea::setFindFrameVisibility(bool show)
|
||||
@@ -202,8 +207,8 @@ void SqlExecutionArea::setFindFrameVisibility(bool show)
|
||||
ui->findFrame->show();
|
||||
ui->findLineEdit->setFocus();
|
||||
ui->findLineEdit->selectAll();
|
||||
emit findFrameVisibilityChanged(true);
|
||||
} else {
|
||||
ui->editEditor->setFocus();
|
||||
ui->findFrame->hide();
|
||||
hideFindFrame();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ private slots:
|
||||
void findPrevious();
|
||||
void findNext();
|
||||
void findLineEdit_textChanged(const QString& text);
|
||||
void hideFindFrame();
|
||||
|
||||
signals:
|
||||
void findFrameVisibilityChanged(bool visible);
|
||||
|
||||
private:
|
||||
void find(QString expr, bool forward);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>552</width>
|
||||
<width>579</width>
|
||||
<height>482</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -77,17 +77,11 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="6">
|
||||
<item row="0" column="8">
|
||||
<spacer>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
@@ -156,6 +150,29 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="6">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="9">
|
||||
<widget class="QToolButton" name="hideFindButton">
|
||||
<property name="text">
|
||||
<string notr="true">...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="dialog-close"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user