]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Provide a default name when adding a search query to the places panel
authorPeter Penz <peter.penz19@gmail.com>
Sat, 2 Jun 2012 13:45:40 +0000 (15:45 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 2 Jun 2012 13:47:17 +0000 (15:47 +0200)
BUG: 300430
FIXED-IN: 4.9.0

src/dolphincontextmenu.cpp
src/dolphincontextmenu.h
src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h

index 539c280353a193f104a67980b5e158a6b5496b2b..e1913a82fe3a6e9d08ac6fa06037b18d357179a7 100644 (file)
@@ -295,8 +295,8 @@ void DolphinContextMenu::openItemContextMenu()
             const KUrl selectedUrl(m_fileInfo.url());
             if (selectedUrl.isValid()) {
                 PlacesItemModel model;
-                PlacesItem* item = model.createPlacesItem(placesName(selectedUrl),
-                                                          selectedUrl);
+                const QString text = m_mainWindow->activeViewContainer()->placesText();
+                PlacesItem* item = model.createPlacesItem(text, selectedUrl);
                 model.appendItemToGroup(item);
             }
         } else if (activatedAction == openParentInNewWindowAction) {
@@ -355,10 +355,11 @@ void DolphinContextMenu::openViewportContextMenu()
 
     QAction* action = m_popup->exec(m_pos);
     if (addToPlacesAction && (action == addToPlacesAction)) {
-        const KUrl url = m_mainWindow->activeViewContainer()->url();
-        if (url.isValid()) {
+        const DolphinViewContainer* container =  m_mainWindow->activeViewContainer();
+        if (container->url().isValid()) {
             PlacesItemModel model;
-            PlacesItem* item = model.createPlacesItem(placesName(url), url);
+            PlacesItem* item = model.createPlacesItem(container->placesText(),
+                                                      container->url());
             model.appendItemToGroup(item);
         }
     }
@@ -399,15 +400,6 @@ void DolphinContextMenu::addShowMenuBarAction()
     }
 }
 
-QString DolphinContextMenu::placesName(const KUrl& url) const
-{
-    QString name = url.fileName();
-    if (name.isEmpty()) {
-        name = url.host();
-    }
-    return name;
-}
-
 bool DolphinContextMenu::placeExists(const KUrl& url) const
 {
     PlacesItemModel model;
index 75a6e35e856dbc8cf55fa871f6d258250c6624a8..3d0005d30a21810546dabd754ea166427ada5870 100644 (file)
@@ -130,11 +130,6 @@ private:
      */
     void addShowMenuBarAction();
 
-    /**
-     * Returns a name for adding the URL \a url to the Places panel.
-     */
-    QString placesName(const KUrl& url) const;
-
     bool placeExists(const KUrl& url) const;
 
     QAction* createPasteAction();
index 7c7d7d309173055888e527ed54d0af983e394b3b..4d3f1983bc1dcdf6068ad35df6f1c18db769cddb 100644 (file)
@@ -316,6 +316,22 @@ bool DolphinViewContainer::isSearchModeEnabled() const
     return m_searchBox->isVisible();
 }
 
+QString DolphinViewContainer::placesText() const
+{
+    QString text;
+
+    if (isSearchModeEnabled()) {
+        text = m_searchBox->searchPath().fileName() + QLatin1String(": ") + m_searchBox->text();
+    } else {
+        text = url().fileName();
+        if (text.isEmpty()) {
+            text = url().host();
+        }
+    }
+
+    return text;
+}
+
 void DolphinViewContainer::setUrl(const KUrl& newUrl)
 {
     if (newUrl != m_urlNavigator->locationUrl()) {
index f0a0960d2d953c8ded729ff9ab0ccd8804f88b7e..59d73ec6c103e41a5d9af530cb1c1668b7a63dc0 100644 (file)
@@ -117,6 +117,12 @@ public:
     void setSearchModeEnabled(bool enabled);
     bool isSearchModeEnabled() const;
 
+    /**
+     * @return Text that should be used for the current URL when creating
+     *         a new place.
+     */
+    QString placesText() const;
+
 public slots:
     /**
      * Sets the current active URL, where all actions are applied. The