X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/cad78cdfcf1f3b76acaadc7e9394df3ef466d770..6a09781a3b99bbca2b2c66ee3041208a02ead0ca:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 89a169f32..d8f101454 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 @@ -33,19 +34,22 @@ #include #include #include -#include +#include +#include +#include +#include +#include #include #include #include #include +#include #include -#include #include #include #include #include #include -#include #include #include @@ -74,16 +78,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,38 +128,25 @@ 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); - 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); @@ -172,7 +159,13 @@ void DolphinContextMenu::openTrashContextMenu() addShowMenuBarAction(); if (exec(m_pos) == emptyTrashAction) { - KonqOperations::emptyTrash(m_mainWindow); + KIO::JobUiDelegate uiDelegate; + uiDelegate.setWindow(m_mainWindow); + if (uiDelegate.askDeleteConfirmation(QList(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) { + KIO::Job* job = KIO::emptyTrash(); + KJobWidgets::setWindow(job, m_mainWindow); + job->ui()->setAutoErrorHandlingEnabled(true); + } } } @@ -196,7 +189,9 @@ void DolphinContextMenu::openTrashItemContextMenu() selectedUrls.append(item.url()); } - KonqOperations::restoreTrashedItems(selectedUrls, m_mainWindow); + KIO::RestoreJob *job = KIO::restoreFromTrash(selectedUrls); + KJobWidgets::setWindow(job, m_mainWindow); + job->uiDelegate()->setAutoErrorHandlingEnabled(true); } } @@ -204,24 +199,27 @@ void DolphinContextMenu::openItemContextMenu() { Q_ASSERT(!m_fileInfo.isNull()); + QAction* openParentAction = 0; 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(); @@ -231,35 +229,62 @@ 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"), + } else if (m_baseUrl.protocol().contains("search") || m_baseUrl.protocol().contains("timeline")) { + openParentAction = new QAction(QIcon::fromTheme("document-open-folder"), + i18nc("@action:inmenu", + "Open Path"), + this); + addAction(openParentAction); + + 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); 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 +294,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); } @@ -287,6 +312,8 @@ void DolphinContextMenu::openItemContextMenu() PlacesItem* item = model.createPlacesItem(text, selectedUrl); model.appendItemToGroup(item); } + } else if (activatedAction == openParentAction) { + m_command = OpenParentFolder; } else if (activatedAction == openParentInNewWindowAction) { m_command = OpenParentFolderInNewWindow; } else if (activatedAction == openParentInNewTabAction) { @@ -314,7 +341,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")); } @@ -353,7 +380,7 @@ void DolphinContextMenu::openViewportContextMenu() } } -void DolphinContextMenu::insertDefaultItemActions() +void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& properties) { const KActionCollection* collection = m_mainWindow->actionCollection(); @@ -369,12 +396,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,11 +449,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)); } @@ -469,7 +509,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; @@ -509,28 +549,3 @@ 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"