┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/dolphintabwidget.h
diff options
context:
space:
mode:
authorFelix Ernst <[email protected]>2022-08-09 16:02:55 +0200
committerFelix Ernst <[email protected]>2022-10-11 15:26:31 +0200
commit4d81aabd1ee78c2fca61452ef3a866cfad0c88a5 (patch)
tree83b182680cfd8bab3a76054478a56896e60b8f61 /src/dolphintabwidget.h
parent8916a647d6701c910c04c2cacecf60c014ac944f (diff)
Fix item highlighting through DBus
Before this commit, even items that are distant children of currently open views were considered selectable. This lead to the bug that items meant to be highlighted through DBus would not be highlighted if any ancestor of the item was open in any view. This was fixed by only considering items in view if they can be seen by scrolling. Main difficulty here was to make this also work for the details view mode which allows expanding. To implement this cleanly, some refactoring seemed necessary because the logic to determine if an item is already in view was previously intertwined with the logic to identify already open directories. This commit also contains the following refactorings aiming to make the code more readable: - A magic value (-1) is replaced using std::optional. - A boolean trap is removed. - A QPair is replaced by a struct with named variables. - More and improved documentation
Diffstat (limited to 'src/dolphintabwidget.h')
-rw-r--r--src/dolphintabwidget.h39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/dolphintabwidget.h b/src/dolphintabwidget.h
index 28c51024c..8342d719d 100644
--- a/src/dolphintabwidget.h
+++ b/src/dolphintabwidget.h
@@ -13,6 +13,8 @@
#include <QTabWidget>
#include <QUrl>
+#include <optional>
+
class DolphinViewContainer;
class KConfigGroup;
@@ -75,10 +77,10 @@ public:
bool isUrlOpen(const QUrl& url) const;
/**
- * @return Whether any of the tab pages has @p url or it's parent opened
- * in their primary or secondary view.
+ * @return Whether the item with @p url can be found in any view only by switching
+ * between already open tabs and scrolling in their primary or secondary view.
*/
- bool isUrlOrParentOpen(const QUrl& url) const;
+ bool isItemVisibleInAnyView(const QUrl& urlOfItem) const;
Q_SIGNALS:
/**
@@ -127,10 +129,9 @@ public Q_SLOTS:
/**
* Opens each directory in \p dirs in a separate tab unless it is already open.
* If \a splitView is set, 2 directories are collected within one tab.
- * If \a skipChildUrls is set, do not open a directory if it's parent is already open.
* \pre \a dirs must contain at least one url.
*/
- void openDirectories(const QList<QUrl>& dirs, bool splitView, bool skipChildUrls = false);
+ void openDirectories(const QList<QUrl>& dirs, bool splitView);
/**
* Opens the directories which contain the files \p files and selects all files.
@@ -221,21 +222,27 @@ private:
*/
QString tabName(DolphinTabPage* tabPage) const;
- enum ChildUrlBehavior {
- ReturnIndexForOpenedUrlOnly,
- ReturnIndexForOpenedParentAlso
+ struct ViewIndex {
+ const int tabIndex;
+ const bool isInPrimaryView;
};
+ /**
+ * Get the position of the view within this widget that is open at @p directory.
+ * @param directory The URL of the directory we want to find.
+ * @return a small struct containing the tab index of the view and whether it is
+ * in the primary view. A std::nullopt is returned if there is no view open for @p directory.
+ */
+ const std::optional<const ViewIndex> viewOpenAtDirectory(const QUrl& directory) const;
/**
- * @param url The URL that we would like
- * @param childUrlBehavior Whether a tab with opened parent of the URL can be returned too
- * @return a QPair with:
- * First containing the index of the tab with the desired URL or -1 if not found.
- * Second says true if URL is in primary view container, false otherwise.
- * False means the URL is in the secondary view container, unless first == -1.
- * In that case the value of second is meaningless.
+ * Get the position of the view within this widget that has @p item in the view.
+ * This means that the item can be seen by the user in that view when scrolled to the right position.
+ * If the view has folders expanded and @p item is one of them, the view will also be returned.
+ * @param item The URL of the item we want to find.
+ * @return a small struct containing the tab index of the view and whether it is
+ * in the primary view. A std::nullopt is returned if there is no view open that has @p item visible anywhere.
*/
- QPair<int, bool> indexByUrl(const QUrl& url, ChildUrlBehavior childUrlBehavior = ReturnIndexForOpenedUrlOnly) const;
+ const std::optional<const ViewIndex> viewShowingItem(const QUrl& item) const;
private:
QPointer<DolphinTabPage> m_lastViewedTab;