X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/600166152d857ccfc9df15b25bd1237b74c71d43..a05db2f0d081a67f306141e2f31442eea49dd71b:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 89a169f32..f66847334 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -24,6 +24,7 @@ #include "dolphinnewfilemenu.h" #include "dolphinviewcontainer.h" #include "dolphin_generalsettings.h" +#include "dolphinremoveaction.h" #include #include @@ -73,17 +74,14 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, m_context(NoContext), m_copyToMenu(parent), m_customActions(), - m_command(None), - m_shiftPressed(qApp->keyboardModifiers() & Qt::ShiftModifier), - m_removeAction(0) + m_command(None) { // The context menu either accesses the URLs of the selected items // or the items itself. To increase the performance both lists are cached. const DolphinView* view = m_mainWindow->activeViewContainer()->view(); m_selectedItems = view->selectedItems(); - m_removeAction = new QAction(this); - connect(m_removeAction, SIGNAL(triggered()), this, SLOT(slotRemoveActionTriggered())); + m_removeAction = new DolphinRemoveAction(this, m_mainWindow->actionCollection()); } DolphinContextMenu::~DolphinContextMenu() @@ -129,8 +127,7 @@ DolphinContextMenu::Command DolphinContextMenu::open() void DolphinContextMenu::keyPressEvent(QKeyEvent *ev) { if (ev->key() == Qt::Key_Shift) { - m_shiftPressed = true; - updateRemoveAction(); + m_removeAction->update(); } KMenu::keyPressEvent(ev); } @@ -138,23 +135,11 @@ void DolphinContextMenu::keyPressEvent(QKeyEvent *ev) void DolphinContextMenu::keyReleaseEvent(QKeyEvent *ev) { if (ev->key() == Qt::Key_Shift) { - // not just "m_shiftPressed = false", the user could be playing with both Shift keys... - m_shiftPressed = qApp->keyboardModifiers() & Qt::ShiftModifier; - updateRemoveAction(); + m_removeAction->update(); } KMenu::keyReleaseEvent(ev); } -void DolphinContextMenu::slotRemoveActionTriggered() -{ - const KActionCollection* collection = m_mainWindow->actionCollection(); - if (moveToTrash()) { - collection->action("move_to_trash")->trigger(); - } else { - collection->action("delete")->trigger(); - } -} - void DolphinContextMenu::openTrashContextMenu() { Q_ASSERT(m_context & TrashContext); @@ -250,6 +235,27 @@ void DolphinContextMenu::openItemContextMenu() this); addAction(openParentInNewTabAction); + addSeparator(); + } else if (!DolphinView::openItemAsFolderUrl(m_fileInfo).isEmpty()) { + // insert 'Open in new window' and 'Open in new tab' entries + addAction(m_mainWindow->actionCollection()->action("open_in_new_window")); + addAction(m_mainWindow->actionCollection()->action("open_in_new_tab")); + + addSeparator(); + } + } else { + bool selectionHasOnlyDirs = true; + foreach (const KFileItem& item, m_selectedItems) { + const KUrl& url = DolphinView::openItemAsFolderUrl(item); + if (url.isEmpty()) { + selectionHasOnlyDirs = false; + break; + } + } + + if (selectionHasOnlyDirs) { + // insert 'Open in new tab' entry + addAction(m_mainWindow->actionCollection()->action("open_in_new_tabs")); addSeparator(); } } @@ -374,7 +380,7 @@ void DolphinContextMenu::insertDefaultItemActions() addAction(collection->action("delete")); } else { addAction(m_removeAction); - updateRemoveAction(); + m_removeAction->update(); } } @@ -470,20 +476,25 @@ void DolphinContextMenu::addFileItemPluginActions() const KConfigGroup showGroup = config.group("Show"); foreach (const KSharedPtr& service, pluginServices) { - if (!showGroup.readEntry(service->desktopEntryName(), true)) { - // The plugin has been disabled - continue; - } - // Old API (kdelibs-4.6.0 only) KFileItemActionPlugin* plugin = service->createInstance(); if (plugin) { + if (!showGroup.readEntry(service->desktopEntryName(), true)) { + // The plugin has been disabled + continue; + } + plugin->setParent(this); addActions(plugin->actions(props, m_mainWindow)); } // New API (kdelibs >= 4.6.1) KAbstractFileItemActionPlugin* abstractPlugin = service->createInstance(); if (abstractPlugin) { + if (!showGroup.readEntry(service->desktopEntryName(), abstractPlugin->enabledByDefault())) { + // The plugin has been disabled + continue; + } + abstractPlugin->setParent(this); addActions(abstractPlugin->actions(props, m_mainWindow)); } @@ -509,28 +520,4 @@ void DolphinContextMenu::addCustomActions() } } -void DolphinContextMenu::updateRemoveAction() -{ - const KActionCollection* collection = m_mainWindow->actionCollection(); - - // 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")); - } - m_removeAction->setIcon(action->icon()); - m_removeAction->setShortcuts(action->shortcuts()); -} - -bool DolphinContextMenu::moveToTrash() const -{ - return !m_shiftPressed; -} - #include "dolphincontextmenu.moc"