Skip to content

Commit ca48b99

Browse files
dhhclaude
andcommitted
Start the columns at a place picked in the sidebar
Picking Dropbox in the sidebar showed ~ as the first column, Dropbox beside it, then its contents. The place picked is now the first column in sight, with the folders above it scrolled out to the left, there to scroll back to. Going deeper keeps it first; going up past it (with ←, or ~ in the path bar) shows what's above again. The details column, filling the rest of the window, counts only the columns in sight. Also covered now: a click on a folder in the last column (the selected folder's contents) goes into it. Installed builds from before #136 didn't. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 768e2a8 commit ca48b99

5 files changed

Lines changed: 166 additions & 15 deletions

File tree

‎src/FolderColumns.qml‎

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,32 @@ Item {
3333
// column, and the rest stay as they are instead of reloading (which
3434
// flashed).
3535
ListModel { id: trail }
36+
// How many of the folders on the way here are scrolled out of sight to
37+
// the left: a place picked in the sidebar is the first column shown,
38+
// with the folders above it there to scroll back to. Going up past it
39+
// shows what's above again.
40+
property int hidden: 0
41+
property string startingAt: ""
42+
function startAt(path) {
43+
startingAt = path
44+
if (backend.path === path)
45+
started()
46+
}
47+
function started() {
48+
startingAt = ""
49+
hidden = trail.count
50+
revealEnd()
51+
}
3652
function syncTrail() {
3753
const want = []
3854
for (let i = 0; i + 1 < crumbs.length; ++i)
3955
want.push({ path: crumbs[i].path, next: crumbs[i + 1].name })
4056
let same = 0
4157
while (same < trail.count && same < want.length && trail.get(same).path === want[same].path)
4258
++same
59+
// Somewhere else altogether (another drive, /) starts from its top.
60+
if (same === 0)
61+
hidden = 0
4362
// Columns that stay may now point at a different next folder.
4463
for (let i = 0; i < same; ++i)
4564
if (trail.get(i).next !== want[i].next)
@@ -48,14 +67,24 @@ Item {
4867
trail.remove(same, trail.count - same)
4968
for (let i = same; i < want.length; ++i)
5069
trail.append(want[i])
70+
hidden = Math.min(hidden, trail.count)
71+
if (startingAt.length > 0 && backend.path === startingAt)
72+
started()
5173
}
5274
onCrumbsChanged: syncTrail()
5375
Component.onCompleted: syncTrail()
5476
readonly property var selected: here.currentIndex >= 0 ? (backend.folder.count, backend.folder.get(here.currentIndex)) : ({})
5577

56-
// Keeps the newest columns in view as the trail grows: on the left,
57-
// when mirrored.
58-
function revealEnd() { flick.contentX = view.LayoutMirroring.enabled ? 0 : Math.max(0, flick.contentWidth - flick.width) }
78+
// Where the first column shown starts, from the side the columns grow
79+
// from: past the hidden ones and their separators.
80+
readonly property int hiddenWidth: hidden * (columnWidth + 1)
81+
// Keeps the newest columns in view as the trail grows, and the hidden
82+
// ones out of it: on the left, when mirrored.
83+
function revealEnd() {
84+
const from = Math.max(view.hiddenWidth, row.width - flick.width)
85+
const most = Math.max(0, flick.contentWidth - flick.width)
86+
flick.contentX = view.LayoutMirroring.enabled ? most - from : from
87+
}
5988
LayoutMirroring.onEnabledChanged: revealEnd()
6089
function enter() {
6190
if (view.selected.isDir && (insideFolder.loading || insideFolder.count > 0 || insideFolder.error.length > 0))
@@ -73,7 +102,9 @@ Item {
73102
anchors.fill: parent
74103
clip: true
75104
acceptedButtons: Qt.NoButton
76-
contentWidth: Math.max(width, row.width)
105+
// Room to scroll the hidden columns out of sight even when the rest
106+
// would fit.
107+
contentWidth: Math.max(width, row.width, view.hiddenWidth + width)
77108
contentHeight: height
78109
boundsBehavior: Flickable.StopAtBounds
79110
onContentWidthChanged: view.revealEnd()
@@ -232,9 +263,9 @@ Item {
232263
active: !!view.detailsPane && view.selected.path !== undefined && view.selected.isDir !== true
233264
visible: active
234265
sourceComponent: PreviewPane {
235-
// All the room right of the columns, and no narrower
236-
// than it reads well.
237-
width: Math.max(300, flick.width - (trail.count + 1) * (view.columnWidth + 1))
266+
// All the room right of the columns in sight, and no
267+
// narrower than it reads well.
268+
width: Math.max(300, flick.width - (trail.count - view.hidden + 1) * (view.columnWidth + 1))
238269
height: row.height
239270
folderPane: view.detailsPane
240271
onFinished: view.focusView()

‎src/FolderPane.qml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ FocusScope {
135135
// follow.
136136
onActiveFocusChanged: if (activeFocus && host) host.activePane = pane
137137
function focusView() { if (view.item) view.item.focusView() }
138+
// A place picked in the sidebar: the columns start at it.
139+
function startAt(path) { if (view.item && view.item.startAt) view.item.startAt(path) }
138140

139141
// Pins a folder to the sidebar, or unpins it when it's pinned already.
140142
function togglePin(target) {

‎src/Main.qml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ ApplicationWindow {
159159
id: sidebar
160160
target: win.activePane ? win.activePane.paneBackend : backend
161161
onFinished: win.activePane.focusView()
162+
onPlaceChosen: (path) => win.activePane.startAt(path)
162163
onFormatRequested: (disk) => win.activePane.formatDrive(disk)
163164
Layout.topMargin: parent.parent.barHeight
164165
Layout.preferredWidth: 190

‎src/Sidebar.qml‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ Rectangle {
1919
signal finished()
2020
// Format… in a drive's menu, with what udisks knows of the drive.
2121
signal formatRequested(var disk)
22+
// A place picked here: the columns start at it, rather than at the
23+
// folders above it.
24+
signal placeChosen(string path)
25+
function go(path) {
26+
placeChosen(path)
27+
target.navigate(path)
28+
}
2229
property int cursor: 0
2330
// The pane the sidebar acts on: the one used last.
2431
property var target: backend
@@ -65,7 +72,7 @@ Rectangle {
6572
if (row.root !== undefined)
6673
sidebar.target.open(row.path)
6774
else
68-
sidebar.target.navigate(row.path)
75+
sidebar.go(row.path)
6976
finished()
7077
}
7178
function reveal(item) {
@@ -115,7 +122,7 @@ Rectangle {
115122

116123
DriveMenu {
117124
id: driveMenu
118-
onOpenRequested: (path) => { sidebar.target.navigate(path); sidebar.finished() }
125+
onOpenRequested: (path) => { sidebar.go(path); sidebar.finished() }
119126
onFormatRequested: (disk) => sidebar.formatRequested(disk)
120127
}
121128

@@ -274,7 +281,7 @@ Rectangle {
274281
: homeHover.hovered ? theme.foreground : theme.secondaryForeground
275282
Accessible.role: Accessible.Button
276283
HoverHandler { id: homeHover; cursorShape: Qt.PointingHandCursor }
277-
TapHandler { onTapped: sidebar.target.navigate(places.home) }
284+
TapHandler { onTapped: sidebar.go(places.home) }
278285
}
279286
Repeater {
280287
model: places.places
@@ -288,7 +295,7 @@ Rectangle {
288295
text: modelData.name
289296
glyph: modelData.icon
290297
active: sidebar.activePath === modelData.path
291-
onClicked: sidebar.target.navigate(modelData.path)
298+
onClicked: sidebar.go(modelData.path)
292299
}
293300
}
294301

@@ -309,7 +316,7 @@ Rectangle {
309316
text: modelData.name
310317
glyph: modelData.icon
311318
active: sidebar.activePath === modelData.path
312-
onClicked: sidebar.target.navigate(modelData.path)
319+
onClicked: sidebar.go(modelData.path)
313320
// The name ends short of the unpin button while it shows:
314321
// hovered, or on the keyboard's row, where Delete does
315322
// the same.
@@ -368,7 +375,7 @@ Rectangle {
368375
text: modelData.icon === "trash" ? qsTr("Trash") : qsTr("Recents")
369376
glyph: modelData.icon
370377
active: sidebar.activePath === modelData.path
371-
onClicked: sidebar.target.navigate(modelData.path)
378+
onClicked: sidebar.go(modelData.path)
372379
keyed: sidebar.activeFocus && sidebar.cursor === sidebar.viewsAt + index
373380
onKeyedChanged: if (keyed) sidebar.reveal(this)
374381
}
@@ -393,7 +400,7 @@ Rectangle {
393400
text: modelData.name
394401
glyph: eject.visible ? "" : modelData.icon
395402
active: sidebar.activePath === modelData.path
396-
onClicked: sidebar.target.navigate(modelData.path)
403+
onClicked: sidebar.go(modelData.path)
397404
detail: {
398405
translator.language // Re-read when the language (and so its digits) changes.
399406
return modelData.free < 0 ? "" : Format.free(modelData.free)
@@ -471,7 +478,7 @@ Rectangle {
471478
return section.modelData.view ? section.modelData.view.count.toLocaleString(Qt.locale(), "f", 0) : ""
472479
}
473480
statusColor: theme.secondaryForeground
474-
onClicked: sidebar.target.navigate(section.modelData.view.path)
481+
onClicked: sidebar.go(section.modelData.view.path)
475482
}
476483
}
477484
}

‎tests/folio_tests.cpp‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,116 @@ private slots:
672672
QTRY_COMPARE(orders(), expected);
673673
}
674674

675+
// A place picked in the sidebar is the first column shown, with the
676+
// folders above it scrolled out of sight to the left; going up shows
677+
// them again.
678+
void columnsStartAtAPlacePicked()
679+
{
680+
QTemporaryDir home;
681+
QDir(home.path()).mkpath("Dropbox/Audio");
682+
QDir(home.path()).mkpath("Work");
683+
const QString dropbox = home.filePath("Dropbox");
684+
Backend backend(home.path());
685+
backend.navigate(home.filePath("Work"));
686+
Theme theme(home.filePath("theme"));
687+
FileOps fileOps;
688+
Translator translator(home.filePath("language"), home.path());
689+
Thumbnails thumbnails(home.filePath("cache"), {home.filePath("none")});
690+
qmlRegisterType<FolderModel>("Folio", 1, 0, "FolderModel");
691+
QQmlEngine engine;
692+
engine.rootContext()->setContextProperty("backend", &backend);
693+
engine.rootContext()->setContextProperty("theme", &theme);
694+
engine.rootContext()->setContextProperty("fileOps", &fileOps);
695+
engine.rootContext()->setContextProperty("translator", &translator);
696+
engine.rootContext()->setContextProperty("plugins", QVariantMap{{"views", QVariantMap{}}});
697+
engine.addImageProvider("thumb", new ThumbnailProvider(&thumbnails));
698+
QQmlComponent component(&engine);
699+
component.setData(R"(
700+
import QtQuick
701+
Window {
702+
width: 1200; height: 480; visible: true
703+
FolderColumns { id: folderView; anchors.fill: parent; Component.onCompleted: focusView() }
704+
function startAt(path) { folderView.startAt(path) }
705+
function scrolled() {
706+
const flick = folderView.children[folderView.children.length - 1]
707+
return flick.contentX
708+
}
709+
}
710+
)", QUrl::fromLocalFile(sourceFolder() + "/ColumnsStartTest.qml"));
711+
std::unique_ptr<QObject> root(component.create());
712+
QVERIFY2(root, qPrintable(component.errorString()));
713+
const auto scrolled = [&] {
714+
QVariant x;
715+
QMetaObject::invokeMethod(root.get(), "scrolled", Q_RETURN_ARG(QVariant, x));
716+
return x.toReal();
717+
};
718+
// Wide enough for home, Work and more: nothing's scrolled.
719+
QTRY_COMPARE(backend.path(), home.filePath("Work"));
720+
QCOMPARE(scrolled(), 0.0);
721+
// Dropbox from the sidebar: home's column is out of sight.
722+
QMetaObject::invokeMethod(root.get(), "startAt", Q_ARG(QVariant, dropbox));
723+
backend.navigate(dropbox);
724+
QTRY_COMPARE(scrolled(), 261.0);
725+
// Deeper, it stays out of sight.
726+
backend.navigate(dropbox + "/Audio");
727+
QTRY_COMPARE(scrolled(), 261.0);
728+
// Back up to Dropbox and then home, it's shown again.
729+
backend.goUp();
730+
QTRY_COMPARE(scrolled(), 261.0);
731+
backend.goUp();
732+
QTRY_COMPARE(scrolled(), 0.0);
733+
// Picking where it already is starts there too.
734+
backend.navigate(dropbox);
735+
QTRY_COMPARE(scrolled(), 0.0);
736+
QMetaObject::invokeMethod(root.get(), "startAt", Q_ARG(QVariant, dropbox));
737+
QTRY_COMPARE(scrolled(), 261.0);
738+
}
739+
740+
// A click on a folder in the last column, the one showing what's inside
741+
// the selected folder, goes there: the folder it's in is shown, with it
742+
// selected and its own contents beside it.
743+
void columnsClickIntoTheLastColumn()
744+
{
745+
QTemporaryDir home;
746+
QDir(home.path()).mkpath("Documents/Racing/2025/Le Mans");
747+
Backend backend(home.path());
748+
backend.navigate(home.filePath("Documents"));
749+
Theme theme(home.filePath("theme"));
750+
FileOps fileOps;
751+
Translator translator(home.filePath("language"), home.path());
752+
Thumbnails thumbnails(home.filePath("cache"), {home.filePath("none")});
753+
qmlRegisterType<FolderModel>("Folio", 1, 0, "FolderModel");
754+
QQmlEngine engine;
755+
engine.rootContext()->setContextProperty("backend", &backend);
756+
engine.rootContext()->setContextProperty("theme", &theme);
757+
engine.rootContext()->setContextProperty("fileOps", &fileOps);
758+
engine.rootContext()->setContextProperty("translator", &translator);
759+
engine.rootContext()->setContextProperty("plugins", QVariantMap{{"views", QVariantMap{}}});
760+
engine.addImageProvider("thumb", new ThumbnailProvider(&thumbnails));
761+
QQmlComponent component(&engine);
762+
component.setData(R"(
763+
import QtQuick
764+
Window {
765+
width: 1200; height: 480; visible: true
766+
property alias cursor: folderView.currentIndex
767+
readonly property string selected: folderView.selected.name || ""
768+
FolderColumns { id: folderView; anchors.fill: parent; Component.onCompleted: focusView() }
769+
}
770+
)", QUrl::fromLocalFile(sourceFolder() + "/ColumnsClickTest.qml"));
771+
std::unique_ptr<QObject> root(component.create());
772+
QVERIFY2(root, qPrintable(component.errorString()));
773+
auto *window = qobject_cast<QQuickWindow *>(root.get());
774+
QVERIFY(QTest::qWaitForWindowExposed(window));
775+
QTRY_COMPARE(backend.folder()->rowCount(), 1);
776+
root->setProperty("cursor", 0);
777+
QTRY_COMPARE(root->property("selected").toString(), QString("Racing"));
778+
// home's column, Documents', then Racing's contents: 2025.
779+
QTest::qWait(300);
780+
QTest::mouseClick(window, Qt::LeftButton, {}, QPoint(2 * 261 + 80, 20));
781+
QTRY_COMPARE(backend.path(), home.filePath("Documents/Racing"));
782+
QTRY_COMPARE(root->property("selected").toString(), QString("2025"));
783+
}
784+
675785
void folderListsDirectoriesFirstWithoutHidden()
676786
{
677787
QTemporaryDir dir;

0 commit comments

Comments
 (0)