From 01761798a93bc93f3e16f8fb68fe5739ab66d98b Mon Sep 17 00:00:00 2001 From: Dawit Alemayehu Date: Sat, 9 Feb 2013 15:56:51 -0500 Subject: - Factored out the Delete/Move To Trash action into own class. - Updated both the Dolphin KPart and context menu to use the new DolphinRemoveAction class to manage "Delete/Move to Trash" actions. See also https://git.reviewboard.kde.org/r/107509/. REVIEW: 108802 --- src/dolphinremoveaction.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/dolphinremoveaction.cpp (limited to 'src/dolphinremoveaction.cpp') diff --git a/src/dolphinremoveaction.cpp b/src/dolphinremoveaction.cpp new file mode 100644 index 000000000..200fc407d --- /dev/null +++ b/src/dolphinremoveaction.cpp @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2013 by Dawit Alemayehu + +#include + + +DolphinRemoveAction::DolphinRemoveAction(QObject* parent, KActionCollection* collection) : + QAction(parent), + m_collection(collection) +{ + update(); + connect(this, SIGNAL(triggered()), this, SLOT(slotRemoveActionTriggered())); +} + +void DolphinRemoveAction::slotRemoveActionTriggered() +{ + if (m_action) { + m_action->trigger(); + } +} + +void DolphinRemoveAction::update() +{ + Q_ASSERT(m_collection); + // Using 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. + if (qApp->keyboardModifiers() & Qt::ShiftModifier) { + m_action = m_collection ? m_collection->action("delete") : 0; + setText(i18nc("@action:inmenu", "&Delete")); + } else { + m_action = m_collection ? m_collection->action("move_to_trash") : 0; + setText(i18nc("@action:inmenu", "&Move to Trash")); + } + + if (m_action) { + setIcon(m_action->icon()); + setShortcuts(m_action->shortcuts()); + } +} -- cgit v1.3