Tunal/crates/tunal/ui/app.slint
2026-11-19 00:11:52 -06:00

896 lines
30 KiB
Text

import "../../../assets/fonts/MaterialSymbolsRounded[FILL,GRAD,opsz,wght].ttf";
import { Theme } from "theme.slint";
import { Shapes, ShapeKind } from "shapes.slint";
import { Icons } from "components/icon.slint";
import { Motion, MotionPrefs } from "motion.slint";
import { Menu, MenuItem, MenuEntry } from "components/menu.slint";
import { Dialog } from "components/dialog.slint";
import { ButtonKind } from "components/button.slint";
import { TextField } from "components/text-field.slint";
import { DetailRow, FolderState, FolderStatus, Grouping, NavKey, SortColumn, Travel, ViewMode } from "views/details-view.slint";
import { GridRow } from "views/grid-view.slint";
import { TabBar, TabData } from "shell/tab-bar.slint";
import { Toolbar } from "shell/toolbar.slint";
import { Crumb, Completion, CompletionList } from "shell/breadcrumb.slint";
import { Pane, PaneData } from "shell/pane.slint";
import { Sidebar, SidebarSection, PlaceItem } from "shell/sidebar.slint";
import { StatusBar } from "shell/status-bar.slint";
import { PlayerBar, PlayerData } from "shell/player-bar.slint";
import { ToastStack, ToastData, ToastProgress } from "components/toast.slint";
import { DialogAction } from "components/dialog.slint";
import { ConflictDialog, ConflictInfo } from "dialogs/conflict.slint";
import { ConfirmDialog } from "dialogs/confirm.slint";
import { ErrorsDialog } from "dialogs/errors.slint";
import { PropertiesDialog, PropertiesInfo, PropRow } from "dialogs/properties.slint";
import { OpenWithDialog, AppRow } from "dialogs/open-with.slint";
import { FolderAppearanceDialog, IconChoice } from "dialogs/folder-appearance.slint";
import { TagEditorDialog, TagEditorData, TagField } from "dialogs/tag-editor.slint";
import { TagLookupDialog, TagLookupData, ReleaseRow, MapRow } from "dialogs/tag-lookup.slint";
import { SettingsDialog, SettingsData, EditRow } from "dialogs/settings.slint";
import { Dnd, DropAction, DropMenu, DropTarget } from "components/drop-menu.slint";
export { Theme, Shapes, ShapeKind, MotionPrefs, MenuItem, MenuEntry, DetailRow, FolderState, FolderStatus, Grouping, NavKey, SortColumn, Travel, ViewMode, GridRow }
export { ButtonKind, TabData, PaneData, Crumb, Completion, SidebarSection, PlaceItem, ToastData, ToastProgress, DialogAction, ConflictInfo, SettingsData, EditRow }
export { PlayerData }
export { PropertiesInfo, PropRow, AppRow, IconChoice, Dnd, DropAction, DropTarget, TagEditorData, TagField, TagLookupData, ReleaseRow, MapRow }
export { Gallery, GalleryPage } from "gallery.slint";
// The window: sidebar, tab bar, toolbar with the breadcrumb, the panes of the current tab
// (two in split view) and the status bar. State comes from Rust (shell/).
export component MainWindow inherits Window {
title: "Tunal";
icon: @image-url("../../../assets/tunal.png");
min-width: 720px;
min-height: 480px;
preferred-width: 960px;
preferred-height: 640px;
// The sidebar and tab bar sit on the window; the panes on a rounded card above it.
background: Theme.surface-container;
animate background { duration: Motion.time(Motion.medium2); easing: Motion.standard; }
// Tabs, by opening order (see TabData).
in property <[TabData]> tabs;
in property <int> current-tab;
in property <int> current-slot;
callback tab-selected(int);
callback tab-closed(int);
callback tab-moved(int, int);
callback new-tab();
callback cycle-tab(bool);
callback close-tab();
// The panes of the current tab; the toolbar, breadcrumb and keys act on the active one.
in property <[PaneData]> panes;
in property <int> active-pane;
// Bumped by Rust to move keyboard focus into the active pane.
in property <int> focus-request;
// The pane under the pointer (mouse back and forward buttons), -1 for none.
out property <int> hovered-pane: -1;
callback pane-activated(int);
callback sort-by(int, SortColumn);
callback filter-typed(int, string);
callback filter-edited(int, string);
callback toggle-hidden(int);
callback toggle-previews(int);
callback viewport-changed(int, length, length, length, length);
callback row-clicked(int, int, bool, bool);
callback row-activated(int, int);
callback select-all(int);
callback clear-selection(int);
callback navigate(int, NavKey, bool, int) -> int;
callback grid-columns-changed(int, int);
callback motion-settled(int);
callback view-mode-selected(int, ViewMode);
in property <[MenuItem]> sort-menu;
callback sort-menu-activated(int, int);
// File actions (actions.rs): the keys, the context menu, inline rename, jobs.
// Called for every key the window sees with Ctrl, or a function or Delete key; true when
// it was an action's shortcut.
callback action-key(string, bool, bool, bool) -> bool;
in property <[MenuItem]> context-menu-items;
// A right click in pane `i` on row (-1: none) at window coordinates.
callback context-menu-requested(int, int, length, length);
callback actions-menu-requested(length, length);
callback context-menu-activated(int);
callback row-renamed(int, int, string);
callback rename-cancelled(int);
in property <[ToastData]> toasts;
callback toast-cancelled(int);
callback toast-removed(int);
in property <ConflictInfo> conflict;
callback conflict-chosen(int, bool);
in property <string> confirm-title;
in property <string> confirm-body;
in property <string> confirm-action;
callback confirm-answered(bool);
in property <string> errors-title;
in property <string> errors-body;
in property <[string]> errors-lines;
in property <[DialogAction]> errors-actions;
// The button Enter and Escape press.
in property <int> errors-default;
callback errors-answered(int);
// Settings dialog (settings.rs). `settings-opening` runs before it shows, so Rust can
// fill it in.
in-out property <SettingsData> settings;
in property <[string]> menu-contexts;
in property <int> menu-context;
in property <[EditRow]> menu-rows;
in property <[EditRow]> menu-available;
in property <bool> menu-can-reset;
callback settings-opening();
callback settings-changed(SettingsData);
callback menu-context-selected(int);
callback menu-moved(int, int);
callback menu-removed(int);
callback menu-added(int);
callback menu-separator-added();
callback menu-reset();
// Folder appearance (folder/appearance.rs).
in property <[IconChoice]> appearance-icons;
in-out property <int> appearance-choice;
in-out property <string> appearance-name;
in-out property <string> appearance-image;
in-out property <bool> appearance-remember;
in property <string> appearance-placeholder;
in property <string> appearance-error;
in property <bool> appearance-can-elevate;
callback appearance-saved(bool);
callback appearance-done(bool);
// Tag editor and lookup (tags_bridge.rs).
in-out property <TagEditorData> tag-editor;
callback tag-editor-saved();
callback tag-editor-lookup();
callback tag-field-changed(int, string);
callback tag-cover-path(string);
callback tag-cover-dropped(data-transfer);
callback tag-cover-removed();
callback tag-cover-reset();
in-out property <TagLookupData> tag-lookup;
callback tag-artist-edited(string);
callback tag-album-edited(string);
callback tag-search();
callback tag-release-picked(int);
callback tag-next();
callback tag-back();
callback tag-lookup-cancelled();
callback tag-map-step(int, int);
callback tag-embed-toggled(bool);
callback tag-apply();
// Tags were written to the files; the argument is the message for a toast.
callback tags-written(string);
// The quick player (player_bridge.rs): `player-peaks` has `player-bar-count` bars.
in property <PlayerData> player;
in property <[float]> player-peaks;
in property <float> player-position;
out property <int> player-bar-count: player-bar.bar-count;
callback player-toggle();
callback player-close();
// Fraction of the track.
callback player-seek(float);
// -1 back, 1 forward.
callback player-step(int);
callback player-volume(float);
callback player-mute();
callback player-bars-changed();
// Properties (properties.rs) and Open with (open.rs).
in property <PropertiesInfo> properties;
callback properties-closed();
in property <[AppRow]> open-with-apps;
in-out property <int> open-with-selected;
in-out property <bool> open-with-as-default;
in property <string> open-with-mime;
// Row -1: cancelled.
callback open-with-chosen(int, bool);
// Navigation of the active pane.
in property <bool> can-back;
in property <bool> can-forward;
in property <bool> can-up;
in property <[Crumb]> crumbs;
in property <string> path;
in property <[Completion]> completions;
callback back();
callback forward();
callback up();
callback go-crumb(int);
callback path-edited(string);
callback path-accepted(string);
// Editing the path ended without going anywhere.
callback path-reverted();
callback toggle-split();
// Sidebar.
in property <[SidebarSection]> sections;
in property <bool> show-sidebar: true;
in property <[MenuItem]> place-menu;
callback toggle-sidebar();
callback place-opened(int, int, bool);
callback section-toggled(int);
callback add-bookmark();
callback place-menu-requested(int, int);
callback place-menu-activated(int, int);
callback bookmark-renamed(string);
in property <string> status;
public function open-place-menu(x: length, y: length) {
place-popup.open-at(x, y);
}
public function rename-bookmark(name: string) {
rename-field.text = name;
rename-dialog.show();
}
public function open-context-menu(x: length, y: length) {
context-popup.open-at(x, y);
}
// After a drop without modifiers (dnd.rs): 0 move, 1 copy, 2 link, else cancel.
callback drop-chosen(int);
public function open-drop-menu(x: length, y: length) {
drop-popup.open-at(x, y);
}
public function show-settings(page: int) {
root.settings-opening();
settings-dialog.page = page;
settings-dialog.show();
}
public function show-conflict() {
conflict-dialog.apply-all = false;
conflict-dialog.show();
}
public function close-conflict() {
conflict-dialog.close();
}
public function show-confirm() {
confirm-dialog.show();
}
public function close-confirm() {
confirm-dialog.close();
}
public function show-properties() {
properties-dialog.show();
}
public function close-properties() {
properties-dialog.close();
}
public function show-appearance() {
appearance-dialog.show();
}
public function close-appearance() {
appearance-dialog.close();
}
public function show-tag-editor() {
tag-editor-dialog.show();
}
public function close-tag-editor() {
tag-editor-dialog.close();
}
public function show-tag-lookup() {
tag-lookup-dialog.show();
}
public function close-tag-lookup() {
tag-lookup-dialog.close();
}
public function show-open-with() {
open-with-dialog.show();
}
public function close-open-with() {
open-with-dialog.close();
}
public function show-errors() {
errors-dialog.show();
}
public function close-errors() {
errors-dialog.close();
}
// Puts `text` on the system clipboard.
public function copy-text(text: string) {
clip.text = text;
clip.select-all();
clip.copy();
}
public function edit-path() {
toolbar.edit-path();
}
// Holds the text `copy-text` puts on the clipboard.
clip := TextInput {
visible: false;
width: 0;
height: 0;
}
shortcuts := FocusScope {
// Shift during a drag picks move without the drop menu (see Dnd.shift).
capture-key-released(event) => {
if event.text == Key.Shift || event.text == Key.ShiftR {
Dnd.shift = false;
}
reject
}
capture-key-pressed(event) => {
if event.text == Key.Shift || event.text == Key.ShiftR {
Dnd.shift = true;
}
// Text fields (breadcrumb, rename) keep their own editing keys; Rust checks the rest.
if !toolbar.editing
&& (event.modifiers.control || event.text == Key.F2 || event.text == Key.Delete)
&& root.action-key(event.text, event.modifiers.control, event.modifiers.shift, event.modifiers.alt) {
return accept;
}
if event.modifiers.control && !event.modifiers.alt {
if event.text == Key.Tab || event.text == Key.Backtab {
root.cycle-tab(event.modifiers.shift || event.text == Key.Backtab);
return accept;
}
if event.text == "t" || event.text == "T" {
root.new-tab();
return accept;
}
if event.text == "w" || event.text == "W" {
root.close-tab();
return accept;
}
if event.text == "l" || event.text == "L" {
toolbar.edit-path();
return accept;
}
if event.text == "d" || event.text == "D" {
root.add-bookmark();
return accept;
}
}
if event.modifiers.alt && !event.modifiers.control && !toolbar.editing {
if event.text == Key.LeftArrow {
root.back();
return accept;
}
if event.text == Key.RightArrow {
root.forward();
return accept;
}
if event.text == Key.UpArrow {
root.up();
return accept;
}
}
if event.text == Key.F3 {
root.toggle-split();
return accept;
}
if event.text == Key.F9 {
root.toggle-sidebar();
return accept;
}
reject
}
HorizontalLayout {
Sidebar {
width: root.show-sidebar ? 240px : 0;
visible: self.width > 0;
sections: root.sections;
animate width { duration: Motion.time(Motion.medium2); easing: Motion.emphasized; }
open(section, index, new-tab) => {
root.place-opened(section, index, new-tab);
}
toggle(section) => {
root.section-toggled(section);
}
add-bookmark => {
root.add-bookmark();
}
item-menu(section, index, x, y) => {
root.place-menu-requested(section, index);
place-popup.open-at(x, y);
}
}
VerticalLayout {
HorizontalLayout {
padding-left: Theme.space-2;
padding-right: Theme.space-2;
padding-top: Theme.space-1;
TabBar {
tabs: root.tabs;
current: root.current-tab;
current-slot: root.current-slot;
selected(id) => {
root.tab-selected(id);
}
close(id) => {
root.tab-closed(id);
}
moved(id, slot) => {
root.tab-moved(id, slot);
}
new-tab => {
root.new-tab();
}
}
}
// The content card: toolbar, panes and status bar, inset from the window edge.
HorizontalLayout {
padding-right: Theme.space-2;
padding-bottom: Theme.space-2;
padding-left: root.show-sidebar ? 0 : Theme.space-2;
Rectangle {
border-radius: Theme.corner-card;
background: Theme.surface;
drop-shadow-blur: Theme.card-shadow-blur;
drop-shadow-offset-y: Theme.card-shadow-offset;
drop-shadow-color: Theme.shadow.with-alpha(Theme.card-shadow-opacity);
clip: true;
animate background { duration: Motion.time(Motion.medium2); easing: Motion.standard; }
VerticalLayout {
toolbar := Toolbar {
can-back: root.can-back;
can-forward: root.can-forward;
can-up: root.can-up;
split: root.panes.length > 1;
sidebar: root.show-sidebar;
crumbs: root.crumbs;
path: root.path;
completions: root.completions;
view-mode: root.active-pane < root.panes.length ? root.panes[root.active-pane].folder.mode : ViewMode.details;
view-mode-selected(mode) => {
root.view-mode-selected(root.active-pane, mode);
}
previews: root.active-pane < root.panes.length ? root.panes[root.active-pane].folder.previews : false;
previews-toggled => {
root.toggle-previews(root.active-pane);
}
back => {
root.back();
}
forward => {
root.forward();
}
up => {
root.up();
}
toggle-split => {
root.toggle-split();
}
actions(x, y) => {
root.actions-menu-requested(x, y);
}
toggle-sidebar => {
root.toggle-sidebar();
}
go(i) => {
root.go-crumb(i);
}
path-edited(text) => {
root.path-edited(text);
}
path-accepted(text) => {
root.path-accepted(text);
}
path-reverted => {
root.path-reverted();
}
}
HorizontalLayout {
padding-left: root.panes.length > 1 ? Theme.space-2 : 0;
padding-right: root.panes.length > 1 ? Theme.space-2 : 0;
spacing: Theme.space-2;
for pane[i] in root.panes: Pane {
property <int> request: root.focus-request + root.refocus;
data: pane;
index: i;
active: i == root.active-pane;
split: root.panes.length > 1;
init => {
if self.active {
self.focus-view();
}
}
changed request => {
if self.active {
self.focus-view();
}
}
changed hovered => {
if self.hovered {
root.hovered-pane = i;
} else if root.hovered-pane == i {
root.hovered-pane = -1;
}
}
activated => {
root.pane-activated(i);
}
sort-by(column) => {
root.sort-by(i, column);
}
open-sort-menu(x, y) => {
sort-popup.open-at(x, y);
}
filter-typed(text) => {
root.filter-typed(i, text);
}
filter-edited(text) => {
root.filter-edited(i, text);
}
toggle-hidden => {
root.toggle-hidden(i);
}
row-clicked(row, ctrl, shift) => {
root.row-clicked(i, row, ctrl, shift);
}
row-activated(row) => {
root.row-activated(i, row);
}
select-all => {
root.select-all(i);
}
clear-selection => {
root.clear-selection(i);
}
navigate(key, shift, page) => {
root.navigate(i, key, shift, page)
}
columns-changed(n) => {
root.grid-columns-changed(i, n);
}
motion-settled => {
root.motion-settled(i);
}
viewport-changed(top, height, row, cell) => {
root.viewport-changed(i, top, height, row, cell);
}
row-renamed(row, text) => {
root.row-renamed(i, row, text);
}
rename-cancelled => {
root.rename-cancelled(i);
}
context-menu(row, x, y) => {
root.context-menu-requested(i, row, x, y);
}
}
}
player-bar := PlayerBar {
data: root.player;
peaks: root.player-peaks;
position: root.player-position;
toggle => {
root.player-toggle();
}
close => {
root.player-close();
}
seek(f) => {
root.player-seek(f);
}
step(d) => {
root.player-step(d);
}
volume(v) => {
root.player-volume(v);
}
mute => {
root.player-mute();
}
changed bar-count => {
root.player-bars-changed();
}
}
StatusBar {
text: root.status;
}
}
}
}
}
}
}
// Focus back to the active pane (after the breadcrumb or a menu).
property <int> refocus;
function focus-pane() {
root.refocus += 1;
}
CompletionList {
x: toolbar.crumb-x;
y: toolbar.crumb-bottom + Theme.space-1;
width: toolbar.crumb-width;
visible: toolbar.editing && root.completions.length > 0;
completions: root.completions;
highlight: toolbar.highlight;
picked(text) => {
toolbar.pick(text);
}
}
sort-popup := Menu {
width: 100%;
height: 100%;
items: root.sort-menu;
leading-icons: true;
activated(index, sub) => {
root.sort-menu-activated(index, sub);
}
closed => {
root.focus-pane();
}
}
context-popup := Menu {
width: 100%;
height: 100%;
items: root.context-menu-items;
leading-icons: true;
activated(index, sub) => {
root.context-menu-activated(index);
}
closed => {
root.focus-pane();
}
}
drop-popup := DropMenu {
width: 100%;
height: 100%;
activated(index, sub) => {
root.drop-chosen(index);
}
closed => {
root.focus-pane();
}
}
place-popup := Menu {
width: 100%;
height: 100%;
items: root.place-menu;
leading-icons: true;
activated(index, sub) => {
root.place-menu-activated(index, sub);
}
}
rename-dialog := Dialog {
glyph: Icons.edit;
width: 100%;
height: 100%;
title: "Rename bookmark";
body: "The folder itself keeps its name.";
content-focus: true;
actions: [{ text: "Cancel", kind: ButtonKind.text }, { text: "Rename", kind: ButtonKind.filled }];
default-action: 1;
cancel-action: 0;
focus-content => {
rename-field.focus();
}
action(i) => {
self.close();
if i == 1 {
root.bookmark-renamed(rename-field.text);
}
}
rename-field := TextField {
label: "Name";
}
}
settings-dialog := SettingsDialog {
width: 100%;
height: 100%;
data <=> root.settings;
menu-contexts: root.menu-contexts;
menu-context: root.menu-context;
menu-rows: root.menu-rows;
menu-available: root.menu-available;
menu-can-reset: root.menu-can-reset;
changed(data) => {
root.settings-changed(data);
}
menu-context-selected(i) => {
root.menu-context-selected(i);
}
menu-moved(from, to) => {
root.menu-moved(from, to);
}
menu-removed(i) => {
root.menu-removed(i);
}
menu-added(i) => {
root.menu-added(i);
}
menu-separator-added => {
root.menu-separator-added();
}
menu-reset => {
root.menu-reset();
}
closed => {
root.focus-pane();
}
}
conflict-dialog := ConflictDialog {
width: 100%;
height: 100%;
info: root.conflict;
chosen(choice, all) => {
root.conflict-chosen(choice, all);
}
}
confirm-dialog := ConfirmDialog {
width: 100%;
height: 100%;
title: root.confirm-title;
body: root.confirm-body;
action-text: root.confirm-action;
answered(yes) => {
root.confirm-answered(yes);
}
}
properties-dialog := PropertiesDialog {
width: 100%;
height: 100%;
info: root.properties;
closed => {
root.properties-closed();
}
}
open-with-dialog := OpenWithDialog {
width: 100%;
height: 100%;
apps: root.open-with-apps;
mime: root.open-with-mime;
selected <=> root.open-with-selected;
as-default <=> root.open-with-as-default;
chosen(row, as-default) => {
root.open-with-chosen(row, as-default);
}
}
appearance-dialog := FolderAppearanceDialog {
width: 100%;
height: 100%;
icons: root.appearance-icons;
choice <=> root.appearance-choice;
name-text <=> root.appearance-name;
image-path <=> root.appearance-image;
remember <=> root.appearance-remember;
placeholder: root.appearance-placeholder;
error: root.appearance-error;
can-elevate: root.appearance-can-elevate;
saved(elevate) => {
root.appearance-saved(elevate);
}
}
tag-editor-dialog := TagEditorDialog {
width: 100%;
height: 100%;
data <=> root.tag-editor;
saved => {
root.tag-editor-saved();
}
lookup => {
root.tag-editor-lookup();
}
field-changed(i, text) => {
root.tag-field-changed(i, text);
}
cover-path-accepted(path) => {
root.tag-cover-path(path);
}
cover-dropped(data) => {
root.tag-cover-dropped(data);
}
cover-removed => {
root.tag-cover-removed();
}
cover-reset => {
root.tag-cover-reset();
}
}
tag-lookup-dialog := TagLookupDialog {
width: 100%;
height: 100%;
data <=> root.tag-lookup;
artist-edited(text) => {
root.tag-artist-edited(text);
}
album-edited(text) => {
root.tag-album-edited(text);
}
search => {
root.tag-search();
}
release-picked(i) => {
root.tag-release-picked(i);
}
next => {
root.tag-next();
}
back => {
root.tag-back();
}
cancelled => {
root.tag-lookup-cancelled();
}
map-step(row, delta) => {
root.tag-map-step(row, delta);
}
embed-toggled(on) => {
root.tag-embed-toggled(on);
}
apply => {
root.tag-apply();
}
}
errors-dialog := ErrorsDialog {
width: 100%;
height: 100%;
title: root.errors-title;
body: root.errors-body;
lines: root.errors-lines;
actions: root.errors-actions;
default-action: root.errors-default;
cancel-action: root.errors-default;
answered(i) => {
root.errors-answered(i);
}
}
ToastStack {
width: 100%;
height: 100%;
toasts: root.toasts;
cancelled(i) => {
root.toast-cancelled(i);
}
removed(i) => {
root.toast-removed(i);
}
}
}