Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,20 @@ 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, the app's filters and the button that answers. ⏎ 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`, for a window rule to float them.

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
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
167 changes: 167 additions & 0 deletions src/ChooserBar.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
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, the app's filters, Cancel, and the button that
// answers. 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
// 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))
}

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: !confirm.visible; onActivated: root.answer(root.picked) }
Comment thread
dhh marked this conversation as resolved.
Resolved

Rectangle {
id: bar
anchors.bottom: parent.bottom
width: parent.width
height: 64
color: theme.background
Rectangle { width: parent.width; height: 1; color: Qt.alpha(theme.foreground, 0.12) }

RowLayout {
anchors.fill: parent
anchors.leftMargin: 24
anchors.rightMargin: 20
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
}
// Otherwise, what the button would answer with.
Text {
visible: !root.naming
Layout.fillWidth: true
horizontalAlignment: Text.AlignLeft
text: !root.pane ? "" : chooser.answer(root.pane.paneBackend.path, root.picked, "")
.map(path => path.slice(path.lastIndexOf("/") + 1) || path).join(", ")
color: theme.secondaryForeground
elide: Text.ElideRight
}
PlainButton {
id: filterButton
visible: chooser.filters.length > 0
text: chooser.filters[chooser.filter] || ""
onClicked: filterMenu.open()
FolioMenu {
id: filterMenu
y: -height - 4
Repeater {
model: chooser.filters
FolioMenuItem {
required property int index
required property string modelData
text: modelData
checked: index === chooser.filter
onTriggered: chooser.filter = index
}
}
}
}
PlainButton {
text: qsTr("Cancel")
onClicked: chooser.cancel()
}
PlainButton {
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
2 changes: 2 additions & 0 deletions src/FolderPane.qml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,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
20 changes: 17 additions & 3 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, and smaller.
width: chooser ? 1040 : 1280
height: chooser ? 680 : 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 @@ -135,6 +138,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 +153,7 @@ ApplicationWindow {

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

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

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

HelpOverlay {
id: help
anchors.fill: parent
Expand Down
6 changes: 6 additions & 0 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ void Backend::open(const QString &path) {
navigate(path);
return;
}
if (m_choosing) {
emit chosen(path);
return;
}
// The desktop's default app for the type, or for the nearest type it
// belongs to.
if (const QString problem = FileOps::openInDefaultApp(path); !problem.isEmpty())
Expand Down Expand Up @@ -552,6 +556,8 @@ QString Backend::completePath(const QString &text) const {
}

void Backend::newWindow() {
if (m_choosing)
return;
emit newWindowRequested(FolderModel::isView(path()) ? m_home : path());
}

Expand Down
6 changes: 6 additions & 0 deletions src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class Backend : public QObject {
Q_INVOKABLE void togglePreview(const QString &path);
// Ctrl+N: another window, on the folder this one shows.
Q_INVOKABLE void newWindow();
// In a file chooser, opening a file picks it (chosen) rather than opening
// it in its app, and there are no other windows to open.
void setChoosing(bool choosing) { m_choosing = choosing; }
bool choosing() const { return m_choosing; }
// Keeps an open preview on the item selected in the grid.
Q_INVOKABLE void followSelection(const QString &path);
// Omarchy's Super+Return opens a terminal in the focused window's working
Expand Down Expand Up @@ -120,6 +124,7 @@ class Backend : public QObject {
void previewingChanged();
void detailsChanged();
void newWindowRequested(const QString &path);
void chosen(const QString &path);
void selectRequested(const QString &name);
void activateRequested();

Expand Down Expand Up @@ -160,6 +165,7 @@ class Backend : public QObject {
QTimer m_noticeTimer;
QString m_busy;
QString m_pendingSelection;
bool m_choosing = false;
Plugins *m_plugins = nullptr;
Mounter m_mounter;
// What's being connected to, as the window names it, and whether it's
Expand Down
Loading
Loading