509 lines
18 KiB
Text
509 lines
18 KiB
Text
import { ScrollView } from "std-widgets.slint";
|
|
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 { Icons } from "../components/icon.slint";
|
|
import { MenuEditor, EditRow } from "menu-editor.slint";
|
|
import { ChoiceSetting, Setting, Stepper } from "setting-rows.slint";
|
|
import { AppearancePage } from "appearance-page.slint";
|
|
import { MousePage } from "mouse-page.slint";
|
|
import { ShortcutEditor, KeyRow } from "shortcut-editor.slint";
|
|
|
|
export { EditRow, KeyRow }
|
|
|
|
// 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,
|
|
// Appearance page: indexes into its choices, and the palette's seed (empty: the desktop's).
|
|
scheme: int,
|
|
palette: string,
|
|
color-style: int,
|
|
icon-shapes: bool,
|
|
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,
|
|
// Network page.
|
|
ssh-hosts: bool,
|
|
connect-timeout: int,
|
|
keepalive: int,
|
|
idle-close: int,
|
|
// Mouse page: indexes into its choices (mouse-page.slint).
|
|
click: int,
|
|
middle-item: int,
|
|
middle-empty: int,
|
|
side-buttons: int,
|
|
empty-double: int,
|
|
executables: int,
|
|
}
|
|
|
|
// 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 5).
|
|
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;
|
|
// The shortcut editor (page 7).
|
|
in property <[KeyRow]> key-rows;
|
|
in property <int> key-recording: -1;
|
|
in property <string> key-message;
|
|
in property <bool> key-conflict;
|
|
in property <bool> key-can-reset-all;
|
|
callback key-search(string);
|
|
callback key-record(int);
|
|
callback key-pressed(string, bool, bool, bool, bool);
|
|
callback key-replace();
|
|
callback key-cancel();
|
|
callback key-reset(int);
|
|
callback key-reset-all();
|
|
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", "Appearance", "Network", "Context menus", "Mouse", "Shortcuts"];
|
|
property <[string]> glyphs: ["\u{e8b8}", "\u{e8f4}", "\u{e3f4}", "\u{e40a}", "\u{e2bd}", "\u{e5d4}", "\u{e323}", "\u{e312}"];
|
|
|
|
title: "Settings";
|
|
dialog-width: 780px;
|
|
actions: [{ text: "Done", kind: ButtonKind.filled }];
|
|
default-action: 0;
|
|
cancel-action: 0;
|
|
// While a shortcut is recorded, Escape, Tab and Enter are keys to record.
|
|
pass-keys: root.page == 7 && root.key-recording >= 0;
|
|
action(i) => {
|
|
self.close();
|
|
root.closed();
|
|
}
|
|
|
|
// The pages scroll when the window is too short for them.
|
|
HorizontalLayout {
|
|
spacing: Theme.space-4;
|
|
height: min(400px, max(160px, root.height - 250px));
|
|
|
|
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 => {
|
|
if root.key-recording >= 0 {
|
|
root.key-cancel();
|
|
}
|
|
root.page = i;
|
|
}
|
|
}
|
|
}
|
|
|
|
Rectangle {
|
|
horizontal-stretch: 1;
|
|
|
|
if root.page < 5 || root.page == 6: ScrollView {
|
|
VerticalLayout {
|
|
alignment: start;
|
|
|
|
if root.page == 0: VerticalLayout {
|
|
alignment: start;
|
|
|
|
Setting {
|
|
title: "Show hidden files";
|
|
hint: "Files whose names start with a dot. The keys are on the Shortcuts page.";
|
|
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", "Large 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, file-type icons and folders' own icons. Off: plain icons.";
|
|
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: AppearancePage {
|
|
scheme: root.data.scheme;
|
|
palette: root.data.palette;
|
|
color-style: root.data.color-style;
|
|
icon-shapes: root.data.icon-shapes;
|
|
motion: root.data.motion;
|
|
scheme-picked(i) => {
|
|
root.data.scheme = i;
|
|
root.changed(root.data);
|
|
}
|
|
palette-picked(seed) => {
|
|
root.data.palette = seed;
|
|
root.changed(root.data);
|
|
}
|
|
style-picked(i) => {
|
|
root.data.color-style = i;
|
|
root.changed(root.data);
|
|
}
|
|
shapes-toggled(on) => {
|
|
root.data.icon-shapes = on;
|
|
root.changed(root.data);
|
|
}
|
|
motion-picked(i) => {
|
|
root.data.motion = i;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
|
|
if root.page == 4: VerticalLayout {
|
|
alignment: start;
|
|
|
|
Setting {
|
|
title: "Hosts from ~/.ssh/config";
|
|
hint: "Lists them in the sidebar under Network. Tunal only reads that file.";
|
|
Switch {
|
|
checked: root.data.ssh-hosts;
|
|
changed checked => {
|
|
root.data.ssh-hosts = self.checked;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
Setting {
|
|
title: "Connection timeout";
|
|
hint: "How long to wait for a server to answer.";
|
|
Stepper {
|
|
value: root.data.connect-timeout;
|
|
lo: 5;
|
|
hi: 120;
|
|
step: 5;
|
|
unit: "s";
|
|
picked(v) => {
|
|
root.data.connect-timeout = v;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
Setting {
|
|
title: "Keep alive";
|
|
hint: "Sends a small message this often so quiet connections stay open. 0 turns it off.";
|
|
Stepper {
|
|
value: root.data.keepalive;
|
|
lo: 0;
|
|
hi: 300;
|
|
step: 10;
|
|
unit: "s";
|
|
picked(v) => {
|
|
root.data.keepalive = v;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
Setting {
|
|
title: "Close idle connections";
|
|
hint: "After this long without use. They open again when you need them.";
|
|
Stepper {
|
|
value: root.data.idle-close;
|
|
lo: 1;
|
|
hi: 120;
|
|
step: 1;
|
|
unit: "min";
|
|
picked(v) => {
|
|
root.data.idle-close = v;
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if root.page == 6: MousePage {
|
|
click: root.data.click;
|
|
middle-item: root.data.middle-item;
|
|
middle-empty: root.data.middle-empty;
|
|
side-buttons: root.data.side-buttons;
|
|
empty-double: root.data.empty-double;
|
|
executables: root.data.executables;
|
|
picked(row, value) => {
|
|
if row == 0 {
|
|
root.data.click = value;
|
|
} else if row == 1 {
|
|
root.data.middle-item = value;
|
|
} else if row == 2 {
|
|
root.data.middle-empty = value;
|
|
} else if row == 3 {
|
|
root.data.side-buttons = value;
|
|
} else if row == 4 {
|
|
root.data.empty-double = value;
|
|
} else {
|
|
root.data.executables = value;
|
|
}
|
|
root.changed(root.data);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if root.page == 7: ShortcutEditor {
|
|
rows: root.key-rows;
|
|
recording: root.key-recording;
|
|
message: root.key-message;
|
|
conflict: root.key-conflict;
|
|
can-reset-all: root.key-can-reset-all;
|
|
search(text) => {
|
|
root.key-search(text);
|
|
}
|
|
record(i) => {
|
|
root.key-record(i);
|
|
}
|
|
pressed(text, ctrl, shift, alt, meta) => {
|
|
root.key-pressed(text, ctrl, shift, alt, meta);
|
|
}
|
|
replace => {
|
|
root.key-replace();
|
|
}
|
|
cancel => {
|
|
root.key-cancel();
|
|
}
|
|
reset(i) => {
|
|
root.key-reset(i);
|
|
}
|
|
reset-all => {
|
|
root.key-reset-all();
|
|
}
|
|
}
|
|
|
|
if root.page == 5: 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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|