]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontextmenu.cpp
Always clear DolphinView's m_currentItemUrl member in updateViewState()
[dolphin.git] / src / dolphincontextmenu.cpp
index cddcc8936c68a745758a286787aa1d72086e7779..e692c8fa9a0cd8c9ef3f53cc5c6ff71d04043a9c 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,15 +191,17 @@ 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
-            DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow);
+            DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow);
             const DolphinView* view = m_mainWindow->activeViewContainer()->view();
             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()));
 
@@ -235,12 +236,19 @@ void DolphinContextMenu::openItemContextMenu()
                                                    this);
             addAction(openParentInNewTabAction);
 
+            addSeparator();
+        } else if (!DolphinView::openItemAsFolderUrl(m_fileInfo).isEmpty()) {
+            // insert 'Open in new window' and 'Open in new tab' entries
+            addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
+            addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
+
             addSeparator();
         }
     } else {
         bool selectionHasOnlyDirs = true;
         foreach (const KFileItem& item, m_selectedItems) {
-            if (!item.isDir()) {
+            const KUrl& url = DolphinView::openItemAsFolderUrl(item);
+            if (url.isEmpty()) {
                 selectionHasOnlyDirs = false;
                 break;
             }
@@ -253,12 +261,12 @@ void DolphinContextMenu::openItemContextMenu()
         }
     }
 
-    insertDefaultItemActions();
+    insertDefaultItemActions(selectedItemsProps);
 
     addSeparator();
 
     KFileItemActions fileItemActions;
-    fileItemActions.setItemListProperties(selectedItemsProperties());
+    fileItemActions.setItemListProperties(selectedItemsProps);
     addServiceActions(fileItemActions);
 
     addFileItemPluginActions();
@@ -268,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);
     }
 
@@ -352,7 +360,7 @@ void DolphinContextMenu::openViewportContextMenu()
     }
 }
 
-void DolphinContextMenu::insertDefaultItemActions()
+void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& properties)
 {
     const KActionCollection* collection = m_mainWindow->actionCollection();
 
@@ -368,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();
+        }
     }
 }
 
@@ -407,10 +429,9 @@ QAction* DolphinContextMenu::createPasteAction()
     QAction* action = 0;
     const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir();
     if (isDir && (m_selectedItems.count() == 1)) {
+        const QPair<bool, QString> pasteInfo = KonqOperations::pasteInfo(m_fileInfo.url());
         action = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste Into Folder"), this);
-        const QMimeData* mimeData = QApplication::clipboard()->mimeData();
-        const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);
-        action->setEnabled(!pasteData.isEmpty() && selectedItemsProperties().supportsWriting());
+        action->setEnabled(pasteInfo.first);
         connect(action, SIGNAL(triggered()), m_mainWindow, SLOT(pasteIntoFolder()));
     } else {
         action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste));