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"
|
|
|
|
|
2007-01-21 21:20:37 +00:00
|
|
|
#include "dolphinmainwindow.h"
|
2010-08-27 05:26:27 +00:00
|
|
|
#include "dolphinnewfilemenu.h"
|
2007-06-07 21:10:48 +00:00
|
|
|
#include "dolphinviewcontainer.h"
|
2008-04-02 19:49:04 +00:00
|
|
|
#include "dolphin_generalsettings.h"
|
2013-02-09 20:56:51 +00:00
|
|
|
#include "dolphinremoveaction.h"
|
2007-01-21 21:20:37 +00:00
|
|
|
|
2011-02-11 18:33:29 +00:00
|
|
|
#include <KActionCollection>
|
|
|
|
#include <KDesktopFile>
|
2010-10-25 13:45:34 +00:00
|
|
|
#include <kfileitemactionplugin.h>
|
2011-02-07 12:07:38 +00:00
|
|
|
#include <kabstractfileitemactionplugin.h>
|
2011-02-11 18:33:29 +00:00
|
|
|
#include <KFileItemActions>
|
|
|
|
#include <KFileItemListProperties>
|
|
|
|
#include <KGlobal>
|
2011-02-04 14:43:21 +00:00
|
|
|
#include <KIconLoader>
|
2011-02-10 09:59:35 +00:00
|
|
|
#include <KIO/NetAccess>
|
2011-02-11 18:33:29 +00:00
|
|
|
#include <KMenu>
|
|
|
|
#include <KMenuBar>
|
|
|
|
#include <KMessageBox>
|
|
|
|
#include <KMimeTypeTrader>
|
2011-02-10 09:59:35 +00:00
|
|
|
#include <KNewFileMenu>
|
2007-03-17 21:10:50 +00:00
|
|
|
#include <konqmimedata.h>
|
2007-03-15 21:24:41 +00:00
|
|
|
#include <konq_operations.h>
|
2011-02-11 18:33:29 +00:00
|
|
|
#include <KService>
|
2011-02-04 14:43:21 +00:00
|
|
|
#include <KLocale>
|
2011-02-11 18:33:29 +00:00
|
|
|
#include <KPropertiesDialog>
|
|
|
|
#include <KStandardAction>
|
|
|
|
#include <KStandardDirs>
|
2011-03-27 17:27:27 +00:00
|
|
|
#include <KToolBar>
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2012-06-02 13:02:34 +00:00
|
|
|
#include <panels/places/placesitem.h>
|
|
|
|
#include <panels/places/placesitemmodel.h>
|
|
|
|
|
2011-02-11 18:33:29 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QDir>
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2010-07-24 21:45:49 +00:00
|
|
|
#include "views/dolphinview.h"
|
|
|
|
#include "views/viewmodecontroller.h"
|
|
|
|
|
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,
|
2007-03-25 06:44:28 +00:00
|
|
|
const KUrl& baseUrl) :
|
2013-05-04 18:31:02 +00:00
|
|
|
KMenu(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),
|
2010-10-25 13:45:34 +00:00
|
|
|
m_baseFileItem(0),
|
|
|
|
m_selectedItems(),
|
|
|
|
m_selectedItemsProperties(0),
|
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-02-09 20:56:51 +00:00
|
|
|
m_command(None)
|
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();
|
2010-09-17 19:47:01 +00:00
|
|
|
|
2013-02-09 20:56:51 +00:00
|
|
|
m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection());
|
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;
|
|
|
|
m_selectedItemsProperties = 0;
|
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
|
2010-09-21 19:56:35 +00:00
|
|
|
if (m_baseUrl.protocol() == 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-05-04 18:31:02 +00:00
|
|
|
if (ev->key() == Qt::Key_Shift) {
|
2013-02-09 20:56:51 +00:00
|
|
|
m_removeAction->update();
|
2013-05-04 18:31:02 +00:00
|
|
|
}
|
|
|
|
KMenu::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-05-04 18:31:02 +00:00
|
|
|
if (ev->key() == Qt::Key_Shift) {
|
2013-02-09 20:56:51 +00:00
|
|
|
m_removeAction->update();
|
2013-05-04 18:31:02 +00:00
|
|
|
}
|
|
|
|
KMenu::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);
|
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
QAction* emptyTrashAction = new QAction(KIcon("trash-empty"), i18nc("@action:inmenu", "Empty Trash"), this);
|
KConfig* API overhaul. only cosmetics, so don't panic.
KConfigBase:
- remove separator argument from list entry reading/writing functions
- introduce {read,write}XdgListEntry()
- kill readPathListEntry(), add readPathEntry() overload
instead. the default value is not optional any more, as it defines the
return type. this is consistent with the readEntry() functions.
- rename clean() => markAsClean(), remove rollback()
- rename ConfigState => AccessMode, getConfigState() => accessMode()
- rename {entry,group}IsImmutable() => is{Entry,Group}Immutable()
- remove NLS alias to Localized
KConfig:
- remove setGroup() & group()
- reshuffle OpenFlag enum, introduce NoCascade for symmetry
- remove setExtraConfigFiles() alias to addConfigSources()
KConfigGroup:
- inherit KConfigBase::deleteGroup() overloads
- make convertToQVariant() private, it will probably change somehow
- KConfig & KConfigGroup: deprecate entryMap()
- remove bogus declarations: KConfigGroup::setReadDefaults(),
KConfig::readEntryUntranslated()
- apidox
- reshuffle the declarations in the headers
svn path=/trunk/KDE/kdebase/apps/; revision=728852
2007-10-24 13:08:37 +00:00
|
|
|
KConfig trashConfig("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
|
|
|
|
2007-03-15 22:42:21 +00:00
|
|
|
QAction* propertiesAction = m_mainWindow->actionCollection()->action("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) {
|
2011-04-26 14:10:15 +00:00
|
|
|
KonqOperations::emptyTrash(m_mainWindow);
|
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
|
|
|
|
2007-03-15 22:42:21 +00:00
|
|
|
QAction* deleteAction = m_mainWindow->actionCollection()->action("delete");
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(deleteAction);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2007-03-15 22:42:21 +00:00
|
|
|
QAction* propertiesAction = m_mainWindow->actionCollection()->action("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) {
|
2010-10-25 13:45:34 +00:00
|
|
|
KUrl::List selectedUrls;
|
|
|
|
foreach (const KFileItem &item, m_selectedItems) {
|
|
|
|
selectedUrls.append(item.url());
|
|
|
|
}
|
|
|
|
|
|
|
|
KonqOperations::restoreTrashedItems(selectedUrls, m_mainWindow);
|
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
|
|
|
|
2010-09-22 20:24:49 +00:00
|
|
|
QAction* openParentInNewWindowAction = 0;
|
|
|
|
QAction* openParentInNewTabAction = 0;
|
2010-09-21 19:56:35 +00:00
|
|
|
QAction* addToPlacesAction = 0;
|
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
|
2011-02-09 20:15:55 +00:00
|
|
|
DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(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());
|
2010-10-25 13:45:34 +00:00
|
|
|
newFileMenu->setEnabled(selectedItemsProperties().supportsWriting());
|
2011-02-09 20:15:55 +00:00
|
|
|
connect(newFileMenu, SIGNAL(fileCreated(KUrl)), newFileMenu, SLOT(deleteLater()));
|
|
|
|
connect(newFileMenu, SIGNAL(directoryCreated(KUrl)), newFileMenu, SLOT(deleteLater()));
|
2010-09-22 20:24:49 +00:00
|
|
|
|
|
|
|
KMenu* menu = newFileMenu->menu();
|
|
|
|
menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
|
|
|
|
menu->setIcon(KIcon("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
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
|
|
|
|
addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
|
2010-09-22 20:24:49 +00:00
|
|
|
|
|
|
|
// insert 'Add to Places' entry
|
|
|
|
if (!placeExists(m_fileInfo.url())) {
|
2013-05-04 18:31:02 +00:00
|
|
|
addToPlacesAction = addAction(KIcon("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();
|
2010-09-22 20:24:49 +00:00
|
|
|
} else if (m_baseUrl.protocol().contains("search")) {
|
|
|
|
openParentInNewWindowAction = new QAction(KIcon("window-new"),
|
|
|
|
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
|
|
|
|
|
|
|
openParentInNewTabAction = new QAction(KIcon("tab-new"),
|
|
|
|
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-22 19:47:14 +00:00
|
|
|
addSeparator();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bool selectionHasOnlyDirs = true;
|
|
|
|
foreach (const KFileItem& item, m_selectedItems) {
|
|
|
|
if (!item.isDir()) {
|
|
|
|
selectionHasOnlyDirs = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectionHasOnlyDirs) {
|
|
|
|
// insert 'Open in new tab' entry
|
|
|
|
addAction(m_mainWindow->actionCollection()->action("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
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
insertDefaultItemActions();
|
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;
|
2010-10-25 13:45:34 +00:00
|
|
|
fileItemActions.setItemListProperties(selectedItemsProperties());
|
2010-09-17 19:47:01 +00:00
|
|
|
addServiceActions(fileItemActions);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2010-10-25 13:45:34 +00:00
|
|
|
addFileItemPluginActions();
|
|
|
|
|
|
|
|
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()) {
|
2008-04-02 19:49:04 +00:00
|
|
|
m_copyToMenu.setItems(m_selectedItems);
|
2010-10-25 13:45:34 +00:00
|
|
|
m_copyToMenu.setReadOnly(!selectedItemsProperties().supportsWriting());
|
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
|
2007-03-25 06:44:28 +00:00
|
|
|
QAction* propertiesAction = m_mainWindow->actionCollection()->action("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) {
|
|
|
|
const KUrl selectedUrl(m_fileInfo.url());
|
|
|
|
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();
|
2012-06-02 13:45:40 +00:00
|
|
|
PlacesItem* item = model.createPlacesItem(text, selectedUrl);
|
2012-06-02 13:02:34 +00:00
|
|
|
model.appendItemToGroup(item);
|
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.
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(m_mainWindow->actionCollection()->action("new_window"));
|
|
|
|
addAction(m_mainWindow->actionCollection()->action("new_tab"));
|
2010-10-09 15:39:41 +00:00
|
|
|
|
|
|
|
// Insert 'Add to Places' entry if exactly one item is selected
|
|
|
|
QAction* addToPlacesAction = 0;
|
|
|
|
if (!placeExists(m_mainWindow->activeViewContainer()->url())) {
|
2013-05-04 18:31:02 +00:00
|
|
|
addToPlacesAction = addAction(KIcon("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
|
|
|
|
2010-10-25 13:45:34 +00:00
|
|
|
addFileItemPluginActions();
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-04-10 16:47:25 +00:00
|
|
|
QAction* propertiesAction = m_mainWindow->actionCollection()->action("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();
|
|
|
|
if (container->url().isValid()) {
|
2012-06-02 13:02:34 +00:00
|
|
|
PlacesItemModel model;
|
2012-06-02 13:45:40 +00:00
|
|
|
PlacesItem* item = model.createPlacesItem(container->placesText(),
|
|
|
|
container->url());
|
2012-06-02 13:02:34 +00:00
|
|
|
model.appendItemToGroup(item);
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
void DolphinContextMenu::insertDefaultItemActions()
|
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'
|
2007-03-25 06:44:28 +00:00
|
|
|
QAction* renameAction = collection->action("rename");
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(renameAction);
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2010-09-17 22:23:11 +00:00
|
|
|
// Insert 'Move to Trash' and/or 'Delete'
|
|
|
|
if (KGlobal::config()->group("KDE").readEntry("ShowDeleteCommand", false)) {
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(collection->action("move_to_trash"));
|
|
|
|
addAction(collection->action("delete"));
|
2007-04-09 19:12:54 +00:00
|
|
|
} else {
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(m_removeAction);
|
2013-02-09 20:56:51 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 20:22:22 +00:00
|
|
|
bool DolphinContextMenu::placeExists(const KUrl& url) const
|
|
|
|
{
|
2012-06-02 13:02:34 +00:00
|
|
|
PlacesItemModel model;
|
2009-11-12 20:22:22 +00:00
|
|
|
|
2012-06-02 13:02:34 +00:00
|
|
|
const int count = model.count();
|
2009-11-12 20:22:22 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
2012-06-02 13:02:34 +00:00
|
|
|
const KUrl placeUrl = model.placesItem(i)->url();
|
|
|
|
if (placeUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
|
2009-11-12 20:22:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-06-02 13:02:34 +00:00
|
|
|
|
2009-11-12 20:22:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-29 07:44:03 +00:00
|
|
|
QAction* DolphinContextMenu::createPasteAction()
|
|
|
|
{
|
|
|
|
QAction* action = 0;
|
2008-06-18 19:34:03 +00:00
|
|
|
const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir();
|
|
|
|
if (isDir && (m_selectedItems.count() == 1)) {
|
2008-03-29 07:44:03 +00:00
|
|
|
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);
|
2010-10-25 13:45:34 +00:00
|
|
|
action->setEnabled(!pasteData.isEmpty() && selectedItemsProperties().supportsWriting());
|
2008-03-29 14:54:56 +00:00
|
|
|
connect(action, SIGNAL(triggered()), m_mainWindow, SLOT(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) {
|
2010-10-25 13:45:34 +00:00
|
|
|
m_baseFileItem = new KFileItem(KFileItem::Unknown, KFileItem::Unknown, 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
|
2013-05-04 18:31:02 +00:00
|
|
|
fileItemActions.addOpenWithActionsTo(this, "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::addFileItemPluginActions()
|
|
|
|
{
|
|
|
|
KFileItemListProperties props;
|
|
|
|
if (m_selectedItems.isEmpty()) {
|
|
|
|
props.setItems(KFileItemList() << baseFileItem());
|
|
|
|
} else {
|
|
|
|
props = selectedItemsProperties();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString commonMimeType = props.mimeType();
|
|
|
|
if (commonMimeType.isEmpty()) {
|
|
|
|
commonMimeType = QLatin1String("application/octet-stream");
|
|
|
|
}
|
|
|
|
|
|
|
|
const KService::List pluginServices = KMimeTypeTrader::self()->query(commonMimeType, "KFileItemAction/Plugin", "exist Library");
|
|
|
|
if (pluginServices.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const KConfig config("kservicemenurc", KConfig::NoGlobals);
|
|
|
|
const KConfigGroup showGroup = config.group("Show");
|
|
|
|
|
|
|
|
foreach (const KSharedPtr<KService>& service, pluginServices) {
|
2011-02-07 12:07:38 +00:00
|
|
|
// Old API (kdelibs-4.6.0 only)
|
2010-10-25 13:45:34 +00:00
|
|
|
KFileItemActionPlugin* plugin = service->createInstance<KFileItemActionPlugin>();
|
2011-02-07 12:07:38 +00:00
|
|
|
if (plugin) {
|
2013-05-29 05:48:11 +00:00
|
|
|
if (!showGroup.readEntry(service->desktopEntryName(), true)) {
|
|
|
|
// The plugin has been disabled
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
plugin->setParent(this);
|
|
|
|
addActions(plugin->actions(props, m_mainWindow));
|
2010-10-25 13:45:34 +00:00
|
|
|
}
|
2011-02-07 12:07:38 +00:00
|
|
|
// New API (kdelibs >= 4.6.1)
|
|
|
|
KAbstractFileItemActionPlugin* abstractPlugin = service->createInstance<KAbstractFileItemActionPlugin>();
|
|
|
|
if (abstractPlugin) {
|
2013-05-29 05:48:11 +00:00
|
|
|
if (!showGroup.readEntry(service->desktopEntryName(), abstractPlugin->enabledByDefault())) {
|
|
|
|
// The plugin has been disabled
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-04 18:31:02 +00:00
|
|
|
abstractPlugin->setParent(this);
|
|
|
|
addActions(abstractPlugin->actions(props, m_mainWindow));
|
2010-10-25 13:45:34 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-27 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
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()) {
|
|
|
|
foreach (QAction* action, versionControlActions) {
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(action);
|
2009-07-23 06:10:01 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
foreach (QAction* action, m_customActions) {
|
2013-05-04 18:31:02 +00:00
|
|
|
addAction(action);
|
2010-09-17 19:47:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-17 20:42:26 +00:00
|
|
|
#include "dolphincontextmenu.moc"
|