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
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
#include <kactioncollection.h>
|
2009-05-26 18:41:20 +00:00
|
|
|
#include <kdesktopfile.h>
|
2009-03-23 19:10:13 +00:00
|
|
|
#include <kfileitemlistproperties.h>
|
2007-04-09 09:16:39 +00:00
|
|
|
#include <kfileplacesmodel.h>
|
2006-11-21 06:02:05 +00:00
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kiconloader.h>
|
|
|
|
#include <kio/netaccess.h>
|
2006-11-22 08:22:45 +00:00
|
|
|
#include <kmenu.h>
|
2007-11-18 14:37:57 +00:00
|
|
|
#include <kmenubar.h>
|
2007-03-15 21:24:41 +00:00
|
|
|
#include <kmessagebox.h>
|
2007-01-21 21:20:37 +00:00
|
|
|
#include <kmimetypetrader.h>
|
2010-09-21 16:18:20 +00:00
|
|
|
#include <kmodifierkeyinfo.h>
|
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>
|
2010-01-26 12:04:56 +00:00
|
|
|
#include <kfileitemactions.h>
|
2007-01-21 21:20:37 +00:00
|
|
|
#include <klocale.h>
|
|
|
|
#include <kpropertiesdialog.h>
|
2006-12-19 02:26:06 +00:00
|
|
|
#include <kstandardaction.h>
|
2007-01-21 21:20:37 +00:00
|
|
|
#include <kstandarddirs.h>
|
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),
|
2008-04-18 19:43:16 +00:00
|
|
|
m_capabilities(0),
|
2007-05-06 17:41:49 +00:00
|
|
|
m_fileInfo(fileInfo),
|
|
|
|
m_baseUrl(baseUrl),
|
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(),
|
|
|
|
m_popup(new KMenu(m_mainWindow)),
|
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_selectedUrls = view->selectedUrls();
|
|
|
|
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()));
|
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
|
|
|
{
|
2008-04-18 19:43:16 +00:00
|
|
|
delete m_capabilities;
|
|
|
|
m_capabilities = 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;
|
|
|
|
}
|
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
void DolphinContextMenu::open()
|
|
|
|
{
|
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();
|
|
|
|
}
|
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-09-17 19:47:01 +00:00
|
|
|
addShowMenubarAction();
|
2007-11-18 14:37:57 +00:00
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
QAction* emptyTrashAction = new QAction(KIcon("trash-empty"), i18nc("@action:inmenu", "Empty Trash"), m_popup.data());
|
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-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);
|
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
addShowMenubarAction();
|
2007-11-18 14:37:57 +00:00
|
|
|
|
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) {
|
2007-03-15 22:42:21 +00:00
|
|
|
KonqOperations::restoreTrashedItems(m_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-21 19:56:35 +00:00
|
|
|
QAction* addToPlacesAction = 0;
|
2008-10-25 10:32:55 +00:00
|
|
|
if (m_fileInfo.isDir() && (m_selectedUrls.count() == 1)) {
|
2008-11-14 19:51:13 +00:00
|
|
|
// setup 'Create New' menu
|
2010-09-17 19:47:01 +00:00
|
|
|
DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_popup.data(), m_mainWindow);
|
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_fileInfo.url());
|
|
|
|
newFileMenu->setEnabled(capabilities().supportsWriting());
|
2008-12-12 06:55:26 +00:00
|
|
|
|
2010-08-27 05:26:27 +00:00
|
|
|
KMenu* menu = newFileMenu->menu();
|
2008-11-14 19:51:13 +00:00
|
|
|
menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
|
|
|
|
menu->setIcon(KIcon("document-new"));
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addMenu(menu);
|
|
|
|
m_popup->addSeparator();
|
2008-12-12 06:55:26 +00:00
|
|
|
|
2008-11-14 19:51:13 +00:00
|
|
|
// insert 'Open in new window' and 'Open in new tab' entries
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
|
|
|
|
m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
|
2010-09-21 19:56:35 +00:00
|
|
|
|
|
|
|
// 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"));
|
|
|
|
}
|
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addSeparator();
|
2008-10-25 10:32:55 +00:00
|
|
|
}
|
2010-09-17 19:47:01 +00:00
|
|
|
addShowMenubarAction();
|
|
|
|
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;
|
|
|
|
fileItemActions.setItemListProperties(capabilities());
|
2010-09-17 19:47:01 +00:00
|
|
|
addServiceActions(fileItemActions);
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
addVersionControlActions();
|
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);
|
2008-05-19 19:44:42 +00:00
|
|
|
m_copyToMenu.setReadOnly(!capabilities().supportsWriting());
|
2010-09-17 19:47:01 +00:00
|
|
|
m_copyToMenu.addActionsTo(m_popup.data());
|
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());
|
2007-03-15 21:24:41 +00:00
|
|
|
|
2007-08-25 10:42:10 +00:00
|
|
|
if ((addToPlacesAction != 0) && (activatedAction == addToPlacesAction)) {
|
2007-08-13 21:57:20 +00:00
|
|
|
const KUrl selectedUrl(m_fileInfo.url());
|
2007-04-09 09:16:39 +00:00
|
|
|
if (selectedUrl.isValid()) {
|
2008-01-25 19:14:12 +00:00
|
|
|
DolphinSettings::instance().placesModel()->addPlace(placesName(selectedUrl),
|
2007-06-20 20:44:18 +00:00
|
|
|
selectedUrl);
|
2007-03-15 21:24:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
void DolphinContextMenu::openViewportContextMenu()
|
|
|
|
{
|
2010-09-17 19:47:01 +00:00
|
|
|
addShowMenubarAction();
|
2007-11-18 14:37:57 +00:00
|
|
|
|
2006-11-21 06:02:05 +00:00
|
|
|
// 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
|
|
|
|
|
|
|
// insert 'Open in new window' and 'Open in new tab' entries
|
2010-09-17 19:47:01 +00:00
|
|
|
m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_window"));
|
|
|
|
m_popup->addAction(m_mainWindow->actionCollection()->action("open_in_new_tab"));
|
|
|
|
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-08-27 05:26:27 +00:00
|
|
|
// insert service actions
|
|
|
|
const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, m_baseUrl);
|
|
|
|
const KFileItemListProperties baseUrlProperties(KFileItemList() << item);
|
|
|
|
KFileItemActions fileItemActions;
|
|
|
|
fileItemActions.setItemListProperties(baseUrlProperties);
|
2010-09-17 19:47:01 +00:00
|
|
|
addServiceActions(fileItemActions);
|
2009-07-23 06:10:01 +00:00
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
addVersionControlActions();
|
2009-02-11 20:45:12 +00:00
|
|
|
|
2010-08-27 05:26:27 +00:00
|
|
|
// insert 'Add to Places' entry if exactly one item is selected
|
|
|
|
QAction* addToPlacesAction = 0;
|
|
|
|
if (!placeExists(m_mainWindow->activeViewContainer()->url())) {
|
2010-09-17 19:47:01 +00:00
|
|
|
addToPlacesAction = m_popup->addAction(KIcon("bookmark-new"),
|
2010-08-27 05:26:27 +00:00
|
|
|
i18nc("@action:inmenu Add current folder to places", "Add to Places"));
|
2009-11-12 20:22:22 +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-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->addAction(showMenuBar);
|
|
|
|
m_popup->addSeparator();
|
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);
|
2008-04-18 19:43:16 +00:00
|
|
|
action->setEnabled(!pasteData.isEmpty() && capabilities().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;
|
|
|
|
}
|
|
|
|
|
2009-04-01 23:34:33 +00:00
|
|
|
KFileItemListProperties& DolphinContextMenu::capabilities()
|
2008-04-18 19:43:16 +00:00
|
|
|
{
|
|
|
|
if (m_capabilities == 0) {
|
2009-04-01 23:34:33 +00:00
|
|
|
m_capabilities = new KFileItemListProperties(m_selectedItems);
|
2008-04-18 19:43:16 +00:00
|
|
|
}
|
|
|
|
return *m_capabilities;
|
|
|
|
}
|
|
|
|
|
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-09-17 19:47:01 +00:00
|
|
|
fileItemActions.addOpenWithActionsTo(m_popup.data(), "DesktopEntryName != 'dolphin'");
|
2010-08-27 05:26:27 +00:00
|
|
|
|
|
|
|
// insert 'Actions' sub menu
|
2010-09-21 19:56:35 +00:00
|
|
|
fileItemActions.addServiceActionsTo(m_popup.data());
|
2010-08-27 05:26:27 +00:00
|
|
|
}
|
|
|
|
|
2010-09-17 19:47:01 +00:00
|
|
|
void DolphinContextMenu::addVersionControlActions()
|
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();
|
|
|
|
const bool moveToTrash = capabilities().isLocal() && !m_shiftPressed;
|
|
|
|
const QAction* action = moveToTrash ? collection->action("move_to_trash") : collection->action("delete");
|
|
|
|
m_removeAction->setText(action->text());
|
|
|
|
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"
|