]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincolumnwidget.cpp
Enable Dolphin to show the revision states of files that are under revision control...
[dolphin.git] / src / dolphincolumnwidget.cpp
index 037818cecdaf94082c5a3b782de9502101405389..afa79e78f2fe3883a0877b315f3a77526136dfa7 100644 (file)
@@ -30,6 +30,7 @@
 #include "dolphin_generalsettings.h"
 #include "draganddrophelper.h"
 #include "folderexpander.h"
+#include "revisioncontrolobserver.h"
 #include "selectionmanager.h"
 #include "tooltips/tooltipmanager.h"
 
@@ -126,6 +127,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
     const DolphinView* dolphinView = m_view->m_controller->dolphinView();
     m_proxyModel->setSorting(dolphinView->sorting());
     m_proxyModel->setSortOrder(dolphinView->sortOrder());
+    m_proxyModel->setSortFoldersFirst(dolphinView->sortFoldersFirst());
 
     setModel(m_proxyModel);
 
@@ -153,6 +155,8 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
     folderExpander->setEnabled(DolphinSettings::instance().generalSettings()->autoExpandFolders());
     connect (folderExpander, SIGNAL(enterDir(const QModelIndex&)),
              m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
+
+    new RevisionControlObserver(this);
 }
 
 DolphinColumnWidget::~DolphinColumnWidget()
@@ -170,7 +174,7 @@ void DolphinColumnWidget::setDecorationSize(const QSize& size)
     m_decorationSize = size;
     doItemsLayout();
     if (m_previewGenerator != 0) {
-        m_previewGenerator->updatePreviews();
+        m_previewGenerator->updateIcons();
     }
     if (m_selectionManager != 0) {
         m_selectionManager->reset();
@@ -210,6 +214,11 @@ void DolphinColumnWidget::setSortOrder(Qt::SortOrder order)
     m_proxyModel->setSortOrder(order);
 }
 
+void DolphinColumnWidget::setSortFoldersFirst(bool foldersFirst)
+{
+    m_proxyModel->setSortFoldersFirst(foldersFirst);
+}
+
 void DolphinColumnWidget::setShowHiddenFiles(bool show)
 {
     if (show != m_dirLister->showingDotFiles()) {
@@ -390,7 +399,31 @@ void DolphinColumnWidget::keyPressEvent(QKeyEvent* event)
 {
     QListView::keyPressEvent(event);
     requestActivation();
-    m_view->m_controller->handleKeyPressEvent(event);
+
+    DolphinController* controller = m_view->m_controller;
+    controller->handleKeyPressEvent(event);
+    switch (event->key()) {
+    case Qt::Key_Right: {
+        // Special key handling for the column: A Key_Right should
+        // open a new column for the currently selected folder.
+        const QModelIndex index = currentIndex();
+        const KFileItem item = controller->itemForIndex(index);
+        if (!item.isNull() && item.isDir()) {
+            controller->emitItemTriggered(item);
+        }
+        break;
+    }
+
+    case Qt::Key_Escape:
+        selectionModel()->setCurrentIndex(selectionModel()->currentIndex(),
+                                          QItemSelectionModel::Current |
+                                          QItemSelectionModel::Clear);
+        break;
+
+    default:
+        break;
+    }
+
     if (m_toolTipManager != 0) {
         m_toolTipManager->hideTip();
     }
@@ -412,9 +445,13 @@ void DolphinColumnWidget::contextMenuEvent(QContextMenuEvent* event)
         clearSelection();
     }
 
+    if (m_toolTipManager != 0) {
+        m_toolTipManager->hideTip();
+    }
+
     const QPoint pos = m_view->viewport()->mapFromGlobal(event->globalPos());
     Q_ASSERT(m_view->m_controller->itemView() == this);
-    m_view->m_controller->triggerContextMenuRequest(event->pos());
+    m_view->m_controller->triggerContextMenuRequest(pos);
 }
 
 void DolphinColumnWidget::wheelEvent(QWheelEvent* event)
@@ -457,9 +494,7 @@ void DolphinColumnWidget::selectionChanged(const QItemSelection& selected, const
 void DolphinColumnWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous)
 {
     QListView::currentChanged(current, previous);
-    if (current.isValid() && !m_autoScroller->isActive()) {
-        scrollTo(current);
-    }
+    m_autoScroller->handleCurrentIndexChange(current, previous);
 }
 
 void DolphinColumnWidget::slotEntered(const QModelIndex& index)
@@ -495,18 +530,15 @@ void DolphinColumnWidget::activate()
 
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
-            m_view->m_controller, SLOT(requestTab(const QModelIndex&)));
-        connect(this, SIGNAL(clicked(const QModelIndex&)),
-            m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
+                m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
     } else {
         connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-            m_view->m_controller, SLOT(requestTab(const QModelIndex&)));
-        connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-            m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
+                m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
     }
 
-    if (selectionModel() && selectionModel()->currentIndex().isValid())
+    if (selectionModel() && selectionModel()->currentIndex().isValid()) {
         selectionModel()->setCurrentIndex(selectionModel()->currentIndex(), QItemSelectionModel::SelectCurrent);
+    }
 
     updateBackground();
 }
@@ -514,17 +546,14 @@ void DolphinColumnWidget::activate()
 void DolphinColumnWidget::deactivate()
 {
     clearFocus();
-     if (KGlobalSettings::singleClick()) {
-        disconnect(this, SIGNAL(clicked(const QModelIndex&)),
-            m_view->m_controller, SLOT(requestTab(const QModelIndex&)));
+    if (KGlobalSettings::singleClick()) {
         disconnect(this, SIGNAL(clicked(const QModelIndex&)),
-            m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
+                   m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
     } else {
         disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-            m_view->m_controller, SLOT(requestTab(const QModelIndex&)));
-        disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-            m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
+                   m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
     }
+
     const QModelIndex current = selectionModel()->currentIndex();
     selectionModel()->clear();
     selectionModel()->setCurrentIndex(current, QItemSelectionModel::NoUpdate);