From 86472b348de03a2ee3112721cdfa71f7856167f7 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 17 Nov 2026 15:41:00 +0100 Subject: [PATCH 1/3] Give the sidebar's folders a menu: Rename, Hide or Unpin, and Trash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Right-click (or Alt+Return on) a folder in the sidebar's Home or Pinned section for its menu, its first entry highlighted, as the drives' menu's now is too: - Rename… renames the folder itself. A pinned folder's pin follows it to its new name, from here or from the files. - Hide takes one of home's folders out of Home. It's kept by name in ~/.config/folio/hidden-in-home, and Show in Home in the folder's own menu, in ~, puts it back. Hidden, it can be pinned. A pinned folder has Unpin instead. - Trash moves the folder to the trash; with Alt held it becomes Delete…, for good after asking. The sidebar reads Home again as soon as file work ends, so a folder trashed or renamed there changes at once rather than at the next look. Co-Authored-By: Claude Opus 5.5 --- src/DriveMenu.qml | 2 + src/FileMenu.qml | 6 +++ src/FolderPane.qml | 5 ++ src/Main.qml | 2 + src/PlaceMenu.qml | 54 +++++++++++++++++++ src/RenameDialog.qml | 8 ++- src/Sidebar.qml | 38 +++++++++++-- src/fileops.cpp | 4 ++ src/fileops.h | 1 + src/i18n/en.json | 2 + src/places.cpp | 122 ++++++++++++++++++++++++++++++++++++------ src/places.h | 16 ++++++ src/resources.qrc | 1 + tests/folio_tests.cpp | 45 ++++++++++++++++ 14 files changed, 282 insertions(+), 24 deletions(-) create mode 100644 src/PlaceMenu.qml diff --git a/src/DriveMenu.qml b/src/DriveMenu.qml index 52638e3a..ba24d3e5 100644 --- a/src/DriveMenu.qml +++ b/src/DriveMenu.qml @@ -22,6 +22,8 @@ FolioMenu { popup(near, Math.min(near.width / 2, 120), near.height / 2) else popup() + // The first entry is highlighted already, as in the folders' menu. + currentIndex = 0 } FolioMenuItem { diff --git a/src/FileMenu.qml b/src/FileMenu.qml index dcee506e..6af294eb 100644 --- a/src/FileMenu.qml +++ b/src/FileMenu.qml @@ -139,6 +139,12 @@ FolioMenu { keys: "Ctrl+P" onTriggered: fileMenu.pinRequested(fileMenu.target.path) } + // A folder of home's hidden from its sidebar section goes back there. + FolioMenuItem { + shown: fileMenu.forFolder && places.hiddenFromHome(fileMenu.target.path) + text: qsTr("Show in Home") + onTriggered: places.showInHome(fileMenu.target.path) + } MenuLine { shown: fileMenu.forItem && fileMenu.forFiles } FolioMenuItem { shown: !fileMenu.trashView && fileMenu.forItem && fileMenu.forFiles diff --git a/src/FolderPane.qml b/src/FolderPane.qml index f22020d4..8b96c515 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() } + // Rename… in a sidebar folder's menu. + function renameFolder(path) { rename.open({ path: path, isDir: true }) } // A place picked in the sidebar: the columns start at it. function startAt(path) { if (view.item && view.item.startAt) view.item.startAt(path) } @@ -275,6 +277,9 @@ FocusScope { } function onFailed(message) { backend.showMessage(message) } function onNotice(notice) { backend.showNotice(notice) } + // Work done (a folder of home's trashed, say) shows in the sidebar + // at once, not at its next look in 15 seconds. + function onBusyChanged() { if (!fileOps.busy) places.refresh() } // A drive about to be formatted or burned is left first, by every // pane, and the sidebar shows it as it is afterwards. function onReleasing(root) { places.leave(root) } diff --git a/src/Main.qml b/src/Main.qml index 53006289..f8e3133a 100644 --- a/src/Main.qml +++ b/src/Main.qml @@ -172,6 +172,8 @@ ApplicationWindow { target: win.activePane ? win.activePane.paneBackend : backend onFinished: win.activePane.focusView() onPlaceChosen: (path) => win.activePane.startAt(path) + onRenameRequested: (path) => win.activePane.renameFolder(path) + onDeleteRequested: (path) => win.activePane.confirmDelete([path]) onFormatRequested: (disk) => win.activePane.formatDrive(disk) Layout.topMargin: parent.parent.barHeight Layout.preferredWidth: 190 diff --git a/src/PlaceMenu.qml b/src/PlaceMenu.qml new file mode 100644 index 00000000..c6205504 --- /dev/null +++ b/src/PlaceMenu.qml @@ -0,0 +1,54 @@ +import QtQuick + +// The menu of a folder in the sidebar's Home or Pinned section: Rename…, +// Hide (taking it out of Home, until Show in Home in its own menu puts it +// back) or Unpin, and Trash, which with Alt held becomes Delete… (for +// good, after asking). +FolioMenu { + id: menu + + // The sidebar's row for the folder: {name, path}, and whether it's + // pinned rather than one of home's own. + property var place: ({}) + property bool pinned: false + + signal renameRequested(string path) + signal deleteRequested(string path) + + // Opens at the pointer, or (from the keyboard) beside the row, with + // its first entry already highlighted. + function show(row, isPinned, near) { + place = row + pinned = isPinned + held = fileOps.altHeld() + if (near) + popup(near, Math.min(near.width / 2, 120), near.height / 2) + else + popup() + currentIndex = 0 + } + + // Alt can go down or up anywhere while the menu's open, so it's checked + // a few times a second rather than through key events. + property bool held: false + Timer { + interval: 50 + repeat: true + running: menu.visible + onTriggered: menu.held = fileOps.altHeld() + } + + FolioMenuItem { + text: qsTr("Rename…") + onTriggered: menu.renameRequested(menu.place.path) + } + FolioMenuItem { + text: menu.pinned ? qsTr("Unpin") : qsTr("Hide") + onTriggered: menu.pinned ? places.unpin(menu.place.path) : places.hideFromHome(menu.place.path) + } + MenuLine { } + FolioMenuItem { + text: menu.held ? qsTr("Delete…") : qsTr("Trash") + onTriggered: menu.held ? menu.deleteRequested(menu.place.path) : fileOps.trash([menu.place.path]) + } +} diff --git a/src/RenameDialog.qml b/src/RenameDialog.qml index 8e8aea4c..0f0a2a1d 100644 --- a/src/RenameDialog.qml +++ b/src/RenameDialog.qml @@ -28,8 +28,12 @@ FolioDialog { function close() { item = null } function submit() { problem = fileOps.rename(item.path, field.text) - if (problem.length === 0) - close() + if (problem.length > 0) + return + // A pinned folder's pin, or a folder hidden from Home, follows it. + if (item.isDir && typeof places !== "undefined") + places.renamed(item.path, item.path.slice(0, item.path.lastIndexOf("/") + 1) + field.text.trim()) + close() } // On the dialog, not the field, so Escape still cancels after Tab has diff --git a/src/Sidebar.qml b/src/Sidebar.qml index f0b425af..1998e821 100644 --- a/src/Sidebar.qml +++ b/src/Sidebar.qml @@ -19,6 +19,9 @@ Rectangle { signal finished() // Format… in a drive's menu, with what udisks knows of the drive. signal formatRequested(var disk) + // Rename… and Delete… in a folder's menu. + signal renameRequested(string path) + signal deleteRequested(string path) // A place picked here: the columns start at it, rather than at the // folders above it. signal placeChosen(string path) @@ -102,24 +105,38 @@ Rectangle { // Rows taken away under the keyboard leave it on the last one. onRowsChanged: cursor = Math.max(0, Math.min(cursor, rows.length - 1)) - // Alt+⏎ (or the Menu key) on a drive opens its menu beside it; the - // files' menu stands aside for it. + // Alt+⏎ (or the Menu key) on a drive or a folder of Home or Pinned + // opens its menu beside it; the files' menu stands aside for it. readonly property var keyedDrive: activeFocus && cursor >= devicesAt && cursor < pluginsAt ? driveRows.itemAt(cursor - devicesAt) : null + readonly property var keyedPlace: !activeFocus ? null + : cursor < pinnedAt ? homeRows.itemAt(cursor) + : cursor < viewsAt ? pinRows.itemAt(cursor - pinnedAt) : null function menuKey(event) { return ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && (event.modifiers & Qt.AltModifier)) || event.key === Qt.Key_Menu || (event.key === Qt.Key_F10 && (event.modifiers & Qt.ShiftModifier)) } - Keys.onShortcutOverride: (event) => event.accepted = menuKey(event) && keyedDrive !== null + Keys.onShortcutOverride: (event) => event.accepted = menuKey(event) && (keyedDrive !== null || keyedPlace !== null) // Return has its own handler, which Keys calls before this one. Keys.onPressed: (event) => event.accepted = openDriveMenu(event) function openDriveMenu(event) { - if (!menuKey(event) || !keyedDrive) + if (!menuKey(event)) + return false + if (keyedDrive) + driveMenu.show(keyedDrive.modelData, keyedDrive) + else if (keyedPlace) + placeMenu.show(keyedPlace.modelData, cursor >= pinnedAt, keyedPlace) + else return false - driveMenu.show(keyedDrive.modelData, keyedDrive) return true } + PlaceMenu { + id: placeMenu + onRenameRequested: (path) => sidebar.renameRequested(path) + onDeleteRequested: (path) => sidebar.deleteRequested(path) + } + DriveMenu { id: driveMenu onOpenRequested: (path) => { sidebar.go(path); sidebar.finished() } @@ -284,8 +301,10 @@ Rectangle { TapHandler { onTapped: sidebar.go(places.home) } } Repeater { + id: homeRows model: places.places PlaceRow { + id: homeRow required property var modelData required property int index dropPath: modelData.path @@ -296,6 +315,10 @@ Rectangle { glyph: modelData.icon active: sidebar.activePath === modelData.path onClicked: sidebar.go(modelData.path) + TapHandler { + acceptedButtons: Qt.RightButton + onTapped: placeMenu.show(homeRow.modelData, false, null) + } } } @@ -304,6 +327,7 @@ Rectangle { // empty) as the place to drop it. SectionLabel { text: qsTr("Pinned"); visible: places.pinned.length > 0 || sidebar.dragging } Repeater { + id: pinRows model: places.pinned PlaceRow { id: pinRow @@ -321,6 +345,10 @@ Rectangle { // hovered, or on the keyboard's row, where Delete does // the same. endPadding: unpin.visible ? unpin.implicitWidth + 6 : 14 + TapHandler { + acceptedButtons: Qt.RightButton + onTapped: placeMenu.show(pinRow.modelData, true, null) + } IconButton { id: unpin anchors.right: parent.right diff --git a/src/fileops.cpp b/src/fileops.cpp index bb4e36a6..45a9c0dd 100644 --- a/src/fileops.cpp +++ b/src/fileops.cpp @@ -151,6 +151,10 @@ bool FileOps::shiftHeld() { return QGuiApplication::queryKeyboardModifiers() & Qt::ShiftModifier; } +bool FileOps::altHeld() { + return QGuiApplication::queryKeyboardModifiers() & Qt::AltModifier; +} + void FileOps::copy(const QStringList &paths) { if (!paths.isEmpty()) QGuiApplication::clipboard()->setMimeData(mimeDataFor(paths, false)); diff --git a/src/fileops.h b/src/fileops.h index 9a87ecd8..662e8ec7 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -89,6 +89,7 @@ class FileOps : public QObject { // plain text, so pasting into a terminal or editor gives the path. // Whether Shift is held right now, for menus that change with it. Q_INVOKABLE static bool shiftHeld(); + Q_INVOKABLE static bool altHeld(); Q_INVOKABLE void copy(const QStringList &paths); Q_INVOKABLE void cut(const QStringList &paths); Q_INVOKABLE void yank(const QStringList &paths); diff --git a/src/i18n/en.json b/src/i18n/en.json index 03cb472a..3948ae3b 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -210,6 +210,7 @@ "GVfs gave no local folder for the mount": "GVfs gave no local folder for the mount", "Go home": "Go home", "Go to the parent folder": "Go to the parent folder", + "Hide": "Hide", "Hide Hidden Files": "Hide Hidden Files", "Home": "Home", "In list and columns: into a folder / back out": "In list and columns: into a folder / back out", @@ -364,6 +365,7 @@ "Show as grid": "Show as grid", "Show as list": "Show as list", "Show hidden files": "Show hidden files", + "Show in Home": "Show in Home", "Show these shortcuts": "Show these shortcuts", "Sign in": "Sign in", "Size": "Size", diff --git a/src/places.cpp b/src/places.cpp index e0a7d8cf..1abe9fb5 100644 --- a/src/places.cpp +++ b/src/places.cpp @@ -24,17 +24,17 @@ namespace { -// Home's own folders, all but the hidden ones (as refreshPlaces lists them), -// are already under Home. -bool listedUnderHome(const QString &path, const QString &home) { - const QString clean = QDir::cleanPath(home); - const QFileInfo info(path); - return path == clean || (info.absolutePath() == clean && !info.isHidden()); +// Whether `path` is one of home's own folders, which only Home lists. +bool inHome(const QString &path, const QString &home) { + return QFileInfo(path).absolutePath() == QDir::cleanPath(home); } -// Omarchy's own folder reads as the name it goes by. -QString displayName(const QString &name) { - return name == "omarchy" ? QStringLiteral("Omarchy") : name; +// Home's own folders, all but the dot-hidden ones and those hidden from +// Home (as refreshPlaces lists them), are already under Home. +bool listedUnderHome(const QString &path, const QString &home, const QStringList &hidden) { + const QString clean = QDir::cleanPath(home); + const QFileInfo info(path); + return path == clean || (inHome(path, home) && !info.isHidden() && !hidden.contains(info.fileName())); } // Home's folders read capitalized there, as the XDG ones are: go as Go, @@ -43,9 +43,14 @@ QString homeName(const QString &name) { return name.isEmpty() ? name : name.left(1).toUpper() + name.mid(1); } +// Omarchy's own folder reads as the name it goes by. +QString displayName(const QString &name) { + return name == "omarchy" ? QStringLiteral("Omarchy") : name; +} + // Reads bookmark lines ("file:///path Label") into pinned entries, leaving // out folders already listed under Home and missing folders. -QVariantList parseBookmarks(const QStringList &lines, const QString &home) { +QVariantList parseBookmarks(const QStringList &lines, const QString &home, const QStringList &hidden) { QVariantList pinned; QStringList seen; for (const QString &raw : lines) { @@ -62,7 +67,7 @@ QVariantList parseBookmarks(const QStringList &lines, const QString &home) { const QString path = QDir::cleanPath(url.toLocalFile()); // Home's visible folders are already under Home; Omarchy also seeds // a few of those as bookmarks for the file dialogs. - if (listedUnderHome(path, home) || seen.contains(path) || !QFileInfo(path).isDir()) + if (listedUnderHome(path, home, hidden) || seen.contains(path) || !QFileInfo(path).isDir()) continue; seen << path; pinned << QVariantMap{{"name", label.isEmpty() ? displayName(QFileInfo(path).fileName()) : label}, @@ -175,7 +180,10 @@ void Places::refreshPlaces() { collator.setNumericMode(true); collator.setCaseSensitivity(Qt::CaseInsensitive); std::sort(names.begin(), names.end(), [&](const QString &a, const QString &b) { return collator.compare(a, b) < 0; }); + m_hidden = readHidden(); for (const QString &name : names) { + if (m_hidden.contains(name)) + continue; const QString path = m_home + "/" + name; add(homeName(name), path, icons.value(path, "folder")); } @@ -188,11 +196,91 @@ void Places::refreshPlaces() { QVariantMap{{"path", QDir::cleanPath(FileOps::homeTrash() + "/files")}, {"icon", "trash"}}}; } +QString Places::configPath() const { + // Tests use a temporary home, whose settings live inside it. + return m_realHome ? QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + : m_home + "/.config"; +} + QString Places::bookmarksPath() const { - // Tests use a temporary home, whose bookmarks live inside it. - const QString config = m_realHome ? QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) - : m_home + "/.config"; - return config + "/gtk-3.0/bookmarks"; + return configPath() + "/gtk-3.0/bookmarks"; +} + +QString Places::hiddenPath() const { + return configPath() + "/folio/hidden-in-home"; +} + +QStringList Places::readHidden() const { + QFile file(hiddenPath()); + if (!file.open(QIODevice::ReadOnly)) + return {}; + QStringList names = QString::fromUtf8(file.readAll()).split('\n'); + names.removeAll(QString()); + return names; +} + +bool Places::writeHidden(const QStringList &names) { + QDir().mkpath(QFileInfo(hiddenPath()).absolutePath()); + QSaveFile file(hiddenPath()); + if (!file.open(QIODevice::WriteOnly)) + return false; + file.write(names.isEmpty() ? QByteArray() : (names.join('\n') + '\n').toUtf8()); + return file.commit(); +} + +bool Places::hiddenFromHome(const QString &path) const { + const QString clean = QDir::cleanPath(path); + return inHome(clean, m_home) && m_hidden.contains(QFileInfo(clean).fileName()); +} + +void Places::hideFromHome(const QString &path) { + const QString clean = QDir::cleanPath(path); + if (!inHome(clean, m_home) || hiddenFromHome(clean)) + return; + QStringList names = readHidden(); + names << QFileInfo(clean).fileName(); + if (!writeHidden(names)) + return; + refreshPlaces(); + refreshPinned(); + emit changed(); +} + +void Places::showInHome(const QString &path) { + const QString clean = QDir::cleanPath(path); + QStringList names = readHidden(); + if (!inHome(clean, m_home) || names.removeAll(QFileInfo(clean).fileName()) == 0 || !writeHidden(names)) + return; + refreshPlaces(); + refreshPinned(); + emit changed(); +} + +void Places::renamed(const QString &from, const QString &to) { + const QString before = QDir::cleanPath(from), after = QDir::cleanPath(to); + if (hiddenFromHome(before)) { + QStringList names = readHidden(); + names.removeAll(QFileInfo(before).fileName()); + if (inHome(after, m_home)) + names << QFileInfo(after).fileName(); + writeHidden(names); + } + // A pin keeps its label, and only its path changes. + QStringList lines = readBookmarkLines(); + bool moved = false; + for (QString &line : lines) { + const int space = line.indexOf(' '); + const QUrl url(space < 0 ? line : line.left(space)); + if (url.isLocalFile() && QDir::cleanPath(url.toLocalFile()) == before) { + line = QString::fromUtf8(QUrl::fromLocalFile(after).toEncoded()) + (space < 0 ? QString() : line.mid(space)); + moved = true; + } + } + if (moved) + writeBookmarkLines(lines); + refreshPlaces(); + refreshPinned(); + emit changed(); } QStringList Places::readBookmarkLines() const { @@ -216,7 +304,7 @@ bool Places::writeBookmarkLines(const QStringList &lines) { } void Places::refreshPinned() { - m_pinned = parseBookmarks(readBookmarkLines(), m_home); + m_pinned = parseBookmarks(readBookmarkLines(), m_home, m_hidden); } bool Places::isPinned(const QString &path) const { @@ -232,7 +320,7 @@ QString Places::pin(const QString &path) { const QFileInfo info(clean); if (!info.isDir()) return tr("Only folders can be pinned."); - if (listedUnderHome(clean, m_home)) + if (listedUnderHome(clean, m_home, m_hidden)) return tr("%1 is already under Home.").arg(displayName(info.fileName())); if (isPinned(clean)) return {}; diff --git a/src/places.h b/src/places.h index 077d11ce..eed13461 100644 --- a/src/places.h +++ b/src/places.h @@ -36,6 +36,16 @@ class Places : public QObject { Q_INVOKABLE void unpin(const QString &path); Q_INVOKABLE bool isPinned(const QString &path) const; + // Home's folders can be left out of its section (Hide in the sidebar's + // menu) and put back (Show in Home in the folder's own menu, in home). + // Kept by name in ~/.config/folio/hidden-in-home, one per line. + Q_INVOKABLE void hideFromHome(const QString &path); + Q_INVOKABLE void showInHome(const QString &path); + Q_INVOKABLE bool hiddenFromHome(const QString &path) const; + // A folder renamed: its pin, or its place among those hidden from Home, + // follows it to its new name. + Q_INVOKABLE void renamed(const QString &from, const QString &to); + // Lets go of the drive at `path`: ejects it when it can be (so a stick // or card is safe to pull out), otherwise unmounts it. Off the UI // thread, in GIO; `failed` says why when it can't. @@ -78,6 +88,10 @@ class Places : public QObject { void mountsRead(); void refreshPinned(); QString bookmarksPath() const; + QString configPath() const; + QString hiddenPath() const; + QStringList readHidden() const; + bool writeHidden(const QStringList &names); QStringList readBookmarkLines() const; bool writeBookmarkLines(const QStringList &lines); QString userDirectory(int location, const QString &fallback) const; @@ -85,6 +99,8 @@ class Places : public QObject { QString m_home; bool m_realHome; QVariantList m_places, m_pinned, m_views, m_devices; + // The names of home's folders left out of its section. + QStringList m_hidden; QTimer m_poll; QFutureWatcher> m_mounts; // Another refresh was asked for while one was reading. diff --git a/src/resources.qrc b/src/resources.qrc index c3997409..8ecd4571 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -31,6 +31,7 @@ ChooserBar.qml FormatDialog.qml DriveMenu.qml + PlaceMenu.qml RenameDialog.qml MountPrompt.qml PreviewWindow.qml diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 5aae20e4..b3405ea7 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -3934,6 +3934,51 @@ private slots: QCOMPARE(places.pinned().size(), 1); } + // Hide in a Home folder's sidebar menu takes it out of Home; Show in + // Home puts it back. A hidden one can be pinned, and a rename takes its + // hiding (or its pin) along. + void placesHideFoldersFromHome() + { + QTemporaryDir home; + for (const char *dir : {"Work", "go", "Dropbox", "Elsewhere/deep"}) + QDir(home.path()).mkpath(dir); + auto names = [](const Places &p) { + QStringList list; + for (const auto &v : p.places()) list << v.toMap().value("name").toString(); + return list; + }; + Places places(home.path()); + QCOMPARE(names(places), QStringList({"Dropbox", "Elsewhere", "Go", "Work"})); + + places.hideFromHome(home.filePath("go")); + QCOMPARE(names(places), QStringList({"Dropbox", "Elsewhere", "Work"})); + QVERIFY(places.hiddenFromHome(home.filePath("go"))); + QVERIFY(!places.hiddenFromHome(home.filePath("Work"))); + // Only home's own folders are hidden from Home. + places.hideFromHome(home.filePath("Elsewhere/deep")); + QVERIFY(!places.hiddenFromHome(home.filePath("Elsewhere/deep"))); + // Kept between launches. + QCOMPARE(names(Places(home.path())), QStringList({"Dropbox", "Elsewhere", "Work"})); + + // No longer under Home, it can be pinned. + QCOMPARE(places.pin(home.filePath("go")), QString()); + QCOMPARE(places.pinned().size(), 1); + + // Renamed, it stays hidden and pinned under its new name. + QVERIFY(QDir(home.path()).rename("go", "golang")); + places.renamed(home.filePath("go"), home.filePath("golang")); + QVERIFY(places.hiddenFromHome(home.filePath("golang"))); + QVERIFY(!places.hiddenFromHome(home.filePath("go"))); + QVERIFY(places.isPinned(home.filePath("golang"))); + QCOMPARE(names(places), QStringList({"Dropbox", "Elsewhere", "Work"})); + + // Shown in Home again, it's there rather than among the pins. + places.showInHome(home.filePath("golang")); + QCOMPARE(names(places), QStringList({"Dropbox", "Elsewhere", "Golang", "Work"})); + QVERIFY(!places.hiddenFromHome(home.filePath("golang"))); + QCOMPARE(places.pinned().size(), 0); + } + void typedViewsGoToTheirView() { // The path bar shows a view as its own name, so Return on it, or From b75055e18fd538512e4e490c7d9ee62131c8f65b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 17 Nov 2026 16:03:23 +0100 Subject: [PATCH 2/3] Follow renames through undo and redo, and say when a save fails A pinned folder's pin, and a folder hidden from Home, followed a rename only from the Rename dialog. Undoing or redoing the rename moved the folder without them, so the pin pointed at a folder no longer there and went, and a hidden folder came back under Home. And a blank name, which renames nothing, still moved the pin to the folder above. File work now tells of every rename (by Rename, and by undoing and redoing one), and each pane hands it to the sidebar's places; the dialog no longer does. A blank or unchanged name renames nothing and tells of nothing. Saving the pins or the hidden folders could fail (a read-only settings folder, a full disk) without a word, leaving a pin behind or a folder not hidden. Each failure is now said, as the drives' are. Co-Authored-By: Claude Opus 5.5 --- src/FolderPane.qml | 3 +++ src/RenameDialog.qml | 3 --- src/fileops.cpp | 7 +++++++ src/fileops.h | 3 +++ src/i18n/en.json | 1 + src/places.cpp | 17 ++++++++++++----- src/places.h | 2 +- tests/folio_tests.cpp | 25 +++++++++++++++++++++++++ 8 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/FolderPane.qml b/src/FolderPane.qml index 8b96c515..cc872c73 100644 --- a/src/FolderPane.qml +++ b/src/FolderPane.qml @@ -266,6 +266,9 @@ FocusScope { Connections { target: fileOps + // A pinned folder's pin, or a folder hidden from Home, follows it + // through a rename, and through undoing and redoing one. + function onRenamed(from, to) { places.renamed(from, to) } function onDone(folder, name) { if (folder !== backend.path) return diff --git a/src/RenameDialog.qml b/src/RenameDialog.qml index 0f0a2a1d..846f86e8 100644 --- a/src/RenameDialog.qml +++ b/src/RenameDialog.qml @@ -30,9 +30,6 @@ FolioDialog { problem = fileOps.rename(item.path, field.text) if (problem.length > 0) return - // A pinned folder's pin, or a folder hidden from Home, follows it. - if (item.isDir && typeof places !== "undefined") - places.renamed(item.path, item.path.slice(0, item.path.lastIndexOf("/") + 1) + field.text.trim()) close() } diff --git a/src/fileops.cpp b/src/fileops.cpp index 45a9c0dd..6bdd7b5d 100644 --- a/src/fileops.cpp +++ b/src/fileops.cpp @@ -1642,6 +1642,7 @@ QString FileOps::rename(const QString &path, const QString &name) { return QFileInfo::exists(destination) ? tr("%1 already exists here.").arg(clean) : tr("Couldn't rename %1.").arg(info.fileName()); remember({Renaming, info.fileName(), 1, {identified({false, destination, path})}}); + emit renamed(path, destination); emit done(info.absolutePath(), clean); return {}; } @@ -1945,6 +1946,12 @@ void FileOps::step(bool undoing) { sayStopped(job); else emit notice(didMessage(change, undoing)); + // A rename undone or redone moves the item back or on again; + // each flipped step is now at `path`, from `other`. + if (change.kind == Renaming) + for (const Step &step : result.steps.mid(result.left)) + if (!step.trash && !step.folder) + emit renamed(step.other, step.path); // What's back in a folder is selected there, as after a paste. for (const Step &step : result.steps.mid(result.left)) if (!step.folder && (!step.trash || step.other.isEmpty())) { diff --git a/src/fileops.h b/src/fileops.h index 662e8ec7..60713436 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -278,6 +278,9 @@ class FileOps : public QObject { void drivesChanged(); // Work finished in `folder`, which now holds `name` (to select it). void done(const QString &folder, const QString &name); + // An item renamed from `from` to `to`, by Rename or by undoing or + // redoing one, for the sidebar's pins and hidden folders to follow. + void renamed(const QString &from, const QString &to); private: void setBusy(const QString &busy); diff --git a/src/i18n/en.json b/src/i18n/en.json index 3948ae3b..f46d43ca 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -125,6 +125,7 @@ "Couldn't recreate %1.": "Couldn't recreate %1.", "Couldn't remove %1.": "Couldn't remove %1.", "Couldn't rename %1.": "Couldn't rename %1.", + "Couldn't save the hidden folders to %1.": "Couldn't save the hidden folders to %1.", "Couldn't save the pin to %1.": "Couldn't save the pin to %1.", "Couldn't start a terminal: xdg-terminal-exec isn't installed.": "Couldn't start a terminal: xdg-terminal-exec isn't installed.", "Couldn't unmount %1: %2": "Couldn't unmount %1: %2", diff --git a/src/places.cpp b/src/places.cpp index 1abe9fb5..8bb7a084 100644 --- a/src/places.cpp +++ b/src/places.cpp @@ -239,8 +239,10 @@ void Places::hideFromHome(const QString &path) { return; QStringList names = readHidden(); names << QFileInfo(clean).fileName(); - if (!writeHidden(names)) + if (!writeHidden(names)) { + emit failed(tr("Couldn't save the hidden folders to %1.").arg(hiddenPath())); return; + } refreshPlaces(); refreshPinned(); emit changed(); @@ -249,8 +251,12 @@ void Places::hideFromHome(const QString &path) { void Places::showInHome(const QString &path) { const QString clean = QDir::cleanPath(path); QStringList names = readHidden(); - if (!inHome(clean, m_home) || names.removeAll(QFileInfo(clean).fileName()) == 0 || !writeHidden(names)) + if (!inHome(clean, m_home) || names.removeAll(QFileInfo(clean).fileName()) == 0) + return; + if (!writeHidden(names)) { + emit failed(tr("Couldn't save the hidden folders to %1.").arg(hiddenPath())); return; + } refreshPlaces(); refreshPinned(); emit changed(); @@ -263,7 +269,8 @@ void Places::renamed(const QString &from, const QString &to) { names.removeAll(QFileInfo(before).fileName()); if (inHome(after, m_home)) names << QFileInfo(after).fileName(); - writeHidden(names); + if (!writeHidden(names)) + emit failed(tr("Couldn't save the hidden folders to %1.").arg(hiddenPath())); } // A pin keeps its label, and only its path changes. QStringList lines = readBookmarkLines(); @@ -276,8 +283,8 @@ void Places::renamed(const QString &from, const QString &to) { moved = true; } } - if (moved) - writeBookmarkLines(lines); + if (moved && !writeBookmarkLines(lines)) + emit failed(tr("Couldn't save the pin to %1.").arg(bookmarksPath())); refreshPlaces(); refreshPinned(); emit changed(); diff --git a/src/places.h b/src/places.h index eed13461..2a538053 100644 --- a/src/places.h +++ b/src/places.h @@ -43,7 +43,7 @@ class Places : public QObject { Q_INVOKABLE void showInHome(const QString &path); Q_INVOKABLE bool hiddenFromHome(const QString &path) const; // A folder renamed: its pin, or its place among those hidden from Home, - // follows it to its new name. + // follows it to its new name. Saving either failing says so (failed). Q_INVOKABLE void renamed(const QString &from, const QString &to); // Lets go of the drive at `path`: ejects it when it can be (so a stick diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index b3405ea7..e6f534ac 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -2577,19 +2577,29 @@ private slots: QDir(dir.path()).mkdir("sub"); FileOps ops; QSignalSpy notice(&ops, &FileOps::notice), failed(&ops, &FileOps::failed); + // Each rename is told, so the sidebar's pins follow it: by Rename, + // and by undoing and redoing one. A blank name renames nothing. + QSignalSpy renamed(&ops, &FileOps::renamed); + const auto lastRename = [&] { return renamed.last().at(0).toString() + " > " + renamed.last().at(1).toString(); }; QCOMPARE(ops.undoName(), QString()); + QCOMPARE(ops.rename(dir.filePath("a.txt"), " "), QString()); + QCOMPARE(renamed.count(), 0); QCOMPARE(ops.rename(dir.filePath("a.txt"), "b.txt"), QString()); + QCOMPARE(lastRename(), dir.filePath("a.txt") + " > " + dir.filePath("b.txt")); QCOMPARE(ops.undoName(), QString("Undo Rename")); ops.undo(); QTRY_VERIFY(ops.busy().isEmpty()); QVERIFY(QFile::exists(dir.filePath("a.txt"))); QVERIFY(!QFile::exists(dir.filePath("b.txt"))); QCOMPARE(notice.last().first().toString(), QString("Undid renaming a.txt.")); + QCOMPARE(lastRename(), dir.filePath("b.txt") + " > " + dir.filePath("a.txt")); ops.redo(); QTRY_VERIFY(ops.busy().isEmpty()); QVERIFY(QFile::exists(dir.filePath("b.txt"))); QCOMPARE(notice.last().first().toString(), QString("Redid renaming a.txt.")); + QCOMPARE(lastRename(), dir.filePath("a.txt") + " > " + dir.filePath("b.txt")); + const int renames = renamed.count(); ops.cut({dir.filePath("b.txt"), dir.filePath("c.txt")}); ops.paste(dir.filePath("sub")); @@ -2623,6 +2633,8 @@ private slots: QVERIFY(QDir(dir.filePath("sub")).isEmpty()); QCOMPARE(QDir(data.filePath("Trash/files")).entryList(QDir::Files), QStringList({"b.txt", "c.txt"})); QCOMPARE(failed.count(), 0); + // Moving and trashing aren't renaming. + QCOMPARE(renamed.count(), renames); // Undo goes back through them all, the newest first. for (int i = 0; i < 3; ++i) { @@ -2633,6 +2645,9 @@ private slots: QCOMPARE(contents(dir.filePath("c.txt")), QByteArray("c")); QCOMPARE(ops.undoName(), QString()); QCOMPARE(failed.count(), 0); + // The last of them a rename, told as the others weren't. + QCOMPARE(renamed.count(), renames + 1); + QCOMPARE(lastRename(), dir.filePath("b.txt") + " > " + dir.filePath("a.txt")); } void undoAndRedoPasteAndReplace() @@ -3977,6 +3992,16 @@ private slots: QCOMPARE(names(places), QStringList({"Dropbox", "Elsewhere", "Golang", "Work"})); QVERIFY(!places.hiddenFromHome(home.filePath("golang"))); QCOMPARE(places.pinned().size(), 0); + + // A save that fails says so, and changes nothing. + const QString settings = home.filePath(".config/folio"); + QVERIFY(QFile::setPermissions(settings, QFile::ReadOwner | QFile::ExeOwner)); + QSignalSpy failed(&places, &Places::failed); + places.hideFromHome(home.filePath("Work")); + QCOMPARE(failed.count(), 1); + QVERIFY(failed.last().first().toString().startsWith("Couldn't save the hidden folders")); + QVERIFY(names(places).contains("Work")); + QVERIFY(QFile::setPermissions(settings, QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)); } void typedViewsGoToTheirView() From 548b5676317fe622c70b809e970a3576fb06a7dd Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 17 Nov 2026 16:19:40 +0100 Subject: [PATCH 3/3] Trash a sidebar folder from the pane used last, and keep hidden names whole The sidebar's Trash went through the window's first pane, whatever pane was in use: its progress and errors showed there, and it refused to start while that pane was busy. It now goes through the pane used last, as Rename and Delete in the same menu do. The folders hidden from Home were saved a name to a line, so a folder whose name has a newline in it came back as two names: it stayed in Home, and folders named after its halves went. They're now saved as a JSON array, which keeps every name whole. Co-Authored-By: Claude Opus 5.5 --- src/Main.qml | 1 + src/PlaceMenu.qml | 3 ++- src/Sidebar.qml | 3 +++ src/places.cpp | 12 +++++++++--- src/places.h | 2 +- tests/folio_tests.cpp | 12 ++++++++++++ 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Main.qml b/src/Main.qml index f8e3133a..9be2f931 100644 --- a/src/Main.qml +++ b/src/Main.qml @@ -174,6 +174,7 @@ ApplicationWindow { onPlaceChosen: (path) => win.activePane.startAt(path) onRenameRequested: (path) => win.activePane.renameFolder(path) onDeleteRequested: (path) => win.activePane.confirmDelete([path]) + onTrashRequested: (path) => win.activePane.paneFileOps.trash([path]) onFormatRequested: (disk) => win.activePane.formatDrive(disk) Layout.topMargin: parent.parent.barHeight Layout.preferredWidth: 190 diff --git a/src/PlaceMenu.qml b/src/PlaceMenu.qml index c6205504..194ad29e 100644 --- a/src/PlaceMenu.qml +++ b/src/PlaceMenu.qml @@ -13,6 +13,7 @@ FolioMenu { property bool pinned: false signal renameRequested(string path) + signal trashRequested(string path) signal deleteRequested(string path) // Opens at the pointer, or (from the keyboard) beside the row, with @@ -49,6 +50,6 @@ FolioMenu { MenuLine { } FolioMenuItem { text: menu.held ? qsTr("Delete…") : qsTr("Trash") - onTriggered: menu.held ? menu.deleteRequested(menu.place.path) : fileOps.trash([menu.place.path]) + onTriggered: menu.held ? menu.deleteRequested(menu.place.path) : menu.trashRequested(menu.place.path) } } diff --git a/src/Sidebar.qml b/src/Sidebar.qml index 1998e821..64dfa2c9 100644 --- a/src/Sidebar.qml +++ b/src/Sidebar.qml @@ -22,6 +22,8 @@ Rectangle { // Rename… and Delete… in a folder's menu. signal renameRequested(string path) signal deleteRequested(string path) + // Trash in a folder's menu, done by the pane used last, as the rest are. + signal trashRequested(string path) // A place picked here: the columns start at it, rather than at the // folders above it. signal placeChosen(string path) @@ -135,6 +137,7 @@ Rectangle { id: placeMenu onRenameRequested: (path) => sidebar.renameRequested(path) onDeleteRequested: (path) => sidebar.deleteRequested(path) + onTrashRequested: (path) => sidebar.trashRequested(path) } DriveMenu { diff --git a/src/places.cpp b/src/places.cpp index 8bb7a084..272de4c6 100644 --- a/src/places.cpp +++ b/src/places.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -210,12 +212,16 @@ QString Places::hiddenPath() const { return configPath() + "/folio/hidden-in-home"; } +// A JSON array of names, so a name with any character in it (a newline +// even) is kept whole. QStringList Places::readHidden() const { QFile file(hiddenPath()); if (!file.open(QIODevice::ReadOnly)) return {}; - QStringList names = QString::fromUtf8(file.readAll()).split('\n'); - names.removeAll(QString()); + QStringList names; + for (const QJsonValue &name : QJsonDocument::fromJson(file.readAll()).array()) + if (!name.toString().isEmpty()) + names << name.toString(); return names; } @@ -224,7 +230,7 @@ bool Places::writeHidden(const QStringList &names) { QSaveFile file(hiddenPath()); if (!file.open(QIODevice::WriteOnly)) return false; - file.write(names.isEmpty() ? QByteArray() : (names.join('\n') + '\n').toUtf8()); + file.write(QJsonDocument(QJsonArray::fromStringList(names)).toJson()); return file.commit(); } diff --git a/src/places.h b/src/places.h index 2a538053..9026fabc 100644 --- a/src/places.h +++ b/src/places.h @@ -38,7 +38,7 @@ class Places : public QObject { // Home's folders can be left out of its section (Hide in the sidebar's // menu) and put back (Show in Home in the folder's own menu, in home). - // Kept by name in ~/.config/folio/hidden-in-home, one per line. + // Kept by name in ~/.config/folio/hidden-in-home, a JSON array. Q_INVOKABLE void hideFromHome(const QString &path); Q_INVOKABLE void showInHome(const QString &path); Q_INVOKABLE bool hiddenFromHome(const QString &path) const; diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index e6f534ac..15ce0155 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -3993,6 +3993,18 @@ private slots: QVERIFY(!places.hiddenFromHome(home.filePath("golang"))); QCOMPARE(places.pinned().size(), 0); + + // A name is kept whole, whatever it has in it: hiding one with a + // newline hides it, not folders named after its halves. + QVERIFY(QDir(home.path()).mkdir("Two\nLines")); + QVERIFY(QDir(home.path()).mkdir("Two")); + Places lines(home.path()); + lines.hideFromHome(home.filePath("Two\nLines")); + QVERIFY(lines.hiddenFromHome(home.filePath("Two\nLines"))); + QVERIFY(!lines.hiddenFromHome(home.filePath("Two"))); + QVERIFY(names(Places(home.path())).contains("Two")); + QVERIFY(!names(Places(home.path())).contains("Two\nLines")); + lines.showInHome(home.filePath("Two\nLines")); // A save that fails says so, and changes nothing. const QString settings = home.filePath(".config/folio"); QVERIFY(QFile::setPermissions(settings, QFile::ReadOwner | QFile::ExeOwner));