X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/7a7cfa6addc3c6089a0d48e17ec623d248b97df2..3614b7fea7563300974982cca27a787749ea3f0f:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 7073dbf13..952ffcc99 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -74,14 +75,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 +126,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 +134,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); @@ -144,7 +144,7 @@ void DolphinContextMenu::openTrashContextMenu() { Q_ASSERT(m_context & TrashContext); - QAction* emptyTrashAction = new QAction(KIcon("trash-empty"), i18nc("@action:inmenu", "Empty Trash"), this); + QAction* emptyTrashAction = new QAction(QIcon::fromTheme("trash-empty"), i18nc("@action:inmenu", "Empty Trash"), this); KConfig trashConfig("trashrc", KConfig::SimpleConfig); emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true)); addAction(emptyTrashAction); @@ -192,21 +192,23 @@ 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()); - connect(newFileMenu, SIGNAL(fileCreated(KUrl)), newFileMenu, SLOT(deleteLater())); - connect(newFileMenu, SIGNAL(directoryCreated(KUrl)), newFileMenu, SLOT(deleteLater())); + newFileMenu->setEnabled(selectedItemsProps.supportsWriting()); + connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); + connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); - KMenu* menu = newFileMenu->menu(); + QMenu* menu = newFileMenu->menu(); menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); - menu->setIcon(KIcon("document-new")); + menu->setIcon(QIcon::fromTheme("document-new")); addMenu(menu); addSeparator(); @@ -216,20 +218,20 @@ void DolphinContextMenu::openItemContextMenu() // insert 'Add to Places' entry if (!placeExists(m_fileInfo.url())) { - addToPlacesAction = addAction(KIcon("bookmark-new"), + addToPlacesAction = addAction(QIcon::fromTheme("bookmark-new"), i18nc("@action:inmenu Add selected folder to places", "Add to Places")); } addSeparator(); } else if (m_baseUrl.protocol().contains("search")) { - openParentInNewWindowAction = new QAction(KIcon("window-new"), + openParentInNewWindowAction = new QAction(QIcon::fromTheme("window-new"), i18nc("@action:inmenu", "Open Path in New Window"), this); addAction(openParentInNewWindowAction); - openParentInNewTabAction = new QAction(KIcon("tab-new"), + openParentInNewTabAction = new QAction(QIcon::fromTheme("tab-new"), i18nc("@action:inmenu", "Open Path in New Tab"), this); @@ -260,12 +262,12 @@ void DolphinContextMenu::openItemContextMenu() } } - insertDefaultItemActions(); + insertDefaultItemActions(selectedItemsProps); addSeparator(); KFileItemActions fileItemActions; - fileItemActions.setItemListProperties(selectedItemsProperties()); + fileItemActions.setItemListProperties(selectedItemsProps); addServiceActions(fileItemActions); addFileItemPluginActions(); @@ -275,7 +277,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); } @@ -320,7 +322,7 @@ void DolphinContextMenu::openViewportContextMenu() // Insert 'Add to Places' entry if exactly one item is selected QAction* addToPlacesAction = 0; if (!placeExists(m_mainWindow->activeViewContainer()->url())) { - addToPlacesAction = addAction(KIcon("bookmark-new"), + addToPlacesAction = addAction(QIcon::fromTheme("bookmark-new"), i18nc("@action:inmenu Add current folder to places", "Add to Places")); } @@ -359,7 +361,7 @@ void DolphinContextMenu::openViewportContextMenu() } } -void DolphinContextMenu::insertDefaultItemActions() +void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& properties) { const KActionCollection* collection = m_mainWindow->actionCollection(); @@ -375,12 +377,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(); + } } } @@ -414,11 +430,10 @@ QAction* DolphinContextMenu::createPasteAction() QAction* action = 0; const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir(); if (isDir && (m_selectedItems.count() == 1)) { - 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()); - connect(action, SIGNAL(triggered()), m_mainWindow, SLOT(pasteIntoFolder())); + const QPair pasteInfo = KonqOperations::pasteInfo(m_fileInfo.url()); + action = new QAction(QIcon::fromTheme("edit-paste"), i18nc("@action:inmenu", "Paste Into Folder"), this); + action->setEnabled(pasteInfo.first); + connect(action, &QAction::triggered, m_mainWindow, &DolphinMainWindow::pasteIntoFolder); } else { action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste)); } @@ -475,7 +490,7 @@ void DolphinContextMenu::addFileItemPluginActions() const KConfig config("kservicemenurc", KConfig::NoGlobals); const KConfigGroup showGroup = config.group("Show"); - foreach (const KSharedPtr& service, pluginServices) { + foreach (const KService::Ptr& service, pluginServices) { if (!showGroup.readEntry(service->desktopEntryName(), true)) { // The plugin has been disabled continue;