]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontextmenu.cpp
[DolphinContextMenu] Restore check for whether place already exists
[dolphin.git] / src / dolphincontextmenu.cpp
index 439de930aab99b5f7f137dd6d8fa287059ce6282..1dfbe054dd12a8afe251bfe44d5b72d5896540d0 100644 (file)
@@ -23,6 +23,7 @@
 #include "dolphin_generalsettings.h"
 #include "dolphinmainwindow.h"
 #include "dolphinnewfilemenu.h"
+#include "dolphinplacesmodelsingleton.h"
 #include "dolphinremoveaction.h"
 #include "dolphinviewcontainer.h"
 #include "panels/places/placesitem.h"
@@ -351,7 +352,12 @@ void DolphinContextMenu::openViewportContextMenu()
     KFileItemActions fileItemActions;
     fileItemActions.setParentWidget(m_mainWindow);
     fileItemActions.setItemListProperties(baseUrlProperties);
-    addOpenWithActions(fileItemActions);
+
+    // Don't show "Open With" menu items if the current dir is empty, because there's
+    // generally no app that can do anything interesting with an empty directory
+    if (view->itemsCount() != 0) {
+        addOpenWithActions(fileItemActions);
+    }
 
     // Insert 'New Window' and 'New Tab' entries. Don't use "open_in_new_window" and
     // "open_in_new_tab" here, as the current selection should get ignored.
@@ -455,13 +461,11 @@ void DolphinContextMenu::addShowMenuBarAction()
 
 bool DolphinContextMenu::placeExists(const QUrl& url) const
 {
-    Q_UNUSED(url)
-    // Creating up a PlacesItemModel to find out if 'url' is one of the Places
-    // can be expensive because the model asks Solid for the devices which are
-    // available, which can take some time.
-    // TODO: Consider restoring this check if the handling of Places and devices
-    // will be decoupled in the future.
-    return false;
+    const KFilePlacesModel* placesModel = DolphinPlacesModelSingleton::instance().placesModel();
+
+    const auto& matchedPlaces = placesModel->match(placesModel->index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly);
+
+    return !matchedPlaces.isEmpty();
 }
 
 QAction* DolphinContextMenu::createPasteAction()