]> cloud.milkyroute.net Git - dolphin.git/commitdiff
After renaming an item the view should be scrolled in a way to still have a fully...
authorPeter Penz <peter.penz19@gmail.com>
Tue, 24 Feb 2009 08:09:35 +0000 (08:09 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 24 Feb 2009 08:09:35 +0000 (08:09 +0000)
BUG: 185191

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

src/dolphincolumnview.cpp
src/dolphincolumnview.h
src/dolphincontroller.cpp
src/dolphincontroller.h
src/dolphindetailsview.cpp
src/dolphindetailsview.h
src/dolphiniconsview.cpp
src/dolphiniconsview.h
src/dolphinview.cpp
src/dolphinview.h

index 4d180442b750da734adac1ee3f6ad3400239ec16..16d72c0f0622161a730b4471f2745303ead60b5c 100644 (file)
@@ -59,6 +59,8 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control
             this, SLOT(setZoomLevel(int)));
     connect(controller, SIGNAL(activationChanged(bool)),
             this, SLOT(updateColumnsBackground(bool)));
+    connect(controller, SIGNAL(scrollToCurrentItem()),
+            this, SLOT(scrollToCurrentItem()));
 
     const DolphinView* view = controller->dolphinView();
     connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
@@ -465,6 +467,12 @@ void DolphinColumnView::slotShowPreviewChanged()
     }
 }
 
+void DolphinColumnView::scrollToCurrentItem()
+{
+    const QModelIndex activeIndex = activeColumn()->currentIndex();
+    activeColumn()->scrollTo(activeIndex);
+}
+
 void DolphinColumnView::setActiveColumnIndex(int index)
 {
     if (m_index == index) {
index caa54eab84aba56b7d42198e692bda640ea10c56..756037874f74d9e8842b53628d00e89613eb6a76 100644 (file)
@@ -112,7 +112,7 @@ public:
      * Returns the selected items of the active column.
      */
     KFileItemList selectedItems() const;
-    
+
     /**
      * Returns the MIME data for the selected items
      * of the active column.
@@ -169,6 +169,7 @@ private slots:
     void slotSortOrderChanged(Qt::SortOrder order);
     void slotShowHiddenFilesChanged();
     void slotShowPreviewChanged();
+    void scrollToCurrentItem();
 
 private:
     DolphinColumnWidget* activeColumn() const;
index b128c90335e2c89804458b7a0ac88f1b86f9b47d..cfa0d62c821b0226653f62aa9a3e30b748db715f 100644 (file)
@@ -124,6 +124,11 @@ void DolphinController::setZoomLevel(int level)
     }
 }
 
+void DolphinController::triggerScrollToCurrentItem()
+{
+    emit scrollToCurrentItem();
+}
+
 void DolphinController::handleKeyPressEvent(QKeyEvent* event)
 {
     Q_ASSERT(m_itemView != 0);
index 29dd7dfb1bfcc56dd7fa9d03226e88914a2a640e..ba10360602c7fe850c55cf8105444d17bb4055b4 100644 (file)
@@ -73,6 +73,7 @@ class QWidget;
  * - setShowPreview()
  * - indicateActivationChange()
  * - setZoomLevel()
+ * - triggerScrollToCurrentItem()
  */
 class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
 {
@@ -189,6 +190,12 @@ public:
     void setZoomLevel(int level);
     int zoomLevel() const;
 
+    /**
+     * Triggers the view implementation to assure having a fully visible
+     * current item. The signal scrollToCurrentItem() will be emitted.
+     */
+    void triggerScrollToCurrentItem();
+
     /**
      * Tells the view implementation to zoom out by emitting the signal zoomOut()
      * and is invoked by the abstract Dolphin view.
@@ -369,6 +376,12 @@ signals:
      */
     void hideToolTip();
 
+    /**
+     * Is emitted if the view implementation should scroll to the current item, so
+     * that it is fully visible.
+     */
+    void scrollToCurrentItem();
+
 private slots:
     void updateMouseButtonState();
 
index dd58e584248bbf57e73e1f722375bb9fb004783c..fbd7e41d5c612e4bd2c1b0026e469ca7d14241bb 100644 (file)
@@ -128,6 +128,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
             this, SLOT(updateColumnVisibility()));
     connect(controller, SIGNAL(activationChanged(bool)),
             this, SLOT(slotActivationChanged(bool)));
+    connect(controller, SIGNAL(scrollToCurrentItem()),
+            this, SLOT(scrollToCurrentItem()));
 
     if (settings->useSystemFont()) {
         m_font = KGlobalSettings::generalFont();
@@ -866,6 +868,11 @@ void DolphinDetailsView::setFoldersExpandable(bool expandable)
     setItemsExpandable(expandable);
 }
 
+void DolphinDetailsView::scrollToCurrentItem()
+{
+    scrollTo(currentIndex());
+}
+
 void DolphinDetailsView::updateDecorationSize(bool showPreview)
 {
     DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
index 38aea12deef7463f0b9ac286d3a9651bdaea3b0e..e60400b445cf783127f75653262dcada8a389a91 100644 (file)
@@ -159,6 +159,8 @@ private slots:
      */
     void setFoldersExpandable(bool expandable);
 
+    void scrollToCurrentItem();
+
 private:
     /**
      * Updates the size of the decoration dependent on the
index f5b69bade49cb6e9e7cb7830543ec88d97048987..4b861df449a4ba09d6947c04d8dab71a05253975 100644 (file)
@@ -88,6 +88,8 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
             controller, SLOT(emitViewportEntered()));
     connect(controller, SIGNAL(zoomLevelChanged(int)),
             this, SLOT(setZoomLevel(int)));
+    connect(controller, SIGNAL(scrollToCurrentItem()),
+            this, SLOT(scrollToCurrentItem()));
 
     const DolphinView* view = controller->dolphinView();
     connect(view, SIGNAL(showPreviewChanged()),
@@ -390,6 +392,13 @@ void DolphinIconsView::slotGlobalSettingsChanged(int category)
     }
 }
 
+void DolphinIconsView::scrollToCurrentItem()
+{
+    m_enableScrollTo = true;
+    scrollTo(currentIndex());
+    m_enableScrollTo = false;
+}
+
 void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
 {
     const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
index 76a369db987783ffea3a0298d4bee9be4fba2a1f..8a1f1f8dd661aa8ce0c85a1d41c2cbbfb91f7d22 100644 (file)
@@ -76,6 +76,7 @@ private slots:
     void setZoomLevel(int level);
     void requestActivation();
     void slotGlobalSettingsChanged(int category);
+    void scrollToCurrentItem();
 
 private:
     /**
index f40accddea79fd09a1bdf9f548adb7c27e888317..638e6e7cb0fb33a55657b83d04d1382d5df4e8b9 100644 (file)
@@ -88,6 +88,7 @@ DolphinView::DolphinView(QWidget* parent,
     m_tabsForFiles(false),
     m_isContextMenuOpen(false),
     m_ignoreViewProperties(false),
+    m_assureVisibleCurrentIndex(false),
     m_mode(DolphinView::IconsView),
     m_topLayout(0),
     m_controller(0),
@@ -142,6 +143,8 @@ DolphinView::DolphinView(QWidget* parent,
             this, SIGNAL(redirection(KUrl, KUrl)));
     connect(m_dirLister, SIGNAL(completed()),
             this, SLOT(restoreCurrentItem()));
+    connect(m_dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
+            this, SLOT(slotRefreshItems()));
 
     applyViewProperties(url);
     m_topLayout->addWidget(itemView());
@@ -629,30 +632,31 @@ void DolphinView::renameSelectedItems()
         const QString newName = dialog.newName();
         if (newName.isEmpty()) {
             emit errorMessage(dialog.errorString());
-        } else {
-            // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
-            // as one operation instead of n rename operations like it is done now...
-            Q_ASSERT(newName.contains('#'));
-
-            // currently the items are sorted by the selection order, resort
-            // them by the file name
-            qSort(items.begin(), items.end(), lessThan);
-
-            // iterate through all selected items and rename them...
-            int index = 1;
-            foreach (const KFileItem& item, items) {
-                const KUrl& oldUrl = item.url();
-                QString number;
-                number.setNum(index++);
-
-                QString name = newName;
-                name.replace('#', number);
-
-                if (oldUrl.fileName() != name) {
-                    KUrl newUrl = oldUrl;
-                    newUrl.setFileName(name);
-                    KonqOperations::rename(this, oldUrl, newUrl);
-                }
+            return;
+        }
+
+        // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
+        // as one operation instead of n rename operations like it is done now...
+        Q_ASSERT(newName.contains('#'));
+
+        // currently the items are sorted by the selection order, resort
+        // them by the file name
+        qSort(items.begin(), items.end(), lessThan);
+
+        // iterate through all selected items and rename them...
+        int index = 1;
+        foreach (const KFileItem& item, items) {
+            const KUrl& oldUrl = item.url();
+            QString number;
+            number.setNum(index++);
+
+            QString name = newName;
+            name.replace('#', number);
+
+            if (oldUrl.fileName() != name) {
+                KUrl newUrl = oldUrl;
+                newUrl.setFileName(name);
+                KonqOperations::rename(this, oldUrl, newUrl);
             }
         }
     } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
@@ -676,13 +680,18 @@ void DolphinView::renameSelectedItems()
         const QString& newName = dialog.newName();
         if (newName.isEmpty()) {
             emit errorMessage(dialog.errorString());
-        } else {
-            const KUrl& oldUrl = items.first().url();
-            KUrl newUrl = oldUrl;
-            newUrl.setFileName(newName);
-            KonqOperations::rename(this, oldUrl, newUrl);
+            return;
         }
+
+        const KUrl& oldUrl = items.first().url();
+        KUrl newUrl = oldUrl;
+        newUrl.setFileName(newName);
+        KonqOperations::rename(this, oldUrl, newUrl);
     }
+
+    // assure that the current index remains visible when KDirLister
+    // will notify the view about changed items
+    m_assureVisibleCurrentIndex = true;
 }
 
 void DolphinView::trashSelectedItems()
@@ -1147,6 +1156,17 @@ void DolphinView::restoreCurrentItem()
     }
 }
 
+void DolphinView::slotRefreshItems()
+{
+    if (m_assureVisibleCurrentIndex) {
+        m_assureVisibleCurrentIndex = false;
+        // Invoking itemView()->scrollTo(itemView()->currentIndex()) is
+        // not sufficient, as QListView and QTreeView have an inconsistent
+        // default behavior.
+        m_controller->triggerScrollToCurrentItem();
+    }
+}
+
 void DolphinView::loadDirectory(const KUrl& url, bool reload)
 {
     if (!url.isValid()) {
index 5cedeecfa86d3402a4f7a867932907cfc8e9e9ee..1498de08aac98e0b57067935061fad4175a39c8f 100644 (file)
@@ -630,6 +630,11 @@ private slots:
      */
     void restoreCurrentItem();
 
+    /**
+     * Is invoked when the KDirLister indicates refreshed items.
+     */
+    void slotRefreshItems();
+
     /**
      * If \a view can be positively identified as not being the source for the
      * current drag operation, deleteLater() it immediately.  Else stores
@@ -716,6 +721,7 @@ private:
     bool m_tabsForFiles : 1;
     bool m_isContextMenuOpen : 1;   // TODO: workaround for Qt-issue 207192
     bool m_ignoreViewProperties : 1;
+    bool m_assureVisibleCurrentIndex : 1;
 
     Mode m_mode;
 
@@ -739,7 +745,7 @@ private:
     KUrl m_rootUrl;
     KUrl m_currentItemUrl;
 
-    QAbstractItemView*  m_expandedDragSource;
+    QAbstractItemView* m_expandedDragSource;
 };
 
 inline bool DolphinView::isColumnViewActive() const