]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Do not show "Move To Trash" action in context menu for remote URLs.
authorDawit Alemayehu <adawit@kde.org>
Mon, 24 Jun 2013 05:11:16 +0000 (01:11 -0400)
committerDawit Alemayehu <adawit@kde.org>
Tue, 25 Jun 2013 02:41:53 +0000 (22:41 -0400)
BUG: 261762
REVIEW: 111206
FIXED-IN: 4.11

src/dolphincontextmenu.cpp
src/dolphincontextmenu.h
src/dolphinpart.cpp

index 7073dbf132a41ebf13a2d8377241f8241644f685..f4b46988619e7bde82c4b6db588b2ce5f60d3386 100644 (file)
@@ -74,14 +74,13 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
     m_context(NoContext),
     m_copyToMenu(parent),
     m_customActions(),
-    m_command(None)
+    m_command(None),
+    m_removeAction(0)
 {
     // The context menu either accesses the URLs of the selected items
     // or the items itself. To increase the performance both lists are cached.
     const DolphinView* view = m_mainWindow->activeViewContainer()->view();
     m_selectedItems = view->selectedItems();
-
-    m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection());
 }
 
 DolphinContextMenu::~DolphinContextMenu()
@@ -126,7 +125,7 @@ DolphinContextMenu::Command DolphinContextMenu::open()
 
 void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
 {
-    if (ev->key() == Qt::Key_Shift) {
+    if (m_removeAction && ev->key() == Qt::Key_Shift) {
         m_removeAction->update();
     }
     KMenu::keyPressEvent(ev);
@@ -134,7 +133,7 @@ void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
 
 void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev)
 {
-    if (ev->key() == Qt::Key_Shift) {
+    if (m_removeAction && ev->key() == Qt::Key_Shift) {
         m_removeAction->update();
     }
     KMenu::keyReleaseEvent(ev);
@@ -192,6 +191,8 @@ void DolphinContextMenu::openItemContextMenu()
     QAction* openParentInNewWindowAction = 0;
     QAction* openParentInNewTabAction = 0;
     QAction* addToPlacesAction = 0;
+    const KFileItemListProperties& selectedItemsProps = selectedItemsProperties();
+
     if (m_selectedItems.count() == 1) {
         if (m_fileInfo.isDir()) {
             // setup 'Create New' menu
@@ -200,7 +201,7 @@ void DolphinContextMenu::openItemContextMenu()
             newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown());
             newFileMenu->checkUpToDate();
             newFileMenu->setPopupFiles(m_fileInfo.url());
-            newFileMenu->setEnabled(selectedItemsProperties().supportsWriting());
+            newFileMenu->setEnabled(selectedItemsProps.supportsWriting());
             connect(newFileMenu, SIGNAL(fileCreated(KUrl)), newFileMenu, SLOT(deleteLater()));
             connect(newFileMenu, SIGNAL(directoryCreated(KUrl)), newFileMenu, SLOT(deleteLater()));
 
@@ -260,12 +261,12 @@ void DolphinContextMenu::openItemContextMenu()
         }
     }
 
-    insertDefaultItemActions();
+    insertDefaultItemActions(selectedItemsProps);
 
     addSeparator();
 
     KFileItemActions fileItemActions;
-    fileItemActions.setItemListProperties(selectedItemsProperties());
+    fileItemActions.setItemListProperties(selectedItemsProps);
     addServiceActions(fileItemActions);
 
     addFileItemPluginActions();
@@ -275,7 +276,7 @@ void DolphinContextMenu::openItemContextMenu()
     // insert 'Copy To' and 'Move To' sub menus
     if (GeneralSettings::showCopyMoveMenu()) {
         m_copyToMenu.setItems(m_selectedItems);
-        m_copyToMenu.setReadOnly(!selectedItemsProperties().supportsWriting());
+        m_copyToMenu.setReadOnly(!selectedItemsProps.supportsWriting());
         m_copyToMenu.addActionsTo(this);
     }
 
@@ -359,7 +360,7 @@ void DolphinContextMenu::openViewportContextMenu()
     }
 }
 
-void DolphinContextMenu::insertDefaultItemActions()
+void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& properties)
 {
     const KActionCollection* collection = m_mainWindow->actionCollection();
 
@@ -375,12 +376,26 @@ void DolphinContextMenu::insertDefaultItemActions()
     addAction(renameAction);
 
     // Insert 'Move to Trash' and/or 'Delete'
-    if (KGlobal::config()->group("KDE").readEntry("ShowDeleteCommand", false)) {
-        addAction(collection->action("move_to_trash"));
-        addAction(collection->action("delete"));
-    } else {
-        addAction(m_removeAction);
-        m_removeAction->update();
+    if (properties.supportsDeleting()) {
+        const bool showDeleteAction = (KGlobal::config()->group("KDE").readEntry("ShowDeleteCommand", false) ||
+                                       !properties.isLocal());
+        const bool showMoveToTrashAction = (properties.isLocal() &&
+                                            properties.supportsMoving());
+
+        if (showDeleteAction && showMoveToTrashAction) {
+            delete m_removeAction;
+            m_removeAction = 0;
+            addAction(m_mainWindow->actionCollection()->action("move_to_trash"));
+            addAction(m_mainWindow->actionCollection()->action("delete"));
+        } else if (showDeleteAction && !showMoveToTrashAction) {
+            addAction(m_mainWindow->actionCollection()->action("delete"));
+        } else {
+            if (!m_removeAction) {
+                m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection());
+            }
+            addAction(m_removeAction);
+            m_removeAction->update();
+        }
     }
 }
 
index 160f088040190ee3a2db4ebdb5957eee9f12fc6b..180f91787c0f3ccb842bc900d878185940e7f9c7 100644 (file)
@@ -101,7 +101,7 @@ private:
     void openItemContextMenu();
     void openViewportContextMenu();
 
-    void insertDefaultItemActions();
+    void insertDefaultItemActions(const KFileItemListProperties&);
 
     /**
      * Adds the "Show menubar" action to the menu if the
index 642b1501365a1774a75ac25238e485e96efa29d8..e8138eb8e9f2d54554e37eeb2f0d9e8439dc4234 100644 (file)
@@ -426,10 +426,27 @@ void DolphinPart::slotOpenContextMenu(const QPoint& pos,
     editActions += customActions;
 
     if (!_item.isNull()) { // only for context menu on one or more items
-        bool supportsDeleting = capabilities.supportsDeleting();
-        bool supportsMoving = capabilities.supportsMoving();
-
-        if (!supportsDeleting) {
+        const bool supportsMoving = capabilities.supportsMoving();
+
+        if (capabilities.supportsDeleting()) {
+            const bool showDeleteAction = (KGlobal::config()->group("KDE").readEntry("ShowDeleteCommand", false) ||
+                                           !item.isLocalFile());
+            const bool showMoveToTrashAction = capabilities.isLocal() && supportsMoving;
+
+            if (showDeleteAction && showMoveToTrashAction) {
+                delete m_removeAction;
+                m_removeAction = 0;
+                editActions.append(actionCollection()->action("move_to_trash"));
+                editActions.append(actionCollection()->action("delete"));
+            } else if (showDeleteAction && !showMoveToTrashAction) {
+                editActions.append(actionCollection()->action("delete"));
+            } else {
+                if (!m_removeAction)
+                    m_removeAction = new DolphinRemoveAction(this, actionCollection());
+                editActions.append(m_removeAction);
+                m_removeAction->update();
+            }
+        } else {
             popupFlags |= KParts::BrowserExtension::NoDeletion;
         }
 
@@ -437,35 +454,6 @@ void DolphinPart::slotOpenContextMenu(const QPoint& pos,
             editActions.append(actionCollection()->action("rename"));
         }
 
-        bool addTrash = capabilities.isLocal() && supportsMoving;
-        bool addDel = false;
-        if (supportsDeleting) {
-            if ( !item.isLocalFile() )
-                addDel = true;
-            else if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
-                addTrash = false;
-                addDel = true;
-            }
-            else {
-                KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals);
-                KConfigGroup configGroup(globalConfig, "KDE");
-                addDel = configGroup.readEntry("ShowDeleteCommand", false);
-            }
-        }
-
-        if (!addTrash || !addDel) {
-            if (!m_removeAction) {
-                m_removeAction = new DolphinRemoveAction(this, actionCollection());
-            }
-            editActions.append(m_removeAction);
-            m_removeAction->update();
-        } else {
-            delete m_removeAction;
-            m_removeAction = 0;
-            editActions.append(actionCollection()->action("move_to_trash"));
-            editActions.append(actionCollection()->action("delete"));
-        }
-
         // Normally KonqPopupMenu only shows the "Create new" submenu in the current view
         // since otherwise the created file would not be visible.
         // But in treeview mode we should allow it.