Implementing shift delete in dolphin, some help would be nice.
Mark
markg85 at gmail.com
Mon Sep 13 21:00:36 BST 2010
On Mon, Sep 13, 2010 at 9:45 PM, Mark <markg85 at gmail.com> wrote:
> Hi,
>
> I'm trying to fix this bug:
> https://bugs.kde.org/show_bug.cgi?id=194275
>
> And for that i made this patch:
> http://pastebin.com/GEi2BJvv
>
> However i have a few issues.
> I'm using "KModifierKeyInfo" :
> http://api.kde.org/4.x-api/kdelibs-apidocs/kdeui/html/classKModifierKeyInfo.html but
> am having issues getting it to work. The way it's used in the patch blocks
> the gui. This is what happens, in the patch i listen to "shift" key pressed
> while opening the context menu however, the effect is that the gui now
> simply blocks when you press shift on a selected file followed by a right
> click (to open the context menu).
>
> Another issue i have is: How can can change the "Move to trash" to
> "Delete"? I made a class wide for it: "m_deleteOrTrashMenuEntry" but if i
> change it to some other menu entry while the context menu is open it simply
> remains what is was before i changed it... I guess i need to repaint
> something but what?
>
> I hope this made some sense and that someone can point me in the right
> direction to solve this issue.
>
> Thanx,
> Mark
>
Hmm, using pastebin for a mailing list isn't really smart.. Here is the raw
diff:
Index: src/dolphincontextmenu.cpp
===================================================================
--- src/dolphincontextmenu.cpp (revision 1174907)
+++ src/dolphincontextmenu.cpp (working copy)
@@ -69,6 +69,9 @@
const DolphinView* view = m_mainWindow->activeViewContainer()->view();
m_selectedUrls = view->selectedUrls();
m_selectedItems = view->selectedItems();
+ m_keyInfo = new KModifierKeyInfo();
+
+ connect(m_keyInfo, SIGNAL(keyPressed(Qt::Key,bool)), this,
SLOT(deleteOrTrashMenuEntry(Qt::Key,bool)));
}
DolphinContextMenu::~DolphinContextMenu()
@@ -337,8 +340,8 @@
const KUrl& url = m_mainWindow->activeViewContainer()->url();
if (url.isLocalFile()) {
- QAction* moveToTrashAction = collection->action("move_to_trash");
- popup->addAction(moveToTrashAction);
+ m_deleteOrTrashMenuEntry = collection->action("move_to_trash");
+ popup->addAction(m_deleteOrTrashMenuEntry);
} else {
showDeleteCommand = true;
}
@@ -439,4 +442,24 @@
}
}
+void DolphinContextMenu::deleteOrTrashMenuEntry(Qt::Key key, bool pressed)
+{
+ // insert 'Move to Trash' and (optionally) 'Delete'
+ KSharedConfig::Ptr globalConfig =
KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals);
+ KConfigGroup configGroup(globalConfig, "KDE");
+ bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand",
false);
+
+ if(key == Qt::Key_Shift && !showDeleteCommand) {
+ if(pressed) {
+ m_deleteOrTrashMenuEntry =
m_mainWindow->actionCollection()->action("delete");
+ qDebug() << "DELETE...";
+ }
+ else {
+ m_deleteOrTrashMenuEntry =
m_mainWindow->actionCollection()->action("move_to_trash");
+ qDebug() << "MOVE TO TRASH...";
+ }
+
+ }
+}
+
#include "dolphincontextmenu.moc"
Index: src/dolphincontextmenu.h
===================================================================
--- src/dolphincontextmenu.h (revision 1174907)
+++ src/dolphincontextmenu.h (working copy)
@@ -25,6 +25,7 @@
#include <kservice.h>
#include <kurl.h>
#include <konq_copytomenu.h>
+#include <kmodifierkeyinfo.h>
#include <QtCore/QObject>
@@ -74,6 +75,9 @@
/** Opens the context menu model. */
void open();
+public slots:
+ void deleteOrTrashMenuEntry(Qt::Key key, bool pressed);
+
private:
void openTrashContextMenu();
void openTrashItemContextMenu();
@@ -130,6 +134,8 @@
int m_context;
KonqCopyToMenu m_copyToMenu;
QList<QAction*> m_customActions;
+ QAction* m_deleteOrTrashMenuEntry;
+ KModifierKeyInfo* m_keyInfo;
};
#endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20100913/4355bf1d/attachment.htm>
More information about the kde-core-devel
mailing list