]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Make Saved Search feature discoverable
authorNathaniel Graham <pointedstick@zoho.com>
Tue, 24 Oct 2017 19:10:41 +0000 (13:10 -0600)
committerNathaniel Graham <pointedstick@zoho.com>
Wed, 1 Nov 2017 15:00:48 +0000 (09:00 -0600)
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

src/dolphincontextmenu.cpp
src/dolphinviewcontainer.cpp
src/search/dolphinsearchbox.cpp
src/search/dolphinsearchbox.h

index b4d249d761420d468248f6f9ec0b16d5bf13c8ff..881ef34b410d8befa000e7e4f5f163d242f50467 100644 (file)
@@ -369,11 +369,16 @@ void DolphinContextMenu::openViewportContextMenu()
     QAction* action = exec(m_pos);
     if (addToPlacesAction && (action == addToPlacesAction)) {
         const DolphinViewContainer* container =  m_mainWindow->activeViewContainer();
-        if (container->url().isValid()) {
+        const QUrl url = container->url();
+        if (url.isValid()) {
             PlacesItemModel model;
-            PlacesItem* item = model.createPlacesItem(container->placesText(),
-                                                      container->url(),
-                                                      KIO::iconNameForUrl(container->url()));
+            QString icon;
+            if (container->isSearchModeEnabled()) {
+                icon = QStringLiteral("folder-saved-search-symbolic");
+            } else {
+                icon = KIO::iconNameForUrl(url);
+            }
+            PlacesItem* item = model.createPlacesItem(container->placesText(), url, icon);
             model.appendItemToGroup(item);
             model.saveBookmarks();
         }
index d830166109fb8617dc33257cebbaa83d36ccc3bc..e92ec6022f8297e4805bea8ef83add447409c317 100644 (file)
@@ -362,7 +362,7 @@ QString DolphinViewContainer::placesText() const
     QString text;
 
     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 {
         text = url().fileName();
         if (text.isEmpty()) {
index c6943c60881c6dcfe8fc6c5bf2b3729e318d3742..3456920089eb972d606b5f5b3aabe7d32fe34539 100644 (file)
@@ -22,6 +22,8 @@
 #include "dolphin_searchsettings.h"
 #include "dolphinfacetswidget.h"
 
+#include <panels/places/placesitemmodel.h>
+
 #include <QIcon>
 #include <QLineEdit>
 #include <KLocalizedString>
@@ -54,6 +56,7 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
     m_topLayout(0),
     m_searchLabel(0),
     m_searchInput(0),
+    m_saveSearchAction(0),
     m_optionsScrollArea(0),
     m_fileNameButton(0),
     m_contentButton(0),
@@ -250,6 +253,7 @@ void DolphinSearchBox::emitSearchRequest()
 {
     m_startSearchTimer->stop();
     m_startedSearching = true;
+    m_saveSearchAction->setEnabled(true);
     emit searchRequest();
 }
 
@@ -257,6 +261,7 @@ void DolphinSearchBox::emitCloseRequest()
 {
     m_startSearchTimer->stop();
     m_startedSearching = false;
+    m_saveSearchAction->setEnabled(false);
     emit closeRequest();
 }
 
@@ -299,6 +304,20 @@ void DolphinSearchBox::slotFacetChanged()
     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)
 {
     button->installEventFilter(this);
@@ -356,6 +375,14 @@ void DolphinSearchBox::init()
             this, &DolphinSearchBox::slotSearchTextChanged);
     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
     QHBoxLayout* searchInputLayout = new QHBoxLayout();
     searchInputLayout->setMargin(0);
index 5063c2bf506e5c79b2e1e2766153f5c7022b2119..f1ea49091890feaef82e7f4975a668e2b091d86f 100644 (file)
@@ -139,6 +139,7 @@ private slots:
     void slotReturnPressed();
     void slotFacetsButtonToggled();
     void slotFacetChanged();
+    void slotSearchSaved();
 
 private:
     void initButton(QToolButton* button);
@@ -167,6 +168,7 @@ private:
 
     QLabel* m_searchLabel;
     QLineEdit* m_searchInput;
+    QAction* m_saveSearchAction;
     QScrollArea* m_optionsScrollArea;
     QToolButton* m_fileNameButton;
     QToolButton* m_contentButton;