[gwenview] /: Fix issues with clicking directories in tree view

Peter Mühlenpfordt null at kde.org
Fri Jan 26 07:35:48 UTC 2018


Git commit 8a6a4ea6b9853ef4c9a916d2d91d8a7a02ad6b64 by Peter Mühlenpfordt.
Committed on 26/01/2018 at 07:35.
Pushed by muhlenpfordt into branch 'master'.

Fix issues with clicking directories in tree view

Summary:
Selecting another directory in tree while showing an image in view mode,
opens the first image from the selected directory in view mode. If the
folder contains subfolders, gwenview selects the first one and switches
to browse mode.
This patch changes selection of first **item** back to first **image**
(introduced in D8934) to fix this and toggles between browse/view mode
only after clicking the already selected directory in tree.
Additionally a trailing slash is stripped from the current dir url in
context manager to fix a failing compare to initially stored dir url.

BUG: 306835

Test Plan:
1. Open image in view mode
2. Click on another directory in tree view
-> Should view the first image in new directory

1. Open image in view mode
2. Click multiple times on the same directory in tree view
-> Should toggle browse/view mode

Reviewers: rkflx

Reviewed By: rkflx

Subscribers: ngraham, rkflx

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

M  +28   -5    app/mainwindow.cpp
M  +2    -0    app/mainwindow.h
M  +2    -1    doc/index.docbook
M  +2    -1    lib/contextmanager.cpp

https://commits.kde.org/gwenview/8a6a4ea6b9853ef4c9a916d2d91d8a7a02ad6b64

diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp
index bc74b37d..bfba3974 100644
--- a/app/mainwindow.cpp
+++ b/app/mainwindow.cpp
@@ -514,8 +514,8 @@ struct MainWindow::Private
 
         // Create context manager items
         FolderViewContextManagerItem* folderViewItem = new FolderViewContextManagerItem(mContextManager);
-        connect(folderViewItem, SIGNAL(urlChanged(QUrl)),
-                q, SLOT(openDirUrl(QUrl)));
+        connect(folderViewItem, &FolderViewContextManagerItem::urlChanged,
+                q, &MainWindow::folderViewUrlChanged);
 
         InfoContextManagerItem* infoItem = new InfoContextManagerItem(mContextManager);
 
@@ -1046,6 +1046,25 @@ void MainWindow::openDirUrl(const QUrl &url)
     d->mViewMainPage->reset();
 }
 
+void MainWindow::folderViewUrlChanged(const QUrl &url) {
+    const QUrl currentUrl = d->mContextManager->currentDirUrl();
+
+    if (url == currentUrl) {
+        switch (d->mCurrentMainPageId) {
+        case ViewMainPageId:
+            d->mBrowseAction->trigger();
+            break;
+        case BrowseMainPageId:
+            d->mViewAction->trigger();
+            break;
+        case StartMainPageId:
+            break;
+        }
+    } else {
+        openDirUrl(url);
+    }
+}
+
 void MainWindow::toggleSideBar(bool on)
 {
     d->mSideBar->setVisible(on);
@@ -1155,9 +1174,13 @@ void MainWindow::slotDirListerCompleted()
     if (d->mContextManager->selectionModel()->hasSelection()) {
         updatePreviousNextActions();
     } else {
-        QModelIndex index = d->mThumbnailView->model()->index(0, 0);
-        if (index.isValid()) {
-            d->mThumbnailView->setCurrentIndex(index);
+        d->goToFirstDocument();
+
+        if (!d->mContextManager->selectionModel()->hasSelection()) {
+            const QModelIndex index = d->mThumbnailView->model()->index(0, 0);
+            if (index.isValid()) {
+                d->mThumbnailView->setCurrentIndex(index);
+            }
         }
     }
     d->mThumbnailView->scrollToSelectedIndex();
diff --git a/app/mainwindow.h b/app/mainwindow.h
index e8a472d6..9183f380 100644
--- a/app/mainwindow.h
+++ b/app/mainwindow.h
@@ -136,6 +136,8 @@ private:
 
     void openSelectedDocuments();
     void saveConfig();
+
+    void folderViewUrlChanged(const QUrl &url);
 };
 
 } // namespace
diff --git a/doc/index.docbook b/doc/index.docbook
index 5aa43ae1..61ac18e4 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -428,7 +428,8 @@ The sidebar contains several tabs:</para>
 switch between them.  In Browse Mode thumbnails from the folder will be displayed,
 while in View Mode the first image in the folder will appear, from which you can
 browse through the folder using the <guibutton>Previous</guibutton> and
-<guibutton>Next</guibutton> buttons or shortcuts.</para></listitem>
+<guibutton>Next</guibutton> buttons or shortcuts. Clicking on a folder multiple
+times toggles between View Mode and Browse Mode.</para></listitem>
 </varlistentry>
 
 <varlistentry>
diff --git a/lib/contextmanager.cpp b/lib/contextmanager.cpp
index 9e8fb352..0b1275b2 100644
--- a/lib/contextmanager.cpp
+++ b/lib/contextmanager.cpp
@@ -174,8 +174,9 @@ KFileItemList ContextManager::selectedFileItemList() const
     return d->mSelectedFileItemList;
 }
 
-void ContextManager::setCurrentDirUrl(const QUrl &url)
+void ContextManager::setCurrentDirUrl(const QUrl &_url)
 {
+    const QUrl url = _url.adjusted(QUrl::StripTrailingSlash);
     if (url == d->mCurrentDirUrl) {
         return;
     }


More information about the kde-doc-english mailing list