Tunal/crates/tunal/ui/dialogs/connection.slint
astar76 7b13c1658e Seek bar, spring motion, archive formats, file pickers, icon browser and launchers
Seeking and the sidebar selection spring to the click. Compress and extract
cover the 7z formats. Path fields get a file picker, icon dialogs a browser
with categories. Create new makes launchers, Edit launcher changes them. New
tabs open Home and a file path opens its folder. Dialogs opened from a menu
keep the focus. Remote noted in CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-25 01:51:39 -06:00

150 lines
4.6 KiB
Text

import { Theme } from "../theme.slint";
import { Icons } from "../components/icon.slint";
import { Dialog } from "../components/dialog.slint";
import { ButtonKind } from "../components/button.slint";
import { FileKind, TextField } from "../components/text-field.slint";
import { Chip } from "../components/chip.slint";
// A saved SFTP connection as the dialog edits it. The password is never part of it.
export struct ConnectionData {
name: string,
host: string,
port: string,
user: string,
folder: string,
// 0 automatic (agent, default keys, password), 1 key file, 2 password.
auth: int,
key-file: string,
// An existing connection: the dialog offers Remove.
editing: bool,
error: string,
}
// Adds or edits a connection. `saved` returns the reason it can't be saved, or an empty
// string; the dialog stays open on a reason and shows it under the host.
export component ConnectionDialog inherits Dialog {
in-out property <ConnectionData> data;
callback saved(ConnectionData) -> string;
callback removed();
// The host changed: returns the data with a pasted `sftp://` or `ssh://` address split
// into the host, user, port and folder fields, or the data as it was.
callback host-edited(ConnectionData) -> ConnectionData;
glyph: Icons.cloud;
title: root.data.editing ? "Edit connection" : "New connection";
dialog-width: 520px;
content-focus: true;
actions: root.data.editing
? [{ text: "Cancel", kind: ButtonKind.text }, { text: "Remove", kind: ButtonKind.text }, { text: "Save", kind: ButtonKind.filled }]
: [{ text: "Cancel", kind: ButtonKind.text }, { text: "Save", kind: ButtonKind.filled }];
default-action: root.actions.length - 1;
cancel-action: 0;
focus-content => {
name-field.focus-input();
}
action(i) => {
if i == 0 {
self.close();
} else if root.data.editing && i == 1 {
self.close();
root.removed();
} else {
let reason = root.saved(root.data);
if reason == "" {
self.close();
} else {
root.data.error = reason;
}
}
}
name-field := TextField {
label: "Name";
placeholder: "Home server";
text <=> root.data.name;
}
HorizontalLayout {
spacing: Theme.space-3;
TextField {
horizontal-stretch: 1;
label: "Host";
placeholder: "name, address or sftp:// address";
error: root.data.error;
text <=> root.data.host;
edited => {
root.data.error = "";
root.data = root.host-edited(root.data);
}
}
TextField {
width: 96px;
label: "Port";
placeholder: "22";
text <=> root.data.port;
}
}
HorizontalLayout {
spacing: Theme.space-3;
TextField {
horizontal-stretch: 1;
label: "User";
placeholder: "your name on the server";
text <=> root.data.user;
}
TextField {
horizontal-stretch: 1;
label: "Start folder";
placeholder: "home folder";
text <=> root.data.folder;
}
}
HorizontalLayout {
spacing: Theme.space-2;
alignment: start;
Text {
text: "Sign in with";
color: Theme.on-surface-variant;
font-size: Theme.body-small.size;
font-weight: Theme.body-small.weight;
vertical-alignment: center;
}
for name[i] in ["Automatic", "Key file", "Password"]: Chip {
property <bool> sel: i == root.data.auth;
text: name;
checked: self.sel;
changed sel => {
self.checked = self.sel;
}
clicked => {
root.data.auth = i;
self.checked = true;
}
}
}
if root.data.auth == 1: TextField {
label: "Key file";
placeholder: "~/.ssh/id_ed25519";
picks: FileKind.key;
supporting: "The passphrase is asked when needed and never saved.";
text <=> root.data.key-file;
}
if root.data.auth != 1: Text {
text: root.data.auth == 0 ? "Uses your key agent and default keys, then asks for a password." : "Asks for the password each time it connects. It is never saved.";
color: Theme.on-surface-variant;
font-size: Theme.body-small.size;
font-weight: Theme.body-small.weight;
wrap: word-wrap;
}
}