diff --git a/src/FolderColumns.qml b/src/FolderColumns.qml index 1148d4bf..d469bc48 100644 --- a/src/FolderColumns.qml +++ b/src/FolderColumns.qml @@ -33,6 +33,22 @@ Item { // column, and the rest stay as they are instead of reloading (which // flashed). ListModel { id: trail } + // How many of the folders on the way here are scrolled out of sight to + // the left: a place picked in the sidebar is the first column shown, + // with the folders above it there to scroll back to. Going up past it + // shows what's above again. + property int hidden: 0 + property string startingAt: "" + function startAt(path) { + startingAt = path + if (backend.path === path) + started() + } + function started() { + startingAt = "" + hidden = trail.count + revealEnd() + } function syncTrail() { const want = [] for (let i = 0; i + 1 < crumbs.length; ++i) @@ -40,6 +56,9 @@ Item { let same = 0 while (same < trail.count && same < want.length && trail.get(same).path === want[same].path) ++same + // Somewhere else altogether (another drive, /) starts from its top. + if (same === 0) + hidden = 0 // Columns that stay may now point at a different next folder. for (let i = 0; i < same; ++i) if (trail.get(i).next !== want[i].next) @@ -48,14 +67,24 @@ Item { trail.remove(same, trail.count - same) for (let i = same; i < want.length; ++i) trail.append(want[i]) + hidden = Math.min(hidden, trail.count) + if (startingAt.length > 0 && backend.path === startingAt) + started() } onCrumbsChanged: syncTrail() Component.onCompleted: syncTrail() readonly property var selected: here.currentIndex >= 0 ? (backend.folder.count, backend.folder.get(here.currentIndex)) : ({}) - // Keeps the newest columns in view as the trail grows: on the left, - // when mirrored. - function revealEnd() { flick.contentX = view.LayoutMirroring.enabled ? 0 : Math.max(0, flick.contentWidth - flick.width) } + // Where the first column shown starts, from the side the columns grow + // from: past the hidden ones and their separators. + readonly property int hiddenWidth: hidden * (columnWidth + 1) + // Keeps the newest columns in view as the trail grows, and the hidden + // ones out of it: on the left, when mirrored. + function revealEnd() { + const from = Math.max(view.hiddenWidth, row.width - flick.width) + const most = Math.max(0, flick.contentWidth - flick.width) + flick.contentX = view.LayoutMirroring.enabled ? most - from : from + } LayoutMirroring.onEnabledChanged: revealEnd() function enter() { if (view.selected.isDir && (insideFolder.loading || insideFolder.count > 0 || insideFolder.error.length > 0)) @@ -73,7 +102,9 @@ Item { anchors.fill: parent clip: true acceptedButtons: Qt.NoButton - contentWidth: Math.max(width, row.width) + // Room to scroll the hidden columns out of sight even when the rest + // would fit. + contentWidth: Math.max(width, row.width, view.hiddenWidth + width) contentHeight: height boundsBehavior: Flickable.StopAtBounds onContentWidthChanged: view.revealEnd() @@ -232,9 +263,9 @@ Item { active: !!view.detailsPane && view.selected.path !== undefined && view.selected.isDir !== true visible: active sourceComponent: PreviewPane { - // All the room right of the columns, and no narrower - // than it reads well. - width: Math.max(300, flick.width - (trail.count + 1) * (view.columnWidth + 1)) + // All the room right of the columns in sight, and no + // narrower than it reads well. + width: Math.max(300, flick.width - (trail.count - view.hidden + 1) * (view.columnWidth + 1)) height: row.height folderPane: view.detailsPane onFinished: view.focusView() diff --git a/src/FolderPane.qml b/src/FolderPane.qml index 1627ae9d..f22020d4 100644 --- a/src/FolderPane.qml +++ b/src/FolderPane.qml @@ -135,6 +135,8 @@ FocusScope { // follow. onActiveFocusChanged: if (activeFocus && host) host.activePane = pane function focusView() { if (view.item) view.item.focusView() } + // A place picked in the sidebar: the columns start at it. + function startAt(path) { if (view.item && view.item.startAt) view.item.startAt(path) } // Pins a folder to the sidebar, or unpins it when it's pinned already. function togglePin(target) { diff --git a/src/Main.qml b/src/Main.qml index 7c682029..53006289 100644 --- a/src/Main.qml +++ b/src/Main.qml @@ -171,6 +171,7 @@ ApplicationWindow { id: sidebar target: win.activePane ? win.activePane.paneBackend : backend onFinished: win.activePane.focusView() + onPlaceChosen: (path) => win.activePane.startAt(path) onFormatRequested: (disk) => win.activePane.formatDrive(disk) Layout.topMargin: parent.parent.barHeight Layout.preferredWidth: 190 diff --git a/src/Sidebar.qml b/src/Sidebar.qml index 61b2c708..f0b425af 100644 --- a/src/Sidebar.qml +++ b/src/Sidebar.qml @@ -19,6 +19,13 @@ Rectangle { signal finished() // Format… in a drive's menu, with what udisks knows of the drive. signal formatRequested(var disk) + // A place picked here: the columns start at it, rather than at the + // folders above it. + signal placeChosen(string path) + function go(path) { + placeChosen(path) + target.navigate(path) + } property int cursor: 0 // The pane the sidebar acts on: the one used last. property var target: backend @@ -65,7 +72,7 @@ Rectangle { if (row.root !== undefined) sidebar.target.open(row.path) else - sidebar.target.navigate(row.path) + sidebar.go(row.path) finished() } function reveal(item) { @@ -115,7 +122,7 @@ Rectangle { DriveMenu { id: driveMenu - onOpenRequested: (path) => { sidebar.target.navigate(path); sidebar.finished() } + onOpenRequested: (path) => { sidebar.go(path); sidebar.finished() } onFormatRequested: (disk) => sidebar.formatRequested(disk) } @@ -274,7 +281,7 @@ Rectangle { : homeHover.hovered ? theme.foreground : theme.secondaryForeground Accessible.role: Accessible.Button HoverHandler { id: homeHover; cursorShape: Qt.PointingHandCursor } - TapHandler { onTapped: sidebar.target.navigate(places.home) } + TapHandler { onTapped: sidebar.go(places.home) } } Repeater { model: places.places @@ -288,7 +295,7 @@ Rectangle { text: modelData.name glyph: modelData.icon active: sidebar.activePath === modelData.path - onClicked: sidebar.target.navigate(modelData.path) + onClicked: sidebar.go(modelData.path) } } @@ -309,7 +316,7 @@ Rectangle { text: modelData.name glyph: modelData.icon active: sidebar.activePath === modelData.path - onClicked: sidebar.target.navigate(modelData.path) + onClicked: sidebar.go(modelData.path) // The name ends short of the unpin button while it shows: // hovered, or on the keyboard's row, where Delete does // the same. @@ -368,7 +375,7 @@ Rectangle { text: modelData.icon === "trash" ? qsTr("Trash") : qsTr("Recents") glyph: modelData.icon active: sidebar.activePath === modelData.path - onClicked: sidebar.target.navigate(modelData.path) + onClicked: sidebar.go(modelData.path) keyed: sidebar.activeFocus && sidebar.cursor === sidebar.viewsAt + index onKeyedChanged: if (keyed) sidebar.reveal(this) } @@ -393,7 +400,7 @@ Rectangle { text: modelData.name glyph: eject.visible ? "" : modelData.icon active: sidebar.activePath === modelData.path - onClicked: sidebar.target.navigate(modelData.path) + onClicked: sidebar.go(modelData.path) detail: { translator.language // Re-read when the language (and so its digits) changes. return modelData.free < 0 ? "" : Format.free(modelData.free) @@ -471,7 +478,7 @@ Rectangle { return section.modelData.view ? section.modelData.view.count.toLocaleString(Qt.locale(), "f", 0) : "" } statusColor: theme.secondaryForeground - onClicked: sidebar.target.navigate(section.modelData.view.path) + onClicked: sidebar.go(section.modelData.view.path) } } } diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 7c6079f8..5aae20e4 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -672,6 +672,116 @@ private slots: QTRY_COMPARE(orders(), expected); } + // A place picked in the sidebar is the first column shown, with the + // folders above it scrolled out of sight to the left; going up shows + // them again. + void columnsStartAtAPlacePicked() + { + QTemporaryDir home; + QDir(home.path()).mkpath("Dropbox/Audio"); + QDir(home.path()).mkpath("Work"); + const QString dropbox = home.filePath("Dropbox"); + Backend backend(home.path()); + backend.navigate(home.filePath("Work")); + Theme theme(home.filePath("theme")); + FileOps fileOps; + Translator translator(home.filePath("language"), home.path()); + Thumbnails thumbnails(home.filePath("cache"), {home.filePath("none")}); + qmlRegisterType("Folio", 1, 0, "FolderModel"); + QQmlEngine engine; + engine.rootContext()->setContextProperty("backend", &backend); + engine.rootContext()->setContextProperty("theme", &theme); + engine.rootContext()->setContextProperty("fileOps", &fileOps); + engine.rootContext()->setContextProperty("translator", &translator); + engine.rootContext()->setContextProperty("plugins", QVariantMap{{"views", QVariantMap{}}}); + engine.addImageProvider("thumb", new ThumbnailProvider(&thumbnails)); + QQmlComponent component(&engine); + component.setData(R"( + import QtQuick + Window { + width: 1200; height: 480; visible: true + FolderColumns { id: folderView; anchors.fill: parent; Component.onCompleted: focusView() } + function startAt(path) { folderView.startAt(path) } + function scrolled() { + const flick = folderView.children[folderView.children.length - 1] + return flick.contentX + } + } + )", QUrl::fromLocalFile(sourceFolder() + "/ColumnsStartTest.qml")); + std::unique_ptr root(component.create()); + QVERIFY2(root, qPrintable(component.errorString())); + const auto scrolled = [&] { + QVariant x; + QMetaObject::invokeMethod(root.get(), "scrolled", Q_RETURN_ARG(QVariant, x)); + return x.toReal(); + }; + // Wide enough for home, Work and more: nothing's scrolled. + QTRY_COMPARE(backend.path(), home.filePath("Work")); + QCOMPARE(scrolled(), 0.0); + // Dropbox from the sidebar: home's column is out of sight. + QMetaObject::invokeMethod(root.get(), "startAt", Q_ARG(QVariant, dropbox)); + backend.navigate(dropbox); + QTRY_COMPARE(scrolled(), 261.0); + // Deeper, it stays out of sight. + backend.navigate(dropbox + "/Audio"); + QTRY_COMPARE(scrolled(), 261.0); + // Back up to Dropbox and then home, it's shown again. + backend.goUp(); + QTRY_COMPARE(scrolled(), 261.0); + backend.goUp(); + QTRY_COMPARE(scrolled(), 0.0); + // Picking where it already is starts there too. + backend.navigate(dropbox); + QTRY_COMPARE(scrolled(), 0.0); + QMetaObject::invokeMethod(root.get(), "startAt", Q_ARG(QVariant, dropbox)); + QTRY_COMPARE(scrolled(), 261.0); + } + + // A click on a folder in the last column, the one showing what's inside + // the selected folder, goes there: the folder it's in is shown, with it + // selected and its own contents beside it. + void columnsClickIntoTheLastColumn() + { + QTemporaryDir home; + QDir(home.path()).mkpath("Documents/Racing/2025/Le Mans"); + Backend backend(home.path()); + backend.navigate(home.filePath("Documents")); + Theme theme(home.filePath("theme")); + FileOps fileOps; + Translator translator(home.filePath("language"), home.path()); + Thumbnails thumbnails(home.filePath("cache"), {home.filePath("none")}); + qmlRegisterType("Folio", 1, 0, "FolderModel"); + QQmlEngine engine; + engine.rootContext()->setContextProperty("backend", &backend); + engine.rootContext()->setContextProperty("theme", &theme); + engine.rootContext()->setContextProperty("fileOps", &fileOps); + engine.rootContext()->setContextProperty("translator", &translator); + engine.rootContext()->setContextProperty("plugins", QVariantMap{{"views", QVariantMap{}}}); + engine.addImageProvider("thumb", new ThumbnailProvider(&thumbnails)); + QQmlComponent component(&engine); + component.setData(R"( + import QtQuick + Window { + width: 1200; height: 480; visible: true + property alias cursor: folderView.currentIndex + readonly property string selected: folderView.selected.name || "" + FolderColumns { id: folderView; anchors.fill: parent; Component.onCompleted: focusView() } + } + )", QUrl::fromLocalFile(sourceFolder() + "/ColumnsClickTest.qml")); + std::unique_ptr root(component.create()); + QVERIFY2(root, qPrintable(component.errorString())); + auto *window = qobject_cast(root.get()); + QVERIFY(QTest::qWaitForWindowExposed(window)); + QTRY_COMPARE(backend.folder()->rowCount(), 1); + root->setProperty("cursor", 0); + QTRY_COMPARE(root->property("selected").toString(), QString("Racing")); + // home's column, Documents', then Racing's contents: 2025. + QTest::qWait(300); + QTest::mouseClick(window, Qt::LeftButton, {}, QPoint(2 * 261 + 80, 20)); + QTRY_COMPARE(backend.path(), home.filePath("Documents/Racing")); + QTRY_COMPARE(root->property("selected").toString(), QString("2025")); + } + void folderListsDirectoriesFirstWithoutHidden() { QTemporaryDir dir;