2023-10-18 08:31:08 +13:00
|
|
|
import { Button, VerticalBox , HorizontalBox, TabWidget, ListView, StandardListView, StandardTableView, CheckBox} from "std-widgets.slint";
|
2023-10-22 23:18:41 +13:00
|
|
|
import {TypeOfOpenedItem} from "common.slint";
|
2023-10-29 05:20:46 +13:00
|
|
|
import {ColorPalette} from "color_palette.slint";
|
2023-10-29 07:08:14 +13:00
|
|
|
import {MainListModel} from "common.slint";
|
|
|
|
|
2023-10-18 08:31:08 +13:00
|
|
|
|
|
|
|
export component SelectableTableView inherits Rectangle {
|
2023-10-22 23:18:41 +13:00
|
|
|
callback item_opened(string);
|
2023-10-18 08:31:08 +13:00
|
|
|
in property <[string]> columns;
|
2023-10-22 10:33:29 +13:00
|
|
|
in property <string> last_column;
|
2023-10-29 07:08:14 +13:00
|
|
|
in-out property <[MainListModel]> values;
|
2023-10-22 23:18:41 +13:00
|
|
|
in-out property <[length]> column_sizes;
|
2023-11-11 05:11:32 +13:00
|
|
|
private property <[length]> real_sizes: [0px, 0px, 0px, 0px, 0px, 0px, 0px, 0px, 0px, 0px, 0px, 0px, 0px, 0px, 0px, 0px, 0px, 0px];
|
2023-10-22 22:32:13 +13:00
|
|
|
private property <int> column_number: column-sizes.length + 1;
|
2023-10-22 23:18:41 +13:00
|
|
|
// This idx, starts from zero, but since first is always a checkbox, and is not in model.val values, remove 1 from idx
|
|
|
|
in-out property <int> parentPathIdx;
|
|
|
|
in-out property <int> fileNameIdx;
|
2023-10-22 10:33:29 +13:00
|
|
|
in-out property <int> selected_item: -1;
|
2023-10-23 09:12:59 +13:00
|
|
|
forward-focus: focus_item;
|
2023-10-27 07:57:17 +13:00
|
|
|
// TODO not works
|
2023-10-23 09:12:59 +13:00
|
|
|
focus_item := FocusScope {
|
|
|
|
key-released(event) => {
|
2023-10-27 07:57:17 +13:00
|
|
|
// debug(event);
|
2023-10-23 09:12:59 +13:00
|
|
|
accept
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-18 08:31:08 +13:00
|
|
|
VerticalBox {
|
|
|
|
padding: 5px;
|
2023-10-23 09:12:59 +13:00
|
|
|
forward-focus: focus-item;
|
2023-10-18 08:31:08 +13:00
|
|
|
HorizontalLayout {
|
2023-11-11 05:11:32 +13:00
|
|
|
padding: 5px;
|
2023-10-19 20:32:37 +13:00
|
|
|
spacing: 5px;
|
2023-10-18 08:31:08 +13:00
|
|
|
vertical-stretch: 0;
|
2023-11-11 05:11:32 +13:00
|
|
|
for title [idx] in root.columns: HorizontalLayout {
|
2023-10-22 10:33:29 +13:00
|
|
|
width: root.column-sizes[idx];
|
2023-11-11 05:11:32 +13:00
|
|
|
Text {
|
|
|
|
overflow: elide;
|
|
|
|
text: title;
|
|
|
|
}
|
2023-10-22 10:33:29 +13:00
|
|
|
|
2023-10-18 08:31:08 +13:00
|
|
|
Rectangle {
|
|
|
|
width: 1px;
|
|
|
|
background: gray;
|
2023-10-23 09:12:59 +13:00
|
|
|
forward-focus: focus-item;
|
2023-10-18 08:31:08 +13:00
|
|
|
TouchArea {
|
|
|
|
width: 5px;
|
|
|
|
x: (parent.width - self.width) / 2;
|
|
|
|
property <length> cached;
|
2023-10-23 09:12:59 +13:00
|
|
|
forward-focus: focus-item;
|
2023-10-18 08:31:08 +13:00
|
|
|
pointer-event(event) => {
|
|
|
|
if (event.button == PointerEventButton.left && event.kind == PointerEventKind.down) {
|
|
|
|
self.cached = root.column_sizes[idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
moved => {
|
|
|
|
if (self.pressed) {
|
|
|
|
root.column_sizes[idx] += (self.mouse-x - self.pressed-x);
|
2023-10-19 20:32:37 +13:00
|
|
|
if (root.column_sizes[idx] < 20px) {
|
|
|
|
root.column_sizes[idx] = 20px;
|
2023-10-18 08:31:08 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mouse-cursor: ew-resize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-11 05:11:32 +13:00
|
|
|
|
|
|
|
Text {
|
|
|
|
overflow: elide;
|
|
|
|
text: last-column;
|
|
|
|
}
|
2023-10-18 08:31:08 +13:00
|
|
|
}
|
2023-11-11 05:11:32 +13:00
|
|
|
|
2023-10-22 10:33:29 +13:00
|
|
|
list_view := ListView {
|
2023-10-21 19:36:56 +13:00
|
|
|
min-width: 100px;
|
2023-10-23 09:12:59 +13:00
|
|
|
forward-focus: focus-item;
|
2023-11-11 05:11:32 +13:00
|
|
|
for r [idx] in root.values: Rectangle {
|
2023-10-30 01:19:28 +13:00
|
|
|
border-radius: 5px;
|
2023-10-23 09:12:59 +13:00
|
|
|
forward-focus: focus-item;
|
2023-10-25 09:05:09 +13:00
|
|
|
height: 20px;
|
2023-11-11 05:11:32 +13:00
|
|
|
background: r.header-row ? ColorPalette.list_view_normal_header_color : (touch-area.has-hover ? (r.selected_row ? ColorPalette.list-view-normal-selected-header : ColorPalette.list_view_normal_color) : (r.selected_row ? ColorPalette.list-view-normal-selected-header : ColorPalette.list_view_normal_color));
|
|
|
|
touch_area := TouchArea {
|
2023-10-23 09:12:59 +13:00
|
|
|
forward-focus: focus-item;
|
2023-10-18 08:31:08 +13:00
|
|
|
clicked => {
|
2023-10-21 19:36:56 +13:00
|
|
|
if (!r.header_row) {
|
2023-10-22 10:33:29 +13:00
|
|
|
r.selected_row = !r.selected_row;
|
|
|
|
if (root.selected-item == -1) {
|
|
|
|
root.selected-item = idx;
|
|
|
|
} else {
|
|
|
|
if (r.selected_row == true) {
|
|
|
|
root.values[root.selected-item].selected_row = false;
|
|
|
|
root.selected-item = idx;
|
|
|
|
} else {
|
|
|
|
root.selected-item = -1;
|
|
|
|
}
|
|
|
|
}
|
2023-10-21 19:36:56 +13:00
|
|
|
}
|
2023-10-18 08:31:08 +13:00
|
|
|
}
|
2023-10-22 23:18:41 +13:00
|
|
|
pointer-event(event) => {
|
|
|
|
// TODO this should be clicked by double-click
|
|
|
|
if (event.button == PointerEventButton.right && event.kind == PointerEventKind.up) {
|
|
|
|
root.item_opened(r.val[root.parentPathIdx - 1])
|
|
|
|
} else if (event.button == PointerEventButton.middle && event.kind == PointerEventKind.up) {
|
|
|
|
root.item_opened(r.val[root.parentPathIdx - 1] + "/" + r.val[root.fileNameIdx - 1])
|
|
|
|
}
|
|
|
|
}
|
2023-10-18 08:31:08 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
HorizontalLayout {
|
2023-10-23 09:12:59 +13:00
|
|
|
forward-focus: focus-item;
|
2023-10-18 08:31:08 +13:00
|
|
|
CheckBox {
|
2023-10-21 19:36:56 +13:00
|
|
|
visible: !r.header-row;
|
|
|
|
checked: r.checked && !r.header-row;
|
2023-10-18 08:31:08 +13:00
|
|
|
width: root.column-sizes[0];
|
2023-10-23 09:12:59 +13:00
|
|
|
forward-focus: focus-item;
|
2023-10-20 08:39:48 +13:00
|
|
|
toggled => {
|
|
|
|
r.checked = self.checked;
|
|
|
|
}
|
2023-10-18 08:31:08 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
HorizontalLayout {
|
|
|
|
spacing: 5px;
|
2023-11-11 05:11:32 +13:00
|
|
|
for f [idx] in r.val: Text {
|
2023-10-18 08:31:08 +13:00
|
|
|
width: root.column-sizes[idx + 1];
|
|
|
|
text: f;
|
2023-10-22 10:33:29 +13:00
|
|
|
font-size: 12px;
|
2023-10-23 09:12:59 +13:00
|
|
|
forward-focus: focus-item;
|
2023-10-18 08:31:08 +13:00
|
|
|
vertical-alignment: center;
|
|
|
|
overflow: elide;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-11 05:11:32 +13:00
|
|
|
}
|