Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ add_executable(folio src/main.cpp src/resources.qrc)
target_link_libraries(folio PRIVATE folio_core)

# The tests compile the same sources, run offscreen, and read the QML they
# check straight from src/.
# check straight from src/, or whole windows from the resources.
enable_testing()
add_executable(folio_tests tests/folio_tests.cpp)
add_executable(folio_tests tests/folio_tests.cpp src/resources.qrc)
target_link_libraries(folio_tests PRIVATE folio_core Qt6::Test)
add_test(NAME folio_tests COMMAND folio_tests)
set_tests_properties(folio_tests PROPERTIES ENVIRONMENT QT_QPA_PLATFORM=offscreen)
Expand Down
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,30 @@ Files (`folio`) is Omarchy's file manager. It's one quiet window that follows yo
| Tab, Shift+Tab | Sidebar, panes and details |
| ? | Every other shortcut |

## Building
## Open and save dialogs

Files can also be the Open and Save dialog in other apps. `folio chooser` is a file chooser for xdg-desktop-portal, which apps like Firefox, Chromium and every Flatpak ask for their dialogs. To use it, put this in `~/.config/xdg-desktop-portal/hyprland-portals.conf`:

```ini
[preferred]
default=hyprland;gtk
org.freedesktop.impl.portal.FileChooser=folio
```

Then `systemctl --user restart xdg-desktop-portal`. A dialog is then a Files window, with a bar along the bottom for the name to save under, Cancel and the button that answers. When the app offers a choice of filters (Images, All files), they're under the funnel beside the view buttons. ⏎ on a file or a double click picks it, Ctrl+⏎ answers from anywhere, and Escape or closing the window cancels.

Its windows have their own app id, `folio-chooser`, and open at 875×600, the size Omarchy gives its floating windows. To float and center them the way Omarchy does GTK's dialogs, add this to `~/.config/hypr/hyprland.lua`:

```lua
o.window("folio-chooser", { tag = "+floating-window" })
```

| Open | Save |
| --- | --- |
| ![Open, in Pictures with the app's Images filter](docs/chooser-open.png) | ![Save, with the name selected up to its extension](docs/chooser-save.png) |

Two things it leaves out. Some apps add their own choices to a dialog (an encoding, say); those aren't shown, and the app keeps its defaults. And the dialog isn't attached to the app's window: it opens as a window of its own, not over the app.


Files is C++ and Qt Quick. `bin/build` compiles it into `build/folio`, and `bin/test` runs the tests. Omarchy installs it from [omarchy-pkgs](https://github.com/omacom/omarchy-pkgs).

Expand Down
Binary file added docs/chooser-open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/chooser-save.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion plans/folio.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ Done, tested, and verified offscreen:

## Open questions

- **File chooser.** Open/save dialogs in other apps come from `xdg-desktop-portal-gtk`, not Nautilus, so they keep working. Should Folio later provide the portal's FileChooser so dialogs look and behave like Folio?
- **File chooser.** Open/save dialogs in other apps come from `xdg-desktop-portal-gtk`, not Nautilus, so they keep working. Folio now provides the portal's FileChooser too, as `folio chooser`, turned on in `hyprland-portals.conf` (see the README). Should Omarchy make it the default, and float `folio-chooser` windows?
- **Nautilus as an option.** Offer `omarchy-install-nautilus` for people who want it back (with LocalSearch masked)?
- **Thumbnail sizes on HiDPI.** Request `x-large` (512) on scaled outputs, or keep `large` and accept softer tiles?
9 changes: 9 additions & 0 deletions share/folio-chooser.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]
Type=Application
Name=Files
Comment=Open and save dialogs for other apps
Exec=folio chooser
Icon=folio
Terminal=false
NoDisplay=true
StartupWMClass=folio-chooser
3 changes: 3 additions & 0 deletions share/folio.portal
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[portal]
DBusName=org.freedesktop.impl.portal.desktop.folio
Interfaces=org.freedesktop.impl.portal.FileChooser;
3 changes: 3 additions & 0 deletions share/org.freedesktop.impl.portal.desktop.folio.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[D-BUS Service]
Name=org.freedesktop.impl.portal.desktop.folio
Exec=/usr/bin/folio chooser
161 changes: 161 additions & 0 deletions src/ChooserBar.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

// What a file chooser's window adds to a Folio window, along the bottom:
// the name to save under, Cancel, and the button that answers. (The app's
// filters are in the path bar, with the other ways of showing the files.)
// The answer comes from the pane used last, with what's selected there;
// Return on a file or a double click answers with it, and so does
// Ctrl+Return from anywhere. It lies over the whole window, so that asking
// before replacing a file covers it.
Item {
id: root

required property var pane
readonly property int barHeight: bar.height
readonly property var host: ApplicationWindow.window
readonly property bool naming: chooser.mode === "save"
// Keys go to the name or the Replace prompt, not the window's shortcuts.
readonly property bool typing: nameField.activeFocus || confirm.visible
// Whether the window's Tab has stopped here.
readonly property bool hasKeyboard: nameField.activeFocus || cancelButton.activeFocus || answerButton.activeFocus
// Something else in the window is asking a question: the bar waits
// for it, rather than answering the app from under it.
readonly property bool waiting: confirm.visible || (!!pane && pane.asking) || (!!host && host.helpVisible)
// The selection, or the item under the cursor, as it changes.
readonly property var picked: pane ? (pane.paneBackend.folder.selectedCount, pane.selectedPaths()) : []

function answer(items) {
const backend = pane.paneBackend
const paths = chooser.answer(backend.path, items, nameField.text)
if (paths.length === 0) {
// Nothing to answer with yet: a folder typed as the name is gone
// into, and a folder picked to open is opened.
if (naming && nameField.text.trim().length > 0) {
// Read the way answer() reads it: a bare name exactly as
// typed, and only a path the way the path bar does.
const name = nameField.text
const here = backend.path + "/" + name
if (!name.includes("/") && !name.startsWith("~")) {
if (chooser.folders([here]).length > 0) {
backend.navigate(here)
nameField.text = ""
}
} else if (backend.goTyped(name)) {
nameField.text = ""
}
} else if (pane.current.isDir) {
backend.open(pane.current.path)
}
return
}
// The app names the files it saves, so a folder taking one of those
// names here can't be asked about: the files go somewhere else.
const folders = chooser.mode === "saveFiles" ? chooser.folders(paths) : []
if (folders.length > 0) {
backend.showNotice(qsTr("A folder here is already called %1.").arg(folders[0].slice(folders[0].lastIndexOf("/") + 1)))
return
}
const there = chooser.mode.startsWith("save") ? chooser.existing(paths) : []
if (there.length === 0) {
chooser.accept(paths)
return
}
const names = there.map(path => path.slice(path.lastIndexOf("/") + 1))
confirm.ask(names.length === 1 ? qsTr("Replace %1?").arg(names[0]) : qsTr("Replace %Ln files?", "", names.length),
names.length === 1 ? qsTr("%1 already exists here.").arg(names[0])
: qsTr("These already exist here: %1").arg(names.join(", ")),
qsTr("Replace"), () => chooser.accept(paths))
}

// Tab arrives at the name when saving, and at the answer otherwise.
function focusKeyboard() {
if (naming)
focusName()
else
answerButton.forceActiveFocus(Qt.TabFocusReason)
}

function focusName() {
nameField.forceActiveFocus()
const dot = fileOps.extensionStart(nameField.text, false)
nameField.select(0, dot > 0 ? dot : nameField.text.length)
}

// Saving starts in the name, once the window has given the files the
// keyboard.
Connections {
target: root.host
function onSettledChanged() { if (root.naming) Qt.callLater(root.focusName) }
}
Connections {
target: chooser
function onDone() { root.host.close() }
}
// A file opened in the pane: the answer, first of the selection when
// it's part of one; or when saving, the name to save under.
Connections {
target: root.pane ? root.pane.paneBackend : null
function onChosen(path) {
if (root.naming) {
nameField.text = path.slice(path.lastIndexOf("/") + 1)
root.focusName()
} else if (chooser.mode === "open") {
root.answer(root.picked.includes(path) ? [path].concat(root.picked.filter(p => p !== path)) : [path])
}
}
}
Shortcut { sequences: ["Ctrl+Return", "Ctrl+Enter"]; enabled: !root.waiting; onActivated: root.answer(root.picked) }

Rectangle {
id: bar
anchors.bottom: parent.bottom
width: parent.width
// As tall as the bar across the top, with the buttons as far from
// the window's edges below and beside them as the path bar's are
// from the edges above and beside its own.
height: 60
color: theme.background
enabled: !root.waiting
Rectangle { width: parent.width; height: 1; color: Qt.alpha(theme.foreground, 0.12) }

RowLayout {
anchors.fill: parent
anchors.margins: 12
spacing: 10

PlainField {
id: nameField
visible: root.naming
Layout.fillWidth: true
text: chooser.name
placeholderText: qsTr("Name")
onAccepted: root.answer(root.picked)
Comment thread
dhh marked this conversation as resolved.
Resolved
// The field keeps the window's Tab from moving on while it
// types, so it moves on itself.
Keys.onTabPressed: root.host.moveKeyboard(1)
Keys.onBacktabPressed: root.host.moveKeyboard(-1)
}
Item { visible: !root.naming; Layout.fillWidth: true }
PlainButton {
id: cancelButton
text: qsTr("Cancel")
onClicked: chooser.cancel()
}
PlainButton {
id: answerButton
primary: true
text: chooser.acceptLabel || (chooser.mode.startsWith("save") ? qsTr("Save")
: chooser.mode === "directory" ? qsTr("Choose") : qsTr("Open"))
onClicked: root.answer(root.picked)
}
}
}

ConfirmDialog {
id: confirm
anchors.fill: parent
onVisibleChanged: if (!visible && root.pane) root.pane.focusView()
}
}
2 changes: 2 additions & 0 deletions src/FolderColumns.qml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Item {
path: ancestor.path
showHidden: backend.folder.showHidden
sortMode: backend.folder.sortMode
filter: backend.folder.filter
onLoaded: column.revealNext()
}
// Names sort by the language's alphabet.
Expand Down Expand Up @@ -210,6 +211,7 @@ Item {
path: view.selected.isDir === true ? view.selected.path : ""
showHidden: backend.folder.showHidden
sortMode: backend.folder.sortMode
filter: backend.folder.filter
}
Connections {
target: translator
Expand Down
6 changes: 5 additions & 1 deletion src/FolderPane.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ FocusScope {
property bool cursorLetGo: false
// While a text field has the keyboard (renaming, a password), single-key
// and clipboard shortcuts stand aside so typing works.
readonly property bool typing: rename.visible || confirm.visible || clash.visible || formatDialog.visible || backend.mounter.asking || pathBar.editing || pathBar.searchFocused || (!!host && host.helpVisible)
readonly property bool typing: asking || pathBar.editing || pathBar.searchFocused || (!!host && host.helpVisible)
// Whether one of the pane's dialogs is up, waiting on an answer.
readonly property bool asking: rename.visible || confirm.visible || clash.visible || formatDialog.visible || backend.mounter.asking
// Keys for the pane as a whole (undo, a new window, typing a path) work
// wherever the keyboard is; keys for its files only while the files
// have it, not while Tab has put it in the sidebar or the details, where
Expand Down Expand Up @@ -84,6 +86,8 @@ FocusScope {
readonly property bool inView: backend.path.startsWith("plugin:")
readonly property bool fileKeys: keys && !inView
Binding { target: backend.folder; property: "items"; value: (plugins.views[backend.path] || {}).items || [] }
// In a file chooser, only the files that fit the app's filter.
Binding { target: backend.folder; property: "filter"; value: chooser ? chooser.patterns : [] }
function deleteSelected() {
const paths = pane.selectedPaths()
if (pane.inTrash)
Expand Down
2 changes: 2 additions & 0 deletions src/Glyph.qml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Item {
case "folder": return folderBox()
case "back": return "M15 6l-6 6 6 6"
case "forward": return "M9 6l6 6-6 6"
case "down": return "M6 9l6 6 6-6"
case "filter": return "M4 5h16l-6 7v6l-4 2v-8z"
case "grid": return box(4, 4, 6, 6, r / 2) + box(14, 4, 6, 6, r / 2) + box(4, 14, 6, 6, r / 2) + box(14, 14, 6, 6, r / 2)
case "list": return "M4 6h16M4 12h16M4 18h16"
case "columns": return box(3, 4, 18, 16, r) + "M9 4v16M15 4v16"
Expand Down
28 changes: 23 additions & 5 deletions src/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import QtCore
// the sidebar and the details follow the pane used last.
ApplicationWindow {
id: win
width: 1280
height: 800
// A file chooser's window is a dialog, the size of GTK's.
width: chooser ? 875 : 1280
height: chooser ? 600 : 800
minimumWidth: 720
minimumHeight: 460
visible: true
// The backend's title (Home, Trash) is translated in C++, which
// retranslating QML doesn't redo, so the language is read here too.
title: {
translator.language
if (chooser && chooser.title.length > 0)
return chooser.title
return activePane && activePane.paneBackend.title.length > 0 ? activePane.paneBackend.title : qsTr("Files")
}
color: theme.background
Expand Down Expand Up @@ -65,7 +68,7 @@ ApplicationWindow {
readonly property bool split: rightPane !== null
// Whether keys are going into a text field. The right pane can go before
// the window does when it closes, leaving activePane null.
readonly property bool typing: !!activePane && activePane.typing
readonly property bool typing: (!!activePane && activePane.typing) || (!!chooserBar.item && chooserBar.item.typing)
// The rightmost pane's path bar reaches over the details column.
readonly property int detailsWidth: details.visible ? details.width : 0
// Whether the window is wide enough for the details column at all.
Expand Down Expand Up @@ -119,13 +122,17 @@ ApplicationWindow {
Shortcut { sequence: "Tab"; enabled: !win.typing; onActivated: win.moveKeyboard(1) }
Shortcut { sequence: "Shift+Backtab"; enabled: !win.typing; onActivated: win.moveKeyboard(-1) }
function moveKeyboard(step) {
const stops = [sidebar, leftPane].concat(split ? [rightPane] : [], details.takesKeyboard ? [details] : [])
const here = sidebar.activeFocus ? sidebar : details.hasKeyboard ? details : activePane
// A file chooser's bar is the last stop: its name, or its answer.
const bar = chooserBar.item
const stops = [sidebar, leftPane].concat(split ? [rightPane] : [], details.takesKeyboard ? [details] : [], bar ? [bar] : [])
const here = sidebar.activeFocus ? sidebar : details.hasKeyboard ? details : bar && bar.hasKeyboard ? bar : activePane
const next = stops[(stops.indexOf(here) + step + stops.length) % stops.length]
if (next === sidebar)
sidebar.focusSidebar()
else if (next === details)
details.focusKeyboard()
else if (next === bar)
bar.focusKeyboard()
else
next.focusView()
}
Expand All @@ -135,6 +142,9 @@ ApplicationWindow {
enabled: win.settled
opacity: win.settled ? 1 : 0
Behavior on opacity { NumberAnimation { duration: 100 } }
// A file chooser cancels on Escape that nothing inside wanted.
Keys.enabled: !!chooser
Keys.onEscapePressed: chooser.cancel()

// The bar across the top; the panes' path bars draw over it.
readonly property int barHeight: 60
Expand All @@ -147,6 +157,7 @@ ApplicationWindow {

RowLayout {
anchors.fill: parent
anchors.bottomMargin: chooserBar.item ? chooserBar.item.barHeight : 0
spacing: 0

Sidebar {
Expand Down Expand Up @@ -192,6 +203,13 @@ ApplicationWindow {
}
}

Loader {
id: chooserBar
anchors.fill: parent
active: !!chooser
sourceComponent: ChooserBar { pane: win.activePane }
}

HelpOverlay {
id: help
anchors.fill: parent
Expand Down
Loading
Loading