diff -Naur plasma/applets/kickoff/CMakeLists.txt plasma/applets/kickoff/CMakeLists.txt --- plasma/applets/kickoff/CMakeLists.txt 2009-03-22 12:26:45.000000000 +0100 +++ plasma/applets/kickoff/CMakeLists.txt 2009-03-22 12:27:57.000000000 +0100 @@ -68,7 +68,12 @@ ####################################################################################### # Kickoff Simple KMenu Plasma Applet -set(SimpleApplet_SRCS ${Kickoff_SRCS} simpleapplet/menuview.cpp simpleapplet/simpleapplet.cpp simpleapplet/toptile.cpp) +set(SimpleApplet_SRCS ${Kickoff_SRCS} + simpleapplet/menuview.cpp + simpleapplet/simpleapplet.cpp + simpleapplet/toptile.cpp + ui/contextmenufactory.cpp + ) kde4_add_plugin(plasma_applet_simplelauncher ${SimpleApplet_SRCS}) target_link_libraries(plasma_applet_simplelauncher ${KDE4_KUTILS_LIBS} ${KDE4_PLASMA_LIBS} solidcontrol ${Kickoff_LIBS} kickoff) install(TARGETS plasma_applet_simplelauncher DESTINATION ${PLUGIN_INSTALL_DIR}) diff -Naur plasma/applets/kickoff/simpleapplet/simpleapplet.h plasma/applets/kickoff/simpleapplet/simpleapplet.h --- plasma/applets/kickoff/simpleapplet/simpleapplet.h 2009-03-22 12:26:45.000000000 +0100 +++ plasma/applets/kickoff/simpleapplet/simpleapplet.h 2009-03-22 12:27:57.000000000 +0100 @@ -113,6 +113,10 @@ * Start the menu editor by launching kmenuedit. */ void startMenuEditor(); + /** + * Show a custom context menu for the selected action. + */ + void customContextMenuRequested(const QPoint& pos); protected: /** diff -Naur plasma/applets/kickoff/ui/contextmenufactory.cpp plasma/applets/kickoff/ui/contextmenufactory.cpp --- plasma/applets/kickoff/ui/contextmenufactory.cpp 2009-01-06 18:22:34.000000000 +0100 +++ plasma/applets/kickoff/ui/contextmenufactory.cpp 2009-03-22 12:27:57.000000000 +0100 @@ -47,6 +47,8 @@ #include "core/favoritesmodel.h" #include "core/models.h" +Q_DECLARE_METATYPE(QPersistentModelIndex) + using namespace Kickoff; class ContextMenuFactory::Private @@ -101,11 +103,15 @@ delete d; } -void ContextMenuFactory::showContextMenu(QAbstractItemView *view, const QPoint &pos) +void ContextMenuFactory::showContextMenu(QAbstractItemView *view, + const QPersistentModelIndex& index, const QPoint& pos) { - Q_ASSERT(view); + Q_UNUSED(pos); + + if (!index.isValid()) { + return; + } - const QModelIndex index = view->indexAt(pos); const QString url = index.data(UrlRole).value<QString>(); if (url.isEmpty()) { @@ -192,9 +198,11 @@ // add view specific actions QAction *viewSeparator = new QAction(this); - viewSeparator->setSeparator(true); - actions << viewSeparator; - actions << viewActions(view); + if (view) { + viewSeparator->setSeparator(true); + actions << viewSeparator; + actions << viewActions(view); + } // display menu KMenu menu; diff -Naur plasma/applets/kickoff/ui/contextmenufactory.h plasma/applets/kickoff/ui/contextmenufactory.h --- plasma/applets/kickoff/ui/contextmenufactory.h 2008-11-19 11:18:14.000000000 +0100 +++ plasma/applets/kickoff/ui/contextmenufactory.h 2009-03-22 12:31:57.000000000 +0100 @@ -21,6 +21,7 @@ // Qt #include <QAction> +#include <QPersistentModelIndex> // Plasma #include <Plasma/Applet> @@ -44,7 +45,7 @@ void setApplet(Plasma::Applet *applet); public Q_SLOTS: - void showContextMenu(QAbstractItemView *view, const QPoint& pos); + void showContextMenu(QAbstractItemView *view, const QPersistentModelIndex& index, const QPoint& pos); private: class Private; diff -Naur plasma/applets/kickoff/ui/launcher.cpp plasma/applets/kickoff/ui/launcher.cpp --- plasma/applets/kickoff/ui/launcher.cpp 2009-01-01 17:26:06.000000000 +0100 +++ plasma/applets/kickoff/ui/launcher.cpp 2009-03-22 12:27:57.000000000 +0100 @@ -707,7 +707,8 @@ { QAbstractItemView *view = qobject_cast<QAbstractItemView*>(sender()); if (view) { - d->contextMenuFactory->showContextMenu(view, pos); + const QModelIndex index = view->indexAt(pos); + d->contextMenuFactory->showContextMenu(view, index, pos); } } --- plasma/applets/kickoff/simpleapplet/simpleapplet.cpp~ 2009-04-02 05:40:33.000000000 +0200 +++ plasma/applets/kickoff/simpleapplet/simpleapplet.cpp 2009-04-02 05:45:13.000000000 +0200 @@ -75,6 +75,9 @@ #include "core/leavemodel.h" #include "core/urlitemlauncher.h" #include "core/recentapplications.h" +#include "ui/contextmenufactory.h" + +Q_DECLARE_METATYPE(QPersistentModelIndex) // @internal KBookmarkOwner specialization class BookmarkOwner : public KBookmarkOwner @@ -119,6 +122,7 @@ QList<QAction*> actions; QAction* switcher; + Kickoff::ContextMenuFactory *contextMenuFactory; explicit Private(MenuLauncherApplet *q); ~Private() { @@ -278,7 +282,8 @@ view(0), iconButton(0), formatComboBox(0), - switcher(0) + switcher(0), + contextMenuFactory(0) { } @@ -306,6 +311,9 @@ layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); layout->addItem(d->icon); + + d->contextMenuFactory = new Kickoff::ContextMenuFactory(this); + d->contextMenuFactory->setApplet(this); } MenuLauncherApplet::~MenuLauncherApplet() @@ -410,6 +418,20 @@ KProcess::execute("kmenuedit"); } +void MenuLauncherApplet::customContextMenuRequested(const QPoint& pos) +{ + if (!d->menuview) { + return; + } + + QAction* menuAction = d->menuview->actionAt(pos); + if (menuAction) { + const QPersistentModelIndex index = menuAction->data().value<QPersistentModelIndex>(); + d->contextMenuFactory->showContextMenu(0, index, pos); + } +} + + void MenuLauncherApplet::createConfigurationInterface(KConfigDialog *parent) { QWidget *viewpage = new QWidget(parent); @@ -551,8 +573,11 @@ d->menuview = new Kickoff::MenuView(); d->menuview->setAttribute(Qt::WA_DeleteOnClose); d->menuview->setFormatType( (Kickoff::MenuView::FormatType) d->formattype ); + d->menuview->setContextMenuPolicy(Qt::CustomContextMenu); connect(d->menuview, SIGNAL(triggered(QAction*)), this, SLOT(actionTriggered(QAction*))); connect(d->menuview, SIGNAL(aboutToHide()), d->icon, SLOT(setUnpressed())); + connect(d->menuview, SIGNAL(customContextMenuRequested(const QPoint&)), + this, SLOT(customContextMenuRequested(const QPoint&))); //connect(d->menuview, SIGNAL(afterBeingHidden()), d->menuview, SLOT(deleteLater())); KConfig *cfg = new KConfig("mandrivarc"); KConfigGroup grp = cfg->group("menu");