76 lines
3.3 KiB
Text
76 lines
3.3 KiB
Text
import { Theme } from "../theme.slint";
|
|
import { Motion } from "../motion.slint";
|
|
import { Icons } from "icon.slint";
|
|
import { Menu } from "menu.slint";
|
|
|
|
// What a drop landed on; `a` and `b` of the Dnd callbacks name it:
|
|
// row (pane, row), pane (pane, -), tab (tab, -), crumb (crumb, -), place (section, index),
|
|
// section (section, slot or -1 for the end: adds folders to the sidebar).
|
|
export enum DropTarget { row, pane, tab, crumb, place, section }
|
|
|
|
// What the drop does: `ask` opens the drop menu (no modifier held).
|
|
export enum DropAction { ask, move, copy, link }
|
|
|
|
// Drag and drop, served by Rust (dnd.rs).
|
|
export global Dnd {
|
|
// Shift is held. Tracked from the window's keys: Slint's drop event can't tell Shift
|
|
// from no modifier (both propose a move).
|
|
in-out property <bool> shift;
|
|
// The payload of a drag from row `row` of pane `pane`. `fresh` only makes the binding
|
|
// read the selection again (pass the row's pressed state).
|
|
pure callback payload(pane: int, row: int, fresh: bool) -> data-transfer;
|
|
// The picture under the pointer: the first name and, for several items, their count.
|
|
pure callback image(pane: int, row: int, fresh: bool, fill: color, ink: color, badge: color, badge-ink: color) -> image;
|
|
// A sidebar entry's payload (moving it to another slot).
|
|
pure callback place-payload(section: int, index: int) -> data-transfer;
|
|
pure callback accepts(data: data-transfer, target: DropTarget, a: int, b: int) -> bool;
|
|
// At window coordinates, for the drop menu.
|
|
callback dropped(data: data-transfer, action: DropAction, target: DropTarget, a: int, b: int, x: length, y: length);
|
|
}
|
|
|
|
// A drop target over its parent: glows while a drag it accepts hovers it.
|
|
export component DropZone inherits DropArea {
|
|
in property <DropTarget> target;
|
|
in property <int> a;
|
|
in property <int> b: -1;
|
|
in property <length> radius;
|
|
|
|
can-drop(event) => {
|
|
Dnd.accepts(event.data, root.target, root.a, root.b) ? event.proposed-action : DragAction.none
|
|
}
|
|
dropped(event) => {
|
|
Dnd.dropped(
|
|
event.data,
|
|
event.proposed-action == DragAction.copy ? DropAction.copy
|
|
: event.proposed-action == DragAction.link ? DropAction.link
|
|
: Dnd.shift ? DropAction.move : DropAction.ask,
|
|
root.target, root.a, root.b,
|
|
self.absolute-position.x + event.position.x,
|
|
self.absolute-position.y + event.position.y);
|
|
event.proposed-action
|
|
}
|
|
|
|
@children
|
|
|
|
// Above the content: a primary outline and a faint drag tint.
|
|
Rectangle {
|
|
border-radius: root.radius;
|
|
border-width: Theme.focus-ring-width;
|
|
border-color: Theme.primary;
|
|
background: Theme.primary.with-alpha(Theme.state-drag);
|
|
opacity: root.has-drag ? 1 : 0;
|
|
animate opacity { duration: Motion.time(Motion.short3); easing: Motion.standard; }
|
|
}
|
|
}
|
|
|
|
// Move / Copy / Link / Cancel, opened at the pointer after a drop without modifiers.
|
|
export component DropMenu inherits Menu {
|
|
leading-icons: true;
|
|
items: [
|
|
{ text: "Move here", icon: Icons.drive-file-move, shortcut: "Shift" },
|
|
{ text: "Copy here", icon: Icons.content-copy, shortcut: "Ctrl" },
|
|
{ text: "Link here", icon: Icons.link, shortcut: "Ctrl+Shift" },
|
|
{ separator: true },
|
|
{ text: "Cancel", icon: Icons.cancel, shortcut: "Esc" },
|
|
];
|
|
}
|