X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/600166152d857ccfc9df15b25bd1237b74c71d43..abd114f710b9d1247ecea4a82fb338492e9caf78:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 89a169f32..e692c8fa9 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -24,6 +24,7 @@ #include "dolphinnewfilemenu.h" #include "dolphinviewcontainer.h" #include "dolphin_generalsettings.h" +#include "dolphinremoveaction.h" #include #include @@ -74,16 +75,12 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, m_copyToMenu(parent), m_customActions(), m_command(None), - m_shiftPressed(qApp->keyboardModifiers() & Qt::ShiftModifier), 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 QAction(this); - connect(m_removeAction, SIGNAL(triggered()), this, SLOT(slotRemoveActionTriggered())); } DolphinContextMenu::~DolphinContextMenu() @@ -128,33 +125,20 @@ DolphinContextMenu::Command DolphinContextMenu::open() void DolphinContextMenu::keyPressEvent(QKeyEvent *ev) { - if (ev->key() == Qt::Key_Shift) { - m_shiftPressed = true; - updateRemoveAction(); + if (m_removeAction && ev->key() == Qt::Key_Shift) { + m_removeAction->update(); } KMenu::keyPressEvent(ev); } void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev) { - if (ev->key() == Qt::Key_Shift) { - // not just "m_shiftPressed = false", the user could be playing with both Shift keys... - m_shiftPressed = qApp->keyboardModifiers() & Qt::ShiftModifier; - updateRemoveAction(); + if (m_removeAction && ev->key() == Qt::Key_Shift) { + m_removeAction->update(); } KMenu::keyReleaseEvent(ev); } -void DolphinContextMenu::slotRemoveActionTriggered() -{ - const KActionCollection* collection = m_mainWindow->actionCollection(); - if (moveToTrash()) { - collection->action("move_to_trash")->trigger(); - } else { - collection->action("delete")->trigger(); - } -} - void DolphinContextMenu::openTrashContextMenu() { Q_ASSERT(m_context & TrashContext); @@ -207,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())); @@ -250,16 +236,37 @@ 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) { + const KUrl& url = DolphinView::openItemAsFolderUrl(item); + if (url.isEmpty()) { + selectionHasOnlyDirs = false; + break; + } + } + + if (selectionHasOnlyDirs) { + // insert 'Open in new tab' entry + addAction(m_mainWindow->actionCollection()->action("open_in_new_tabs")); addSeparator(); } } - insertDefaultItemActions(); + insertDefaultItemActions(selectedItemsProps); addSeparator(); KFileItemActions fileItemActions; - fileItemActions.setItemListProperties(selectedItemsProperties()); + fileItemActions.setItemListProperties(selectedItemsProps); addServiceActions(fileItemActions); addFileItemPluginActions(); @@ -269,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); } @@ -353,7 +360,7 @@ void DolphinContextMenu::openViewportContextMenu() } } -void DolphinContextMenu::insertDefaultItemActions() +void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& properties) { const KActionCollection* collection = m_mainWindow->actionCollection(); @@ -369,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); - updateRemoveAction(); + 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(); + } } } @@ -408,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 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)); @@ -509,28 +529,4 @@ void DolphinContextMenu::addCustomActions() } } -void DolphinContextMenu::updateRemoveAction() -{ - const KActionCollection* collection = m_mainWindow->actionCollection(); - - // Using m_removeAction->setText(action->text()) does not apply the &-shortcut. - // This is only done until the original action has been shown at least once. To - // bypass this issue, the text and &-shortcut is applied manually. - const QAction* action = 0; - if (moveToTrash()) { - action = collection->action("move_to_trash"); - m_removeAction->setText(i18nc("@action:inmenu", "&Move to Trash")); - } else { - action = collection->action("delete"); - m_removeAction->setText(i18nc("@action:inmenu", "&Delete")); - } - m_removeAction->setIcon(action->icon()); - m_removeAction->setShortcuts(action->shortcuts()); -} - -bool DolphinContextMenu::moveToTrash() const -{ - return !m_shiftPressed; -} - #include "dolphincontextmenu.moc"