@gtkx/react 0.18.0 → 0.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +1 -0
- package/dist/errors.js.map +1 -0
- package/dist/factory.d.ts +1 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +1 -0
- package/dist/factory.js.map +1 -0
- package/dist/fiber-root.d.ts +1 -0
- package/dist/fiber-root.d.ts.map +1 -0
- package/dist/fiber-root.js +1 -0
- package/dist/fiber-root.js.map +1 -0
- package/dist/generated/internal.d.ts +1 -0
- package/dist/generated/internal.d.ts.map +1 -0
- package/dist/generated/internal.js +1 -0
- package/dist/generated/internal.js.map +1 -0
- package/dist/generated/jsx.d.ts +1 -0
- package/dist/generated/jsx.d.ts.map +1 -0
- package/dist/generated/jsx.js +1 -0
- package/dist/generated/jsx.js.map +1 -0
- package/dist/generated/registry.d.ts +1 -0
- package/dist/generated/registry.d.ts.map +1 -0
- package/dist/generated/registry.js +1 -0
- package/dist/generated/registry.js.map +1 -0
- package/dist/host-config.d.ts +1 -0
- package/dist/host-config.d.ts.map +1 -0
- package/dist/host-config.js +1 -0
- package/dist/host-config.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx.d.ts +1 -0
- package/dist/jsx.d.ts.map +1 -0
- package/dist/jsx.js +1 -0
- package/dist/jsx.js.map +1 -0
- package/dist/metadata.d.ts +1 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +1 -0
- package/dist/metadata.js.map +1 -0
- package/dist/node.d.ts +1 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +1 -0
- package/dist/node.js.map +1 -0
- package/dist/nodes/adjustable.d.ts +1 -0
- package/dist/nodes/adjustable.d.ts.map +1 -0
- package/dist/nodes/adjustable.js +1 -0
- package/dist/nodes/adjustable.js.map +1 -0
- package/dist/nodes/alert-dialog-response.d.ts +1 -0
- package/dist/nodes/alert-dialog-response.d.ts.map +1 -0
- package/dist/nodes/alert-dialog-response.js +1 -0
- package/dist/nodes/alert-dialog-response.js.map +1 -0
- package/dist/nodes/animation.d.ts +1 -0
- package/dist/nodes/animation.d.ts.map +1 -0
- package/dist/nodes/animation.js +1 -0
- package/dist/nodes/animation.js.map +1 -0
- package/dist/nodes/application.d.ts +1 -0
- package/dist/nodes/application.d.ts.map +1 -0
- package/dist/nodes/application.js +1 -0
- package/dist/nodes/application.js.map +1 -0
- package/dist/nodes/calendar.d.ts +1 -0
- package/dist/nodes/calendar.d.ts.map +1 -0
- package/dist/nodes/calendar.js +1 -0
- package/dist/nodes/calendar.js.map +1 -0
- package/dist/nodes/color-dialog-button.d.ts +1 -0
- package/dist/nodes/color-dialog-button.d.ts.map +1 -0
- package/dist/nodes/color-dialog-button.js +1 -0
- package/dist/nodes/color-dialog-button.js.map +1 -0
- package/dist/nodes/column-view-column.d.ts +1 -0
- package/dist/nodes/column-view-column.d.ts.map +1 -0
- package/dist/nodes/column-view-column.js +1 -0
- package/dist/nodes/column-view-column.js.map +1 -0
- package/dist/nodes/column-view.d.ts +1 -0
- package/dist/nodes/column-view.d.ts.map +1 -0
- package/dist/nodes/column-view.js +1 -0
- package/dist/nodes/column-view.js.map +1 -0
- package/dist/nodes/container-slot.d.ts +1 -0
- package/dist/nodes/container-slot.d.ts.map +1 -0
- package/dist/nodes/container-slot.js +1 -0
- package/dist/nodes/container-slot.js.map +1 -0
- package/dist/nodes/dialog.d.ts +1 -0
- package/dist/nodes/dialog.d.ts.map +1 -0
- package/dist/nodes/dialog.js +1 -0
- package/dist/nodes/dialog.js.map +1 -0
- package/dist/nodes/drawing-area.d.ts +1 -0
- package/dist/nodes/drawing-area.d.ts.map +1 -0
- package/dist/nodes/drawing-area.js +1 -0
- package/dist/nodes/drawing-area.js.map +1 -0
- package/dist/nodes/drop-down.d.ts +1 -0
- package/dist/nodes/drop-down.d.ts.map +1 -0
- package/dist/nodes/drop-down.js +1 -0
- package/dist/nodes/drop-down.js.map +1 -0
- package/dist/nodes/event-controller.d.ts +1 -0
- package/dist/nodes/event-controller.d.ts.map +1 -0
- package/dist/nodes/event-controller.js +1 -0
- package/dist/nodes/event-controller.js.map +1 -0
- package/dist/nodes/fixed-child.d.ts +1 -0
- package/dist/nodes/fixed-child.d.ts.map +1 -0
- package/dist/nodes/fixed-child.js +1 -0
- package/dist/nodes/fixed-child.js.map +1 -0
- package/dist/nodes/font-dialog-button.d.ts +1 -0
- package/dist/nodes/font-dialog-button.d.ts.map +1 -0
- package/dist/nodes/font-dialog-button.js +1 -0
- package/dist/nodes/font-dialog-button.js.map +1 -0
- package/dist/nodes/grid-child.d.ts +1 -0
- package/dist/nodes/grid-child.d.ts.map +1 -0
- package/dist/nodes/grid-child.js +1 -0
- package/dist/nodes/grid-child.js.map +1 -0
- package/dist/nodes/grid-view.d.ts +1 -0
- package/dist/nodes/grid-view.d.ts.map +1 -0
- package/dist/nodes/grid-view.js +1 -0
- package/dist/nodes/grid-view.js.map +1 -0
- package/dist/nodes/internal/base-item-renderer.d.ts +1 -0
- package/dist/nodes/internal/base-item-renderer.d.ts.map +1 -0
- package/dist/nodes/internal/base-item-renderer.js +1 -0
- package/dist/nodes/internal/base-item-renderer.js.map +1 -0
- package/dist/nodes/internal/grid-item-renderer.d.ts +1 -0
- package/dist/nodes/internal/grid-item-renderer.d.ts.map +1 -0
- package/dist/nodes/internal/grid-item-renderer.js +1 -0
- package/dist/nodes/internal/grid-item-renderer.js.map +1 -0
- package/dist/nodes/internal/list-item-renderer.d.ts +1 -0
- package/dist/nodes/internal/list-item-renderer.d.ts.map +1 -0
- package/dist/nodes/internal/list-item-renderer.js +1 -0
- package/dist/nodes/internal/list-item-renderer.js.map +1 -0
- package/dist/nodes/internal/list-store.d.ts +1 -0
- package/dist/nodes/internal/list-store.d.ts.map +1 -0
- package/dist/nodes/internal/list-store.js +1 -0
- package/dist/nodes/internal/list-store.js.map +1 -0
- package/dist/nodes/internal/predicates.d.ts +1 -0
- package/dist/nodes/internal/predicates.d.ts.map +1 -0
- package/dist/nodes/internal/predicates.js +1 -0
- package/dist/nodes/internal/predicates.js.map +1 -0
- package/dist/nodes/internal/props.d.ts +1 -0
- package/dist/nodes/internal/props.d.ts.map +1 -0
- package/dist/nodes/internal/props.js +1 -0
- package/dist/nodes/internal/props.js.map +1 -0
- package/dist/nodes/internal/selection-model-controller.d.ts +1 -0
- package/dist/nodes/internal/selection-model-controller.d.ts.map +1 -0
- package/dist/nodes/internal/selection-model-controller.js +1 -0
- package/dist/nodes/internal/selection-model-controller.js.map +1 -0
- package/dist/nodes/internal/signal-store.d.ts +1 -0
- package/dist/nodes/internal/signal-store.d.ts.map +1 -0
- package/dist/nodes/internal/signal-store.js +1 -0
- package/dist/nodes/internal/signal-store.js.map +1 -0
- package/dist/nodes/internal/simple-list-store.d.ts +1 -0
- package/dist/nodes/internal/simple-list-store.d.ts.map +1 -0
- package/dist/nodes/internal/simple-list-store.js +1 -0
- package/dist/nodes/internal/simple-list-store.js.map +1 -0
- package/dist/nodes/internal/text-buffer-controller.d.ts +1 -0
- package/dist/nodes/internal/text-buffer-controller.d.ts.map +1 -0
- package/dist/nodes/internal/text-buffer-controller.js +1 -0
- package/dist/nodes/internal/text-buffer-controller.js.map +1 -0
- package/dist/nodes/internal/tree-store.d.ts +1 -0
- package/dist/nodes/internal/tree-store.d.ts.map +1 -0
- package/dist/nodes/internal/tree-store.js +1 -0
- package/dist/nodes/internal/tree-store.js.map +1 -0
- package/dist/nodes/internal/widget.d.ts +1 -0
- package/dist/nodes/internal/widget.d.ts.map +1 -0
- package/dist/nodes/internal/widget.js +1 -0
- package/dist/nodes/internal/widget.js.map +1 -0
- package/dist/nodes/level-bar.d.ts +1 -0
- package/dist/nodes/level-bar.d.ts.map +1 -0
- package/dist/nodes/level-bar.js +1 -0
- package/dist/nodes/level-bar.js.map +1 -0
- package/dist/nodes/list-item.d.ts +1 -0
- package/dist/nodes/list-item.d.ts.map +1 -0
- package/dist/nodes/list-item.js +1 -0
- package/dist/nodes/list-item.js.map +1 -0
- package/dist/nodes/list-view.d.ts +1 -0
- package/dist/nodes/list-view.d.ts.map +1 -0
- package/dist/nodes/list-view.js +1 -0
- package/dist/nodes/list-view.js.map +1 -0
- package/dist/nodes/menu.d.ts +1 -0
- package/dist/nodes/menu.d.ts.map +1 -0
- package/dist/nodes/menu.js +1 -0
- package/dist/nodes/menu.js.map +1 -0
- package/dist/nodes/models/grid.d.ts +1 -0
- package/dist/nodes/models/grid.d.ts.map +1 -0
- package/dist/nodes/models/grid.js +1 -0
- package/dist/nodes/models/grid.js.map +1 -0
- package/dist/nodes/models/list.d.ts +1 -0
- package/dist/nodes/models/list.d.ts.map +1 -0
- package/dist/nodes/models/list.js +1 -0
- package/dist/nodes/models/list.js.map +1 -0
- package/dist/nodes/models/menu.d.ts +1 -0
- package/dist/nodes/models/menu.d.ts.map +1 -0
- package/dist/nodes/models/menu.js +1 -0
- package/dist/nodes/models/menu.js.map +1 -0
- package/dist/nodes/navigation-page.d.ts +1 -0
- package/dist/nodes/navigation-page.d.ts.map +1 -0
- package/dist/nodes/navigation-page.js +1 -0
- package/dist/nodes/navigation-page.js.map +1 -0
- package/dist/nodes/navigation-view.d.ts +1 -0
- package/dist/nodes/navigation-view.d.ts.map +1 -0
- package/dist/nodes/navigation-view.js +1 -0
- package/dist/nodes/navigation-view.js.map +1 -0
- package/dist/nodes/notebook-page-tab.d.ts +1 -0
- package/dist/nodes/notebook-page-tab.d.ts.map +1 -0
- package/dist/nodes/notebook-page-tab.js +1 -0
- package/dist/nodes/notebook-page-tab.js.map +1 -0
- package/dist/nodes/notebook-page.d.ts +1 -0
- package/dist/nodes/notebook-page.d.ts.map +1 -0
- package/dist/nodes/notebook-page.js +1 -0
- package/dist/nodes/notebook-page.js.map +1 -0
- package/dist/nodes/notebook.d.ts +1 -0
- package/dist/nodes/notebook.d.ts.map +1 -0
- package/dist/nodes/notebook.js +1 -0
- package/dist/nodes/notebook.js.map +1 -0
- package/dist/nodes/overlay-child.d.ts +1 -0
- package/dist/nodes/overlay-child.d.ts.map +1 -0
- package/dist/nodes/overlay-child.js +1 -0
- package/dist/nodes/overlay-child.js.map +1 -0
- package/dist/nodes/popover-menu.d.ts +1 -0
- package/dist/nodes/popover-menu.d.ts.map +1 -0
- package/dist/nodes/popover-menu.js +1 -0
- package/dist/nodes/popover-menu.js.map +1 -0
- package/dist/nodes/scale.d.ts +1 -0
- package/dist/nodes/scale.d.ts.map +1 -0
- package/dist/nodes/scale.js +1 -0
- package/dist/nodes/scale.js.map +1 -0
- package/dist/nodes/scrolled-window.d.ts +1 -0
- package/dist/nodes/scrolled-window.d.ts.map +1 -0
- package/dist/nodes/scrolled-window.js +1 -0
- package/dist/nodes/scrolled-window.js.map +1 -0
- package/dist/nodes/search-bar.d.ts +1 -0
- package/dist/nodes/search-bar.d.ts.map +1 -0
- package/dist/nodes/search-bar.js +1 -0
- package/dist/nodes/search-bar.js.map +1 -0
- package/dist/nodes/shortcut-controller.d.ts +1 -0
- package/dist/nodes/shortcut-controller.d.ts.map +1 -0
- package/dist/nodes/shortcut-controller.js +1 -0
- package/dist/nodes/shortcut-controller.js.map +1 -0
- package/dist/nodes/shortcut.d.ts +1 -0
- package/dist/nodes/shortcut.d.ts.map +1 -0
- package/dist/nodes/shortcut.js +1 -0
- package/dist/nodes/shortcut.js.map +1 -0
- package/dist/nodes/slot.d.ts +1 -0
- package/dist/nodes/slot.d.ts.map +1 -0
- package/dist/nodes/slot.js +1 -0
- package/dist/nodes/slot.js.map +1 -0
- package/dist/nodes/source-view.d.ts +1 -0
- package/dist/nodes/source-view.d.ts.map +1 -0
- package/dist/nodes/source-view.js +1 -0
- package/dist/nodes/source-view.js.map +1 -0
- package/dist/nodes/stack-page.d.ts +1 -0
- package/dist/nodes/stack-page.d.ts.map +1 -0
- package/dist/nodes/stack-page.js +1 -0
- package/dist/nodes/stack-page.js.map +1 -0
- package/dist/nodes/stack.d.ts +1 -0
- package/dist/nodes/stack.d.ts.map +1 -0
- package/dist/nodes/stack.js +1 -0
- package/dist/nodes/stack.js.map +1 -0
- package/dist/nodes/text-anchor.d.ts +1 -0
- package/dist/nodes/text-anchor.d.ts.map +1 -0
- package/dist/nodes/text-anchor.js +1 -0
- package/dist/nodes/text-anchor.js.map +1 -0
- package/dist/nodes/text-content.d.ts +1 -0
- package/dist/nodes/text-content.d.ts.map +1 -0
- package/dist/nodes/text-content.js +1 -0
- package/dist/nodes/text-content.js.map +1 -0
- package/dist/nodes/text-paintable.d.ts +1 -0
- package/dist/nodes/text-paintable.d.ts.map +1 -0
- package/dist/nodes/text-paintable.js +1 -0
- package/dist/nodes/text-paintable.js.map +1 -0
- package/dist/nodes/text-segment.d.ts +1 -0
- package/dist/nodes/text-segment.d.ts.map +1 -0
- package/dist/nodes/text-segment.js +1 -0
- package/dist/nodes/text-segment.js.map +1 -0
- package/dist/nodes/text-tag.d.ts +1 -0
- package/dist/nodes/text-tag.d.ts.map +1 -0
- package/dist/nodes/text-tag.js +1 -0
- package/dist/nodes/text-tag.js.map +1 -0
- package/dist/nodes/text-view.d.ts +1 -0
- package/dist/nodes/text-view.d.ts.map +1 -0
- package/dist/nodes/text-view.js +1 -0
- package/dist/nodes/text-view.js.map +1 -0
- package/dist/nodes/toggle-group.d.ts +1 -0
- package/dist/nodes/toggle-group.d.ts.map +1 -0
- package/dist/nodes/toggle-group.js +1 -0
- package/dist/nodes/toggle-group.js.map +1 -0
- package/dist/nodes/toggle.d.ts +1 -0
- package/dist/nodes/toggle.d.ts.map +1 -0
- package/dist/nodes/toggle.js +1 -0
- package/dist/nodes/toggle.js.map +1 -0
- package/dist/nodes/virtual.d.ts +1 -0
- package/dist/nodes/virtual.d.ts.map +1 -0
- package/dist/nodes/virtual.js +1 -0
- package/dist/nodes/virtual.js.map +1 -0
- package/dist/nodes/web-view.d.ts +1 -0
- package/dist/nodes/web-view.d.ts.map +1 -0
- package/dist/nodes/web-view.js +1 -0
- package/dist/nodes/web-view.js.map +1 -0
- package/dist/nodes/widget.d.ts +1 -0
- package/dist/nodes/widget.d.ts.map +1 -0
- package/dist/nodes/widget.js +1 -0
- package/dist/nodes/widget.js.map +1 -0
- package/dist/nodes/window.d.ts +1 -0
- package/dist/nodes/window.d.ts.map +1 -0
- package/dist/nodes/window.js +1 -0
- package/dist/nodes/window.js.map +1 -0
- package/dist/portal.d.ts +1 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +1 -0
- package/dist/portal.js.map +1 -0
- package/dist/reconciler.d.ts +1 -0
- package/dist/reconciler.d.ts.map +1 -0
- package/dist/reconciler.js +1 -0
- package/dist/reconciler.js.map +1 -0
- package/dist/registry.d.ts +1 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +1 -0
- package/dist/registry.js.map +1 -0
- package/dist/render.d.ts +1 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +1 -0
- package/dist/render.js.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/package.json +6 -4
- package/src/errors.ts +52 -0
- package/src/factory.ts +62 -0
- package/src/fiber-root.ts +20 -0
- package/src/generated/internal.ts +2134 -0
- package/src/generated/jsx.ts +20068 -0
- package/src/generated/registry.ts +16 -0
- package/src/host-config.ts +186 -0
- package/src/index.ts +11 -0
- package/src/jsx.ts +1294 -0
- package/src/metadata.ts +36 -0
- package/src/node.ts +109 -0
- package/src/nodes/adjustable.ts +68 -0
- package/src/nodes/alert-dialog-response.ts +78 -0
- package/src/nodes/animation.ts +402 -0
- package/src/nodes/application.ts +56 -0
- package/src/nodes/calendar.ts +38 -0
- package/src/nodes/color-dialog-button.ts +69 -0
- package/src/nodes/column-view-column.ts +84 -0
- package/src/nodes/column-view.ts +192 -0
- package/src/nodes/container-slot.ts +87 -0
- package/src/nodes/dialog.ts +25 -0
- package/src/nodes/drawing-area.ts +51 -0
- package/src/nodes/drop-down.ts +92 -0
- package/src/nodes/event-controller.ts +100 -0
- package/src/nodes/fixed-child.ts +108 -0
- package/src/nodes/font-dialog-button.ts +97 -0
- package/src/nodes/grid-child.ts +103 -0
- package/src/nodes/grid-view.ts +96 -0
- package/src/nodes/internal/base-item-renderer.ts +108 -0
- package/src/nodes/internal/grid-item-renderer.ts +71 -0
- package/src/nodes/internal/list-item-renderer.ts +155 -0
- package/src/nodes/internal/list-store.ts +105 -0
- package/src/nodes/internal/predicates.ts +80 -0
- package/src/nodes/internal/props.ts +51 -0
- package/src/nodes/internal/selection-model-controller.ts +115 -0
- package/src/nodes/internal/signal-store.ts +141 -0
- package/src/nodes/internal/simple-list-store.ts +99 -0
- package/src/nodes/internal/text-buffer-controller.ts +374 -0
- package/src/nodes/internal/tree-store.ts +237 -0
- package/src/nodes/internal/widget.ts +78 -0
- package/src/nodes/level-bar.ts +36 -0
- package/src/nodes/list-item.ts +107 -0
- package/src/nodes/list-view.ts +97 -0
- package/src/nodes/menu.ts +27 -0
- package/src/nodes/models/grid.ts +105 -0
- package/src/nodes/models/list.ts +140 -0
- package/src/nodes/models/menu.ts +310 -0
- package/src/nodes/navigation-page.ts +154 -0
- package/src/nodes/navigation-view.ts +58 -0
- package/src/nodes/notebook-page-tab.ts +55 -0
- package/src/nodes/notebook-page.ts +185 -0
- package/src/nodes/notebook.ts +28 -0
- package/src/nodes/overlay-child.ts +109 -0
- package/src/nodes/popover-menu.ts +59 -0
- package/src/nodes/scale.ts +28 -0
- package/src/nodes/scrolled-window.ts +23 -0
- package/src/nodes/search-bar.ts +27 -0
- package/src/nodes/shortcut-controller.ts +27 -0
- package/src/nodes/shortcut.ts +69 -0
- package/src/nodes/slot.ts +138 -0
- package/src/nodes/source-view.ts +130 -0
- package/src/nodes/stack-page.ts +170 -0
- package/src/nodes/stack.ts +35 -0
- package/src/nodes/text-anchor.ts +74 -0
- package/src/nodes/text-content.ts +14 -0
- package/src/nodes/text-paintable.ts +51 -0
- package/src/nodes/text-segment.ts +55 -0
- package/src/nodes/text-tag.ts +287 -0
- package/src/nodes/text-view.ts +93 -0
- package/src/nodes/toggle-group.ts +27 -0
- package/src/nodes/toggle.ts +72 -0
- package/src/nodes/virtual.ts +16 -0
- package/src/nodes/web-view.ts +22 -0
- package/src/nodes/widget.ts +398 -0
- package/src/nodes/window.ts +159 -0
- package/src/portal.ts +37 -0
- package/src/reconciler.ts +52 -0
- package/src/registry.ts +123 -0
- package/src/render.tsx +192 -0
- package/src/types.ts +7 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type * as Gio from "@gtkx/ffi/gio";
|
|
2
|
+
import type * as GObject from "@gtkx/ffi/gobject";
|
|
3
|
+
import * as Gtk from "@gtkx/ffi/gtk";
|
|
4
|
+
import type { GtkListViewProps } from "../../jsx.js";
|
|
5
|
+
import { SelectionModelController } from "../internal/selection-model-controller.js";
|
|
6
|
+
import type { SignalStore } from "../internal/signal-store.js";
|
|
7
|
+
import { TreeStore } from "../internal/tree-store.js";
|
|
8
|
+
import { ListItemNode } from "../list-item.js";
|
|
9
|
+
|
|
10
|
+
export type ListModelProps = Pick<GtkListViewProps, "autoexpand" | "selectionMode" | "selected" | "onSelectionChanged">;
|
|
11
|
+
|
|
12
|
+
type ListModelConfig = {
|
|
13
|
+
owner: object;
|
|
14
|
+
signalStore: SignalStore;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export class ListModel {
|
|
18
|
+
private config: ListModelConfig;
|
|
19
|
+
private store: TreeStore;
|
|
20
|
+
private treeListModel: Gtk.TreeListModel;
|
|
21
|
+
private selectionManager: SelectionModelController;
|
|
22
|
+
|
|
23
|
+
private initialSelected: string[] | null | undefined;
|
|
24
|
+
|
|
25
|
+
constructor(config: ListModelConfig, props: ListModelProps = {}) {
|
|
26
|
+
this.config = config;
|
|
27
|
+
this.store = new TreeStore();
|
|
28
|
+
this.store.beginBatch();
|
|
29
|
+
this.initialSelected = props.selected;
|
|
30
|
+
|
|
31
|
+
this.treeListModel = new Gtk.TreeListModel(
|
|
32
|
+
this.store.getRootModel(),
|
|
33
|
+
false,
|
|
34
|
+
props.autoexpand ?? false,
|
|
35
|
+
(item: GObject.Object) => this.createChildModel(item),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
this.selectionManager = new SelectionModelController(
|
|
39
|
+
{ ...config, ...props },
|
|
40
|
+
this.treeListModel,
|
|
41
|
+
() => this.getSelection(),
|
|
42
|
+
(ids) => this.resolveSelectionIndices(ids),
|
|
43
|
+
() => this.treeListModel.getNItems(),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public flushBatch(): void {
|
|
48
|
+
this.store.flushBatch();
|
|
49
|
+
this.selectionManager.reapplySelection(this.initialSelected);
|
|
50
|
+
this.initialSelected = undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private createChildModel(item: GObject.Object): Gio.ListModel | null {
|
|
54
|
+
if (!(item instanceof Gtk.StringObject)) return null;
|
|
55
|
+
const parentId = item.getString();
|
|
56
|
+
return this.store.getChildrenModel(parentId);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public getStore(): TreeStore {
|
|
60
|
+
return this.store;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public getSelectionModel(): Gtk.NoSelection | Gtk.SingleSelection | Gtk.MultiSelection {
|
|
64
|
+
return this.selectionManager.getSelectionModel();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public appendChild(child: ListItemNode): void {
|
|
68
|
+
child.setStore(this.store);
|
|
69
|
+
this.addItemWithChildren(child);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private addItemWithChildren(node: ListItemNode, parentId?: string): void {
|
|
73
|
+
const id = node.props.id;
|
|
74
|
+
|
|
75
|
+
for (const child of node.getChildNodes()) {
|
|
76
|
+
this.addItemWithChildren(child, id);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.store.addItem(id, ListItemNode.createItemData(node.props), parentId);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public insertBefore(child: ListItemNode, before: ListItemNode): void {
|
|
83
|
+
child.setStore(this.store);
|
|
84
|
+
this.store.insertItemBefore(child.props.id, before.props.id, ListItemNode.createItemData(child.props));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public removeChild(child: ListItemNode): void {
|
|
88
|
+
this.store.removeItem(child.props.id);
|
|
89
|
+
child.setStore(null);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public updateProps(oldProps: ListModelProps | null, newProps: ListModelProps): void {
|
|
93
|
+
if (!oldProps || oldProps.autoexpand !== newProps.autoexpand) {
|
|
94
|
+
this.treeListModel.setAutoexpand(newProps.autoexpand ?? false);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this.selectionManager.update(
|
|
98
|
+
oldProps ? { ...this.config, ...oldProps } : null,
|
|
99
|
+
{ ...this.config, ...newProps },
|
|
100
|
+
this.treeListModel,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private getSelection(): string[] {
|
|
105
|
+
const selection = this.selectionManager.getSelectionModel().getSelection();
|
|
106
|
+
const size = selection.getSize();
|
|
107
|
+
const ids: string[] = [];
|
|
108
|
+
|
|
109
|
+
for (let i = 0; i < size; i++) {
|
|
110
|
+
const index = selection.getNth(i);
|
|
111
|
+
const row = this.treeListModel.getRow(index);
|
|
112
|
+
if (!row) continue;
|
|
113
|
+
|
|
114
|
+
const item = row.getItem();
|
|
115
|
+
if (item instanceof Gtk.StringObject) {
|
|
116
|
+
ids.push(item.getString());
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return ids;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private resolveSelectionIndices(ids: string[]): Gtk.Bitset {
|
|
124
|
+
const nItems = this.treeListModel.getNItems();
|
|
125
|
+
const selected = new Gtk.Bitset();
|
|
126
|
+
const idSet = new Set(ids);
|
|
127
|
+
|
|
128
|
+
for (let i = 0; i < nItems; i++) {
|
|
129
|
+
const row = this.treeListModel.getRow(i);
|
|
130
|
+
if (!row) continue;
|
|
131
|
+
|
|
132
|
+
const item = row.getItem();
|
|
133
|
+
if (item instanceof Gtk.StringObject && idSet.has(item.getString())) {
|
|
134
|
+
selected.add(i);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return selected;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import * as Gio from "@gtkx/ffi/gio";
|
|
2
|
+
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
3
|
+
import type { Node } from "../../node.js";
|
|
4
|
+
import type { Container } from "../../types.js";
|
|
5
|
+
import { VirtualNode } from "../virtual.js";
|
|
6
|
+
|
|
7
|
+
export type MenuModelProps = {
|
|
8
|
+
id?: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
accels?: string | string[];
|
|
11
|
+
onActivate?: () => boolean | undefined;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type MenuType = "root" | "item" | "section" | "submenu";
|
|
15
|
+
|
|
16
|
+
export class MenuModel extends VirtualNode<MenuModelProps, MenuModel, MenuModel> {
|
|
17
|
+
private actionMap: Gio.ActionMap | null = null;
|
|
18
|
+
private actionPrefix: string;
|
|
19
|
+
private menu: Gio.Menu;
|
|
20
|
+
private type: MenuType;
|
|
21
|
+
private application: Gtk.Application | null = null;
|
|
22
|
+
private action: Gio.SimpleAction | null = null;
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
type: MenuType,
|
|
26
|
+
props: MenuModelProps,
|
|
27
|
+
rootContainer: Container,
|
|
28
|
+
actionMap?: Gio.ActionMap,
|
|
29
|
+
application?: Gtk.Application,
|
|
30
|
+
) {
|
|
31
|
+
super("", props, undefined, rootContainer);
|
|
32
|
+
this.type = type;
|
|
33
|
+
this.actionMap = actionMap ?? null;
|
|
34
|
+
this.actionPrefix = application ? "app" : "menu";
|
|
35
|
+
this.application = application ?? null;
|
|
36
|
+
this.menu = new Gio.Menu();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public override isValidChild(child: Node): boolean {
|
|
40
|
+
return child instanceof MenuModel;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public override isValidParent(parent: Node): boolean {
|
|
44
|
+
return parent instanceof MenuModel;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public setActionMap(actionMap: Gio.ActionMap, prefix: string): void {
|
|
48
|
+
this.actionMap = actionMap;
|
|
49
|
+
this.actionPrefix = prefix;
|
|
50
|
+
|
|
51
|
+
for (const child of this.children) {
|
|
52
|
+
child.setActionMap(actionMap, prefix);
|
|
53
|
+
|
|
54
|
+
if (child.type === "item") {
|
|
55
|
+
child.createAction();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private getAccels(): string[] {
|
|
61
|
+
const accels = this.props.accels;
|
|
62
|
+
|
|
63
|
+
if (!accels) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return Array.isArray(accels) ? accels : [accels];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private getActionName(): string {
|
|
71
|
+
return `${this.actionPrefix}.${this.props.id}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private getOnActivate(): () => void {
|
|
75
|
+
if (!this.props.onActivate) {
|
|
76
|
+
throw new Error("Expected 'onActivate' prop to be present on MenuItem");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return this.props.onActivate;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private getId(): string {
|
|
83
|
+
if (!this.props.id) {
|
|
84
|
+
throw new Error("Expected 'id' prop to be present on MenuItem");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return this.props.id;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private getParentMenu(): Gio.Menu {
|
|
91
|
+
if (!this.parent) {
|
|
92
|
+
throw new Error("Expected parent menu to be set on MenuNode");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return this.parent.getMenu();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private getActionMap(): Gio.ActionMap {
|
|
99
|
+
if (!this.actionMap) {
|
|
100
|
+
throw new Error("Expected actionMap to be set on MenuNode");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return this.actionMap;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public createAction(): void {
|
|
107
|
+
if (this.action) {
|
|
108
|
+
this.signalStore.set(this, this.action, "activate", null);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
this.action = new Gio.SimpleAction(this.getId());
|
|
112
|
+
this.signalStore.set(this, this.action, "activate", this.getOnActivate());
|
|
113
|
+
this.getActionMap().addAction(this.action);
|
|
114
|
+
|
|
115
|
+
if (this.application && this.props.accels) {
|
|
116
|
+
this.application.setAccelsForAction(this.getActionName(), this.getAccels());
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private removeAction(): void {
|
|
121
|
+
if (this.application && this.props.accels) {
|
|
122
|
+
this.application.setAccelsForAction(this.getActionName(), []);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (this.action) {
|
|
126
|
+
this.getActionMap().removeAction(this.getId());
|
|
127
|
+
this.signalStore.set(this, this.action, "activate", null);
|
|
128
|
+
this.action = null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private getPosition(): number {
|
|
133
|
+
return this.findPositionIn(this.getParentMenu());
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private findPositionIn(parentMenu: Gio.Menu): number {
|
|
137
|
+
for (let i = 0; i < parentMenu.getNItems(); i++) {
|
|
138
|
+
if (this.type === "item") {
|
|
139
|
+
const actionName = parentMenu.getItemAttributeValue(i, "action")?.getString();
|
|
140
|
+
|
|
141
|
+
if (actionName === this.getActionName()) {
|
|
142
|
+
return i;
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
const link = parentMenu.getItemLink(i, this.type);
|
|
146
|
+
|
|
147
|
+
if (link && link === this.menu) {
|
|
148
|
+
return i;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return -1;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public getMenu(): Gio.Menu {
|
|
157
|
+
return this.menu;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private getAction(): Gio.SimpleAction {
|
|
161
|
+
if (!this.action) {
|
|
162
|
+
throw new Error("Expected action to be created on MenuItem");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return this.action;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public removeFromParentMenu(): void {
|
|
169
|
+
if (!this.parent) return;
|
|
170
|
+
|
|
171
|
+
const parentMenu = this.parent.getMenu();
|
|
172
|
+
const position = this.findPositionIn(parentMenu);
|
|
173
|
+
|
|
174
|
+
if (position >= 0) {
|
|
175
|
+
parentMenu.remove(position);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public insertInParentBefore(before: MenuModel): void {
|
|
180
|
+
if (this.type === "item" && this.actionMap) {
|
|
181
|
+
this.createAction();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const parentMenu = this.getParentMenu();
|
|
185
|
+
const beforePosition = before.getPosition();
|
|
186
|
+
|
|
187
|
+
switch (this.type) {
|
|
188
|
+
case "item": {
|
|
189
|
+
parentMenu.insert(beforePosition, this.props.label, this.getActionName());
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case "section":
|
|
193
|
+
parentMenu.insertSection(beforePosition, this.menu, this.props.label);
|
|
194
|
+
break;
|
|
195
|
+
case "submenu":
|
|
196
|
+
parentMenu.insertSubmenu(beforePosition, this.menu, this.props.label);
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public appendToParentMenu(): void {
|
|
202
|
+
if (this.type === "item" && this.actionMap) {
|
|
203
|
+
this.createAction();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const parentMenu = this.getParentMenu();
|
|
207
|
+
|
|
208
|
+
switch (this.type) {
|
|
209
|
+
case "item":
|
|
210
|
+
parentMenu.append(this.props.label, this.getActionName());
|
|
211
|
+
break;
|
|
212
|
+
case "section":
|
|
213
|
+
parentMenu.appendSection(this.menu, this.props.label);
|
|
214
|
+
break;
|
|
215
|
+
case "submenu":
|
|
216
|
+
parentMenu.appendSubmenu(this.menu, this.props.label);
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public override appendChild(child: MenuModel): void {
|
|
222
|
+
super.appendChild(child);
|
|
223
|
+
|
|
224
|
+
if (this.actionMap) {
|
|
225
|
+
child.setActionMap(this.actionMap, this.actionPrefix);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
child.appendToParentMenu();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public override insertBefore(child: MenuModel, before: MenuModel): void {
|
|
232
|
+
super.insertBefore(child, before);
|
|
233
|
+
|
|
234
|
+
if (this.actionMap) {
|
|
235
|
+
child.setActionMap(this.actionMap, this.actionPrefix);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
child.insertInParentBefore(before);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public override removeChild(child: MenuModel): void {
|
|
242
|
+
child.removeFromParentMenu();
|
|
243
|
+
super.removeChild(child);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public override commitUpdate(oldProps: MenuModelProps | null, newProps: MenuModelProps): void {
|
|
247
|
+
super.commitUpdate(oldProps, newProps);
|
|
248
|
+
|
|
249
|
+
if (this.type === "item") {
|
|
250
|
+
this.updateItemProps(oldProps, newProps);
|
|
251
|
+
} else if (this.type === "section" || this.type === "submenu") {
|
|
252
|
+
this.updateContainerProps(oldProps, newProps);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
private updateItemProps(oldProps: MenuModelProps | null, newProps: MenuModelProps): void {
|
|
257
|
+
if (!this.parent || !this.actionMap) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (!oldProps) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (oldProps.id !== newProps.id || oldProps.label !== newProps.label) {
|
|
266
|
+
this.removeAction();
|
|
267
|
+
this.removeFromParentMenu();
|
|
268
|
+
this.createAction();
|
|
269
|
+
this.appendToParentMenu();
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (oldProps.onActivate !== newProps.onActivate) {
|
|
274
|
+
this.signalStore.set(this, this.getAction(), "activate", newProps.onActivate);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (oldProps.accels !== newProps.accels) {
|
|
278
|
+
if (this.application) {
|
|
279
|
+
this.application.setAccelsForAction(this.getActionName(), this.getAccels());
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
private updateContainerProps(oldProps: MenuModelProps | null, newProps: MenuModelProps): void {
|
|
285
|
+
if (!this.parent) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (!oldProps || oldProps.label !== newProps.label) {
|
|
290
|
+
const parentMenu = this.parent.getMenu();
|
|
291
|
+
const position = this.findPositionIn(parentMenu);
|
|
292
|
+
|
|
293
|
+
if (position >= 0) {
|
|
294
|
+
parentMenu.remove(position);
|
|
295
|
+
|
|
296
|
+
if (this.type === "section") {
|
|
297
|
+
parentMenu.insertSection(position, this.menu, this.props.label);
|
|
298
|
+
} else if (this.type === "submenu") {
|
|
299
|
+
parentMenu.insertSubmenu(position, this.menu, this.props.label);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
public override detachDeletedInstance(): void {
|
|
306
|
+
this.removeAction();
|
|
307
|
+
this.removeFromParentMenu();
|
|
308
|
+
super.detachDeletedInstance();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import * as Adw from "@gtkx/ffi/adw";
|
|
2
|
+
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
3
|
+
import { toCamelCase } from "@gtkx/gir";
|
|
4
|
+
import type { NavigationPageProps } from "../jsx.js";
|
|
5
|
+
import type { Node } from "../node.js";
|
|
6
|
+
import type { ContainerClass } from "../types.js";
|
|
7
|
+
import { hasChanged } from "./internal/props.js";
|
|
8
|
+
import { getFocusWidget, isDescendantOf, resolvePropertySetter } from "./internal/widget.js";
|
|
9
|
+
import { VirtualNode } from "./virtual.js";
|
|
10
|
+
import { WidgetNode } from "./widget.js";
|
|
11
|
+
|
|
12
|
+
export class NavigationPageNode extends VirtualNode<NavigationPageProps, WidgetNode, WidgetNode> {
|
|
13
|
+
private wrappedPage: Adw.NavigationPage | null = null;
|
|
14
|
+
|
|
15
|
+
public override isValidChild(child: Node): boolean {
|
|
16
|
+
return child instanceof WidgetNode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public override isValidParent(parent: Node): boolean {
|
|
20
|
+
return parent instanceof WidgetNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public override setParent(parent: WidgetNode | null): void {
|
|
24
|
+
if (!parent && this.parent && this.wrappedPage) {
|
|
25
|
+
const parentWidget = this.getParentWidget();
|
|
26
|
+
if (parentWidget instanceof Adw.NavigationView) {
|
|
27
|
+
parentWidget.remove(this.wrappedPage);
|
|
28
|
+
} else {
|
|
29
|
+
this.applySlotChild(parentWidget, this.wrappedPage);
|
|
30
|
+
}
|
|
31
|
+
this.wrappedPage = null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
super.setParent(parent);
|
|
35
|
+
|
|
36
|
+
if (parent && this.children[0]) {
|
|
37
|
+
this.onChildChange(null);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public override appendChild(child: WidgetNode): void {
|
|
42
|
+
const oldChildWidget = this.children[0]?.container ?? null;
|
|
43
|
+
super.appendChild(child);
|
|
44
|
+
|
|
45
|
+
if (this.parent) {
|
|
46
|
+
this.onChildChange(oldChildWidget);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public override removeChild(child: WidgetNode): void {
|
|
51
|
+
const oldChildWidget = child.container;
|
|
52
|
+
super.removeChild(child);
|
|
53
|
+
|
|
54
|
+
if (this.parent && oldChildWidget) {
|
|
55
|
+
this.onChildChange(oldChildWidget);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public override commitUpdate(oldProps: NavigationPageProps | null, newProps: NavigationPageProps): void {
|
|
60
|
+
super.commitUpdate(oldProps, newProps);
|
|
61
|
+
this.applyOwnProps(oldProps, newProps);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public override detachDeletedInstance(): void {
|
|
65
|
+
if (this.parent && this.wrappedPage) {
|
|
66
|
+
const parentWidget = this.getParentWidget();
|
|
67
|
+
if (parentWidget instanceof Adw.NavigationView) {
|
|
68
|
+
parentWidget.remove(this.wrappedPage);
|
|
69
|
+
} else {
|
|
70
|
+
this.applySlotChild(parentWidget, this.wrappedPage);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
this.wrappedPage = null;
|
|
74
|
+
super.detachDeletedInstance();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private applyOwnProps(oldProps: NavigationPageProps | null, newProps: NavigationPageProps): void {
|
|
78
|
+
if (!this.wrappedPage) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (hasChanged(oldProps, newProps, "id")) {
|
|
83
|
+
this.wrappedPage.setTag(newProps.id);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (hasChanged(oldProps, newProps, "title")) {
|
|
87
|
+
this.wrappedPage.setTitle(newProps.title ?? "");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (hasChanged(oldProps, newProps, "canPop")) {
|
|
91
|
+
this.wrappedPage.setCanPop(newProps.canPop ?? true);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private onChildChange(oldChild: Gtk.Widget | null): void {
|
|
96
|
+
const parentWidget = this.getParentWidget();
|
|
97
|
+
const title = this.props.title ?? "";
|
|
98
|
+
const childWidget = this.children[0]?.container ?? null;
|
|
99
|
+
|
|
100
|
+
if (childWidget) {
|
|
101
|
+
const wrappedChild = this.props.id
|
|
102
|
+
? Adw.NavigationPage.newWithTag(childWidget, title, this.props.id)
|
|
103
|
+
: new Adw.NavigationPage(childWidget, title);
|
|
104
|
+
|
|
105
|
+
this.wrappedPage = wrappedChild;
|
|
106
|
+
this.applyOwnProps(null, this.props);
|
|
107
|
+
|
|
108
|
+
if (parentWidget instanceof Adw.NavigationView) {
|
|
109
|
+
if (oldChild instanceof Adw.NavigationPage) {
|
|
110
|
+
parentWidget.remove(oldChild);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
parentWidget.add(wrappedChild);
|
|
114
|
+
} else {
|
|
115
|
+
this.applySlotChild(parentWidget, oldChild);
|
|
116
|
+
}
|
|
117
|
+
} else if (parentWidget instanceof Adw.NavigationView) {
|
|
118
|
+
if (oldChild instanceof Adw.NavigationPage) {
|
|
119
|
+
parentWidget.remove(oldChild);
|
|
120
|
+
}
|
|
121
|
+
this.wrappedPage = null;
|
|
122
|
+
} else {
|
|
123
|
+
this.wrappedPage = null;
|
|
124
|
+
this.applySlotChild(parentWidget, oldChild);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private applySlotChild(parentWidget: Gtk.Widget, oldChild: Gtk.Widget | null): void {
|
|
129
|
+
const propId = toCamelCase(this.props.id ?? "");
|
|
130
|
+
const setter = resolvePropertySetter(parentWidget, propId);
|
|
131
|
+
|
|
132
|
+
if (!setter) {
|
|
133
|
+
const parentType = (parentWidget.constructor as ContainerClass).glibTypeName;
|
|
134
|
+
throw new Error(`Unable to find property for slot '${propId}' on type '${parentType}'`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (oldChild && !this.wrappedPage) {
|
|
138
|
+
const focus = getFocusWidget(oldChild);
|
|
139
|
+
|
|
140
|
+
if (focus && isDescendantOf(focus, oldChild)) {
|
|
141
|
+
parentWidget.grabFocus();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
setter(this.wrappedPage);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private getParentWidget(): Gtk.Widget {
|
|
149
|
+
if (!this.parent) {
|
|
150
|
+
throw new Error("Expected parent widget to be set on NavigationPageNode");
|
|
151
|
+
}
|
|
152
|
+
return this.parent.container;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as Adw from "@gtkx/ffi/adw";
|
|
2
|
+
import type { AdwNavigationViewProps } from "../jsx.js";
|
|
3
|
+
import type { Node } from "../node.js";
|
|
4
|
+
import { filterProps, hasChanged, primitiveArrayEqual } from "./internal/props.js";
|
|
5
|
+
import { NavigationPageNode } from "./navigation-page.js";
|
|
6
|
+
import { SlotNode } from "./slot.js";
|
|
7
|
+
import { WidgetNode } from "./widget.js";
|
|
8
|
+
|
|
9
|
+
const OWN_PROPS = ["history", "onHistoryChanged"] as const;
|
|
10
|
+
|
|
11
|
+
type NavigationViewProps = Pick<AdwNavigationViewProps, (typeof OWN_PROPS)[number]>;
|
|
12
|
+
type NavigationViewChild = NavigationPageNode | SlotNode | WidgetNode;
|
|
13
|
+
|
|
14
|
+
export class NavigationViewNode extends WidgetNode<Adw.NavigationView, NavigationViewProps, NavigationViewChild> {
|
|
15
|
+
public override isValidChild(child: Node): boolean {
|
|
16
|
+
return child instanceof NavigationPageNode || child instanceof SlotNode || child instanceof WidgetNode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public override commitUpdate(oldProps: NavigationViewProps | null, newProps: NavigationViewProps): void {
|
|
20
|
+
super.commitUpdate(oldProps ? filterProps(oldProps, OWN_PROPS) : null, filterProps(newProps, OWN_PROPS));
|
|
21
|
+
this.applyOwnProps(oldProps, newProps);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private applyOwnProps(oldProps: NavigationViewProps | null, newProps: NavigationViewProps): void {
|
|
25
|
+
const oldHistory = oldProps?.history;
|
|
26
|
+
const newHistory = newProps.history;
|
|
27
|
+
|
|
28
|
+
if (newHistory && !primitiveArrayEqual(oldHistory, newHistory)) {
|
|
29
|
+
this.container.replaceWithTags(newHistory, newHistory.length);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (hasChanged(oldProps, newProps, "onHistoryChanged")) {
|
|
33
|
+
const { onHistoryChanged } = newProps;
|
|
34
|
+
const handler = onHistoryChanged ? () => onHistoryChanged(this.getCurrentHistory()) : undefined;
|
|
35
|
+
|
|
36
|
+
this.signalStore.set(this, this.container, "popped", handler);
|
|
37
|
+
this.signalStore.set(this, this.container, "pushed", handler);
|
|
38
|
+
this.signalStore.set(this, this.container, "replaced", handler);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private getCurrentHistory(): string[] {
|
|
43
|
+
const stack = this.container.getNavigationStack();
|
|
44
|
+
const history: string[] = [];
|
|
45
|
+
const nItems = stack.getNItems();
|
|
46
|
+
|
|
47
|
+
for (let i = 0; i < nItems; i++) {
|
|
48
|
+
const page = stack.getObject(i);
|
|
49
|
+
if (!(page instanceof Adw.NavigationPage)) continue;
|
|
50
|
+
const tag = page.getTag();
|
|
51
|
+
if (tag) {
|
|
52
|
+
history.push(tag);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return history;
|
|
57
|
+
}
|
|
58
|
+
}
|