]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Move the code for restoring the current item from DolphinViewContainer to DolphinView...
authorPeter Penz <peter.penz19@gmail.com>
Wed, 28 May 2008 20:40:16 +0000 (20:40 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 28 May 2008 20:40:16 +0000 (20:40 +0000)
Beside that this simplifies the code it also fixes a regression of having empty tabs.

svn path=/trunk/KDE/kdebase/apps/; revision=813828

src/dolphinview.cpp
src/dolphinview.h
src/dolphinviewcontainer.cpp
src/dolphinviewcontainer.h

index f0a4487c939d10e5ec9eb7e532e7a69b5e1e82a6..ae6ea5ec7bbfcaf3b9de5a19b6d86f389f7dba90 100644 (file)
@@ -84,7 +84,9 @@ DolphinView::DolphinView(QWidget* parent,
     m_dirLister(dirLister),
     m_proxyModel(proxyModel),
     m_iconManager(0),
-    m_toolTipManager(0)
+    m_toolTipManager(0),
+    m_rootUrl(),
+    m_currentItemUrl()
 {
     m_topLayout = new QVBoxLayout(this);
     m_topLayout->setSpacing(0);
@@ -123,6 +125,9 @@ DolphinView::DolphinView(QWidget* parent,
     connect(m_controller, SIGNAL(viewportEntered()),
             this, SLOT(clearHoverInformation()));
 
+    connect(m_dirLister, SIGNAL(completed()),
+            this, SLOT(restoreCurrentItem()));
+
     applyViewProperties(url);
     m_topLayout->addWidget(itemView());
 }
@@ -347,20 +352,6 @@ QPoint DolphinView::contentsPosition() const
     return QPoint(x, y);
 }
 
-void DolphinView::setCurrentItem(const KUrl& url)
-{
-    const QModelIndex dirIndex = m_dolphinModel->indexForUrl(url);
-    if (dirIndex.isValid()) {
-        const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
-        QAbstractItemView* view = itemView();
-        const bool clearSelection = !hasSelection();
-        view->setCurrentIndex(proxyIndex);
-        if (clearSelection) {
-            view->clearSelection();
-        }
-    }
-}
-
 void DolphinView::zoomIn()
 {
     m_controller->triggerZoomIn();
@@ -493,6 +484,8 @@ void DolphinView::calculateItemCount(int& fileCount, int& folderCount)
 
 void DolphinView::setUrl(const KUrl& url)
 {
+    // remember current item candidate (see restoreCurrentItem())
+    m_currentItemUrl = url;
     updateView(url, KUrl());
 }
 
@@ -969,6 +962,21 @@ void DolphinView::slotDeleteFileFinished(KJob* job)
     }
 }
 
+
+void DolphinView::restoreCurrentItem()
+{
+    const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_currentItemUrl);
+    if (dirIndex.isValid()) {
+        const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+        QAbstractItemView* view = itemView();
+        const bool clearSelection = !hasSelection();
+        view->setCurrentIndex(proxyIndex);
+        if (clearSelection) {
+            view->clearSelection();
+        }
+    }
+}
+
 void DolphinView::loadDirectory(const KUrl& url, bool reload)
 {
     if (!url.isValid()) {
index 7085355674a7224b6ffd0def1af3202e26492ddc..121a7f6dad23e6356e06a803ff978ced2ea1b3b4 100644 (file)
@@ -233,12 +233,6 @@ public:
     /** Returns the upper left position of the view content. */
     QPoint contentsPosition() const;
 
-    /**
-     * Sets the current item (= item that has the keyboard focus) to
-     * the item with the URL \a url.
-     */
-    void setCurrentItem(const KUrl& url);
-
     /** Increases the size of the current set view mode. */
     void zoomIn();
 
@@ -601,6 +595,12 @@ private slots:
      */
     void slotDeleteFileFinished(KJob* job);
 
+    /**
+     * Restores the current item (= item that has the keyboard focus)
+     * to m_currentItemUrl.
+     */
+    void restoreCurrentItem();
+
 private:
     void loadDirectory(const KUrl& url, bool reload = false);
 
@@ -683,6 +683,7 @@ private:
     ToolTipManager* m_toolTipManager;
 
     KUrl m_rootUrl;
+    KUrl m_currentItemUrl;
 };
 
 /// Allow using DolphinView::Mode in QVariant
index 6bc620ee21b217e12bae6a948fa38b30339afd3b..7179c50804e7825b3710d562f7502c811a59d84b 100644 (file)
@@ -68,9 +68,7 @@ DolphinViewContainer::DolphinViewContainer(DolphinMainWindow* mainWindow,
     m_filterBar(0),
     m_statusBar(0),
     m_dirLister(0),
-    m_proxyModel(0),
-    m_previousUrl(),
-    m_currentUrl()
+    m_proxyModel(0)
 {
     hide();
 
@@ -171,16 +169,12 @@ DolphinViewContainer::~DolphinViewContainer()
 
 void DolphinViewContainer::setUrl(const KUrl& newUrl)
 {
-    if (newUrl != m_currentUrl) {
-        m_previousUrl = m_currentUrl;
-        m_currentUrl = newUrl;
-        m_urlNavigator->setUrl(newUrl);
-    }
+    m_urlNavigator->setUrl(newUrl);
 }
 
 const KUrl& DolphinViewContainer::url() const
 {
-    return m_currentUrl;
+    return m_urlNavigator->url();
 }
 
 void DolphinViewContainer::setActive(bool active)
@@ -234,7 +228,6 @@ void DolphinViewContainer::slotDirListerCompleted()
     }
 
     updateStatusBar();
-    m_view->setCurrentItem(m_previousUrl);
     QTimer::singleShot(100, this, SLOT(restoreContentsPos()));
 }
 
index a0ddcb71171e051609fd1142cd8f427ed0e5eb8c..b4f799cb1ff6ad7d80eed354ff200763240e0ac2 100644 (file)
@@ -230,9 +230,6 @@ private:
     DolphinModel* m_dolphinModel;
     DolphinDirLister* m_dirLister;
     DolphinSortFilterProxyModel* m_proxyModel;
-
-    KUrl m_previousUrl;
-    KUrl m_currentUrl;
 };
 
 inline const DolphinStatusBar* DolphinViewContainer::statusBar() const