2006-11-21 06:02:05 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* 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., *
|
2006-12-08 21:24:08 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
2006-11-21 06:02:05 +00:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "dolphincontextmenu.h"
|
|
|
|
|
2018-03-04 13:38:16 +00:00
|
|
|
#include "dolphin_generalsettings.h"
|
2007-01-21 21:20:37 +00:00
|
|
|
#include "dolphinmainwindow.h"
|
2010-08-27 05:26:27 +00:00
|
|
|
#include "dolphinnewfilemenu.h"
|
2013-02-09 20:56:51 +00:00
|
|
|
#include "dolphinremoveaction.h"
|
2018-03-04 13:38:16 +00:00
|
|
|
#include "dolphinviewcontainer.h"
|
|
|
|
#include "panels/places/placesitem.h"
|
|
|
|
#include "panels/places/placesitemmodel.h"
|
|
|
|
#include "views/dolphinview.h"
|
|
|
|
#include "views/viewmodecontroller.h"
|
2007-01-21 21:20:37 +00:00
|
|
|
|
2014-12-14 17:39:08 +00:00
|
|
|
#include <KAbstractFileItemActionPlugin>
|
2018-03-04 13:38:16 +00:00
|
|
|
#include <KActionCollection>
|
2011-02-11 18:33:29 +00:00
|
|
|
#include <KFileItemActions>
|
|
|
|
#include <KFileItemListProperties>
|
2014-08-21 20:01:23 +00:00
|
|
|
#include <KIO/EmptyTrashJob>
|
|
|
|
#include <KIO/JobUiDelegate>
|
2014-10-21 18:44:37 +00:00
|
|
|
#include <KIO/Paste>
|
2018-03-04 13:38:16 +00:00
|
|
|
#include <KIO/RestoreJob>
|
2014-08-17 09:07:42 +00:00
|
|
|
#include <KJobWidgets>
|
2018-03-04 13:38:16 +00:00
|
|
|
#include <KLocalizedString>
|
2011-02-11 18:33:29 +00:00
|
|
|
#include <KMimeTypeTrader>
|
2011-02-10 09:59:35 +00:00
|
|
|
#include <KNewFileMenu>
|
2016-06-08 13:30:52 +00:00
|
|
|
#include <KPluginMetaData>
|
2011-02-11 18:33:29 +00:00
|
|
|
#include <KService>
|
|
|
|
#include <KStandardAction>
|
2011-03-27 17:27:27 +00:00
|
|
|
#include <KToolBar>
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2014-10-21 18:44:37 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2014-11-02 16:03:18 +00:00
|
|
|
#include <QKeyEvent>
|
2014-10-21 18:44:37 +00:00
|
|
|
#include <QMenu>
|
2018-03-04 13:38:16 +00:00
|
|
|
#include <QMenuBar>
|
2016-08-23 15:58:48 +00:00
|
|
|
#include <QMimeDatabase>
|
2014-10-21 18:44:37 +00:00
|
|
|
|
2007-03-15 22:42:21 +00:00
|
|
|
DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
|
2011-10-08 19:40:34 +00:00
|
|
|
const QPoint& pos,
|
2007-08-13 21:57:20 +00:00
|
|
|
const KFileItem& fileInfo,
|
2014-10-21 19:18:43 +00:00
|
|
|
const QUrl& baseUrl) :
|
2014-10-10 21:36:36 +00:00
|
|
|
QMenu(parent),
|
2011-10-08 19:40:34 +00:00
|
|
|
m_pos(pos),
|
2007-05-06 17:41:49 +00:00
|
|
|
m_mainWindow(parent),
|
|
|
|
m_fileInfo(fileInfo),
|
|
|
|
m_baseUrl(baseUrl),
|
2017-11-21 09:52:14 +00:00
|
|
|
m_baseFileItem(nullptr),
|
2010-10-25 13:45:34 +00:00
|
|
|
m_selectedItems(),
|
2017-11-03 07:01:02 +00:00
|
|
|
m_selectedItemsProperties(nullptr),
|
2009-01-19 14:33:10 +00:00
|
|
|
m_context(NoContext),
|
2009-02-11 20:45:12 +00:00
|
|
|
m_copyToMenu(parent),
|
2010-09-17 19:47:01 +00:00
|
|
|
m_customActions(),
|
2013-06-24 05:11:16 +00:00
|
|
|
m_command(None),
|
2017-11-21 09:52:14 +00:00
|
|
|
m_removeAction(nullptr)
|
2006-11-21 06:02:05 +00:00
|
|
|
{
|
2007-03-25 06:44:28 +00:00
|
|
|
// The context menu either accesses the URLs of the selected items
|
|
|
|
// or the items itself. To increase the performance both lists are cached.
|
2009-07-23 06:10:01 +00:00
|
|
|
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
|
2007-03-25 06:44:28 +00:00
|
|
|
m_selectedItems = view->selectedItems();
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
2007-03-17 20:42:26 +00:00
|
|
|
DolphinContextMenu::~DolphinContextMenu()
|
2007-06-20 20:44:18 +00:00
|
|
|
{
|
2010-10-25 13:45:34 +00:00
|
|
|
delete m_selectedItemsProperties;
|
2017-11-03 07:01:02 +00:00
|
|
|
m_selectedItemsProperties = nullptr;
|
2007-06-20 20:44:18 +00:00
|
|
|
}
|
2007-03-17 20:42:26 +00:00
|
|
|
|
2009-02-11 20:45:12 +00:00
|
|
|
void DolphinContextMenu::setCustomActions(const QList<QAction*>& actions)
|
|
|
|
{
|
|
|
|
m_customActions = actions;
|
|
|
|
}
|
|
|
|
|
2010-09-22 20:24:49 +00:00
|
|
|
DolphinContextMenu::Command DolphinContextMenu::open()
|
2006-11-21 06:02:05 +00:00
|
|
|
{
|
2007-03-15 21:24:41 +00:00
|
|
|
// get the context information
|
2014-10-21 19:18:43 +00:00
|
|
|
if (m_baseUrl.scheme() == QLatin1String("trash")) {
|
2007-03-15 21:24:41 +00:00
|
|
|
m_context |= TrashContext;
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2009-07-23 06:14:57 +00:00
|
|
|
if (!m_fileInfo.isNull() && !m_selectedItems.isEmpty()) {
|
2007-03-15 21:24:41 +00:00
|
|
|
m_context |= ItemContext;
|
|
|
|
// TODO: handle other use cases like devices + desktop files
|
2007-04-09 19:12:54 +00:00
|
|
|
}
|
2007-03-15 21:24:41 +00:00
|
|
|
|
|
|
|
// open the corresponding popup for the context
|
|
|
|
if (m_context & TrashContext) {
|
|
|
|
if (m_context & ItemContext) {
|
|
|
|
openTrashItemContextMenu();
|
2007-04-09 19:12:54 +00:00
|
|
|
} else {
|
2007-03-15 21:24:41 +00:00
|
|
|
openTrashContextMenu();
|
|
|
|
}
|
2007-04-09 19:12:54 +00:00
|
|
|
} else if (m_context & ItemContext) {
|
2006-11-21 06:02:05 +00:00
|
|
|
openItemContextMenu();
|
2007-04-09 19:12:54 +00:00
|
|
|
} else {
|
2007-03-15 21:24:41 +00:00
|
|
|
Q_ASSERT(m_context == NoContext);
|
|
|
|
openViewportContextMenu();
|
|
|
|
}
|
2010-09-22 20:24:49 +00:00
|
|
|
|
|
|
|
return m_command;
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
|
2010-09-20 19:52:40 +00:00
|
|
|
{
|
2013-06-24 05:11:16 +00:00
|
|
|
if (m_removeAction && ev->key() == Qt::Key_Shift) {
|
2017-08-24 16:33:27 +00:00
|
|
|
m_removeAction->update(DolphinRemoveAction::ShiftState::Pressed);
|
2013-05-04 18:31:02 +00:00
|
|
|
}
|
2014-10-10 21:36:36 +00:00
|
|
|
QMenu::keyPressEvent(ev);
|
2010-09-20 19:52:40 +00:00
|
|
|
}
|
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev)
|
2010-09-17 22:23:11 +00:00
|
|
|
{
|
2013-06-24 05:11:16 +00:00
|
|
|
if (m_removeAction && ev->key() == Qt::Key_Shift) {
|
2017-08-24 16:33:27 +00:00
|
|
|
m_removeAction->update(DolphinRemoveAction::ShiftState::Released);
|
2013-05-04 18:31:02 +00:00
|
|
|
}
|
2014-10-10 21:36:36 +00:00
|
|
|
QMenu::keyReleaseEvent(ev);
|
2010-09-17 22:23:11 +00:00
|
|
|
}
|
|
|
|
|
2007-03-15 21:24:41 +00:00
|
|
|
void DolphinContextMenu::openTrashContextMenu()
|
|
|
|
{
|
|
|
|
Q_ASSERT(m_context & TrashContext);
|
|
|
|
|
2016-03-16 21:17:37 +00:00
|
|
|
QAction* emptyTrashAction = new QAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18nc("@action:inmenu", "Empty Trash"), this);
|
|
|
|
KConfig trashConfig(QStringLiteral("trashrc"), KConfig::SimpleConfig);
|
2007-03-15 21:24:41 +00:00
|
|
|
emptyTrashAction->setEnabled(!trashConfig.group("Status").readEntry("Empty", true));
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(emptyTrashAction);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
addCustomActions();
|
2009-02-11 20:45:12 +00:00
|
|
|
|
2016-03-16 21:17:37 +00:00
|
|
|
QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties"));
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(propertiesAction);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2011-03-27 17:27:27 +00:00
|
|
|
addShowMenuBarAction();
|
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
if (exec(m_pos) == emptyTrashAction) {
|
2014-08-21 20:01:23 +00:00
|
|
|
KIO::JobUiDelegate uiDelegate;
|
|
|
|
uiDelegate.setWindow(m_mainWindow);
|
|
|
|
if (uiDelegate.askDeleteConfirmation(QList<QUrl>(), KIO::JobUiDelegate::EmptyTrash, KIO::JobUiDelegate::DefaultConfirmation)) {
|
|
|
|
KIO::Job* job = KIO::emptyTrash();
|
|
|
|
KJobWidgets::setWindow(job, m_mainWindow);
|
2017-01-18 22:45:39 +00:00
|
|
|
job->uiDelegate()->setAutoErrorHandlingEnabled(true);
|
2014-08-21 20:01:23 +00:00
|
|
|
}
|
2007-03-15 21:24:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinContextMenu::openTrashItemContextMenu()
|
|
|
|
{
|
|
|
|
Q_ASSERT(m_context & TrashContext);
|
|
|
|
Q_ASSERT(m_context & ItemContext);
|
|
|
|
|
2007-07-09 17:51:39 +00:00
|
|
|
QAction* restoreAction = new QAction(i18nc("@action:inmenu", "Restore"), m_mainWindow);
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(restoreAction);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2017-03-10 18:31:33 +00:00
|
|
|
QAction* deleteAction = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile));
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(deleteAction);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2016-03-16 21:17:37 +00:00
|
|
|
QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties"));
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(propertiesAction);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
if (exec(m_pos) == restoreAction) {
|
2014-10-21 19:18:43 +00:00
|
|
|
QList<QUrl> selectedUrls;
|
2016-03-16 21:17:37 +00:00
|
|
|
selectedUrls.reserve(m_selectedItems.count());
|
2010-10-25 13:45:34 +00:00
|
|
|
foreach (const KFileItem &item, m_selectedItems) {
|
|
|
|
selectedUrls.append(item.url());
|
|
|
|
}
|
|
|
|
|
2014-08-17 09:07:42 +00:00
|
|
|
KIO::RestoreJob *job = KIO::restoreFromTrash(selectedUrls);
|
|
|
|
KJobWidgets::setWindow(job, m_mainWindow);
|
|
|
|
job->uiDelegate()->setAutoErrorHandlingEnabled(true);
|
2007-03-15 21:24:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinContextMenu::openItemContextMenu()
|
|
|
|
{
|
2007-08-13 21:57:20 +00:00
|
|
|
Q_ASSERT(!m_fileInfo.isNull());
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2017-11-03 07:01:02 +00:00
|
|
|
QAction* openParentAction = nullptr;
|
|
|
|
QAction* openParentInNewWindowAction = nullptr;
|
|
|
|
QAction* openParentInNewTabAction = nullptr;
|
|
|
|
QAction* addToPlacesAction = nullptr;
|
2013-06-24 05:11:16 +00:00
|
|
|
const KFileItemListProperties& selectedItemsProps = selectedItemsProperties();
|
|
|
|
|
2010-10-25 13:45:34 +00:00
|
|
|
if (m_selectedItems.count() == 1) {
|
2010-09-22 20:24:49 +00:00
|
|
|
if (m_fileInfo.isDir()) {
|
|
|
|
// setup 'Create New' menu
|
2013-11-20 23:41:23 +00:00
|
|
|
DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow);
|
2010-09-22 20:24:49 +00:00
|
|
|
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
|
2011-07-30 18:13:09 +00:00
|
|
|
newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown());
|
2010-09-22 20:24:49 +00:00
|
|
|
newFileMenu->checkUpToDate();
|
|
|
|
newFileMenu->setPopupFiles(m_fileInfo.url());
|
2013-06-24 05:11:16 +00:00
|
|
|
newFileMenu->setEnabled(selectedItemsProps.supportsWriting());
|
2014-04-10 14:53:41 +00:00
|
|
|
connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater);
|
|
|
|
connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater);
|
2010-09-22 20:24:49 +00:00
|
|
|
|
2014-04-06 01:32:55 +00:00
|
|
|
QMenu* menu = newFileMenu->menu();
|
2010-09-22 20:24:49 +00:00
|
|
|
menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
|
2016-03-16 21:17:37 +00:00
|
|
|
menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
|
2013-05-04 18:31:02 +00:00
|
|
|
addMenu(menu);
|
|
|
|
addSeparator();
|
2010-09-22 20:24:49 +00:00
|
|
|
|
|
|
|
// insert 'Open in new window' and 'Open in new tab' entries
|
2016-03-16 21:17:37 +00:00
|
|
|
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window")));
|
|
|
|
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab")));
|
2010-09-22 20:24:49 +00:00
|
|
|
|
|
|
|
// insert 'Add to Places' entry
|
|
|
|
if (!placeExists(m_fileInfo.url())) {
|
2016-03-16 21:17:37 +00:00
|
|
|
addToPlacesAction = addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")),
|
2010-09-22 20:24:49 +00:00
|
|
|
i18nc("@action:inmenu Add selected folder to places",
|
|
|
|
"Add to Places"));
|
|
|
|
}
|
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
addSeparator();
|
2016-03-16 21:17:37 +00:00
|
|
|
} else if (m_baseUrl.scheme().contains(QStringLiteral("search")) || m_baseUrl.scheme().contains(QStringLiteral("timeline"))) {
|
|
|
|
openParentAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")),
|
2014-09-09 13:31:55 +00:00
|
|
|
i18nc("@action:inmenu",
|
|
|
|
"Open Path"),
|
|
|
|
this);
|
|
|
|
addAction(openParentAction);
|
|
|
|
|
2016-03-16 21:17:37 +00:00
|
|
|
openParentInNewWindowAction = new QAction(QIcon::fromTheme(QStringLiteral("window-new")),
|
2010-09-22 20:24:49 +00:00
|
|
|
i18nc("@action:inmenu",
|
2010-10-05 14:40:42 +00:00
|
|
|
"Open Path in New Window"),
|
2010-09-22 20:24:49 +00:00
|
|
|
this);
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(openParentInNewWindowAction);
|
2010-09-22 20:24:49 +00:00
|
|
|
|
2016-03-16 21:17:37 +00:00
|
|
|
openParentInNewTabAction = new QAction(QIcon::fromTheme(QStringLiteral("tab-new")),
|
2010-09-22 20:24:49 +00:00
|
|
|
i18nc("@action:inmenu",
|
2010-10-05 14:40:42 +00:00
|
|
|
"Open Path in New Tab"),
|
2010-09-22 20:24:49 +00:00
|
|
|
this);
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(openParentInNewTabAction);
|
2010-09-22 20:24:49 +00:00
|
|
|
|
2013-05-28 15:31:14 +00:00
|
|
|
addSeparator();
|
|
|
|
} else if (!DolphinView::openItemAsFolderUrl(m_fileInfo).isEmpty()) {
|
|
|
|
// insert 'Open in new window' and 'Open in new tab' entries
|
2016-03-16 21:17:37 +00:00
|
|
|
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window")));
|
|
|
|
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab")));
|
2013-05-28 15:31:14 +00:00
|
|
|
|
2013-05-22 19:47:14 +00:00
|
|
|
addSeparator();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bool selectionHasOnlyDirs = true;
|
|
|
|
foreach (const KFileItem& item, m_selectedItems) {
|
2014-10-21 19:18:43 +00:00
|
|
|
const QUrl& url = DolphinView::openItemAsFolderUrl(item);
|
2013-05-28 15:31:14 +00:00
|
|
|
if (url.isEmpty()) {
|
2013-05-22 19:47:14 +00:00
|
|
|
selectionHasOnlyDirs = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectionHasOnlyDirs) {
|
|
|
|
// insert 'Open in new tab' entry
|
2016-03-16 21:17:37 +00:00
|
|
|
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tabs")));
|
2013-05-04 18:31:02 +00:00
|
|
|
addSeparator();
|
2010-09-21 19:56:35 +00:00
|
|
|
}
|
2008-10-25 10:32:55 +00:00
|
|
|
}
|
2010-09-22 20:24:49 +00:00
|
|
|
|
2013-06-24 05:11:16 +00:00
|
|
|
insertDefaultItemActions(selectedItemsProps);
|
2007-03-16 00:24:56 +00:00
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
addSeparator();
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2010-08-27 05:26:27 +00:00
|
|
|
KFileItemActions fileItemActions;
|
2013-06-24 05:11:16 +00:00
|
|
|
fileItemActions.setItemListProperties(selectedItemsProps);
|
2010-09-17 19:47:01 +00:00
|
|
|
addServiceActions(fileItemActions);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2017-06-06 17:16:34 +00:00
|
|
|
fileItemActions.addPluginActionsTo(this);
|
2010-10-25 13:45:34 +00:00
|
|
|
|
|
|
|
addVersionControlPluginActions();
|
2009-07-22 19:26:25 +00:00
|
|
|
|
2009-02-11 20:45:12 +00:00
|
|
|
// insert 'Copy To' and 'Move To' sub menus
|
2011-11-06 10:58:48 +00:00
|
|
|
if (GeneralSettings::showCopyMoveMenu()) {
|
2015-02-04 07:56:17 +00:00
|
|
|
m_copyToMenu.setUrls(m_selectedItems.urlList());
|
2013-06-24 05:11:16 +00:00
|
|
|
m_copyToMenu.setReadOnly(!selectedItemsProps.supportsWriting());
|
2015-02-04 07:56:17 +00:00
|
|
|
m_copyToMenu.setAutoErrorHandlingEnabled(true);
|
2013-05-04 18:31:02 +00:00
|
|
|
m_copyToMenu.addActionsTo(this);
|
2010-08-27 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
2007-03-17 20:42:26 +00:00
|
|
|
// insert 'Properties...' entry
|
2016-03-16 21:17:37 +00:00
|
|
|
QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties"));
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(propertiesAction);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
QAction* activatedAction = exec(m_pos);
|
2011-02-09 18:21:58 +00:00
|
|
|
if (activatedAction) {
|
2010-09-22 20:24:49 +00:00
|
|
|
if (activatedAction == addToPlacesAction) {
|
2014-10-21 19:18:43 +00:00
|
|
|
const QUrl selectedUrl(m_fileInfo.url());
|
2010-09-22 20:24:49 +00:00
|
|
|
if (selectedUrl.isValid()) {
|
2012-06-02 13:02:34 +00:00
|
|
|
PlacesItemModel model;
|
2012-07-10 06:23:14 +00:00
|
|
|
const QString text = selectedUrl.fileName();
|
Use Kio::KPlacesModel as source model for PlacesItemModel
Summary:
Use Kio::KPlacesModel as source model for PlacesItemModel avoiding
duplicated code.
Depends on D8862
Depends on D8332
Depends on D8434
Depends on D8348
Depends on D8630
Test Plan: Unit test created
Reviewers: elvisangelaccio, emmanuelp, mlaurent, mwolff
Reviewed By: elvisangelaccio, mlaurent, mwolff
Subscribers: mwolff, mlaurent, anthonyfieroni, nicolasfella, ngraham, #dolphin
Differential Revision: https://phabricator.kde.org/D8855
2017-11-16 15:32:49 +00:00
|
|
|
model.createPlacesItem(text, selectedUrl, KIO::iconNameForUrl(selectedUrl));
|
2010-09-22 20:24:49 +00:00
|
|
|
}
|
2014-09-09 13:31:55 +00:00
|
|
|
} else if (activatedAction == openParentAction) {
|
|
|
|
m_command = OpenParentFolder;
|
2010-09-22 20:24:49 +00:00
|
|
|
} else if (activatedAction == openParentInNewWindowAction) {
|
|
|
|
m_command = OpenParentFolderInNewWindow;
|
|
|
|
} else if (activatedAction == openParentInNewTabAction) {
|
|
|
|
m_command = OpenParentFolderInNewTab;
|
2007-03-15 21:24:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
void DolphinContextMenu::openViewportContextMenu()
|
|
|
|
{
|
|
|
|
// setup 'Create New' menu
|
2010-08-27 05:26:27 +00:00
|
|
|
KNewFileMenu* newFileMenu = m_mainWindow->newFileMenu();
|
2009-11-18 22:27:31 +00:00
|
|
|
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
|
2011-07-30 18:13:09 +00:00
|
|
|
newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown());
|
2010-08-27 05:26:27 +00:00
|
|
|
newFileMenu->checkUpToDate();
|
|
|
|
newFileMenu->setPopupFiles(m_baseUrl);
|
2013-05-04 18:31:02 +00:00
|
|
|
addMenu(newFileMenu->menu());
|
|
|
|
addSeparator();
|
2010-08-27 05:26:27 +00:00
|
|
|
|
2010-10-07 18:25:47 +00:00
|
|
|
// Insert 'New Window' and 'New Tab' entries. Don't use "open_in_new_window" and
|
|
|
|
// "open_in_new_tab" here, as the current selection should get ignored.
|
2016-03-16 21:17:37 +00:00
|
|
|
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("new_window")));
|
|
|
|
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("new_tab")));
|
2010-10-09 15:39:41 +00:00
|
|
|
|
|
|
|
// Insert 'Add to Places' entry if exactly one item is selected
|
2017-11-21 09:52:14 +00:00
|
|
|
QAction* addToPlacesAction = nullptr;
|
2010-10-09 15:39:41 +00:00
|
|
|
if (!placeExists(m_mainWindow->activeViewContainer()->url())) {
|
2016-03-16 21:17:37 +00:00
|
|
|
addToPlacesAction = addAction(QIcon::fromTheme(QStringLiteral("bookmark-new")),
|
2010-10-09 15:39:41 +00:00
|
|
|
i18nc("@action:inmenu Add current folder to places", "Add to Places"));
|
|
|
|
}
|
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
addSeparator();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2008-03-29 07:44:03 +00:00
|
|
|
QAction* pasteAction = createPasteAction();
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(pasteAction);
|
|
|
|
addSeparator();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2010-10-25 13:45:34 +00:00
|
|
|
// Insert service actions
|
|
|
|
const KFileItemListProperties baseUrlProperties(KFileItemList() << baseFileItem());
|
2010-08-27 05:26:27 +00:00
|
|
|
KFileItemActions fileItemActions;
|
|
|
|
fileItemActions.setItemListProperties(baseUrlProperties);
|
2010-09-17 19:47:01 +00:00
|
|
|
addServiceActions(fileItemActions);
|
2009-07-23 06:10:01 +00:00
|
|
|
|
2017-06-06 17:16:34 +00:00
|
|
|
fileItemActions.addPluginActionsTo(this);
|
2010-10-25 13:45:34 +00:00
|
|
|
|
|
|
|
addVersionControlPluginActions();
|
2009-02-11 20:45:12 +00:00
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
addCustomActions();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2016-03-16 21:17:37 +00:00
|
|
|
QAction* propertiesAction = m_mainWindow->actionCollection()->action(QStringLiteral("properties"));
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(propertiesAction);
|
2010-11-17 19:10:23 +00:00
|
|
|
|
2011-03-27 17:27:27 +00:00
|
|
|
addShowMenuBarAction();
|
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
QAction* action = exec(m_pos);
|
2011-04-10 16:47:25 +00:00
|
|
|
if (addToPlacesAction && (action == addToPlacesAction)) {
|
2012-06-02 13:45:40 +00:00
|
|
|
const DolphinViewContainer* container = m_mainWindow->activeViewContainer();
|
Make Saved Search feature discoverable
Summary:
FEATURE: 269332
Make Dolphin's Saved Search feature discoverable by adding a button inside the search field. The button only becomes enabled when there is a valid search term. When pushed, it saves the search to the Places panel, providing a visible-by-default way to do this to complement the existing implementation that is only visible in the context menu.
Also harmonized the label text so that it's consistent no matter how you create a saved search (button or context menu)
Test Plan:
Tested in KDE Neon. Works great:
{F5449508}
Reviewers: #dolphin, broulik, dfaure, markg, emateli, elvisangelaccio
Reviewed By: #dolphin, markg, emateli, elvisangelaccio
Subscribers: anthonyfieroni, markg, emateli, elvisangelaccio, cfeck, #dolphin
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D8454
2017-10-24 19:10:41 +00:00
|
|
|
const QUrl url = container->url();
|
|
|
|
if (url.isValid()) {
|
2012-06-02 13:02:34 +00:00
|
|
|
PlacesItemModel model;
|
Make Saved Search feature discoverable
Summary:
FEATURE: 269332
Make Dolphin's Saved Search feature discoverable by adding a button inside the search field. The button only becomes enabled when there is a valid search term. When pushed, it saves the search to the Places panel, providing a visible-by-default way to do this to complement the existing implementation that is only visible in the context menu.
Also harmonized the label text so that it's consistent no matter how you create a saved search (button or context menu)
Test Plan:
Tested in KDE Neon. Works great:
{F5449508}
Reviewers: #dolphin, broulik, dfaure, markg, emateli, elvisangelaccio
Reviewed By: #dolphin, markg, emateli, elvisangelaccio
Subscribers: anthonyfieroni, markg, emateli, elvisangelaccio, cfeck, #dolphin
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D8454
2017-10-24 19:10:41 +00:00
|
|
|
QString icon;
|
|
|
|
if (container->isSearchModeEnabled()) {
|
|
|
|
icon = QStringLiteral("folder-saved-search-symbolic");
|
|
|
|
} else {
|
|
|
|
icon = KIO::iconNameForUrl(url);
|
|
|
|
}
|
Use Kio::KPlacesModel as source model for PlacesItemModel
Summary:
Use Kio::KPlacesModel as source model for PlacesItemModel avoiding
duplicated code.
Depends on D8862
Depends on D8332
Depends on D8434
Depends on D8348
Depends on D8630
Test Plan: Unit test created
Reviewers: elvisangelaccio, emmanuelp, mlaurent, mwolff
Reviewed By: elvisangelaccio, mlaurent, mwolff
Subscribers: mwolff, mlaurent, anthonyfieroni, nicolasfella, ngraham, #dolphin
Differential Revision: https://phabricator.kde.org/D8855
2017-11-16 15:32:49 +00:00
|
|
|
model.createPlacesItem(container->placesText(), url, icon);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 05:11:16 +00:00
|
|
|
void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties& properties)
|
2006-11-21 06:02:05 +00:00
|
|
|
{
|
2007-03-17 20:42:26 +00:00
|
|
|
const KActionCollection* collection = m_mainWindow->actionCollection();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2010-09-17 22:23:11 +00:00
|
|
|
// Insert 'Cut', 'Copy' and 'Paste'
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(collection->action(KStandardAction::name(KStandardAction::Cut)));
|
|
|
|
addAction(collection->action(KStandardAction::name(KStandardAction::Copy)));
|
|
|
|
addAction(createPasteAction());
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
addSeparator();
|
2010-09-17 19:47:01 +00:00
|
|
|
|
|
|
|
// Insert 'Rename'
|
2017-08-09 20:59:38 +00:00
|
|
|
addAction(collection->action(KStandardAction::name(KStandardAction::RenameFile)));
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2010-09-17 22:23:11 +00:00
|
|
|
// Insert 'Move to Trash' and/or 'Delete'
|
2013-06-24 05:11:16 +00:00
|
|
|
if (properties.supportsDeleting()) {
|
2014-10-07 05:38:16 +00:00
|
|
|
const bool showDeleteAction = (KSharedConfig::openConfig()->group("KDE").readEntry("ShowDeleteCommand", false) ||
|
2013-06-24 05:11:16 +00:00
|
|
|
!properties.isLocal());
|
|
|
|
const bool showMoveToTrashAction = (properties.isLocal() &&
|
|
|
|
properties.supportsMoving());
|
|
|
|
|
|
|
|
if (showDeleteAction && showMoveToTrashAction) {
|
|
|
|
delete m_removeAction;
|
2017-11-21 09:52:14 +00:00
|
|
|
m_removeAction = nullptr;
|
2017-07-18 22:00:37 +00:00
|
|
|
addAction(m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash)));
|
2017-03-10 18:31:33 +00:00
|
|
|
addAction(m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
|
2013-06-24 05:11:16 +00:00
|
|
|
} else if (showDeleteAction && !showMoveToTrashAction) {
|
2017-03-10 18:31:33 +00:00
|
|
|
addAction(m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
|
2013-06-24 05:11:16 +00:00
|
|
|
} else {
|
|
|
|
if (!m_removeAction) {
|
|
|
|
m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection());
|
|
|
|
}
|
|
|
|
addAction(m_removeAction);
|
|
|
|
m_removeAction->update();
|
|
|
|
}
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-27 17:27:27 +00:00
|
|
|
void DolphinContextMenu::addShowMenuBarAction()
|
|
|
|
{
|
|
|
|
const KActionCollection* ac = m_mainWindow->actionCollection();
|
|
|
|
QAction* showMenuBar = ac->action(KStandardAction::name(KStandardAction::ShowMenubar));
|
|
|
|
if (!m_mainWindow->menuBar()->isVisible() && !m_mainWindow->toolBar()->isVisible()) {
|
2013-05-04 18:31:02 +00:00
|
|
|
addSeparator();
|
|
|
|
addAction(showMenuBar);
|
2011-03-27 17:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-21 19:18:43 +00:00
|
|
|
bool DolphinContextMenu::placeExists(const QUrl& url) const
|
2009-11-12 20:22:22 +00:00
|
|
|
{
|
2018-03-08 09:21:13 +00:00
|
|
|
Q_UNUSED(url)
|
2016-01-27 05:56:14 +00:00
|
|
|
// Creating up a PlacesItemModel to find out if 'url' is one of the Places
|
|
|
|
// can be expensive because the model asks Solid for the devices which are
|
|
|
|
// available, which can take some time.
|
|
|
|
// TODO: Consider restoring this check if the handling of Places and devices
|
|
|
|
// will be decoupled in the future.
|
2009-11-12 20:22:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-29 07:44:03 +00:00
|
|
|
QAction* DolphinContextMenu::createPasteAction()
|
|
|
|
{
|
2017-11-21 09:52:14 +00:00
|
|
|
QAction* action = nullptr;
|
2008-06-18 19:34:03 +00:00
|
|
|
const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir();
|
|
|
|
if (isDir && (m_selectedItems.count() == 1)) {
|
2014-10-21 18:44:37 +00:00
|
|
|
const QMimeData *mimeData = QApplication::clipboard()->mimeData();
|
|
|
|
bool canPaste;
|
|
|
|
const QString text = KIO::pasteActionText(mimeData, &canPaste, m_fileInfo);
|
2016-03-16 21:17:37 +00:00
|
|
|
action = new QAction(QIcon::fromTheme(QStringLiteral("edit-paste")), text, this);
|
2014-10-21 18:44:37 +00:00
|
|
|
action->setEnabled(canPaste);
|
2014-04-10 14:53:41 +00:00
|
|
|
connect(action, &QAction::triggered, m_mainWindow, &DolphinMainWindow::pasteIntoFolder);
|
2008-03-29 07:44:03 +00:00
|
|
|
} else {
|
|
|
|
action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
|
|
|
|
}
|
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2012-01-14 19:02:11 +00:00
|
|
|
KFileItemListProperties& DolphinContextMenu::selectedItemsProperties() const
|
2010-10-25 13:45:34 +00:00
|
|
|
{
|
2011-02-09 18:21:58 +00:00
|
|
|
if (!m_selectedItemsProperties) {
|
2010-10-25 13:45:34 +00:00
|
|
|
m_selectedItemsProperties = new KFileItemListProperties(m_selectedItems);
|
|
|
|
}
|
|
|
|
return *m_selectedItemsProperties;
|
|
|
|
}
|
|
|
|
|
|
|
|
KFileItem DolphinContextMenu::baseFileItem()
|
2008-04-18 19:43:16 +00:00
|
|
|
{
|
2011-02-09 18:21:58 +00:00
|
|
|
if (!m_baseFileItem) {
|
2014-12-14 16:46:58 +00:00
|
|
|
m_baseFileItem = new KFileItem(m_baseUrl);
|
2008-04-18 19:43:16 +00:00
|
|
|
}
|
2010-10-25 13:45:34 +00:00
|
|
|
return *m_baseFileItem;
|
2008-04-18 19:43:16 +00:00
|
|
|
}
|
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
void DolphinContextMenu::addServiceActions(KFileItemActions& fileItemActions)
|
2010-08-27 05:26:27 +00:00
|
|
|
{
|
|
|
|
fileItemActions.setParentWidget(m_mainWindow);
|
|
|
|
|
|
|
|
// insert 'Open With...' action or sub menu
|
2016-03-16 21:17:37 +00:00
|
|
|
fileItemActions.addOpenWithActionsTo(this, QStringLiteral("DesktopEntryName != 'dolphin'"));
|
2010-08-27 05:26:27 +00:00
|
|
|
|
|
|
|
// insert 'Actions' sub menu
|
2013-05-04 18:31:02 +00:00
|
|
|
fileItemActions.addServiceActionsTo(this);
|
2010-10-25 13:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinContextMenu::addVersionControlPluginActions()
|
2009-07-23 06:10:01 +00:00
|
|
|
{
|
|
|
|
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
|
2009-08-13 20:48:58 +00:00
|
|
|
const QList<QAction*> versionControlActions = view->versionControlActions(m_selectedItems);
|
|
|
|
if (!versionControlActions.isEmpty()) {
|
2015-01-28 14:25:09 +00:00
|
|
|
addActions(versionControlActions);
|
2013-05-04 18:31:02 +00:00
|
|
|
addSeparator();
|
2009-07-23 06:10:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
void DolphinContextMenu::addCustomActions()
|
2009-02-11 20:45:12 +00:00
|
|
|
{
|
2015-01-28 14:25:09 +00:00
|
|
|
addActions(m_customActions);
|
2010-09-17 19:47:01 +00:00
|
|
|
}
|
|
|
|
|