mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-22 01:40:02 +00:00
Restore the URL when DolphinSearchBox is cleared
Currently, the URL navigator is not updated when the search box is cleared. This MR restores the URL, by closing and reopening the box. The call for emitting closeRequest() on pressing Esc has been replaced with emitCloseRequest(). The wait duration before starting a search has been reduced to 500ms to increase responsiveness. Also, the bugfix for BUG: 423328 is slightly incorrect and causes the search term to not be displayed when opening a saved search for the first time. As a better solution for this bug, DolphinSearchBox::setText() now updates the text only if the text has changed. BUG: 473775
This commit is contained in:
parent
9ba0904013
commit
c4bb3db022
|
@ -84,6 +84,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent)
|
||||||
m_searchBox = new DolphinSearchBox(this);
|
m_searchBox = new DolphinSearchBox(this);
|
||||||
m_searchBox->hide();
|
m_searchBox->hide();
|
||||||
connect(m_searchBox, &DolphinSearchBox::activated, this, &DolphinViewContainer::activate);
|
connect(m_searchBox, &DolphinSearchBox::activated, this, &DolphinViewContainer::activate);
|
||||||
|
connect(m_searchBox, &DolphinSearchBox::openRequest, this, &DolphinViewContainer::openSearchBox);
|
||||||
connect(m_searchBox, &DolphinSearchBox::closeRequest, this, &DolphinViewContainer::closeSearchBox);
|
connect(m_searchBox, &DolphinSearchBox::closeRequest, this, &DolphinViewContainer::closeSearchBox);
|
||||||
connect(m_searchBox, &DolphinSearchBox::searchRequest, this, &DolphinViewContainer::startSearching);
|
connect(m_searchBox, &DolphinSearchBox::searchRequest, this, &DolphinViewContainer::startSearching);
|
||||||
connect(m_searchBox, &DolphinSearchBox::focusViewRequest, this, &DolphinViewContainer::requestFocus);
|
connect(m_searchBox, &DolphinSearchBox::focusViewRequest, this, &DolphinViewContainer::requestFocus);
|
||||||
|
@ -891,6 +892,11 @@ void DolphinViewContainer::startSearching()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DolphinViewContainer::openSearchBox()
|
||||||
|
{
|
||||||
|
setSearchModeEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
void DolphinViewContainer::closeSearchBox()
|
void DolphinViewContainer::closeSearchBox()
|
||||||
{
|
{
|
||||||
setSearchModeEnabled(false);
|
setSearchModeEnabled(false);
|
||||||
|
|
|
@ -382,6 +382,7 @@ private Q_SLOTS:
|
||||||
* Gets the search URL from the searchbox and starts searching.
|
* Gets the search URL from the searchbox and starts searching.
|
||||||
*/
|
*/
|
||||||
void startSearching();
|
void startSearching();
|
||||||
|
void openSearchBox();
|
||||||
void closeSearchBox();
|
void closeSearchBox();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -60,7 +60,9 @@ DolphinSearchBox::~DolphinSearchBox()
|
||||||
|
|
||||||
void DolphinSearchBox::setText(const QString &text)
|
void DolphinSearchBox::setText(const QString &text)
|
||||||
{
|
{
|
||||||
|
if (m_searchInput->text() != text) {
|
||||||
m_searchInput->setText(text);
|
m_searchInput->setText(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DolphinSearchBox::text() const
|
QString DolphinSearchBox::text() const
|
||||||
|
@ -201,7 +203,7 @@ void DolphinSearchBox::keyReleaseEvent(QKeyEvent *event)
|
||||||
QWidget::keyReleaseEvent(event);
|
QWidget::keyReleaseEvent(event);
|
||||||
if (event->key() == Qt::Key_Escape) {
|
if (event->key() == Qt::Key_Escape) {
|
||||||
if (m_searchInput->text().isEmpty()) {
|
if (m_searchInput->text().isEmpty()) {
|
||||||
Q_EMIT closeRequest();
|
emitCloseRequest();
|
||||||
} else {
|
} else {
|
||||||
m_searchInput->clear();
|
m_searchInput->clear();
|
||||||
}
|
}
|
||||||
|
@ -261,7 +263,11 @@ void DolphinSearchBox::slotConfigurationChanged()
|
||||||
void DolphinSearchBox::slotSearchTextChanged(const QString &text)
|
void DolphinSearchBox::slotSearchTextChanged(const QString &text)
|
||||||
{
|
{
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
m_startSearchTimer->stop();
|
// Restore URL when search box is cleared by closing and reopening the box.
|
||||||
|
emitCloseRequest();
|
||||||
|
QTimer::singleShot(0, this, [this] {
|
||||||
|
Q_EMIT openRequest();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
m_startSearchTimer->start();
|
m_startSearchTimer->start();
|
||||||
}
|
}
|
||||||
|
@ -270,6 +276,10 @@ void DolphinSearchBox::slotSearchTextChanged(const QString &text)
|
||||||
|
|
||||||
void DolphinSearchBox::slotReturnPressed()
|
void DolphinSearchBox::slotReturnPressed()
|
||||||
{
|
{
|
||||||
|
if (m_searchInput->text().isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
emitSearchRequest();
|
emitSearchRequest();
|
||||||
Q_EMIT focusViewRequest();
|
Q_EMIT focusViewRequest();
|
||||||
}
|
}
|
||||||
|
@ -443,10 +453,10 @@ void DolphinSearchBox::init()
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
// The searching should be started automatically after the user did not change
|
// The searching should be started automatically after the user did not change
|
||||||
// the text within one second
|
// the text for a while
|
||||||
m_startSearchTimer = new QTimer(this);
|
m_startSearchTimer = new QTimer(this);
|
||||||
m_startSearchTimer->setSingleShot(true);
|
m_startSearchTimer->setSingleShot(true);
|
||||||
m_startSearchTimer->setInterval(1000);
|
m_startSearchTimer->setInterval(500);
|
||||||
connect(m_startSearchTimer, &QTimer::timeout, this, &DolphinSearchBox::emitSearchRequest);
|
connect(m_startSearchTimer, &QTimer::timeout, this, &DolphinSearchBox::emitSearchRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,10 +506,7 @@ void DolphinSearchBox::updateFromQuery(const DolphinQuery &query)
|
||||||
setSearchPath(QUrl::fromLocalFile(QDir::homePath()));
|
setSearchPath(QUrl::fromLocalFile(QDir::homePath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the input box has focus, do not update to avoid messing with user typing
|
|
||||||
if (!m_searchInput->hasFocus()) {
|
|
||||||
setText(query.text());
|
setText(query.text());
|
||||||
}
|
|
||||||
|
|
||||||
if (query.hasContentSearch()) {
|
if (query.hasContentSearch()) {
|
||||||
m_contentButton->setChecked(true);
|
m_contentButton->setChecked(true);
|
||||||
|
|
|
@ -111,6 +111,11 @@ Q_SIGNALS:
|
||||||
*/
|
*/
|
||||||
void closeRequest();
|
void closeRequest();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is emitted when the search box should be opened.
|
||||||
|
*/
|
||||||
|
void openRequest();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is emitted, if the searchbox has been activated by
|
* Is emitted, if the searchbox has been activated by
|
||||||
* an user interaction
|
* an user interaction
|
||||||
|
|
Loading…
Reference in a new issue