Commands with default chords, [shortcuts] overrides in settings.toml, conflict detection; Shortcuts settings page with capture, Replace/Cancel and resets. Ctrl+N opens a new window, tab right-click menu, closed-tab stack (10). Probe gains key and middle-button modes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
245 lines
8.5 KiB
Text
245 lines
8.5 KiB
Text
import { Theme } from "../theme.slint";
|
|
import { Motion } from "../motion.slint";
|
|
import { Icon, Icons } from "../components/icon.slint";
|
|
import { IconButton } from "../components/icon-button.slint";
|
|
import { StateLayer } from "../components/state-layer.slint";
|
|
import { DropTarget, DropZone } from "../components/drop-menu.slint";
|
|
|
|
// One tab as Rust keeps it. Rows stay in the order the tabs were opened, so closing or moving
|
|
// one never rebuilds the others; `slot` is the place it is shown at.
|
|
export struct TabData {
|
|
id: int,
|
|
title: string,
|
|
glyph: string,
|
|
slot: int,
|
|
}
|
|
|
|
component ShellTab inherits StateLayer {
|
|
in property <string> title;
|
|
in property <string> glyph;
|
|
in property <bool> active;
|
|
// Off for the only tab: there is always one.
|
|
in property <bool> closable;
|
|
callback close();
|
|
// A right click, at window coordinates.
|
|
callback menu(length, length);
|
|
// Left press moved past the drag threshold, then each move while dragged.
|
|
callback drag-moved(length);
|
|
callback drag-ended();
|
|
|
|
property <color> content: root.active ? Theme.on-secondary-container : Theme.on-surface-variant;
|
|
property <bool> dragging;
|
|
// Fades in once when the tab opens; tabs are never rebuilt, so this runs once per tab.
|
|
property <bool> born;
|
|
init => {
|
|
root.born = true;
|
|
}
|
|
|
|
border-radius: Theme.corner-full(self.height);
|
|
squeeze: Motion.squeeze-large;
|
|
ring-offset: -Theme.focus-ring-width;
|
|
tint: root.content;
|
|
opacity: root.born ? 1 : 0;
|
|
animate opacity { duration: Motion.time(Motion.short4); easing: Motion.standard-decelerate; }
|
|
|
|
accessible-role: tab;
|
|
accessible-label: root.title;
|
|
accessible-item-selectable: true;
|
|
accessible-item-selected: root.active;
|
|
accessible-action-default => {
|
|
self.activate();
|
|
}
|
|
|
|
pointer(event) => {
|
|
if event.button == PointerEventButton.middle && event.kind == PointerEventKind.up && root.closable {
|
|
root.close();
|
|
}
|
|
if event.button == PointerEventButton.right && event.kind == PointerEventKind.down {
|
|
root.menu(root.absolute-position.x + root.mouse-x, root.absolute-position.y + root.mouse-y);
|
|
}
|
|
if event.button == PointerEventButton.left && event.kind == PointerEventKind.up && root.dragging {
|
|
root.dragging = false;
|
|
root.drag-ended();
|
|
}
|
|
}
|
|
moved => {
|
|
if !root.dragging && abs(root.mouse-x - root.pressed-x) > Theme.space-1 {
|
|
root.dragging = true;
|
|
}
|
|
if root.dragging {
|
|
root.drag-moved(root.mouse-x - root.pressed-x);
|
|
}
|
|
}
|
|
|
|
HorizontalLayout {
|
|
padding-left: Theme.space-3;
|
|
padding-right: root.closable ? Theme.space-1 : Theme.space-3;
|
|
spacing: Theme.space-2;
|
|
|
|
VerticalLayout {
|
|
alignment: center;
|
|
Icon {
|
|
glyph: root.glyph;
|
|
size: 18px;
|
|
color: root.content;
|
|
animate color { duration: Motion.time(Motion.short4); easing: Motion.standard; }
|
|
}
|
|
}
|
|
|
|
Text {
|
|
horizontal-stretch: 1;
|
|
text: root.title;
|
|
color: root.content;
|
|
font-size: Theme.label-large.size;
|
|
font-weight: Theme.label-large.weight;
|
|
vertical-alignment: center;
|
|
overflow: elide;
|
|
animate color { duration: Motion.time(Motion.short4); easing: Motion.standard; }
|
|
}
|
|
|
|
if root.closable: VerticalLayout {
|
|
alignment: center;
|
|
IconButton {
|
|
icon: Icons.close;
|
|
size: 28px;
|
|
icon-size: 18px;
|
|
tooltip: "Close tab (Ctrl+W)";
|
|
clicked => {
|
|
root.close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Pill tabs sharing the width between a minimum and a maximum, one selection pill that slides
|
|
// to the current tab, and a new-tab button after the last tab. A dragged tab stays under the
|
|
// pointer while the others slide aside to show where it drops.
|
|
export component TabBar {
|
|
in property <[TabData]> tabs;
|
|
in property <int> current;
|
|
// Slot of the current tab, for the selection pill.
|
|
in property <int> current-slot;
|
|
callback selected(id: int);
|
|
callback close(id: int);
|
|
// Tab `id` dropped at `slot`.
|
|
callback moved(id: int, slot: int);
|
|
callback new-tab();
|
|
// Right click on tab `id` at window coordinates.
|
|
callback tab-menu(id: int, x: length, y: length);
|
|
|
|
property <length> gap: Theme.space-1;
|
|
property <length> tab-height: 36px;
|
|
property <length> button: 40px;
|
|
property <length> min-tab: 76px;
|
|
property <length> max-tab: 240px;
|
|
property <length> room: root.width - root.button - root.gap;
|
|
property <length> tab-width: root.tabs.length == 0 ? root.max-tab
|
|
: max(root.min-tab, min(root.max-tab, (root.room - (root.tabs.length - 1) * root.gap) / root.tabs.length));
|
|
property <length> step: root.tab-width + root.gap;
|
|
|
|
// The dragged tab (-1 for none), its slot, its x and where it would drop.
|
|
property <int> drag-id: -1;
|
|
property <int> drag-from;
|
|
property <length> drag-x;
|
|
property <int> drag-to: min(root.tabs.length - 1, max(0, round(root.drag-x / root.step)));
|
|
|
|
// Slot a tab is shown at while another one is dragged.
|
|
pure function shown(slot: int) -> int {
|
|
if root.drag-id < 0 {
|
|
return slot;
|
|
}
|
|
if root.drag-from < slot && slot <= root.drag-to {
|
|
return slot - 1;
|
|
}
|
|
if root.drag-to <= slot && slot < root.drag-from {
|
|
return slot + 1;
|
|
}
|
|
slot
|
|
}
|
|
|
|
height: 40px + 2 * Theme.space-1;
|
|
accessible-role: tab-list;
|
|
|
|
Rectangle {
|
|
clip: true;
|
|
width: root.room;
|
|
x: 0;
|
|
|
|
// The selection pill, under the tabs.
|
|
if root.tabs.length > 0: Rectangle {
|
|
// Dragging selects the tab, so a dragged tab is always the current one.
|
|
x: root.drag-id >= 0 ? root.drag-x : root.current-slot * root.step;
|
|
y: (parent.height - root.tab-height) / 2;
|
|
width: root.tab-width;
|
|
height: root.tab-height;
|
|
border-radius: Theme.corner-full(self.height);
|
|
background: Theme.secondary-container;
|
|
animate x { duration: Motion.time(root.drag-id >= 0 ? 0 : Motion.medium2); easing: Motion.emphasized; }
|
|
}
|
|
|
|
for tab in root.tabs: ShellTab {
|
|
property <bool> dragged: tab.id == root.drag-id;
|
|
property <length> rest-x: root.shown(tab.slot) * root.step;
|
|
x: self.dragged ? root.drag-x : self.rest-x;
|
|
y: (parent.height - root.tab-height) / 2;
|
|
width: root.tab-width;
|
|
height: root.tab-height;
|
|
title: tab.title;
|
|
glyph: tab.glyph;
|
|
active: tab.id == root.current;
|
|
closable: root.tabs.length > 1;
|
|
animate x { duration: Motion.time(self.dragged ? 0 : Motion.medium2); easing: Motion.emphasized; }
|
|
|
|
clicked => {
|
|
root.selected(tab.id);
|
|
}
|
|
close => {
|
|
root.close(tab.id);
|
|
}
|
|
menu(x, y) => {
|
|
root.tab-menu(tab.id, x, y);
|
|
}
|
|
drag-moved(dx) => {
|
|
if root.drag-id != tab.id {
|
|
root.drag-id = tab.id;
|
|
root.drag-from = tab.slot;
|
|
root.drag-x = self.x;
|
|
root.selected(tab.id);
|
|
}
|
|
root.drag-x = max(0, min((root.tabs.length - 1) * root.step, root.drag-x + dx));
|
|
}
|
|
drag-ended => {
|
|
root.moved(tab.id, root.drag-to);
|
|
root.drag-id = -1;
|
|
}
|
|
|
|
// A file drag that rests here opens the tab; a drop goes into its folder.
|
|
tab-zone := DropZone {
|
|
target: DropTarget.tab;
|
|
a: tab.id;
|
|
radius: parent.border-radius;
|
|
|
|
Timer {
|
|
interval: Motion.drag-switch-delay;
|
|
running: tab-zone.has-drag && tab.id != root.current;
|
|
triggered => {
|
|
root.selected(tab.id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
IconButton {
|
|
x: min(root.room + root.gap, root.tabs.length * root.step);
|
|
y: (parent.height - self.height) / 2;
|
|
icon: Icons.add;
|
|
size: root.button;
|
|
tooltip: "New tab (Ctrl+T)";
|
|
animate x { duration: Motion.time(Motion.medium2); easing: Motion.emphasized; }
|
|
clicked => {
|
|
root.new-tab();
|
|
}
|
|
}
|
|
}
|