#include "dolphinnewfilemenu.h"
#include "dolphinviewcontainer.h"
#include "dolphin_generalsettings.h"
+#include "dolphinremoveaction.h"
#include <KActionCollection>
#include <KDesktopFile>
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()
void DolphinContextMenu::keyPressEvent(QKeyEvent *ev)
{
if (ev->key() == Qt::Key_Shift) {
- m_shiftPressed = true;
- updateRemoveAction();
+ m_removeAction->update();
}
KMenu::keyPressEvent(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);
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();
}
}
addAction(collection->action("delete"));
} else {
addAction(m_removeAction);
- updateRemoveAction();
+ m_removeAction->update();
}
}
}
}
-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"