478 lines
15 KiB
Text
478 lines
15 KiB
Text
import { Theme } from "../theme.slint";
|
|
import { Motion } from "../motion.slint";
|
|
import { Dialog } from "../components/dialog.slint";
|
|
import { ButtonKind } from "../components/button.slint";
|
|
import { ListRow } from "../components/list-row.slint";
|
|
import { Switch } from "../components/switch.slint";
|
|
import { Chip } from "../components/chip.slint";
|
|
import { Icons } from "../components/icon.slint";
|
|
import { IconButton } from "../components/icon-button.slint";
|
|
import { MenuEditor, EditRow } from "menu-editor.slint";
|
|
|
|
export { EditRow }
|
|
|
|
// What the settings pages show and change; Rust applies and stores every change.
|
|
export struct SettingsData {
|
|
restore-session: bool,
|
|
show-hidden: bool,
|
|
folders-first: bool,
|
|
// Index into the page's choices.
|
|
view: int,
|
|
sort: int,
|
|
sort-descending: bool,
|
|
group: int,
|
|
motion: int,
|
|
// 0 relative, 1 absolute.
|
|
date-style: int,
|
|
// 0 12-hour, 1 24-hour.
|
|
clock: int,
|
|
previews: bool,
|
|
// 0 percent of the video's length, 1 seconds in.
|
|
preview-frame-unit: int,
|
|
preview-frame: int,
|
|
preview-max-mib: int,
|
|
preview-remote: bool,
|
|
player-next: bool,
|
|
}
|
|
|
|
// One choice out of a few, as a row of chips.
|
|
component Choices inherits HorizontalLayout {
|
|
in property <[string]> names;
|
|
in property <int> current;
|
|
callback picked(int);
|
|
|
|
spacing: Theme.space-2;
|
|
alignment: start;
|
|
|
|
for name[i] in root.names: Chip {
|
|
property <bool> sel: i == root.current;
|
|
|
|
text: name;
|
|
checked: self.sel;
|
|
changed sel => {
|
|
self.checked = self.sel;
|
|
}
|
|
clicked => {
|
|
root.picked(i);
|
|
self.checked = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
// A setting: its name and a line about it, the control on the right.
|
|
component Setting inherits HorizontalLayout {
|
|
in property <string> title;
|
|
in property <string> hint;
|
|
|
|
spacing: Theme.space-4;
|
|
height: 52px;
|
|
|
|
VerticalLayout {
|
|
alignment: center;
|
|
horizontal-stretch: 1;
|
|
|
|
Text {
|
|
text: root.title;
|
|
color: Theme.on-surface;
|
|
font-size: Theme.body-medium.size;
|
|
font-weight: Theme.body-medium.weight;
|
|
overflow: elide;
|
|
}
|
|
|
|
if root.hint != "": Text {
|
|
text: root.hint;
|
|
color: Theme.on-surface-variant;
|
|
font-size: Theme.body-small.size;
|
|
font-weight: Theme.body-small.weight;
|
|
overflow: elide;
|
|
}
|
|
}
|
|
|
|
VerticalLayout {
|
|
alignment: center;
|
|
|
|
@children
|
|
}
|
|
}
|
|
|
|
// A whole number with minus and plus buttons.
|
|
component Stepper inherits HorizontalLayout {
|
|
in property <int> value;
|
|
in property <int> lo;
|
|
in property <int> hi;
|
|
in property <int> step;
|
|
in property <string> unit;
|
|
callback picked(int);
|
|
|
|
spacing: Theme.space-2;
|
|
|
|
VerticalLayout {
|
|
alignment: center;
|
|
IconButton {
|
|
icon: Icons.remove;
|
|
tonal: true;
|
|
size: 32px;
|
|
icon-size: 18px;
|
|
enabled: root.value > root.lo;
|
|
tooltip: "Less";
|
|
clicked => {
|
|
root.picked(max(root.lo, root.value - root.step));
|
|
}
|
|
}
|
|
}
|
|
|
|
Text {
|
|
text: "\{root.value} \{root.unit}";
|
|
width: 72px;
|
|
color: Theme.on-surface;
|
|
font-size: Theme.body-medium.size;
|
|
font-weight: Theme.body-medium.weight;
|
|
horizontal-alignment: center;
|
|
vertical-alignment: center;
|
|
}
|
|
|
|
VerticalLayout {
|
|
alignment: center;
|
|
IconButton {
|
|
icon: Icons.add;
|
|
tonal: true;
|
|
size: 32px;
|
|
icon-size: 18px;
|
|
enabled: root.value < root.hi;
|
|
tooltip: "More";
|
|
clicked => {
|
|
root.picked(min(root.hi, root.value + root.step));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// A choice with its name above the chips.
|
|
component ChoiceSetting inherits VerticalLayout {
|
|
in property <string> title;
|
|
in property <[string]> names;
|
|
in property <int> current;
|
|
callback picked(int);
|
|
|
|
spacing: Theme.space-2;
|
|
padding-top: Theme.space-2;
|
|
padding-bottom: Theme.space-2;
|
|
|
|
Text {
|
|
text: root.title;
|
|
color: Theme.on-surface;
|
|
font-size: Theme.body-medium.size;
|
|
font-weight: Theme.body-medium.weight;
|
|
}
|
|
|
|
Choices {
|
|
names: root.names;
|
|
current: root.current;
|
|
picked(i) => {
|
|
root.picked(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
// The settings, one page at a time; the pages are listed on the left.
|
|
export component SettingsDialog inherits Dialog {
|
|
glyph: Icons.settings;
|
|
in-out property <SettingsData> data;
|
|
in-out property <int> page;
|
|
// The context menu editor (page 4).
|
|
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 changed(SettingsData);
|
|
callback menu-context-selected(int);
|
|
callback menu-moved(from: int, to: int);
|
|
callback menu-removed(int);
|
|
callback menu-added(int);
|
|
callback menu-separator-added();
|
|
callback menu-reset();
|
|
callback closed();
|
|
|
|
property <[string]> pages: ["General", "View", "Previews", "Motion", "Context menus"];
|
|
property <[string]> glyphs: ["\u{e8b8}", "\u{e8f4}", "\u{e3f4}", "\u{e037}", "\u{e5d4}"];
|
|
|
|
title: "Settings";
|
|
dialog-width: 780px;
|
|
actions: [{ text: "Done", kind: ButtonKind.filled }];
|
|
default-action: 0;
|
|
cancel-action: 0;
|
|
action(i) => {
|
|
self.close();
|
|
root.closed();
|
|
}
|
|
|
|
HorizontalLayout {
|
|
spacing: Theme.space-4;
|
|
height: 400px;
|
|
|
|
VerticalLayout {
|
|
width: 168px;
|
|
spacing: Theme.space-1;
|
|
alignment: start;
|
|
|
|
for name[i] in root.pages: ListRow {
|
|
title: name;
|
|
icon: root.glyphs[i];
|
|
selected: i == root.page;
|
|
clicked => {
|
|
root.page = i;
|
|
}
|
|
}
|
|
}
|
|
|
|
Rectangle {
|
|
horizontal-stretch: 1;
|
|
|
|
if root.page == 0: VerticalLayout {
|
|
alignment: start;
|
|
|
|
Setting {
|
|
title: "Show hidden files";
|
|
hint: "Files whose names start with a dot. Ctrl+H in a folder.";
|
|
Switch {
|
|
checked: root.data.show-hidden;
|
|
changed checked => {
|
|
root.data.show-hidden = self.checked;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
Setting {
|
|
title: "Folders first";
|
|
hint: "List folders before files when sorting.";
|
|
Switch {
|
|
checked: root.data.folders-first;
|
|
changed checked => {
|
|
root.data.folders-first = self.checked;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
ChoiceSetting {
|
|
title: "Dates";
|
|
names: ["Relative", "Date and time"];
|
|
current: root.data.date-style;
|
|
picked(i) => {
|
|
root.data.date-style = i;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
|
|
ChoiceSetting {
|
|
title: "Clock";
|
|
names: ["12-hour", "24-hour"];
|
|
current: root.data.clock;
|
|
picked(i) => {
|
|
root.data.clock = i;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
|
|
Setting {
|
|
title: "Restore tabs";
|
|
hint: "Open the tabs of the last session at start.";
|
|
Switch {
|
|
checked: root.data.restore-session;
|
|
changed checked => {
|
|
root.data.restore-session = self.checked;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
Setting {
|
|
title: "Play the next track";
|
|
hint: "When a track ends, the player goes on with the next audio file in the folder.";
|
|
Switch {
|
|
checked: root.data.player-next;
|
|
changed checked => {
|
|
root.data.player-next = self.checked;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if root.page == 1: VerticalLayout {
|
|
alignment: start;
|
|
|
|
ChoiceSetting {
|
|
title: "Default view";
|
|
names: ["Details", "Icons"];
|
|
current: root.data.view;
|
|
picked(i) => {
|
|
root.data.view = i;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
|
|
ChoiceSetting {
|
|
title: "Sort by";
|
|
names: ["Name", "Size", "Type", "Modified"];
|
|
current: root.data.sort;
|
|
picked(i) => {
|
|
root.data.sort = i;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
|
|
Setting {
|
|
title: "Largest or newest first";
|
|
hint: "Reverse the default sort order.";
|
|
Switch {
|
|
checked: root.data.sort-descending;
|
|
changed checked => {
|
|
root.data.sort-descending = self.checked;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
ChoiceSetting {
|
|
title: "Group by";
|
|
names: ["None", "Type", "Modified", "Size"];
|
|
current: root.data.group;
|
|
picked(i) => {
|
|
root.data.group = i;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
|
|
Text {
|
|
text: "These are what a new tab starts with. Each pane can change its own.";
|
|
color: Theme.on-surface-variant;
|
|
font-size: Theme.body-small.size;
|
|
font-weight: Theme.body-small.weight;
|
|
wrap: word-wrap;
|
|
}
|
|
}
|
|
|
|
if root.page == 2: VerticalLayout {
|
|
alignment: start;
|
|
|
|
Setting {
|
|
title: "Show previews";
|
|
hint: "Thumbnails of images, covers and videos. The toolbar button sets it per folder.";
|
|
Switch {
|
|
checked: root.data.previews;
|
|
changed checked => {
|
|
root.data.previews = self.checked;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
ChoiceSetting {
|
|
title: "Video frame";
|
|
names: ["Percent of the length", "Seconds in"];
|
|
current: root.data.preview-frame-unit;
|
|
picked(i) => {
|
|
root.data.preview-frame-unit = i;
|
|
root.data.preview-frame = i == 0 ? min(root.data.preview-frame, 99) : root.data.preview-frame;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
|
|
Setting {
|
|
title: "Frame position";
|
|
hint: "Applies to videos that have no thumbnail yet.";
|
|
Stepper {
|
|
value: root.data.preview-frame;
|
|
lo: 0;
|
|
hi: root.data.preview-frame-unit == 0 ? 99 : 3600;
|
|
step: root.data.preview-frame-unit == 0 ? 5 : 5;
|
|
unit: root.data.preview-frame-unit == 0 ? "%" : "s";
|
|
picked(v) => {
|
|
root.data.preview-frame = v;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
Setting {
|
|
title: "Largest image";
|
|
hint: "Images and SVG files above this size get no preview.";
|
|
Stepper {
|
|
value: root.data.preview-max-mib;
|
|
lo: 1;
|
|
hi: 1024;
|
|
step: 8;
|
|
unit: "MiB";
|
|
picked(v) => {
|
|
root.data.preview-max-mib = v;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
Setting {
|
|
title: "Network drives";
|
|
hint: "Previews on network and FUSE mounts. Off keeps them quick to open.";
|
|
Switch {
|
|
checked: root.data.preview-remote;
|
|
changed checked => {
|
|
root.data.preview-remote = self.checked;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if root.page == 3: VerticalLayout {
|
|
alignment: start;
|
|
|
|
ChoiceSetting {
|
|
title: "Animations";
|
|
names: ["Follow the system", "Always reduce", "Never reduce"];
|
|
current: root.data.motion;
|
|
picked(i) => {
|
|
root.data.motion = i;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
|
|
Text {
|
|
text: "Reduced motion makes menus, dialogs and lists change at once.";
|
|
color: Theme.on-surface-variant;
|
|
font-size: Theme.body-small.size;
|
|
font-weight: Theme.body-small.weight;
|
|
wrap: word-wrap;
|
|
}
|
|
}
|
|
|
|
if root.page == 4: MenuEditor {
|
|
contexts: root.menu-contexts;
|
|
context: root.menu-context;
|
|
rows: root.menu-rows;
|
|
available: root.menu-available;
|
|
can-reset: root.menu-can-reset;
|
|
context-selected(i) => {
|
|
root.menu-context-selected(i);
|
|
}
|
|
moved(from, to) => {
|
|
root.menu-moved(from, to);
|
|
}
|
|
removed(i) => {
|
|
root.menu-removed(i);
|
|
}
|
|
added(i) => {
|
|
root.menu-added(i);
|
|
}
|
|
separator-added => {
|
|
root.menu-separator-added();
|
|
}
|
|
reset => {
|
|
root.menu-reset();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|