]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Allow to cut, copy, paste, ... the currently selected item from a sidebar by the...
authorPeter Penz <peter.penz19@gmail.com>
Sat, 17 Mar 2007 20:42:26 +0000 (20:42 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 17 Mar 2007 20:42:26 +0000 (20:42 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=643572

src/dolphincontextmenu.cpp
src/dolphincontextmenu.h
src/dolphinview.cpp
src/dolphinview.h
src/treeviewsidebarpage.cpp

index 2475c68bcf19ed93d2996663bbf4e34d8100c4ea..6ff20fe7f5137d8705718e18a0cbd2161174fd2b 100644 (file)
@@ -68,6 +68,10 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent,
     }
 }
 
+DolphinContextMenu::~DolphinContextMenu()
+{
+}
+
 void DolphinContextMenu::open()
 {
     // get the context information
@@ -98,8 +102,39 @@ void DolphinContextMenu::open()
     }
 }
 
-DolphinContextMenu::~DolphinContextMenu()
+void DolphinContextMenu::cut()
+{
+    // TODO
+}
+
+void DolphinContextMenu::copy()
+{
+    // TODO
+}
+
+void DolphinContextMenu::paste()
+{
+    // TODO
+}
+
+void DolphinContextMenu::rename()
+{
+    // TODO
+}
+
+void DolphinContextMenu::moveToTrash()
+{
+    // TODO
+}
+
+void DolphinContextMenu::deleteItem()
+{
+    // TODO
+}
+
+void DolphinContextMenu::showProperties()
 {
+    new KPropertiesDialog(m_fileInfo->url());
 }
 
 void DolphinContextMenu::openTrashContextMenu()
@@ -159,9 +194,7 @@ void DolphinContextMenu::openItemContextMenu()
     Q_ASSERT(m_fileInfo != 0);
 
     KMenu* popup = new KMenu(m_mainWindow);
-    if (m_viewType == ItemsView) {
-        insertDefaultItemActions(popup);
-    }
+    insertDefaultItemActions(popup);
 
     popup->addSeparator();
 
@@ -180,11 +213,16 @@ void DolphinContextMenu::openItemContextMenu()
     const QList<QAction*> serviceActions = insertActionItems(popup, actionsVector);
     popup->addSeparator();
 
-    if (m_viewType == ItemsView) {
-        // insert 'Properties...' entry
-        QAction* propertiesAction = m_mainWindow->actionCollection()->action("properties");
-        popup->addAction(propertiesAction);
+    // insert 'Properties...' entry
+    QAction* propertiesAction = 0;
+    if (m_viewType == SidebarView) {
+        propertiesAction = new QAction(i18n("Properties..."), this);
+        connect(this, SIGNAL(triggered()), this, SLOT(showProperties()));
     }
+    else {
+        propertiesAction = m_mainWindow->actionCollection()->action("properties");
+    }
+    popup->addAction(propertiesAction);
 
     QAction* activatedAction = popup->exec(QCursor::pos());
 
@@ -283,18 +321,45 @@ void DolphinContextMenu::openViewportContextMenu()
 void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
 {
     Q_ASSERT(popup != 0);
+    const KActionCollection* collection = m_mainWindow->actionCollection();
+    const bool insertSidebarActions = (m_viewType == SidebarView);
 
     // insert 'Cut', 'Copy' and 'Paste'
-    QAction* cutAction   = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Cut));
-    QAction* copyAction  = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Copy));
-    QAction* pasteAction = m_mainWindow->actionCollection()->action(KStandardAction::stdName(KStandardAction::Paste));
+    QAction* cutAction = 0;
+    QAction* copyAction = 0;
+    QAction* pasteAction = 0;
+    if (insertSidebarActions) {
+        cutAction   = new QAction(KIcon("edit-cut"), i18n("Cut"), this);
+        connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
+
+        copyAction  = new QAction(KIcon("edit-copy"), i18n("Copy"), this);
+        connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
+
+        const QAction* menuPasteAction = collection->action(KStandardAction::stdName(KStandardAction::Paste));
+        pasteAction = new QAction(KIcon("edit-paste"), menuPasteAction->text(), this);
+        pasteAction->setEnabled(menuPasteAction->isEnabled());
+        connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
+    }
+    else {
+        cutAction   = collection->action(KStandardAction::stdName(KStandardAction::Cut));
+        copyAction  = collection->action(KStandardAction::stdName(KStandardAction::Copy));
+        pasteAction = collection->action(KStandardAction::stdName(KStandardAction::Paste));
+    }
+
     popup->addAction(cutAction);
     popup->addAction(copyAction);
     popup->addAction(pasteAction);
     popup->addSeparator();
 
     // insert 'Rename'
-    QAction* renameAction = m_mainWindow->actionCollection()->action("rename");
+    QAction* renameAction = 0;
+    if (insertSidebarActions) {
+        renameAction = new QAction(i18n("Rename"), this);
+        connect(renameAction, SIGNAL(triggered()), this, SLOT(paste()));
+    }
+    else {
+        collection->action("rename");
+    }
     popup->addAction(renameAction);
 
     // insert 'Move to Trash' and (optionally) 'Delete'
@@ -303,7 +368,14 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
     bool showDeleteCommand = kdeConfig.readEntry("ShowDeleteCommand", false);
     const KUrl& url = m_mainWindow->activeView()->url();
     if (url.isLocalFile()) {
-        QAction* moveToTrashAction = m_mainWindow->actionCollection()->action("move_to_trash");
+        QAction* moveToTrashAction = 0;
+        if (insertSidebarActions) {
+            moveToTrashAction = new QAction(KIcon("edit-trash"), i18n("Move To Trash"), this);
+            connect(moveToTrashAction, SIGNAL(triggered()), this, SLOT(moveToTrash()));
+        }
+        else {
+            collection->action("move_to_trash");
+        }
         popup->addAction(moveToTrashAction);
     }
     else {
@@ -311,7 +383,14 @@ void DolphinContextMenu::insertDefaultItemActions(KMenu* popup)
     }
 
     if (showDeleteCommand) {
-        QAction* deleteAction = m_mainWindow->actionCollection()->action("delete");
+        QAction* deleteAction = 0;
+        if (insertSidebarActions) {
+            deleteAction = new QAction(KIcon("edit-delete"), i18n("Delete"), this);
+            connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteItem()));
+        }
+        else {
+            collection->action("delete");
+        }
         popup->addAction(deleteAction);
     }
 }
@@ -536,3 +615,5 @@ bool DolphinContextMenu::containsEntry(const KMenu* menu,
 
     return false;
 }
+
+#include "dolphincontextmenu.moc"
index 09288c6026630eb60b72cfb2d09f368c63172330..2a678d9a2b08c61fa2755e8cb934b9b4c1270e0f 100644 (file)
@@ -25,6 +25,7 @@
 #include <kservice.h>
 #include <kurl.h>
 
+#include <QObject>
 #include <QString>
 #include <QVector>
 
@@ -45,8 +46,10 @@ class DolphinMainWindow;
  * - 'Actions':   Contains all actions which can be applied to the
  *                given item.
  */
-class DolphinContextMenu
+class DolphinContextMenu : public QObject
 {
+    Q_OBJECT
+
 public:
     enum ViewType
     {
@@ -74,6 +77,28 @@ public:
     /** Opens the context menu modal. */
     void open();
 
+private slots:
+    /** Cuts the item m_fileInfo. */
+    void cut();
+
+    /** Copies the item m_fileInfo. */
+    void copy();
+
+    /** Paste the clipboard to m_fileInfo. */
+    void paste();
+
+    /** Renames the item m_fileInfo. */
+    void rename();
+
+    /** Moves the item m_fileInfo to the trash. */
+    void moveToTrash();
+
+    /** Deletes the item m_fileInfo. */
+    void deleteItem();
+
+    /** Shows the properties of the item m_fileInfo. */
+    void showProperties();
+
 private:
     void openTrashContextMenu();
     void openTrashItemContextMenu();
index 994f03b6e86280b4456cca1fe13a4da4edc27721..db9c740cc2e83a41c55239bdb020d7b4acddeb94 100644 (file)
@@ -460,6 +460,11 @@ bool DolphinView::hasSelection() const
     return itemView()->selectionModel()->hasSelection();
 }
 
+void DolphinView::clearSelection()
+{
+    itemView()->selectionModel()->clear();
+}
+
 KFileItemList DolphinView::selectedItems() const
 {
     const QAbstractItemView* view = itemView();
index 218411208f4731960375ecb467341b82de41c81a..fd47e1fae24df9f7bab0e159077ceecc955db5af 100644 (file)
@@ -219,11 +219,11 @@ public:
      */
     const QLinkedList<UrlNavigator::HistoryElem> urlHistory(int& index) const;
 
-    /**
-     * Returns true, if at least one item is selected.
-     */
+    /** Returns true, if at least one item is selected. */
     bool hasSelection() const;
 
+    void clearSelection();
+
     /**
      * Returns the selected items. The list is empty if no item has been
      * selected.
@@ -250,7 +250,6 @@ public:
      */
     void rename(const KUrl& source, const QString& newName);
 
-    /** Returns the status bar of the view. */
     DolphinStatusBar* statusBar() const;
 
     /**
index b7c1f1f537b619e19c1f8d4e49b98cc4804f9e93..4dddeae5c7efc4416084b2be71aa294ce6cc3599 100644 (file)
@@ -121,6 +121,7 @@ void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event)
     KFileItem* item = m_dirModel->itemForIndex(index);
 #endif
 
+    mainWindow()->activeView()->clearSelection();
     DolphinContextMenu contextMenu(mainWindow(),
                                    item,
                                    m_dirLister->url(),