]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
Enable Dolphin to show the revision states of files that are under revision control...
[dolphin.git] / src / dolphinview.cpp
index 06805eefcb5036b219f23ab8bd23b4af985f59cd..c454d65a52f4c7d123eb9080b20a1cce876133ab 100644 (file)
@@ -62,6 +62,7 @@
 #include "draganddrophelper.h"
 #include "folderexpander.h"
 #include "renamedialog.h"
+#include "revisioncontrolobserver.h"
 #include "tooltips/tooltipmanager.h"
 #include "settings/dolphinsettings.h"
 #include "viewproperties.h"
@@ -98,6 +99,7 @@ DolphinView::DolphinView(QWidget* parent,
     m_columnView(0),
     m_fileItemDelegate(0),
     m_selectionModel(0),
+    m_selectionChangedTimer(0),
     m_dolphinModel(dolphinModel),
     m_dirLister(dirLister),
     m_proxyModel(proxyModel),
@@ -188,7 +190,7 @@ void DolphinView::setActive(bool active)
 
     QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
     if (active) {
-        emit selectionChanged(selectedItems());
+        emitSelectionChangedSignal();
     } else {
         color.setAlpha(150);
     }
@@ -376,7 +378,7 @@ int DolphinView::selectedItemsCount() const
         return m_columnView->selectedItems().count();
     }
 
-    return itemView()->selectionModel()->selection().count();
+    return itemView()->selectionModel()->selectedIndexes().count();
 }
 
 void DolphinView::setContentsPosition(int x, int y)
@@ -958,6 +960,14 @@ void DolphinView::triggerItem(const KFileItem& item)
     emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart
 }
 
+void DolphinView::emitDelayedSelectionChangedSignal()
+{
+    // Invoke emitSelectionChangedSignal() with a delay of 300 ms. This assures
+    // that fast selection changes don't result in expensive operations to
+    // collect all file items for the signal (see DolphinView::selectedItems()).
+    m_selectionChangedTimer->start();
+}
+
 void DolphinView::emitSelectionChangedSignal()
 {
     emit selectionChanged(DolphinView::selectedItems());
@@ -1216,16 +1226,17 @@ void DolphinView::slotDirListerCompleted()
     if (!m_newFileNames.isEmpty()) {
         // select all newly added items created by a paste operation or
         // a drag & drop operation
-        QItemSelectionModel* selectionModel = itemView()->selectionModel();
         const int rowCount = m_proxyModel->rowCount();
+        QItemSelection selection;
         for (int row = 0; row < rowCount; ++row) {
             const QModelIndex proxyIndex = m_proxyModel->index(row, 0);
             const QModelIndex dirIndex = m_proxyModel->mapToSource(proxyIndex);
             const KUrl url = m_dolphinModel->itemForIndex(dirIndex).url();
             if (m_newFileNames.contains(url.fileName())) {
-                selectionModel->select(proxyIndex, QItemSelectionModel::Select);
+                selection.merge(QItemSelection(proxyIndex, proxyIndex), QItemSelectionModel::Select);
             }
         }
+        itemView()->selectionModel()->select(selection, QItemSelectionModel::Select);
 
         m_newFileNames.clear();
     }
@@ -1435,6 +1446,12 @@ void DolphinView::createView()
         m_selectionModel = view->selectionModel();
     }
 
+    m_selectionChangedTimer = new QTimer(this);
+    m_selectionChangedTimer->setSingleShot(true);
+    m_selectionChangedTimer->setInterval(300);
+    connect(m_selectionChangedTimer, SIGNAL(timeout()),
+            this, SLOT(emitSelectionChangedSignal()));
+
     // reparent the selection model, as it should not be deleted
     // when deleting the model
     m_selectionModel->setParent(this);
@@ -1444,6 +1461,8 @@ void DolphinView::createView()
     m_previewGenerator = new KFilePreviewGenerator(view);
     m_previewGenerator->setPreviewShown(m_showPreview);
 
+    new RevisionControlObserver(view);
+
     if (DolphinSettings::instance().generalSettings()->showToolTips()) {
         m_toolTipManager = new ToolTipManager(view, m_proxyModel);
         connect(m_controller, SIGNAL(hideToolTip()),
@@ -1453,7 +1472,7 @@ void DolphinView::createView()
     m_topLayout->insertWidget(1, view);
 
     connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
-            this, SLOT(emitSelectionChangedSignal()));
+            this, SLOT(emitDelayedSelectionChangedSignal()));
     connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
             this, SLOT(emitContentsMoved()));
     connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),