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"
|
2009-01-14 19:26:23 +00:00
|
|
|
#include "settings/dolphinsettings.h"
|
2007-06-07 21:10:48 +00:00
|
|
|
#include "dolphinviewcontainer.h"
|
2008-04-02 19:49:04 +00:00
|
|
|
#include "dolphin_generalsettings.h"
|
2007-01-21 21:20:37 +00:00
|
|
|
|
2011-02-04 14:43:21 +00:00
|
|
|
#include <KActionCollection>
|
|
|
|
#include <KDesktopFile>
|
2010-10-25 13:45:34 +00:00
|
|
|
#include <kfileitemactionplugin.h>
|
2011-02-04 14:43:21 +00:00
|
|
|
#include <KFileItemActions>
|
|
|
|
#include <KFileItemListProperties>
|
|
|
|
#include <KFilePlacesModel>
|
|
|
|
#include <KGlobal>
|
|
|
|
#include <KIconLoader>
|
|
|
|
#include <KIO/NetAccess>
|
|
|
|
#include <KMenu>
|
|
|
|
#include <KMenuBar>
|
|
|
|
#include <KMessageBox>
|
|
|
|
#include <KMimeTypeTrader>
|
|
|
|
#include <KModifierKeyInfo>
|
2010-08-27 05:26:27 +00:00
|
|
|
#include <knewfilemenu.h>
|
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-04 14:43:21 +00:00
|
|
|
#include <KService>
|
|
|
|
#include <KLocale>
|
|
|
|
#include <KPropertiesDialog>
|
|
|
|
#include <KStandardAction>
|
|
|
|
#include <KStandardDirs>
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2007-05-09 22:23:52 +00:00
|
|
|
#include <QtGui/QApplication>
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
#include <QtCore/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"
|
|
|
|
|
2010-09-21 16:18:20 +00:00
|
|
|
K_GLOBAL_STATIC(KModifierKeyInfo, m_keyInfo)
|
2010-09-20 19:52:40 +00:00
|
|
|
|
2007-03-15 22:42:21 +00:00
|
|
|
DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
|
2007-08-13 21:57:20 +00:00
|
|
|
const KFileItem& fileInfo,
|
2007-03-25 06:44:28 +00:00
|
|
|
const KUrl& baseUrl) :
|
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(),
|
2010-10-25 13:45:34 +00:00
|
|
|
m_popup(0),
|
2010-09-22 20:24:49 +00:00
|
|
|
m_command(None),
|
2010-09-17 21:16:56 +00:00
|
|
|
m_shiftPressed(false),
|
2010-09-17 22:23:11 +00:00
|
|
|
m_removeAction(0)
|
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
|
|
|
|
2010-09-20 19:52:40 +00:00
|
|
|
if (m_keyInfo != 0) {
|
|
|
|
if (m_keyInfo->isKeyPressed(Qt::Key_Shift) || m_keyInfo->isKeyLatched(Qt::Key_Shift)) {
|
|
|
|
m_shiftPressed = true;
|
|
|
|
}
|
|
|
|
connect(m_keyInfo, SIGNAL(keyPressed(Qt::Key, bool)),
|
|
|
|
this, SLOT(slotKeyModifierPressed(Qt::Key, bool)));
|
2010-09-17 21:16:56 +00:00
|
|
|
}
|
|
|
|
|
2010-09-17 22:23:11 +00:00
|
|
|
m_removeAction = new QAction(this);
|
|
|
|
connect(m_removeAction, SIGNAL(triggered()), this, SLOT(slotRemoveActionTriggered()));
|
2010-10-25 13:45:34 +00:00
|
|
|
|
|
|
|
m_popup = new KMenu(m_mainWindow);
|
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;
|
|
|
|
|
|
|
|
delete m_popup;
|
|
|
|
m_popup = 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
|
|
|
}
|
|
|
|
|
2010-09-20 19:52:40 +00:00
|
|
|
void DolphinContextMenu::initializeModifierKeyInfo()
|
|
|
|
{
|
2010-09-21 16:18:20 +00:00
|
|
|
// Access m_keyInfo, so that it gets instantiated by
|
|
|
|
// K_GLOBAL_STATIC
|
|
|
|
KModifierKeyInfo* keyInfo = m_keyInfo;
|
|
|
|
Q_UNUSED(keyInfo);
|
2010-09-20 19:52:40 +00:00
|
|
|
}
|
|
|
|
|
2010-09-17 22:23:11 +00:00
|
|
|
void DolphinContextMenu::slotKeyModifierPressed(Qt::Key key, bool pressed)
|
|
|
|
{
|
|
|
|
m_shiftPressed = (key == Qt::Key_Shift) && pressed;
|
|
|
|
updateRemoveAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinContextMenu::slotRemoveActionTriggered()
|
|
|
|
{
|
|
|
|
const KActionCollection* collection = m_mainWindow->actionCollection();
|
|
|
|
if (m_shiftPressed) {
|
|
|
|
collection->action("delete")->trigger();
|
|
|
|
} else {
|
|
|
|
collection->action("move_to_trash")->trigger();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-15 21:24:41 +00:00
|
|
|
void DolphinContextMenu::openTrashContextMenu()
|
|
|
|
{
|
|
|
|
Q_ASSERT(m_context & TrashContext);
|
|
|
|
|
2010-10-25 13:45:34 +00:00
|
|
|
QAction* emptyTrashAction = new QAction(KIcon("trash-empty"), i18nc("@action:inmenu", "Empty Trash"), m_popup);
|
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));
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addAction(emptyTrashAction);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
QAction* addToPlacesAction = m_popup->addAction(KIcon("bookmark-new"),
|
2007-11-06 17:09:00 +00:00
|
|
|
i18nc("@action:inmenu Add current folder to places", "Add to Places"));
|
|
|
|
|
2009-11-12 20:22:22 +00:00
|
|
|
// Don't show if url is already in places
|
|
|
|
if (placeExists(m_mainWindow->activeViewContainer()->url())) {
|
|
|
|
addToPlacesAction->setVisible(false);
|
|
|
|
}
|
|
|
|
|
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");
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addAction(propertiesAction);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2010-11-17 19:10:23 +00:00
|
|
|
addShowMenubarAction();
|
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
QAction *action = m_popup->exec(QCursor::pos());
|
2007-11-06 17:09:00 +00:00
|
|
|
if (action == emptyTrashAction) {
|
2008-04-01 23:32:40 +00:00
|
|
|
const QString text(i18nc("@info", "Do you really want to empty the Trash? All items will be deleted."));
|
2007-03-15 22:42:21 +00:00
|
|
|
const bool del = KMessageBox::warningContinueCancel(m_mainWindow,
|
2007-06-20 20:44:18 +00:00
|
|
|
text,
|
|
|
|
QString(),
|
2007-07-09 17:51:39 +00:00
|
|
|
KGuiItem(i18nc("@action:button", "Empty Trash"),
|
|
|
|
KIcon("user-trash"))
|
2007-04-09 19:12:54 +00:00
|
|
|
) == KMessageBox::Continue;
|
2007-03-15 21:24:41 +00:00
|
|
|
if (del) {
|
2007-03-15 22:42:21 +00:00
|
|
|
KonqOperations::emptyTrash(m_mainWindow);
|
2007-03-15 21:24:41 +00:00
|
|
|
}
|
2007-11-06 17:09:00 +00:00
|
|
|
} else if (action == addToPlacesAction) {
|
|
|
|
const KUrl& url = m_mainWindow->activeViewContainer()->url();
|
|
|
|
if (url.isValid()) {
|
2008-03-18 22:38:52 +00:00
|
|
|
DolphinSettings::instance().placesModel()->addPlace(i18nc("@label", "Trash"), url);
|
2007-11-06 17:09:00 +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);
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->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");
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->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");
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addAction(propertiesAction);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
if (m_popup->exec(QCursor::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
|
2010-10-25 13:45:34 +00:00
|
|
|
DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_popup, m_mainWindow);
|
2010-09-22 20:24:49 +00:00
|
|
|
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
|
|
|
|
newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles());
|
|
|
|
newFileMenu->checkUpToDate();
|
|
|
|
newFileMenu->setPopupFiles(m_fileInfo.url());
|
2010-10-25 13:45:34 +00:00
|
|
|
newFileMenu->setEnabled(selectedItemsProperties().supportsWriting());
|
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"));
|
|
|
|
m_popup->addMenu(menu);
|
|
|
|
m_popup->addSeparator();
|
|
|
|
|
|
|
|
// insert 'Open in new window' and 'Open in new tab' entries
|
|
|
|
m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
|
|
|
|
m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
|
|
|
|
|
|
|
|
// insert 'Add to Places' entry
|
|
|
|
if (!placeExists(m_fileInfo.url())) {
|
|
|
|
addToPlacesAction = m_popup->addAction(KIcon("bookmark-new"),
|
|
|
|
i18nc("@action:inmenu Add selected folder to places",
|
|
|
|
"Add to Places"));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_popup->addSeparator();
|
|
|
|
} 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);
|
|
|
|
m_popup->addAction(openParentInNewWindowAction);
|
|
|
|
|
|
|
|
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);
|
|
|
|
m_popup->addAction(openParentInNewTabAction);
|
|
|
|
|
|
|
|
m_popup->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
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->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
|
2008-04-02 19:49:04 +00:00
|
|
|
if (DolphinSettings::instance().generalSettings()->showCopyMoveMenu()) {
|
|
|
|
m_copyToMenu.setItems(m_selectedItems);
|
2010-10-25 13:45:34 +00:00
|
|
|
m_copyToMenu.setReadOnly(!selectedItemsProperties().supportsWriting());
|
|
|
|
m_copyToMenu.addActionsTo(m_popup);
|
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");
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addAction(propertiesAction);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
QAction* activatedAction = m_popup->exec(QCursor::pos());
|
2010-09-22 20:24:49 +00:00
|
|
|
if (activatedAction != 0) {
|
|
|
|
if (activatedAction == addToPlacesAction) {
|
|
|
|
const KUrl selectedUrl(m_fileInfo.url());
|
|
|
|
if (selectedUrl.isValid()) {
|
|
|
|
DolphinSettings::instance().placesModel()->addPlace(placesName(selectedUrl),
|
|
|
|
selectedUrl);
|
|
|
|
}
|
|
|
|
} 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();
|
2010-08-27 05:26:27 +00:00
|
|
|
newFileMenu->setViewShowsHiddenFiles(view->showHiddenFiles());
|
|
|
|
newFileMenu->checkUpToDate();
|
|
|
|
newFileMenu->setPopupFiles(m_baseUrl);
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addMenu(newFileMenu->menu());
|
|
|
|
m_popup->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.
|
|
|
|
m_popup->addAction(m_mainWindow->actionCollection()->action("new_window"));
|
|
|
|
m_popup->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())) {
|
|
|
|
addToPlacesAction = m_popup->addAction(KIcon("bookmark-new"),
|
|
|
|
i18nc("@action:inmenu Add current folder to places", "Add to Places"));
|
|
|
|
}
|
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addSeparator();
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2008-03-29 07:44:03 +00:00
|
|
|
QAction* pasteAction = createPasteAction();
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addAction(pasteAction);
|
|
|
|
m_popup->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
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
QAction* propertiesAction = m_popup->addAction(i18nc("@action:inmenu", "Properties"));
|
2009-03-13 01:07:51 +00:00
|
|
|
propertiesAction->setIcon(KIcon("document-properties"));
|
2010-11-17 19:10:23 +00:00
|
|
|
|
|
|
|
addShowMenubarAction();
|
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
QAction* action = m_popup->exec(QCursor::pos());
|
2007-06-12 21:45:22 +00:00
|
|
|
if (action == propertiesAction) {
|
2007-06-07 21:10:48 +00:00
|
|
|
const KUrl& url = m_mainWindow->activeViewContainer()->url();
|
2008-12-12 06:55:26 +00:00
|
|
|
|
2008-08-12 18:46:35 +00:00
|
|
|
KPropertiesDialog* dialog = new KPropertiesDialog(url, m_mainWindow);
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
dialog->show();
|
2010-08-27 05:26:27 +00:00
|
|
|
} else if ((addToPlacesAction != 0) && (action == addToPlacesAction)) {
|
2007-06-07 21:10:48 +00:00
|
|
|
const KUrl& url = m_mainWindow->activeViewContainer()->url();
|
2007-04-09 09:16:39 +00:00
|
|
|
if (url.isValid()) {
|
2008-01-25 19:14:12 +00:00
|
|
|
DolphinSettings::instance().placesModel()->addPlace(placesName(url), url);
|
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'
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addAction(collection->action(KStandardAction::name(KStandardAction::Cut)));
|
|
|
|
m_popup->addAction(collection->action(KStandardAction::name(KStandardAction::Copy)));
|
|
|
|
m_popup->addAction(createPasteAction());
|
2006-11-21 06:02:05 +00:00
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addSeparator();
|
|
|
|
|
|
|
|
// Insert 'Rename'
|
2007-03-25 06:44:28 +00:00
|
|
|
QAction* renameAction = collection->action("rename");
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->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)) {
|
|
|
|
m_popup->addAction(collection->action("move_to_trash"));
|
|
|
|
m_popup->addAction(collection->action("delete"));
|
2007-04-09 19:12:54 +00:00
|
|
|
} else {
|
2010-09-17 22:23:11 +00:00
|
|
|
m_popup->addAction(m_removeAction);
|
|
|
|
updateRemoveAction();
|
2006-11-21 06:02:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
void DolphinContextMenu::addShowMenubarAction()
|
2007-11-18 14:37:57 +00:00
|
|
|
{
|
|
|
|
KAction* showMenuBar = m_mainWindow->showMenuBarAction();
|
|
|
|
if (!m_mainWindow->menuBar()->isVisible()) {
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addSeparator();
|
2010-11-17 19:10:23 +00:00
|
|
|
m_popup->addAction(showMenuBar);
|
2007-11-18 14:37:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-25 19:14:12 +00:00
|
|
|
QString DolphinContextMenu::placesName(const KUrl& url) const
|
|
|
|
{
|
|
|
|
QString name = url.fileName();
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
name = url.host();
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2009-11-12 20:22:22 +00:00
|
|
|
bool DolphinContextMenu::placeExists(const KUrl& url) const
|
|
|
|
{
|
|
|
|
const KFilePlacesModel* placesModel = DolphinSettings::instance().placesModel();
|
|
|
|
const int count = placesModel->rowCount();
|
|
|
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
const QModelIndex index = placesModel->index(i, 0);
|
|
|
|
|
|
|
|
if (url.equals(placesModel->url(index), KUrl::CompareWithoutTrailingSlash)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-10-25 13:45:34 +00:00
|
|
|
KFileItemListProperties& DolphinContextMenu::selectedItemsProperties()
|
|
|
|
{
|
|
|
|
if (m_selectedItemsProperties == 0) {
|
|
|
|
m_selectedItemsProperties = new KFileItemListProperties(m_selectedItems);
|
|
|
|
}
|
|
|
|
return *m_selectedItemsProperties;
|
|
|
|
}
|
|
|
|
|
|
|
|
KFileItem DolphinContextMenu::baseFileItem()
|
2008-04-18 19:43:16 +00:00
|
|
|
{
|
2010-10-25 13:45:34 +00:00
|
|
|
if (m_baseFileItem == 0) {
|
|
|
|
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
|
2010-10-25 13:45:34 +00:00
|
|
|
fileItemActions.addOpenWithActionsTo(m_popup, "DesktopEntryName != 'dolphin'");
|
2010-08-27 05:26:27 +00:00
|
|
|
|
|
|
|
// insert 'Actions' sub menu
|
2010-10-25 13:45:34 +00:00
|
|
|
fileItemActions.addServiceActionsTo(m_popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (!showGroup.readEntry(service->desktopEntryName(), true)) {
|
|
|
|
// The plugin has been disabled
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
KFileItemActionPlugin* plugin = service->createInstance<KFileItemActionPlugin>();
|
|
|
|
if (plugin == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin->setParent(m_popup);
|
|
|
|
const QList<QAction*> actions = plugin->actions(props, m_mainWindow);
|
|
|
|
foreach (QAction* action, actions) {
|
|
|
|
m_popup->addAction(action);
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addAction(action);
|
2009-07-23 06:10:01 +00:00
|
|
|
}
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->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) {
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addAction(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 22:23:11 +00:00
|
|
|
void DolphinContextMenu::updateRemoveAction()
|
2010-09-17 19:47:01 +00:00
|
|
|
{
|
2010-09-17 22:23:11 +00:00
|
|
|
const KActionCollection* collection = m_mainWindow->actionCollection();
|
2010-10-25 13:45:34 +00:00
|
|
|
const bool moveToTrash = selectedItemsProperties().isLocal() && !m_shiftPressed;
|
2010-10-13 15:25:58 +00:00
|
|
|
|
|
|
|
// 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"));
|
|
|
|
}
|
2010-09-17 22:23:11 +00:00
|
|
|
m_removeAction->setIcon(action->icon());
|
|
|
|
m_removeAction->setShortcuts(action->shortcuts());
|
2009-02-11 20:45:12 +00:00
|
|
|
}
|
|
|
|
|
2007-03-17 20:42:26 +00:00
|
|
|
#include "dolphincontextmenu.moc"
|