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..cc872c73 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) } @@ -264,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 @@ -275,6 +280,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..9be2f931 100644 --- a/src/Main.qml +++ b/src/Main.qml @@ -172,6 +172,9 @@ 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]) + 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 new file mode 100644 index 00000000..194ad29e --- /dev/null +++ b/src/PlaceMenu.qml @@ -0,0 +1,55 @@ +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 trashRequested(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) : menu.trashRequested(menu.place.path) + } +} diff --git a/src/RenameDialog.qml b/src/RenameDialog.qml index 8e8aea4c..846f86e8 100644 --- a/src/RenameDialog.qml +++ b/src/RenameDialog.qml @@ -28,8 +28,9 @@ FolioDialog { function close() { item = null } function submit() { problem = fileOps.rename(item.path, field.text) - if (problem.length === 0) - close() + if (problem.length > 0) + return + 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..64dfa2c9 100644 --- a/src/Sidebar.qml +++ b/src/Sidebar.qml @@ -19,6 +19,11 @@ 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) + // 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) @@ -102,24 +107,39 @@ 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) + onTrashRequested: (path) => sidebar.trashRequested(path) + } + DriveMenu { id: driveMenu onOpenRequested: (path) => { sidebar.go(path); sidebar.finished() } @@ -284,8 +304,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 +318,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 +330,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 +348,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..6bdd7b5d 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)); @@ -1638,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 {}; } @@ -1941,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 9a87ecd8..60713436 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); @@ -277,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 03cb472a..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", @@ -210,6 +211,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 +366,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..272de4c6 100644 --- a/src/places.cpp +++ b/src/places.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -24,17 +26,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 +45,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 +69,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 +182,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 +198,102 @@ 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"; +} + +// 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; + for (const QJsonValue &name : QJsonDocument::fromJson(file.readAll()).array()) + if (!name.toString().isEmpty()) + names << name.toString(); + 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(QJsonDocument(QJsonArray::fromStringList(names)).toJson()); + 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)) { + emit failed(tr("Couldn't save the hidden folders to %1.").arg(hiddenPath())); + 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) + return; + if (!writeHidden(names)) { + emit failed(tr("Couldn't save the hidden folders to %1.").arg(hiddenPath())); + 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(); + 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(); + 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)) + emit failed(tr("Couldn't save the pin to %1.").arg(bookmarksPath())); + refreshPlaces(); + refreshPinned(); + emit changed(); } QStringList Places::readBookmarkLines() const { @@ -216,7 +317,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 +333,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..9026fabc 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, 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; + // A folder renamed: its pin, or its place among those hidden from Home, + // 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 // 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..15ce0155 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() @@ -3934,6 +3949,73 @@ 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); + + + // 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)); + 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() { // The path bar shows a view as its own name, so Return on it, or