diff --git a/plans/folio.md b/plans/folio.md index fade4dca..d1955fe6 100644 --- a/plans/folio.md +++ b/plans/folio.md @@ -34,7 +34,7 @@ Done, tested, and verified offscreen: - `/` searches this folder and every folder below it by name as you type: a live breadth-first walk, nearest first, that stays on the folder's drive and doesn't follow symlinked folders. - Three views, remembered between launches: grid (Ctrl+1), list with name, size and date (Ctrl+2; no headings; the date then the size step aside when narrow), and Finder-style columns (Ctrl+3). - Preview pane: large preview, the system's type name, size, modified, dimensions, opening lines of text files, Open. -- Sidebar: a Home section (its label goes home) listing every folder in home (XDG folders and Dropbox with their own glyphs, `omarchy` shown as Omarchy); Pinned folders (Ctrl+D or drag onto the sidebar) stored as GTK bookmarks; Dropbox (with `dropbox-cli` sync status), Trash, physical drives (removable and extra internal disks, not the system's own), online tailnet machines from `tailscale status --json`. +- Sidebar: a Home section holding Home, every folder in home (XDG folders and Dropbox with their own glyphs, `omarchy` shown as Omarchy), Recents and Trash; Pinned folders (Ctrl+D or drag onto the sidebar) stored as GTK bookmarks; Dropbox (with `dropbox-cli` sync status), physical drives (removable and extra internal disks, not the system's own), online tailnet machines from `tailscale status --json`. - Tailnet machines open over SFTP through GIO, landing in the matching home folder; their host keys are accepted without asking (Tailscale already checked the peer), and a password, when keys aren't set up, is asked in the window. - Mouse back/forward buttons move through history (in the preview: previous/next file). - Space opens a large preview in its own process (`folio preview`), like Sushi: pictures at full size with zoom, animated GIF/WebP, video and audio playing (Qt Multimedia's FFmpeg backend), PDFs scrolling (Qt PDF), text and rendered Markdown, folders with their pictures, and the largest cached thumbnail for anything else. Arrows step through the folder and the grid follows; a crash in the preview is reported in the Folio window. Ctrl+I toggles the details pane. diff --git a/src/Glyph.qml b/src/Glyph.qml index dc33af44..dbced627 100644 --- a/src/Glyph.qml +++ b/src/Glyph.qml @@ -85,6 +85,7 @@ Item { case "audio": return "M4 10v4M8 7v10M12 4v16M16 8v8M20 11v2" case "check": return "M5 12l5 5 9-10" case "close": return "M6 6l12 12M18 6L6 18" + case "home": return "M4 10l8-6 8 6v10H4zM10 20v-6h4v6" default: return page() } } diff --git a/src/IconButton.qml b/src/IconButton.qml index 3ca21db3..a3c5e6c6 100644 --- a/src/IconButton.qml +++ b/src/IconButton.qml @@ -8,6 +8,11 @@ AbstractButton { property string glyph property bool active: false + // An on/off switch: off draws in the secondary ink, so on and off differ by brightness alone. + property bool toggle: false + // Some themes set brightForeground dimmer than foreground; on takes whichever stands out more. + readonly property color onInk: (theme.brightForeground.hslLightness > theme.foreground.hslLightness) !== theme.light + ? theme.brightForeground : theme.foreground implicitWidth: 36 implicitHeight: 36 @@ -26,7 +31,8 @@ AbstractButton { background: Rectangle { radius: Math.min(4, theme.radius) - color: button.active ? Qt.alpha(theme.accent, 0.16) + // A toggle says on by its ink alone; any other active button keeps the plate. + color: button.active && !button.toggle ? Qt.alpha(theme.accent, 0.16) : button.hovered && button.enabled ? Qt.alpha(theme.foreground, 0.08) : "transparent" } @@ -36,6 +42,7 @@ AbstractButton { anchors.centerIn: parent name: button.glyph color: !button.enabled ? Qt.alpha(theme.foreground, 0.35) + : button.toggle ? (button.active ? button.onInk : theme.secondaryForeground) : button.active ? theme.brightForeground : theme.foreground } } diff --git a/src/PathBar.qml b/src/PathBar.qml index 47c25d28..33ddf33a 100644 --- a/src/PathBar.qml +++ b/src/PathBar.qml @@ -1,4 +1,5 @@ import QtQuick +import QtQuick.Controls import QtQuick.Layouts // The breadcrumb path from the left edge; view buttons on the right. Back and @@ -85,6 +86,12 @@ Rectangle { cursorPosition = text.length } onActiveFocusChanged: if (!activeFocus && bar.editing) bar.stopEditing() + // A double click on the empty bar lands its second click here: keep the whole path selected, not a word. + MouseArea { + anchors.fill: parent + onPressed: mouse => mouse.accepted = (mouse.flags & Qt.MouseEventCreatedDoubleClick) !== 0 && pathField.selectedText === pathField.text + onDoubleClicked: mouse => mouse.accepted = pressed + } } PlainField { @@ -128,29 +135,79 @@ Rectangle { Keys.onEscapePressed: bar.endSearch() } - Flickable { + Item { + id: trail visible: !bar.editing && !bar.searching Layout.fillWidth: true Layout.fillHeight: true - contentWidth: Math.max(width, crumbs.implicitWidth) clip: true - boundsBehavior: Flickable.StopAtBounds - // Long paths keep their end in view; that's where you are. - // Mirrored, the end is on the left. - function revealEnd() { contentX = LayoutMirroring.enabled ? 0 : Math.max(0, contentWidth - width) } - onContentWidthChanged: revealEnd() - onWidthChanged: revealEnd() - LayoutMirroring.onEnabledChanged: revealEnd() + // The end stays in view; crumbs that don't fit whole fold into "…" at the reading start (the right, when mirrored). + property int first: 0 + property real offset: 0 + // Measured from each crumb's full width, so the current folder's own elide never changes what folds. + function fit() { + let rest = 0 + for (let k = 0; k < crumbRepeater.count; ++k) + rest += crumbRepeater.itemAt(k).fullWidth + (k > 0 ? crumbs.spacing : 0) + let i = 0 + if (rest > width) + while (i < crumbRepeater.count - 1 && rest > width - more.implicitWidth - crumbs.spacing) + rest -= crumbRepeater.itemAt(i++).fullWidth + crumbs.spacing + first = i + // How far the first shown crumb is from the row's start, which a mirrored Row puts at its right. + const shown = crumbRepeater.itemAt(i) + const lead = LayoutMirroring.enabled ? crumbs.width - shown.x - shown.width : shown.x + offset = i > 0 ? lead - more.implicitWidth - crumbs.spacing : 0 + } + onWidthChanged: fit() + LayoutMirroring.onEnabledChanged: fit() + + // A click on the empty part of the bar edits the path, as Ctrl+L does. + MouseArea { + anchors.fill: parent + onClicked: bar.editPath() + } + + Text { + id: more + // Above the folded crumbs, which still lie under it and would take its hover. + z: 1 + visible: trail.first > 0 + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + text: "…" + color: moreMouse.containsMouse ? theme.foreground : theme.secondaryForeground + font.pixelSize: 14 + // A crumb's hit margin, except toward the bar's edge, which would fall outside the clip. + MouseArea { + id: moreMouse + anchors.fill: parent + anchors.margins: -4 + anchors.leftMargin: 0 + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: backend.navigate(backend.crumbs[trail.first - 1].path) + // The folded path as the crumbs write it: "/" root, "~" home. + ToolTip { + visible: moreMouse.containsMouse + delay: 600 + text: crumbRepeater.model.slice(0, trail.first).map(c => c.name).join("/").replace("//", "/") + enter: null + exit: null + } + } + } Row { id: crumbs - // A Row isn't placed by its Flickable, so it's moved to the - // right edge by hand when mirrored. - x: LayoutMirroring.enabled ? parent.width - width : 0 + // A Row isn't placed by its parent, so it's moved to the right edge by hand when mirrored. + x: LayoutMirroring.enabled ? trail.width - width + trail.offset : -trail.offset anchors.verticalCenter: parent.verticalCenter spacing: 10 + onPositioningComplete: trail.fit() Repeater { + id: crumbRepeater // Recents, Trash and plugins' views are named in C++, which // retranslating QML doesn't redo. model: { translator.language; return backend.crumbs } @@ -159,8 +216,13 @@ Rectangle { required property var modelData required property int index readonly property bool last: index === backend.crumbs.length - 1 + readonly property real fullWidth: folderName.implicitWidth + (separator.visible ? separator.implicitWidth + spacing : 0) + // Folded crumbs keep their place so the others don't move. + opacity: index < trail.first ? 0 : 1 + enabled: index >= trail.first spacing: 10 Text { + id: separator // No separator after / itself: "/ run", not "/ / run". visible: crumb.index > 0 && !(crumb.index === 1 && backend.crumbs[0].name === "/") text: "/" @@ -168,6 +230,11 @@ Rectangle { font.pixelSize: 14 } Text { + id: folderName + // The current folder always shows; alone too wide, it elides. + width: crumb.last ? Math.max(0, Math.min(implicitWidth, trail.width - (separator.visible ? separator.implicitWidth + crumb.spacing : 0) + - (trail.first > 0 ? more.implicitWidth + crumbs.spacing : 0))) : implicitWidth + elide: Text.ElideRight text: crumb.modelData.name color: crumb.last ? theme.brightForeground : crumbMouse.containsMouse ? theme.foreground : theme.secondaryForeground font.pixelSize: 14 @@ -209,6 +276,7 @@ Rectangle { SortMenu { id: sortMenu } IconButton { glyph: "preview" + toggle: true // Only where the window has room to show them. visible: bar.previewFits text: qsTr("Details") diff --git a/src/Sidebar.qml b/src/Sidebar.qml index 9826bd11..07e90164 100644 --- a/src/Sidebar.qml +++ b/src/Sidebar.qml @@ -32,11 +32,12 @@ Rectangle { // Each plugin section's rows, then the row for its view. function sectionRows(section) { return section.view ? section.rows.concat([section.view]) : section.rows } readonly property var pluginRows: plugins.sections.reduce((all, section) => all.concat(sectionRows(section)), []) - readonly property var rows: [].concat(places.places, places.pinned, places.views, places.devices, pluginRows) - readonly property int pinnedAt: places.places.length - readonly property int viewsAt: pinnedAt + places.pinned.length - readonly property int devicesAt: viewsAt + places.views.length + readonly property var rows: [].concat([homeRow], places.places, places.views, places.pinned, places.devices, pluginRows) + readonly property int pinnedAt: viewsAt + places.views.length + readonly property int viewsAt: 1 + places.places.length + readonly property int devicesAt: pinnedAt + places.pinned.length readonly property int pluginsAt: devicesAt + places.devices.length + readonly property var homeRow: ({ path: places.home }) // Where a plugin section's rows start in `rows`. function sectionAt(index) { let at = pluginsAt @@ -89,7 +90,7 @@ Rectangle { // A pinned folder is unpinned, a plugin's item taken off the sidebar. Keys.onDeletePressed: { const row = rows[cursor] - if (cursor >= pinnedAt && cursor < viewsAt) + if (cursor >= pinnedAt && cursor < devicesAt) places.unpin(row.path) else if (row && row.forgettable) plugins.forget(row.plugin, row.id) @@ -125,7 +126,7 @@ Rectangle { readonly property string activePath: { let best = "" const here = sidebar.target.path - for (const list of [places.places, places.pinned, places.views, places.devices, + for (const list of [[homeRow], places.places, places.pinned, places.views, places.devices, plugins.sections.filter(section => section.view).map(section => section.view)]) { for (const p of list) { if (p.path !== "/" && (here === p.path || here.startsWith(p.path + "/")) && p.path.length > best.length) @@ -183,7 +184,9 @@ Rectangle { background: Rectangle { radius: Math.min(4, theme.radius) - color: row.active || row.dropHover ? Qt.alpha(theme.accent, 0.16) + // Accent only while the sidebar holds the keyboard; grey while the files do. + color: row.dropHover || row.active && sidebar.activeFocus ? Qt.alpha(theme.accent, 0.16) + : row.active ? Qt.alpha(theme.foreground, 0.10) : row.hovered && row.enabled ? Qt.alpha(theme.foreground, 0.06) : "transparent" border.width: row.dropHover ? 2 : row.keyed ? 1 : 0 border.color: theme.accent @@ -274,15 +277,19 @@ Rectangle { width: sidebar.width - 24 spacing: 1 - // The section's label is home itself: click it to go there. SectionLabel { Layout.topMargin: 0 text: qsTr("Home") - color: sidebar.target.path === places.home ? theme.accent - : homeHover.hovered ? theme.foreground : theme.secondaryForeground - Accessible.role: Accessible.Button - HoverHandler { id: homeHover; cursorShape: Qt.PointingHandCursor } - TapHandler { onTapped: sidebar.target.navigate(places.home) } + } + PlaceRow { + dropPath: places.home + onDropHoverChanged: sidebar.dropHovers += dropHover ? 1 : -1 + keyed: sidebar.activeFocus && sidebar.cursor === 0 + onKeyedChanged: if (keyed) sidebar.reveal(this) + text: qsTr("Home") + glyph: "home" + active: sidebar.activePath === places.home + onClicked: sidebar.target.navigate(places.home) } Repeater { model: places.places @@ -291,7 +298,7 @@ Rectangle { required property int index dropPath: modelData.path onDropHoverChanged: sidebar.dropHovers += dropHover ? 1 : -1 - keyed: sidebar.activeFocus && sidebar.cursor === 0 + index + keyed: sidebar.activeFocus && sidebar.cursor === 1 + index onKeyedChanged: if (keyed) sidebar.reveal(this) text: modelData.name glyph: modelData.icon @@ -300,6 +307,23 @@ Rectangle { } } + // Views: lists that aren't a folder of their own. + Repeater { + model: places.views + PlaceRow { + required property var modelData + required property int index + dropTrashes: modelData.icon === "trash" + onDropHoverChanged: sidebar.dropHovers += dropHover ? 1 : -1 + text: modelData.icon === "trash" ? qsTr("Trash") : qsTr("Recents") + glyph: modelData.icon + active: sidebar.activePath === modelData.path + onClicked: sidebar.target.navigate(modelData.path) + keyed: sidebar.activeFocus && sidebar.cursor === sidebar.viewsAt + index + onKeyedChanged: if (keyed) sidebar.reveal(this) + } + } + // Pinned folders from anywhere, kept in GTK's bookmarks. While a // folder is dragged over the sidebar, the section shows (even // empty) as the place to drop it. @@ -364,24 +388,6 @@ Rectangle { } } - // Views: lists that aren't a folder of their own. - SectionLabel { text: qsTr("Views") } - Repeater { - model: places.views - PlaceRow { - required property var modelData - required property int index - dropTrashes: modelData.icon === "trash" - onDropHoverChanged: sidebar.dropHovers += dropHover ? 1 : -1 - text: modelData.icon === "trash" ? qsTr("Trash") : qsTr("Recents") - glyph: modelData.icon - active: sidebar.activePath === modelData.path - onClicked: sidebar.target.navigate(modelData.path) - keyed: sidebar.activeFocus && sidebar.cursor === sidebar.viewsAt + index - onKeyedChanged: if (keyed) sidebar.reveal(this) - } - } - // Each drive says how much is free under its name, where there's // room for it, and while it's hovered or has the keyboard its icon // becomes the button that ejects it. Right-clicked, it has a menu diff --git a/src/i18n/en.json b/src/i18n/en.json index 369dbda5..42546d3f 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -438,7 +438,6 @@ "Untitled Folder": "Untitled Folder", "Untitled Folder %1": "Untitled Folder %1", "User": "User", - "Views": "Views", "Works almost anywhere, old cameras and car stereos too, but no file can be over 4 GB.": "Works almost anywhere, old cameras and car stereos too, but no file can be over 4 GB.", "Works with Mac, Windows and Linux, and holds big files.": "Works with Mac, Windows and Linux, and holds big files.", "You don't have permission to open this folder.": "You don't have permission to open this folder.", diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index e5278791..b326f2f7 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -4867,6 +4867,94 @@ private slots: QCOMPARE(window->property("answer").toString(), QString()); } + void sidebarDeleteUnpinsOnlyPinnedRows() + { + // Delete unpins the keyed pinned row wherever that section sits, and leaves Recents and Trash alone. + QTemporaryDir home, files; + for (const char *dir : {"Work/folio", "Work/hype"}) + QDir(home.path()).mkpath(dir); + QDir(files.path()).mkpath("plugins"); + const auto dataHome = dataHomeAt(files.filePath("data")); + // The Trash view's own folder, pinned too, so a Delete that reached the views would unpin it. + const QString trashFolder = QDir::cleanPath(FileOps::homeTrash() + "/files"); + QVERIFY(QDir().mkpath(trashFolder)); + Places places(home.path()); + QCOMPARE(places.pin(home.filePath("Work/folio")), QString()); + QCOMPARE(places.pin(home.filePath("Work/hype")), QString()); + QCOMPARE(places.pin(trashFolder), QString()); + Plugins plugins("en", {files.filePath("plugins")}, files.filePath("folio.conf")); + Backend backend(home.path()); + backend.navigate(home.path()); + Theme theme(files.filePath("theme")); + FileOps fileOps; + QQmlEngine engine; + engine.rootContext()->setContextProperty("backend", &backend); + engine.rootContext()->setContextProperty("places", &places); + engine.rootContext()->setContextProperty("plugins", &plugins); + engine.rootContext()->setContextProperty("theme", &theme); + engine.rootContext()->setContextProperty("fileOps", &fileOps); + engine.rootContext()->setContextProperty("translator", QVariantMap{{"language", "en"}}); + QQmlComponent component(&engine); + component.setData("import QtQuick\n" + "Window {\n" + " width: 300; height: 900; visible: true\n" + " Sidebar { id: sidebar; anchors.fill: parent }\n" + " property alias sidebar: sidebar\n" + " function keyed() { return sidebar.rows[sidebar.cursor].path }\n" + "}\n", + QUrl::fromLocalFile(sourceFolder() + "/SidebarDeleteTest.qml")); + std::unique_ptr root(component.create()); + QVERIFY2(root, qPrintable(component.errorString())); + auto *window = qobject_cast(root.get()); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowFocused(window)); + auto *sidebar = window->property("sidebar").value(); + const auto keyed = [&] { + QVariant path; + QMetaObject::invokeMethod(window, "keyed", Q_RETURN_ARG(QVariant, path)); + return path.toString(); + }; + const auto rows = [&] { return sidebar->property("rows").toList().size(); }; + const auto at = [&](const char *name) { return sidebar->property(name).toInt(); }; + const auto pinnedPath = [&](int i) { return places.pinned().at(i).toMap().value("path").toString(); }; + // At most one key per row, so a row the keys cannot reach fails instead of hanging. + const auto moveTo = [&](int row) { + for (int step = 0; step < rows() && at("cursor") != row; ++step) + QTest::keyClick(window, at("cursor") < row ? Qt::Key_Down : Qt::Key_Up); + return at("cursor") == row; + }; + + QVERIFY(QMetaObject::invokeMethod(sidebar, "focusSidebar")); + QVERIFY(sidebar->property("activeFocus").toBool()); + QCOMPARE(at("cursor"), 0); + QCOMPARE(places.views().size(), 2); + QCOMPARE(places.views().at(1).toMap().value("path").toString(), trashFolder); + QCOMPARE(places.pinned().size(), 3); + + // Recents and Trash are views, not pins. + const int before = rows(); + for (int view = 0; view < 2; ++view) { + QVERIFY(moveTo(at("viewsAt") + view)); + QCOMPARE(keyed(), places.views().at(view).toMap().value("path").toString()); + QTest::keyClick(window, Qt::Key_Delete); + QCOMPARE(places.pinned().size(), 3); + QVERIFY(places.isPinned(trashFolder)); + QCOMPARE(rows(), before); + } + + // The last pinned row, then the first: both ends of the range. + const QString first = pinnedPath(0), middle = pinnedPath(1), last = pinnedPath(2); + QVERIFY(moveTo(at("pinnedAt") + 2)); + QCOMPARE(keyed(), last); + QTest::keyClick(window, Qt::Key_Delete); + QVERIFY(!places.isPinned(last)); + QVERIFY(moveTo(at("pinnedAt"))); + QCOMPARE(keyed(), first); + QTest::keyClick(window, Qt::Key_Delete); + QVERIFY(!places.isPinned(first)); + QVERIFY(places.isPinned(middle)); + } + void formattingOffersWhatThisMachineCanMake() { // exFAT first, and only the filesystems whose tools are installed.