diff --git a/plugins/projectmanagerview/projectmanagerview.cpp b/plugins/projectmanagerview/projectmanagerview.cpp --- a/plugins/projectmanagerview/projectmanagerview.cpp +++ b/plugins/projectmanagerview/projectmanagerview.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -146,16 +147,17 @@ if (obj == m_ui->projectTreeView) { if (event->type() == QEvent::KeyRelease) { QKeyEvent* keyEvent = static_cast(event); - if (keyEvent->key() == Qt::Key_Delete && keyEvent->modifiers() == Qt::NoModifier) { + QKeySequence shortcut = QKeySequence(keyEvent->modifiers() + keyEvent->key()); + if (m_plugin->removeAction() && shortcut == m_plugin->removeAction()->shortcut()) { m_plugin->removeItems(selectedItems()); return true; - } else if (keyEvent->key() == Qt::Key_F2 && keyEvent->modifiers() == Qt::NoModifier) { + } else if (m_plugin->renameAction() && shortcut == m_plugin->renameAction()->shortcut()) { m_plugin->renameItems(selectedItems()); return true; - } else if (keyEvent->key() == Qt::Key_C && keyEvent->modifiers() == Qt::ControlModifier) { + } else if (m_plugin->copyAction() && shortcut == m_plugin->copyAction()->shortcut()) { m_plugin->copyFromContextMenu(); return true; - } else if (keyEvent->key() == Qt::Key_V && keyEvent->modifiers() == Qt::ControlModifier) { + } else if (m_plugin->pasteAction() && shortcut == m_plugin->pasteAction()->shortcut()) { m_plugin->pasteFromContextMenu(); return true; } diff --git a/plugins/projectmanagerview/projectmanagerviewplugin.h b/plugins/projectmanagerview/projectmanagerviewplugin.h --- a/plugins/projectmanagerview/projectmanagerviewplugin.h +++ b/plugins/projectmanagerview/projectmanagerviewplugin.h @@ -59,6 +59,11 @@ void removeItems(const QList& items); void renameItems(const QList< KDevelop::ProjectBaseItem* >& items); + const QAction* removeAction(); + const QAction* renameAction(); + const QAction* copyAction(); + const QAction* pasteAction(); + public Q_SLOTS: void buildProjectItems(); void installProjectItems(); diff --git a/plugins/projectmanagerview/projectmanagerviewplugin.cpp b/plugins/projectmanagerview/projectmanagerviewplugin.cpp --- a/plugins/projectmanagerview/projectmanagerviewplugin.cpp +++ b/plugins/projectmanagerview/projectmanagerviewplugin.cpp @@ -83,6 +83,10 @@ { public: ProjectManagerViewPluginPrivate() + : m_remove(0), + m_rename(0), + m_copy(0), + m_paste(0) {} KDevProjectManagerViewFactory *factory; QList ctxProjectItemList; @@ -92,6 +96,10 @@ QAction* m_clean; QAction* m_configure; QAction* m_prune; + QAction* m_remove; + QAction* m_rename; + QAction* m_copy; + QAction* m_paste; }; static QList itemsFromIndexes(const QList& indexes) @@ -285,14 +293,18 @@ menuExt.addAction( ContextMenuExtension::FileGroup, action ); } if ( needsRemoveAndRename ) { - QAction* remove = new QAction( i18n( "Remove" ), this ); - remove->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); - connect( remove, &QAction::triggered, this, &ProjectManagerViewPlugin::removeFromContextMenu ); - menuExt.addAction( ContextMenuExtension::FileGroup, remove ); - QAction* rename = new QAction( i18n( "Rename..." ), this ); - rename->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); - connect( rename, &QAction::triggered, this, &ProjectManagerViewPlugin::renameItemFromContextMenu ); - menuExt.addAction( ContextMenuExtension::FileGroup, rename ); + d->m_remove = new QAction( i18n( "Remove" ), this ); + d->m_remove->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); + actionCollection()->setDefaultShortcut( d->m_remove, Qt::NoModifier + Qt::Key_Delete ); + connect( d->m_remove, &QAction::triggered, this, &ProjectManagerViewPlugin::removeFromContextMenu ); + actionCollection()->addAction( QStringLiteral("trash_items"), d->m_remove ); + menuExt.addAction( ContextMenuExtension::FileGroup, d->m_remove ); + d->m_rename = new QAction( i18n( "Rename..." ), this ); + d->m_rename->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); + actionCollection()->setDefaultShortcut( d->m_rename, Qt::NoModifier + Qt::Key_F2 ); + connect( d->m_rename, &QAction::triggered, this, &ProjectManagerViewPlugin::renameItemFromContextMenu ); + actionCollection()->addAction( QStringLiteral("rename_items"), d->m_rename ); + menuExt.addAction( ContextMenuExtension::FileGroup, d->m_rename ); } if ( needsRemoveTargetFiles ) { QAction* remove = new QAction( i18n( "Remove From Target" ), this ); @@ -302,14 +314,16 @@ } { - QAction* copy = KStandardAction::copy(this, SLOT(copyFromContextMenu()), this); - copy->setShortcutContext(Qt::WidgetShortcut); - menuExt.addAction( ContextMenuExtension::FileGroup, copy ); + d->m_copy = KStandardAction::copy(this, SLOT(copyFromContextMenu()), this); + d->m_copy->setShortcutContext(Qt::WidgetShortcut); + d->m_copy->setShortcut(Qt::ControlModifier + Qt::Key_C); + menuExt.addAction( ContextMenuExtension::FileGroup, d->m_copy ); } if (needsPaste) { - QAction* paste = KStandardAction::paste(this, SLOT(pasteFromContextMenu()), this); - paste->setShortcutContext(Qt::WidgetShortcut); - menuExt.addAction( ContextMenuExtension::FileGroup, paste ); + d->m_paste = KStandardAction::paste(this, SLOT(pasteFromContextMenu()), this); + d->m_paste->setShortcutContext(Qt::WidgetShortcut); + d->m_paste->setShortcut(Qt::ControlModifier + Qt::Key_V); + menuExt.addAction( ContextMenuExtension::FileGroup, d->m_paste ); } return menuExt; @@ -710,6 +724,25 @@ } } +const QAction *ProjectManagerViewPlugin::removeAction() +{ + return d->m_remove; +} + +const QAction *ProjectManagerViewPlugin::renameAction() +{ + return d->m_rename; +} + +const QAction *ProjectManagerViewPlugin::copyAction() +{ + return d->m_copy; +} + +const QAction *ProjectManagerViewPlugin::pasteAction() +{ + return d->m_paste; +} #include "projectmanagerviewplugin.moc"