Tunal/crates/tunal/ui/dialogs/folder-appearance.slint
astar76 7ba6ae8eae S015: .directory folder metadata (lossless dirmeta, folder icons/names/views, appearance dialog)
Needs S016's Bridge::elevation() and tunal-elevate to build.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-18 20:28:31 -06:00

155 lines
4.6 KiB
Text

import { Theme } from "../theme.slint";
import { Motion } from "../motion.slint";
import { Icon, Icons } from "../components/icon.slint";
import { Dialog } from "../components/dialog.slint";
import { ButtonKind } from "../components/button.slint";
import { StateLayer } from "../components/state-layer.slint";
import { Switch } from "../components/switch.slint";
import { TextField } from "../components/text-field.slint";
import { Shape, ShapeKind } from "../components/shape.slint";
// One icon the picker offers: a Material glyph, or an image from the icon theme. The first
// one is the folder's default look.
export struct IconChoice {
glyph: string,
picture: image,
has-picture: bool,
label: string,
}
component Cell inherits StateLayer {
in property <IconChoice> choice;
in property <bool> selected;
width: 44px;
height: 44px;
border-radius: Theme.corner-md;
focusable: false;
tooltip: root.choice.label;
accessible-role: radio-button;
accessible-label: root.choice.label;
accessible-checkable: true;
accessible-checked: root.selected;
Rectangle {
border-radius: parent.border-radius;
background: Theme.secondary-container;
opacity: root.selected ? 1 : 0;
animate opacity {
duration: Motion.time(Motion.short4);
easing: Motion.standard;
}
}
Shape {
size: 32px;
x: (root.width - self.width) / 2;
y: (root.height - self.height) / 2;
shape: ShapeKind.cookie9;
fill: root.selected ? Theme.primary : Theme.primary-container;
glyph: root.choice.glyph;
picture: root.choice.picture;
has-picture: root.choice.has-picture;
glyph-color: root.selected ? Theme.on-primary : Theme.on-primary-container;
}
}
// Display name, icon and per-folder view settings of one folder. `saved` runs on Save with the
// fields; the owner closes the dialog, or sets `error` (with `can-elevate` after a permission
// failure, which turns Save into "Save as administrator").
export component FolderAppearanceDialog inherits Dialog {
glyph: Icons.folder;
in property <[IconChoice]> icons;
in-out property <int> choice;
in-out property <string> name-text;
in-out property <string> image-path;
in-out property <bool> remember;
in property <string> placeholder;
in property <string> error;
in property <bool> can-elevate;
callback saved(bool);
title: "Folder appearance";
dialog-width: 456px;
actions: [
{ text: "Cancel", kind: ButtonKind.text },
{ text: root.can-elevate ? "Save as administrator" : "Save", kind: ButtonKind.filled }
];
default-action: 1;
cancel-action: 0;
content-focus: true;
focus-content => {
name-field.focus-input();
}
action(i) => {
if i == 1 {
root.saved(root.can-elevate);
} else {
root.close();
}
}
name-field := TextField {
label: "Display name";
placeholder: root.placeholder;
text <=> root.name-text;
accepted => {
root.saved(root.can-elevate);
}
}
Text {
text: "Icon";
color: Theme.on-surface-variant;
font-size: Theme.label-medium.size;
font-weight: Theme.label-medium.weight;
}
// Wraps in rows of cells; the height follows the number of choices.
property <int> columns: 9;
Rectangle {
height: ceil(root.icons.length / root.columns) * 44px;
for item[i] in root.icons: Cell {
x: mod(i, root.columns) * 46px;
y: floor(i / root.columns) * 44px;
choice: item;
selected: i == root.choice && root.image-path == "";
clicked => {
root.choice = i;
root.image-path = "";
}
}
}
TextField {
label: "Or an image file";
placeholder: "/path/to/picture.png";
text <=> root.image-path;
}
HorizontalLayout {
spacing: Theme.space-3;
Text {
horizontal-stretch: 1;
text: "Remember this view for the folder";
color: Theme.on-surface;
font-size: Theme.body-medium.size;
font-weight: Theme.body-medium.weight;
vertical-alignment: center;
}
Switch {
checked <=> root.remember;
accessible-label: "Remember this view for the folder";
}
}
if root.error != "": Text {
text: root.error;
color: Theme.error;
font-size: Theme.body-small.size;
wrap: word-wrap;
}
}