[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [krusader/vfs_rework] krusader/Panel: Fix unselecting externally deleted or renamed item. Part of cl
From:       Martin_Kostolný <clearmartin () zoho ! com>
Date:       2016-11-07 20:32:32
Message-ID: E1c3qam-00084b-KV () code ! kde ! org
[Download RAW message or body]

Git commit cfd81da4e1abc0598b8f0c37794118f802c1a6b4 by Martin Kostolný.
Committed on 07/11/2016 at 20:30.
Pushed by martinkostolny into branch 'vfs_rework'.

Fix unselecting externally deleted or renamed item. Part of cleaning VFS

This patch is handling situations when current item is being externally removed or \
renamed.

Differential Revision: https://phabricator.kde.org/D3237

M  +15   -2    krusader/Panel/krinterview.cpp
M  +1    -1    krusader/Panel/krinterview.h
M  +4    -3    krusader/Panel/krview.cpp
M  +1    -1    krusader/Panel/krview.h

http://commits.kde.org/krusader/cfd81da4e1abc0598b8f0c37794118f802c1a6b4

diff --git a/krusader/Panel/krinterview.cpp b/krusader/Panel/krinterview.cpp
index 6930bbc..399d035 100644
--- a/krusader/Panel/krinterview.cpp
+++ b/krusader/Panel/krinterview.cpp
@@ -217,12 +217,25 @@ bool KrInterView::isItemVisible(const KrViewItem *item)
     return _itemView->viewport()->rect().contains(item->itemRect());
 }
 
-void KrInterView::setCurrentItem(const QString& name)
+void KrInterView::setCurrentItem(const QString& name, const QModelIndex \
&fallbackToIndex)  {
+    // find index by given name and set it as current
     QModelIndex ndx = _model->nameIndex(name);
-    if (ndx.isValid())
+    if (ndx.isValid()) {
          // also sets the scrolling position
         _itemView->setCurrentIndex(ndx);
+    } else if (fallbackToIndex.isValid()) {
+        // set fallback index as current index
+        // when fallback index is too big, set the last item as current
+        if (fallbackToIndex.row() >= _itemView->model()->rowCount()) {
+            setCurrentKrViewItem(getLast());
+        } else {
+            _itemView->setCurrentIndex(fallbackToIndex);
+        }
+    } else {
+        // when given parameters fail, set the first item as current
+        setCurrentKrViewItem(getFirst());
+    }
 }
 
 void KrInterView::setCurrentKrViewItem(KrViewItem *item)
diff --git a/krusader/Panel/krinterview.h b/krusader/Panel/krinterview.h
index 391d019..86e39f5 100644
--- a/krusader/Panel/krinterview.h
+++ b/krusader/Panel/krinterview.h
@@ -61,7 +61,7 @@ public:
     virtual KrViewItem *findItemByVfile(vfile *vf) Q_DECL_OVERRIDE;
     virtual QString getCurrentItem() const Q_DECL_OVERRIDE;
     virtual KrViewItem* getKrViewItemAt(const QPoint &vp) Q_DECL_OVERRIDE;
-    virtual void setCurrentItem(const QString& name) Q_DECL_OVERRIDE;
+    virtual void setCurrentItem(const QString& name, const QModelIndex \
&fallbackToIndex=QModelIndex()) Q_DECL_OVERRIDE;  virtual void \
setCurrentKrViewItem(KrViewItem *item) Q_DECL_OVERRIDE;  virtual void \
makeItemVisible(const KrViewItem *item) Q_DECL_OVERRIDE;  virtual bool \
                isItemVisible(const KrViewItem *item) Q_DECL_OVERRIDE;
diff --git a/krusader/Panel/krview.cpp b/krusader/Panel/krview.cpp
index 5f4af1a..a89f4b5 100644
--- a/krusader/Panel/krview.cpp
+++ b/krusader/Panel/krview.cpp
@@ -1107,8 +1107,9 @@ void KrView::customSelection(bool select)
 
 void KrView::refresh()
 {
-    QString current = getCurrentItem();
+    QString currentItem = getCurrentItem();
     QList<QUrl> selection = selectedUrls();
+    QModelIndex currentIndex = getCurrentIndex();
 
     clear();
 
@@ -1141,8 +1142,8 @@ void KrView::refresh()
     if (!nameToMakeCurrent().isEmpty()) {
         setCurrentItem(nameToMakeCurrent());
         setNameToMakeCurrent("");
-    } else if (!current.isEmpty()) {
-        setCurrentItem(current);
+    } else if (!currentItem.isEmpty()) {
+        setCurrentItem(currentItem, currentIndex);
     } else {
         setCurrentKrViewItem(getFirst());
     }
diff --git a/krusader/Panel/krview.h b/krusader/Panel/krview.h
index 4f7927e..1e33fe9 100644
--- a/krusader/Panel/krview.h
+++ b/krusader/Panel/krview.h
@@ -327,7 +327,7 @@ public:
     virtual KrViewItem *findItemByName(const QString &name) = 0;
     virtual KrViewItem *findItemByVfile(vfile *vf) = 0;
     virtual QString getCurrentItem() const = 0;
-    virtual void setCurrentItem(const QString& name) = 0;
+    virtual void setCurrentItem(const QString& name, const QModelIndex \
&fallbackToIndex=QModelIndex()) = 0;  virtual void setCurrentKrViewItem(KrViewItem \
*item) = 0;  virtual void makeItemVisible(const KrViewItem *item) = 0;
     virtual bool isItemVisible(const KrViewItem *item) = 0;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic