X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/600166152d857ccfc9df15b25bd1237b74c71d43..c69ebd1e0c5ae1803f2e7e01d433168aba57115f:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 89a169f32..cddcc8936 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,20 @@ void DolphinContextMenu::openItemContextMenu() this); addAction(openParentInNewTabAction); + 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")); addSeparator(); } } @@ -374,7 +373,7 @@ void DolphinContextMenu::insertDefaultItemActions() addAction(collection->action("delete")); } else { addAction(m_removeAction); - updateRemoveAction(); + m_removeAction->update(); } } @@ -509,28 +508,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"