]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
SVN_SILENT: minor coding style fix (Sebastian likes spaces :-))
[dolphin.git] / src / dolphinview.cpp
index b805543fded0dde982d1f0bcbfd8044a5d0c385c..54294161df6382ec40e689e87a5e2cde35d40fa6 100644 (file)
@@ -285,45 +285,12 @@ bool DolphinView::supportsCategorizedSorting() const
     return m_viewAccessor.supportsCategorizedSorting();
 }
 
-void DolphinView::selectAll()
-{
-    QAbstractItemView* view = m_viewAccessor.itemView();
-    // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
-    // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
-    // selection instead of selecting all items. This is bypassed for KDE 4.0
-    // by invoking clearSelection() first.
-    view->clearSelection();
-    view->selectAll();
-}
-
-void DolphinView::invertSelection()
-{
-    QItemSelectionModel* selectionModel = m_viewAccessor.itemView()->selectionModel();
-    const QAbstractItemModel* itemModel = selectionModel->model();
-
-    const QModelIndex topLeft = itemModel->index(0, 0);
-    const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
-                                                     itemModel->columnCount() - 1);
-
-    const QItemSelection selection(topLeft, bottomRight);
-    selectionModel->select(selection, QItemSelectionModel::Toggle);
-}
-
 bool DolphinView::hasSelection() const
 {
     const QAbstractItemView* view = m_viewAccessor.itemView();
     return view && view->selectionModel()->hasSelection();
 }
 
-void DolphinView::clearSelection()
-{
-    QItemSelectionModel* selModel = m_viewAccessor.itemView()->selectionModel();
-    const QModelIndex currentIndex = selModel->currentIndex();
-    selModel->setCurrentIndex(currentIndex, QItemSelectionModel::Current |
-                                            QItemSelectionModel::Clear);
-    m_selectedItems.clear();
-}
-
 KFileItemList DolphinView::selectedItems() const
 {
     const QAbstractItemView* view = m_viewAccessor.itemView();
@@ -361,6 +328,11 @@ int DolphinView::selectedItemsCount() const
     return m_viewAccessor.itemView()->selectionModel()->selectedIndexes().count();
 }
 
+QItemSelectionModel* DolphinView::selectionModel() const
+{
+    return m_viewAccessor.itemView()->selectionModel();
+}
+
 void DolphinView::setContentsPosition(int x, int y)
 {
     QAbstractItemView* view = m_viewAccessor.itemView();
@@ -466,8 +438,16 @@ KFileItemDelegate::InformationList DolphinView::additionalInfo() const
 
 void DolphinView::reload()
 {
+    QByteArray viewState;
+    QDataStream saveStream(&viewState, QIODevice::WriteOnly);
+    saveState(saveStream);
+    m_selectedItems = selectedItems();
+
     setUrl(url());
     loadDirectory(url(), true);
+
+    QDataStream restoreStream(viewState);
+    restoreState(restoreStream);
 }
 
 void DolphinView::refresh()
@@ -595,6 +575,29 @@ void DolphinView::setUrl(const KUrl& url)
     updateView(url, KUrl());
 }
 
+void DolphinView::selectAll()
+{
+    m_viewAccessor.itemView()->selectAll();
+}
+
+void DolphinView::invertSelection()
+{
+    QItemSelectionModel* selectionModel = m_viewAccessor.itemView()->selectionModel();
+    const QAbstractItemModel* itemModel = selectionModel->model();
+
+    const QModelIndex topLeft = itemModel->index(0, 0);
+    const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
+                                                     itemModel->columnCount() - 1);
+
+    const QItemSelection selection(topLeft, bottomRight);
+    selectionModel->select(selection, QItemSelectionModel::Toggle);
+}
+
+void DolphinView::clearSelection()
+{
+    m_viewAccessor.itemView()->clearSelection();
+}
+
 void DolphinView::changeSelection(const KFileItemList& selection)
 {
     clearSelection();
@@ -1138,12 +1141,6 @@ void DolphinView::selectAndScrollToCreatedItem()
     m_createdItemUrl = KUrl();
 }
 
-void DolphinView::restoreSelection()
-{
-    disconnect(m_viewAccessor.dirLister(), SIGNAL(completed()), this, SLOT(restoreSelection()));
-    changeSelection(m_selectedItems);
-}
-
 void DolphinView::emitContentsMoved()
 {
     // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
@@ -1229,6 +1226,11 @@ void DolphinView::slotLoadingCompleted()
         }
     }
 
+    if (!m_selectedItems.isEmpty()) {
+        changeSelection(m_selectedItems);
+        m_selectedItems.clear();
+    }
+
     // Restore the contents position. This has to be done using a Qt::QueuedConnection
     // because the view might not be in its final state yet.
     QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection);
@@ -1257,11 +1259,6 @@ void DolphinView::loadDirectory(const KUrl& url, bool reload)
     m_loadingDirectory = true;
     m_expanderActive = false;
 
-    if (reload) {
-        m_selectedItems = selectedItems();
-        connect(m_viewAccessor.dirLister(), SIGNAL(completed()), this, SLOT(restoreSelection()));
-    }
-
     m_viewAccessor.dirLister()->openUrl(url, reload ? KDirLister::Reload : KDirLister::NoFlags);
 }