]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/treeviewsidebarpage.cpp
fixed typo
[dolphin.git] / src / treeviewsidebarpage.cpp
index b1fcc8daa87655d9a055d68dde1f9d09a8bd6fa8..b7c1f1f537b619e19c1f8d4e49b98cc4804f9e93 100644 (file)
@@ -20,6 +20,7 @@
 #include "treeviewsidebarpage.h"
 
 #include "bookmarkselector.h"
+#include "dolphincontextmenu.h"
 #include "dolphinmainwindow.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphinview.h"
@@ -78,10 +79,11 @@ TreeViewSidebarPage::TreeViewSidebarPage(DolphinMainWindow* mainWindow,
 
     connect(m_treeView, SIGNAL(clicked(const QModelIndex&)),
             this, SLOT(updateActiveView(const QModelIndex&)));
-    connect(m_treeView, SIGNAL(doubleClicked(const QModelIndex&)),
-            this, SLOT(slotDoubleClicked(const QModelIndex&)));
+    connect(m_treeView, SIGNAL(urlsDropped(const KUrl::List&, const QModelIndex&)),
+            this, SLOT(dropUrls(const KUrl::List&, const QModelIndex&)));
 
     QVBoxLayout* layout = new QVBoxLayout(this);
+    layout->setMargin(0);
     layout->addWidget(m_treeView);
 }
 
@@ -102,6 +104,30 @@ void TreeViewSidebarPage::showEvent(QShowEvent* event)
     connectToActiveView();
 }
 
+void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event)
+{
+    SidebarPage::contextMenuEvent(event);
+
+    const QModelIndex index = m_treeView->indexAt(event->pos());
+    if (!index.isValid()) {
+        // only open a context menu above a directory item
+        return;
+    }
+
+#if defined(USE_PROXY_MODEL)
+    const QModelIndex dirModelIndex = m_proxyModel->mapToSource(index);
+    KFileItem* item = m_dirModel->itemForIndex(dirModelIndex);
+#else
+    KFileItem* item = m_dirModel->itemForIndex(index);
+#endif
+
+    DolphinContextMenu contextMenu(mainWindow(),
+                                   item,
+                                   m_dirLister->url(),
+                                   DolphinContextMenu::SidebarView);
+    contextMenu.open();
+}
+
 void TreeViewSidebarPage::updateSelection(const KUrl& url)
 {
     if (!url.isValid() || (url == m_selectedUrl)) {
@@ -201,6 +227,23 @@ void TreeViewSidebarPage::updateActiveView(const QModelIndex& index)
     }
 }
 
+void TreeViewSidebarPage::dropUrls(const KUrl::List& urls,
+                                   const QModelIndex& index)
+{
+    if (index.isValid()) {
+#if defined(USE_PROXY_MODEL)
+        const QModelIndex& dirIndex = m_proxyModel->mapToSource(index);
+        KFileItem* item = m_dirModel->itemForIndex(dirIndex);
+#else
+        KFileItem* item = m_dirModel->itemForIndex(index);
+#endif
+        Q_ASSERT(item != 0);
+        if (item->isDir()) {
+            mainWindow()->dropUrls(urls, item->url());
+        }
+    }
+}
+
 void TreeViewSidebarPage::connectToActiveView()
 {
     const QWidget* parent = parentWidget();