Port to KStandardAction::MoveToTrash

It was introduced in kconfig(widgets) 5.25. Using the standard action
results in less code and no need to hardcode the Del shortcut.

Test Plan:
- Change shortcut in System Settings -> Shortcuts -> Standard Shortcuts
- Make sure the new shortcut is used by dolphin.

Differential Revision: https://phabricator.kde.org/D6778
This commit is contained in:
Elvis Angelaccio 2017-07-19 00:00:37 +02:00
parent 82b2dbd3ec
commit 4b5ea05b67
8 changed files with 17 additions and 23 deletions

View file

@ -405,7 +405,7 @@ void DolphinContextMenu::insertDefaultItemActions(const KFileItemListProperties&
if (showDeleteAction && showMoveToTrashAction) {
delete m_removeAction;
m_removeAction = 0;
addAction(m_mainWindow->actionCollection()->action(QStringLiteral("move_to_trash")));
addAction(m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash)));
addAction(m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
} else if (showDeleteAction && !showMoveToTrashAction) {
addAction(m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));

View file

@ -1317,7 +1317,7 @@ void DolphinMainWindow::updateEditActions()
KActionCollection* col = actionCollection();
QAction* renameAction = col->action(QStringLiteral("rename"));
QAction* moveToTrashAction = col->action(QStringLiteral("move_to_trash"));
QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler

View file

@ -254,7 +254,7 @@ void DolphinPart::slotSelectionChanged(const KFileItemList& selection)
const bool hasSelection = !selection.isEmpty();
QAction* renameAction = actionCollection()->action(QStringLiteral("rename"));
QAction* moveToTrashAction = actionCollection()->action(QStringLiteral("move_to_trash"));
QAction* moveToTrashAction = actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash));
QAction* deleteAction = actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile));
QAction* editMimeTypeAction = actionCollection()->action(QStringLiteral("editMimeType"));
QAction* propertiesAction = actionCollection()->action(QStringLiteral("properties"));
@ -432,7 +432,7 @@ void DolphinPart::slotOpenContextMenu(const QPoint& pos,
if (showDeleteAction && showMoveToTrashAction) {
delete m_removeAction;
m_removeAction = 0;
editActions.append(actionCollection()->action(QStringLiteral("move_to_trash")));
editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash)));
editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
} else if (showDeleteAction && !showMoveToTrashAction) {
editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));

View file

@ -1,11 +1,11 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="dolphinpart" version="12" translationDomain="dolphin">
<kpartgui name="dolphinpart" version="13" translationDomain="dolphin">
<MenuBar>
<Menu name="edit"><text>&amp;Edit</text>
<Action name="new_menu"/>
<Separator/>
<Action name="rename"/>
<Action name="move_to_trash" />
<Action name="movetotrash" />
<Action name="deletefile"/>
<Action name="editMimeType"/>
<Action name="properties"/>
@ -52,14 +52,14 @@
</ToolBar>
<State name="has_selection" >
<enable>
<Action name="move_to_trash" />
<Action name="movetotrash" />
<Action name="deletefile" />
</enable>
</State>
<State name="has_no_selection" >
<disable>
<Action name="rename" />
<Action name="move_to_trash" />
<Action name="movetotrash" />
<Action name="deletefile" />
</disable>
</State>

View file

@ -49,7 +49,7 @@ void DolphinRemoveAction::update()
m_action = m_collection ? m_collection->action(KStandardAction::name(KStandardAction::DeleteFile)) : 0;
setText(i18nc("@action:inmenu", "&Delete"));
} else {
m_action = m_collection ? m_collection->action(QStringLiteral("move_to_trash")) : 0;
m_action = m_collection ? m_collection->action(KStandardAction::name(KStandardAction::MoveToTrash)) : 0;
setText(i18nc("@action:inmenu", "&Move to Trash"));
}

View file

@ -31,7 +31,7 @@
* A QAction that manages the delete based on the current state of
* the Shift key or the parameter passed to update.
*
* This class expects the presence of both the "move_to_trash" and
* This class expects the presence of both the KStandardAction::MoveToTrash and
* KStandardAction::DeleteFile actions in @ref collection.
*/
class DOLPHIN_EXPORT DolphinRemoveAction : public QAction

View file

@ -1,5 +1,5 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
<kpartgui name="dolphin" version="15">
<kpartgui name="dolphin" version="16">
<MenuBar>
<Menu name="file">
<Action name="new_menu" />
@ -9,7 +9,7 @@
<Action name="undo_close_tab" />
<Separator/>
<Action name="rename" />
<Action name="move_to_trash" />
<Action name="movetotrash" />
<Action name="deletefile" />
<Separator/>
<Action name="properties" />
@ -57,7 +57,7 @@
<Action name="edit_cut" />
<Action name="edit_copy" />
<Action name="rename" />
<Action name="move_to_trash" />
<Action name="movetotrash" />
<Action name="deletefile" />
<Action name="invert_selection" />
<Separator/>
@ -70,7 +70,7 @@
<Action name="edit_cut" />
<Action name="edit_copy" />
<Action name="rename" />
<Action name="move_to_trash" />
<Action name="movetotrash" />
<Action name="deletefile" />
<Action name="invert_selection" />
</enable>
@ -80,7 +80,7 @@
<Action name="edit_cut" />
<Action name="edit_copy" />
<Action name="rename" />
<Action name="move_to_trash" />
<Action name="movetotrash" />
<Action name="deletefile" />
<Action name="delete_shortcut" />
<Action name="invert_selection" />

View file

@ -113,16 +113,10 @@ void DolphinViewActionHandler::createActions()
rename->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename")));
connect(rename, &QAction::triggered, this, &DolphinViewActionHandler::slotRename);
QAction* moveToTrash = m_actionCollection->addAction(QStringLiteral("move_to_trash"));
moveToTrash->setText(i18nc("@action:inmenu File", "Move to Trash"));
moveToTrash->setIcon(QIcon::fromTheme(QStringLiteral("user-trash")));
m_actionCollection->setDefaultShortcut(moveToTrash, QKeySequence::Delete);
connect(moveToTrash, &QAction::triggered,
this, &DolphinViewActionHandler::slotTrashActivated);
KStandardAction::moveToTrash(this, &DolphinViewActionHandler::slotTrashActivated, m_actionCollection);
KStandardAction::deleteFile(this, &DolphinViewActionHandler::slotDeleteItems, m_actionCollection);
// This action is useful for being enabled when "move_to_trash" should be
// This action is useful for being enabled when KStandardAction::MoveToTrash should be
// disabled and KStandardAction::DeleteFile is enabled (e.g. non-local files), so that Key_Del
// can be used for deleting the file (#76016). It needs to be a separate action
// so that the Edit menu isn't affected.