mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-17 15:31:20 +00:00
Make Saved Search feature discoverable
Summary: FEATURE: 269332 Make Dolphin's Saved Search feature discoverable by adding a button inside the search field. The button only becomes enabled when there is a valid search term. When pushed, it saves the search to the Places panel, providing a visible-by-default way to do this to complement the existing implementation that is only visible in the context menu. Also harmonized the label text so that it's consistent no matter how you create a saved search (button or context menu) Test Plan: Tested in KDE Neon. Works great: {F5449508} Reviewers: #dolphin, broulik, dfaure, markg, emateli, elvisangelaccio Reviewed By: #dolphin, markg, emateli, elvisangelaccio Subscribers: anthonyfieroni, markg, emateli, elvisangelaccio, cfeck, #dolphin Tags: #dolphin Differential Revision: https://phabricator.kde.org/D8454
This commit is contained in:
parent
5454283008
commit
64cfc43b97
|
@ -369,11 +369,16 @@ void DolphinContextMenu::openViewportContextMenu()
|
||||||
QAction* action = exec(m_pos);
|
QAction* action = exec(m_pos);
|
||||||
if (addToPlacesAction && (action == addToPlacesAction)) {
|
if (addToPlacesAction && (action == addToPlacesAction)) {
|
||||||
const DolphinViewContainer* container = m_mainWindow->activeViewContainer();
|
const DolphinViewContainer* container = m_mainWindow->activeViewContainer();
|
||||||
if (container->url().isValid()) {
|
const QUrl url = container->url();
|
||||||
|
if (url.isValid()) {
|
||||||
PlacesItemModel model;
|
PlacesItemModel model;
|
||||||
PlacesItem* item = model.createPlacesItem(container->placesText(),
|
QString icon;
|
||||||
container->url(),
|
if (container->isSearchModeEnabled()) {
|
||||||
KIO::iconNameForUrl(container->url()));
|
icon = QStringLiteral("folder-saved-search-symbolic");
|
||||||
|
} else {
|
||||||
|
icon = KIO::iconNameForUrl(url);
|
||||||
|
}
|
||||||
|
PlacesItem* item = model.createPlacesItem(container->placesText(), url, icon);
|
||||||
model.appendItemToGroup(item);
|
model.appendItemToGroup(item);
|
||||||
model.saveBookmarks();
|
model.saveBookmarks();
|
||||||
}
|
}
|
||||||
|
|
|
@ -362,7 +362,7 @@ QString DolphinViewContainer::placesText() const
|
||||||
QString text;
|
QString text;
|
||||||
|
|
||||||
if (isSearchModeEnabled()) {
|
if (isSearchModeEnabled()) {
|
||||||
text = m_searchBox->searchPath().fileName() + QLatin1String(": ") + m_searchBox->text();
|
text = i18n("Search for %1 in %2", m_searchBox->text(), m_searchBox->searchPath().fileName());
|
||||||
} else {
|
} else {
|
||||||
text = url().fileName();
|
text = url().fileName();
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include "dolphin_searchsettings.h"
|
#include "dolphin_searchsettings.h"
|
||||||
#include "dolphinfacetswidget.h"
|
#include "dolphinfacetswidget.h"
|
||||||
|
|
||||||
|
#include <panels/places/placesitemmodel.h>
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
@ -54,6 +56,7 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
|
||||||
m_topLayout(0),
|
m_topLayout(0),
|
||||||
m_searchLabel(0),
|
m_searchLabel(0),
|
||||||
m_searchInput(0),
|
m_searchInput(0),
|
||||||
|
m_saveSearchAction(0),
|
||||||
m_optionsScrollArea(0),
|
m_optionsScrollArea(0),
|
||||||
m_fileNameButton(0),
|
m_fileNameButton(0),
|
||||||
m_contentButton(0),
|
m_contentButton(0),
|
||||||
|
@ -250,6 +253,7 @@ void DolphinSearchBox::emitSearchRequest()
|
||||||
{
|
{
|
||||||
m_startSearchTimer->stop();
|
m_startSearchTimer->stop();
|
||||||
m_startedSearching = true;
|
m_startedSearching = true;
|
||||||
|
m_saveSearchAction->setEnabled(true);
|
||||||
emit searchRequest();
|
emit searchRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,6 +261,7 @@ void DolphinSearchBox::emitCloseRequest()
|
||||||
{
|
{
|
||||||
m_startSearchTimer->stop();
|
m_startSearchTimer->stop();
|
||||||
m_startedSearching = false;
|
m_startedSearching = false;
|
||||||
|
m_saveSearchAction->setEnabled(false);
|
||||||
emit closeRequest();
|
emit closeRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,6 +304,20 @@ void DolphinSearchBox::slotFacetChanged()
|
||||||
emit searchRequest();
|
emit searchRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DolphinSearchBox::slotSearchSaved()
|
||||||
|
{
|
||||||
|
const QUrl searchURL = urlForSearching();
|
||||||
|
if (searchURL.isValid()) {
|
||||||
|
PlacesItemModel model;
|
||||||
|
const QString label = i18n("Search for %1 in %2", text(), searchPath().fileName());
|
||||||
|
PlacesItem* item = model.createPlacesItem(label,
|
||||||
|
searchURL,
|
||||||
|
QStringLiteral("folder-saved-search-symbolic"));
|
||||||
|
model.appendItemToGroup(item);
|
||||||
|
model.saveBookmarks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DolphinSearchBox::initButton(QToolButton* button)
|
void DolphinSearchBox::initButton(QToolButton* button)
|
||||||
{
|
{
|
||||||
button->installEventFilter(this);
|
button->installEventFilter(this);
|
||||||
|
@ -356,6 +375,14 @@ void DolphinSearchBox::init()
|
||||||
this, &DolphinSearchBox::slotSearchTextChanged);
|
this, &DolphinSearchBox::slotSearchTextChanged);
|
||||||
setFocusProxy(m_searchInput);
|
setFocusProxy(m_searchInput);
|
||||||
|
|
||||||
|
// Add "Save search" button inside search box
|
||||||
|
m_saveSearchAction = new QAction(this);
|
||||||
|
m_saveSearchAction->setIcon (QIcon::fromTheme(QStringLiteral("document-save-symbolic")));
|
||||||
|
m_saveSearchAction->setText(i18nc("action:button", "Save this search to quickly access it again in the future"));
|
||||||
|
m_saveSearchAction->setEnabled(false);
|
||||||
|
m_searchInput->addAction(m_saveSearchAction, QLineEdit::TrailingPosition);
|
||||||
|
connect(m_saveSearchAction, &QAction::triggered, this, &DolphinSearchBox::slotSearchSaved);
|
||||||
|
|
||||||
// Apply layout for the search input
|
// Apply layout for the search input
|
||||||
QHBoxLayout* searchInputLayout = new QHBoxLayout();
|
QHBoxLayout* searchInputLayout = new QHBoxLayout();
|
||||||
searchInputLayout->setMargin(0);
|
searchInputLayout->setMargin(0);
|
||||||
|
|
|
@ -139,6 +139,7 @@ private slots:
|
||||||
void slotReturnPressed();
|
void slotReturnPressed();
|
||||||
void slotFacetsButtonToggled();
|
void slotFacetsButtonToggled();
|
||||||
void slotFacetChanged();
|
void slotFacetChanged();
|
||||||
|
void slotSearchSaved();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initButton(QToolButton* button);
|
void initButton(QToolButton* button);
|
||||||
|
@ -167,6 +168,7 @@ private:
|
||||||
|
|
||||||
QLabel* m_searchLabel;
|
QLabel* m_searchLabel;
|
||||||
QLineEdit* m_searchInput;
|
QLineEdit* m_searchInput;
|
||||||
|
QAction* m_saveSearchAction;
|
||||||
QScrollArea* m_optionsScrollArea;
|
QScrollArea* m_optionsScrollArea;
|
||||||
QToolButton* m_fileNameButton;
|
QToolButton* m_fileNameButton;
|
||||||
QToolButton* m_contentButton;
|
QToolButton* m_contentButton;
|
||||||
|
|
Loading…
Reference in a new issue