X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/e0085fb2804eedfe91b05c1c0c272758466fb62f..576a97d8eb9601f4ad74def6528cc90fffe97b1c:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index c8e9629c3..d4807d3a7 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -1,22 +1,8 @@ - /*************************************************************************** - * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and * - * Cvetoslav Ludmiloff * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ +/* + * SPDX-FileCopyrightText: 2006 Peter Penz (peter.penz@gmx.at) and Cvetoslav Ludmiloff + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include "dolphincontextmenu.h" @@ -32,7 +18,6 @@ #include "views/dolphinview.h" #include "views/viewmodecontroller.h" -#include #include #include #include @@ -95,8 +80,13 @@ void DolphinContextMenu::setCustomActions(const QList& actions) DolphinContextMenu::Command DolphinContextMenu::open() { // get the context information - if (m_baseUrl.scheme() == QLatin1String("trash")) { + const auto scheme = m_baseUrl.scheme(); + if (scheme == QLatin1String("trash")) { m_context |= TrashContext; + } else if (scheme.contains(QLatin1String("search"))) { + m_context |= SearchContext; + } else if (scheme.contains(QLatin1String("timeline"))) { + m_context |= TimelineContext; } if (!m_fileInfo.isNull() && !m_selectedItems.isEmpty()) { @@ -184,6 +174,36 @@ void DolphinContextMenu::openTrashItemContextMenu() } } +void DolphinContextMenu::addDirectoryItemContextMenu(KFileItemActions &fileItemActions) +{ + // insert 'Open in new window' and 'Open in new tab' entries + + const KFileItemListProperties& selectedItemsProps = selectedItemsProperties(); + + addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab"))); + addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window"))); + + // Insert 'Open With' entries + addOpenWithActions(fileItemActions); + + // set up 'Create New' menu + DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow); + const DolphinView* view = m_mainWindow->activeViewContainer()->view(); + newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown()); + newFileMenu->checkUpToDate(); + newFileMenu->setPopupFiles(QList() << m_fileInfo.url()); + newFileMenu->setEnabled(selectedItemsProps.supportsWriting()); + connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); + connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); + + QMenu* menu = newFileMenu->menu(); + menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); + menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); + addMenu(menu); + + addSeparator(); +} + void DolphinContextMenu::openItemContextMenu() { Q_ASSERT(!m_fileInfo.isNull()); @@ -198,31 +218,10 @@ void DolphinContextMenu::openItemContextMenu() fileItemActions.setItemListProperties(selectedItemsProps); if (m_selectedItems.count() == 1) { + // single files if (m_fileInfo.isDir()) { - // insert 'Open in new window' and 'Open in new tab' entries - addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window"))); - addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab"))); - - // Insert 'Open With' entries - addOpenWithActions(fileItemActions); - - // set up 'Create New' menu - 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(selectedItemsProps.supportsWriting()); - connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); - connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); - - QMenu* menu = newFileMenu->menu(); - menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); - menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); - addMenu(menu); - - addSeparator(); - } else if (m_baseUrl.scheme().contains(QLatin1String("search")) || m_baseUrl.scheme().contains(QLatin1String("timeline"))) { + addDirectoryItemContextMenu(fileItemActions); + } else if (m_context & TimelineContext || m_context & SearchContext) { addOpenWithActions(fileItemActions); openParentAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), @@ -253,8 +252,9 @@ void DolphinContextMenu::openItemContextMenu() addSeparator(); } } else { + // multiple files bool selectionHasOnlyDirs = true; - foreach (const KFileItem& item, m_selectedItems) { + for (const auto &item : qAsConst(m_selectedItems)) { const QUrl& url = DolphinView::openItemAsFolderUrl(item); if (url.isEmpty()) { selectionHasOnlyDirs = false; @@ -328,19 +328,19 @@ void DolphinContextMenu::openViewportContextMenu() fileItemActions.setParentWidget(m_mainWindow); fileItemActions.setItemListProperties(baseUrlProperties); - // Don't show "Open With" menu items if the current dir is empty, because there's - // generally no app that can do anything interesting with an empty directory - if (view->itemsCount() != 0) { - addOpenWithActions(fileItemActions); - } - // Set up and insert 'Create New' menu KNewFileMenu* newFileMenu = m_mainWindow->newFileMenu(); newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown()); newFileMenu->checkUpToDate(); - newFileMenu->setPopupFiles(m_baseUrl); + newFileMenu->setPopupFiles(QList() << m_baseUrl); addMenu(newFileMenu->menu()); + // Don't show "Open With" menu items if the current dir is empty, because there's + // generally no app that can do anything interesting with an empty directory + if (view->itemsCount() != 0) { + addOpenWithActions(fileItemActions); + } + QAction* pasteAction = createPasteAction(); addAction(pasteAction); @@ -378,10 +378,14 @@ void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& { const KActionCollection* collection = m_mainWindow->actionCollection(); - // Insert 'Cut', 'Copy' and 'Paste' + // Insert 'Cut', 'Copy', 'Copy Location' and 'Paste' addAction(collection->action(KStandardAction::name(KStandardAction::Cut))); addAction(collection->action(KStandardAction::name(KStandardAction::Copy))); + QAction* copyPathAction = collection->action(QString("copy_location")); + copyPathAction->setEnabled(m_selectedItems.size() == 1); + addAction(copyPathAction); addAction(createPasteAction()); + addAction(m_mainWindow->actionCollection()->action(QStringLiteral("duplicate"))); addSeparator();