233 lines
9.6 KiB
Text
233 lines
9.6 KiB
Text
import { Theme } from "../theme.slint";
|
|
import { Motion } from "../motion.slint";
|
|
import { Icon } from "../components/icon.slint";
|
|
import { DetailRow, FolderActions, FolderState, NavKey, SortColumn } from "../views/details-view.slint";
|
|
import { GridRow } from "../views/grid-view.slint";
|
|
import { FolderView } from "../views/view-switch.slint";
|
|
import { DropTarget, DropZone } from "../components/drop-menu.slint";
|
|
|
|
// One pane of a tab, set from Rust (shell/pane.rs).
|
|
export struct PaneData {
|
|
rows: [DetailRow],
|
|
// The grid view's lines over the same rows.
|
|
lines: [GridRow],
|
|
folder: FolderState,
|
|
// Folder name and glyph, for the split-view header and the tab.
|
|
title: string,
|
|
glyph: string,
|
|
}
|
|
|
|
// A folder view with its header. In split view the header names the folder and marks the
|
|
// active pane: the one the toolbar, breadcrumb and shortcuts act on.
|
|
export component Pane inherits Rectangle {
|
|
in property <PaneData> data;
|
|
in property <bool> active;
|
|
in property <bool> split;
|
|
// Index in the tab, for drag and drop.
|
|
in property <int> index;
|
|
out property <bool> hovered: touch.has-hover;
|
|
|
|
// The pointer or keyboard went here: make this the active pane.
|
|
callback activated();
|
|
callback sort-by(SortColumn);
|
|
callback open-sort-menu(length, length);
|
|
callback filter-typed(string);
|
|
callback filter-edited(string);
|
|
callback toggle-hidden();
|
|
callback row-clicked(int, bool, bool);
|
|
callback row-activated(int);
|
|
callback select-all();
|
|
callback clear-selection();
|
|
callback navigate(NavKey, bool, int) -> int;
|
|
callback columns-changed(int);
|
|
callback motion-settled();
|
|
callback row-renamed(int, string);
|
|
callback rename-cancelled();
|
|
callback context-menu(int, length, length);
|
|
callback viewport-changed(length, length, length, length);
|
|
callback band(float, length, float, length, bool, bool);
|
|
|
|
// The view keeps the focus away from a name being edited.
|
|
public function focus-view() {
|
|
if root.data.folder.edit-row < 0 {
|
|
details.focus-view();
|
|
}
|
|
}
|
|
|
|
property <length> header-height: root.split ? 32px : 0;
|
|
|
|
border-radius: root.split ? Theme.corner-lg : 0;
|
|
clip: true;
|
|
background: Theme.surface;
|
|
|
|
// Clicks the view leaves alone (empty space, the header) still activate the pane; the
|
|
// hover is for the mouse back and forward buttons, which go to the pane under the pointer.
|
|
// Dropping on the background (or on a file) goes into the pane's folder.
|
|
DropZone {
|
|
target: DropTarget.pane;
|
|
a: root.index;
|
|
radius: root.border-radius;
|
|
|
|
touch := TouchArea {
|
|
// A drag from empty space draws the selection box (Ctrl or Shift adds to the
|
|
// selection); its release is no click.
|
|
property <bool> banding;
|
|
property <bool> banded;
|
|
property <bool> add;
|
|
moved => {
|
|
if !self.pressed {
|
|
return;
|
|
}
|
|
let ax = self.absolute-position.x + self.mouse-x;
|
|
let ay = self.absolute-position.y + self.mouse-y;
|
|
if self.banding {
|
|
details.band-to(ax, ay, self.add, false);
|
|
} else if !self.banded && (abs(self.mouse-x - self.pressed-x) > Theme.drag-slop || abs(self.mouse-y - self.pressed-y) > Theme.drag-slop) {
|
|
self.banded = true;
|
|
root.activated();
|
|
self.banding = details.band-to(self.absolute-position.x + self.pressed-x, self.absolute-position.y + self.pressed-y, self.add, true);
|
|
if self.banding {
|
|
details.band-to(ax, ay, self.add, false);
|
|
}
|
|
}
|
|
}
|
|
clicked => {
|
|
if self.banded {
|
|
return;
|
|
}
|
|
root.activated();
|
|
root.focus-view();
|
|
// A plain click on the list's empty space lets go of the selection.
|
|
if !self.add && details.in-list(self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y) {
|
|
root.clear-selection();
|
|
}
|
|
}
|
|
double-clicked => {
|
|
FolderActions.empty-double-clicked(root.index);
|
|
}
|
|
pointer-event(event) => {
|
|
if event.button == PointerEventButton.left && event.kind == PointerEventKind.down {
|
|
self.banded = false;
|
|
self.add = event.modifiers.control || event.modifiers.shift;
|
|
}
|
|
if event.button == PointerEventButton.left && event.kind == PointerEventKind.up && self.banding {
|
|
self.banding = false;
|
|
details.band-end();
|
|
root.focus-view();
|
|
}
|
|
if event.button == PointerEventButton.right && event.kind == PointerEventKind.down {
|
|
root.activated();
|
|
root.context-menu(-1, self.absolute-position.x + self.mouse-x, self.absolute-position.y + self.mouse-y);
|
|
}
|
|
if event.button == PointerEventButton.middle && event.kind == PointerEventKind.up {
|
|
root.activated();
|
|
FolderActions.middle-clicked(root.index, -1);
|
|
}
|
|
}
|
|
|
|
VerticalLayout {
|
|
if root.split: Rectangle {
|
|
height: root.header-height;
|
|
background: root.active ? Theme.secondary-container : Theme.surface-container;
|
|
animate background { duration: Motion.time(Motion.short4); easing: Motion.standard; }
|
|
|
|
HorizontalLayout {
|
|
padding-left: Theme.space-3;
|
|
padding-right: Theme.space-3;
|
|
spacing: Theme.space-2;
|
|
|
|
VerticalLayout {
|
|
alignment: center;
|
|
Icon {
|
|
glyph: root.data.glyph;
|
|
size: 18px;
|
|
color: root.active ? Theme.on-secondary-container : Theme.on-surface-variant;
|
|
animate color { duration: Motion.time(Motion.short4); easing: Motion.standard; }
|
|
}
|
|
}
|
|
|
|
Text {
|
|
horizontal-stretch: 1;
|
|
text: root.data.title;
|
|
color: root.active ? Theme.on-secondary-container : Theme.on-surface-variant;
|
|
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; }
|
|
}
|
|
}
|
|
}
|
|
|
|
details := FolderView {
|
|
pane: root.index;
|
|
rows: root.data.rows;
|
|
lines: root.data.lines;
|
|
state: root.data.folder;
|
|
columns-changed(n) => {
|
|
root.columns-changed(n);
|
|
}
|
|
motion-settled => {
|
|
root.motion-settled();
|
|
}
|
|
viewport-changed(top, height, row, cell) => {
|
|
root.viewport-changed(top, height, row, cell);
|
|
}
|
|
band(c1, y1, c2, y2, add, start) => {
|
|
root.band(c1, y1, c2, y2, add, start);
|
|
}
|
|
row-renamed(row, text) => {
|
|
root.row-renamed(row, text);
|
|
}
|
|
rename-cancelled => {
|
|
root.rename-cancelled();
|
|
}
|
|
context-menu(row, x, y) => {
|
|
root.activated();
|
|
root.context-menu(row, x, y);
|
|
}
|
|
sort-by(column) => {
|
|
root.activated();
|
|
root.sort-by(column);
|
|
}
|
|
open-sort-menu(x, y) => {
|
|
root.activated();
|
|
root.open-sort-menu(x, y);
|
|
}
|
|
filter-typed(text) => {
|
|
root.activated();
|
|
root.filter-typed(text);
|
|
}
|
|
filter-edited(text) => {
|
|
root.activated();
|
|
root.filter-edited(text);
|
|
}
|
|
toggle-hidden => {
|
|
root.activated();
|
|
root.toggle-hidden();
|
|
}
|
|
row-clicked(row, ctrl, shift) => {
|
|
root.activated();
|
|
root.row-clicked(row, ctrl, shift);
|
|
}
|
|
row-activated(row) => {
|
|
root.activated();
|
|
root.row-activated(row);
|
|
}
|
|
select-all => {
|
|
root.activated();
|
|
root.select-all();
|
|
}
|
|
clear-selection => {
|
|
root.activated();
|
|
root.clear-selection();
|
|
}
|
|
navigate(key, shift, page) => {
|
|
root.activated();
|
|
root.navigate(key, shift, page)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|