dazscript-framework 0.1.0

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.
Files changed (67) hide show
  1. package/babel/babel.config.js +33 -0
  2. package/babel/trace-babel-plugin.js +243 -0
  3. package/babel/trace-log-babel-plugin.js +164 -0
  4. package/common/core.ts +2 -0
  5. package/common/log.ts +57 -0
  6. package/common/trace.ts +26 -0
  7. package/core/action-decorator.ts +16 -0
  8. package/dialog/basic-dialog.ts +32 -0
  9. package/dialog/builders/button-builder.ts +53 -0
  10. package/dialog/builders/checkbox-builder.ts +30 -0
  11. package/dialog/builders/combo-box-builder.ts +36 -0
  12. package/dialog/builders/combo-edit-builder.ts +36 -0
  13. package/dialog/builders/dialog-builder.ts +49 -0
  14. package/dialog/builders/groupbox-builder.ts +73 -0
  15. package/dialog/builders/label-builder.ts +18 -0
  16. package/dialog/builders/layout-builder.ts +46 -0
  17. package/dialog/builders/line-edit-builder.ts +118 -0
  18. package/dialog/builders/list-view-builder.ts +327 -0
  19. package/dialog/builders/node-selection-builder.ts +44 -0
  20. package/dialog/builders/popup-menu-builder.ts +47 -0
  21. package/dialog/builders/radio-builder.ts +43 -0
  22. package/dialog/builders/splitter-builder.ts +90 -0
  23. package/dialog/builders/tab-builder.ts +106 -0
  24. package/dialog/builders/widget-builder.ts +109 -0
  25. package/dialog/builders/widgets-builder.ts +119 -0
  26. package/dialog/input-dialog.ts +28 -0
  27. package/dialog/input-validator.ts +9 -0
  28. package/dialog/shared.ts +8 -0
  29. package/helpers/action-helper.ts +81 -0
  30. package/helpers/array-helper.ts +145 -0
  31. package/helpers/camera-helper.ts +14 -0
  32. package/helpers/custom-action-helper.ts +176 -0
  33. package/helpers/file-helper.ts +90 -0
  34. package/helpers/input-helper.ts +19 -0
  35. package/helpers/list-view-helper.ts +89 -0
  36. package/helpers/menu-helper.ts +29 -0
  37. package/helpers/message-box-helper.ts +16 -0
  38. package/helpers/node-helper.ts +216 -0
  39. package/helpers/number-helper.ts +11 -0
  40. package/helpers/numeric-property-helper.ts +92 -0
  41. package/helpers/object-helper.ts +3 -0
  42. package/helpers/pane-helper.ts +21 -0
  43. package/helpers/progress-helper.ts +34 -0
  44. package/helpers/property-helper.ts +53 -0
  45. package/helpers/record-helper.ts +16 -0
  46. package/helpers/scene-helper.ts +96 -0
  47. package/helpers/script-helper.ts +16 -0
  48. package/helpers/skeleton-helper.ts +27 -0
  49. package/helpers/splitter-helper.ts +9 -0
  50. package/helpers/string-helper.ts +28 -0
  51. package/helpers/surface-helper.ts +6 -0
  52. package/helpers/undo-helper.ts +7 -0
  53. package/helpers/viewport-helper.ts +9 -0
  54. package/lib/delayed.ts +39 -0
  55. package/lib/dz-dump.ts +121 -0
  56. package/lib/global.ts +5 -0
  57. package/lib/guid.ts +3 -0
  58. package/lib/observable.ts +94 -0
  59. package/lib/set.ts +25 -0
  60. package/lib/settings.ts +104 -0
  61. package/models/custom-action.ts +12 -0
  62. package/models/frame-keys.ts +68 -0
  63. package/package.json +48 -0
  64. package/shared/base-script.ts +30 -0
  65. package/shared/install-generator.js +185 -0
  66. package/shared/set-keyboard-shortcut.ts +103 -0
  67. package/webpack.config.js +48 -0
@@ -0,0 +1,44 @@
1
+ import { Observable } from '@dsf/lib/observable';
2
+ import { WidgetBuilderBase, createWidget } from './widget-builder';
3
+ import { WidgetBuilderContext } from './widgets-builder';
4
+
5
+ export class NodeSelectionComboBoxBuilder extends WidgetBuilderBase<DzNodeSelectionComboBox> {
6
+ constructor(context: WidgetBuilderContext) {
7
+ super(createWidget(context).withArgs(['DzNode', true]).build(DzNodeSelectionComboBox))
8
+ }
9
+
10
+ node(node: Observable<DzNode>): this {
11
+ this.widget.setNode(node.value)
12
+ node.connect((node) => {
13
+ this.widget.setNode(node)
14
+ })
15
+ return this
16
+ }
17
+
18
+ nodes(nodes: Observable<DzNode[]>): this {
19
+ this.widget.setNodes(nodes.value)
20
+ nodes.connect((nodes) => {
21
+ this.widget.setNodes(nodes)
22
+ })
23
+ return this
24
+ }
25
+
26
+ selected(node: Observable<DzNode>): this {
27
+ this.widget.setSelectedNode(node.value)
28
+ node.connect((node) => {
29
+ this.widget.setSelectedNode(node)
30
+ })
31
+ return this
32
+ }
33
+
34
+ bind(node: Observable<DzNode>): this {
35
+ this.widget.nodeSelectionChanged.scriptConnect(() => {
36
+ node.value = this.widget.getSelectedNode()
37
+ })
38
+ return this
39
+ }
40
+
41
+ build(then?: (comboBox: DzNodeSelectionComboBox) => void): DzNodeSelectionComboBox {
42
+ return super.build()
43
+ }
44
+ }
@@ -0,0 +1,47 @@
1
+ import { WidgetBuilderBase, createWidget } from './widget-builder';
2
+ import { WidgetBuilderContext } from './widgets-builder';
3
+
4
+ export class PopupMenuItem {
5
+ id?: number
6
+ text?: string
7
+ checkbox?: boolean
8
+ activated?: (id?: number) => void
9
+ }
10
+
11
+ export class PopupMenuBuilder extends WidgetBuilderBase<DzPopupMenu> {
12
+ constructor(context: WidgetBuilderContext) {
13
+ super(createWidget(context).build(DzPopupMenu));
14
+ }
15
+
16
+ parent(parent: DzWidget): this {
17
+ this.widget.reparent(parent, new Point(0, 0))
18
+ return this
19
+ }
20
+
21
+ items(...items: PopupMenuItem[]): this {
22
+ items?.forEach((item, idx) => {
23
+ if (!item.text) {
24
+ this.widget.insertSeparator(idx)
25
+ }
26
+ else {
27
+ this.widget.insertTextItem(item.text, item.id ?? idx, idx)
28
+
29
+ }
30
+
31
+ if (item.activated) this.widget.connectItem(item.id ?? idx, null, item.activated)
32
+ })
33
+ return this
34
+ }
35
+
36
+ selected(fn: (idx: number) => void): this {
37
+ this.widget.activated.scriptConnect((idx) => {
38
+ fn(idx)
39
+ })
40
+ return this
41
+ }
42
+
43
+ build(then?: (popupMenu: DzPopupMenu) => void): DzPopupMenu {
44
+ then?.(this.widget)
45
+ return this.widget
46
+ }
47
+ }
@@ -0,0 +1,43 @@
1
+ import { Observable } from '@dsf/lib/observable';
2
+ import { WidgetBuilderBase, createWidget } from './widget-builder';
3
+ import { WidgetBuilderContext } from './widgets-builder';
4
+
5
+ export default class RadioButtonBuilder extends WidgetBuilderBase<DzRadioButton> {
6
+ constructor(context: WidgetBuilderContext) {
7
+ super(createWidget(context).build(DzRadioButton))
8
+ }
9
+
10
+ label(text: string): this {
11
+ this.widget.text = text ?? ''
12
+ return this
13
+ }
14
+
15
+ value(source: boolean | Observable<boolean>): this {
16
+ if (typeof source === 'boolean') {
17
+ this.widget.checked = source
18
+ }
19
+ else {
20
+ this.widget.checked = source.value
21
+ source.connect((value) => {
22
+ this.widget.checked = value
23
+ })
24
+ this.widget.toggled.scriptConnect((value) => {
25
+ source.value = value
26
+ })
27
+ }
28
+ return this
29
+ }
30
+
31
+ toggled(fn: (value: boolean) => void): this {
32
+ this.widget.toggled.scriptConnect((value) => {
33
+ fn(value)
34
+ })
35
+ return this
36
+ }
37
+
38
+ build(checkbox?: (checkbox: DzRadioButton) => void): DzRadioButton {
39
+ checkbox?.(this.widget)
40
+ return this.widget
41
+ }
42
+
43
+ }
@@ -0,0 +1,90 @@
1
+ import { debug } from '@dsf/common/log';
2
+ import { WidgetBuilderBase, createWidget } from './widget-builder';
3
+ import { WidgetBuilderContext } from './widgets-builder';
4
+ import { Observable } from '@dsf/lib/observable';
5
+ import { getState, restoreState } from '@dsf/helpers/splitter-helper';
6
+
7
+ export class SplitterBuilder extends WidgetBuilderBase<DzSplitter> {
8
+ private _items: DzWidget[] = []
9
+
10
+ constructor(private context: SplitterBuilderContext) {
11
+ super(createWidget(context.widgetContext).build(DzSplitter))
12
+ }
13
+
14
+ vertical(): this {
15
+ this.context.orientation = DzSplitter.Vertical
16
+ return this
17
+ }
18
+
19
+ horizontal(): this {
20
+ this.context.orientation = DzSplitter.Horizontal
21
+ return this
22
+ }
23
+
24
+ items(...items: DzWidget[]): this {
25
+ this._items = items
26
+ return this
27
+ }
28
+
29
+ collapsible(...collapsible: boolean[]): this {
30
+ this.context.collapsible = collapsible
31
+ return this
32
+ }
33
+
34
+ strech(...strech: number[]): this {
35
+ this.context.strech = strech
36
+ return this
37
+ }
38
+
39
+ state(bind: Observable<string>): this {
40
+ this.context.state = bind
41
+ return this
42
+ }
43
+
44
+ build(then?: (splitter: DzSplitter) => void): DzSplitter {
45
+ let splitter = createWidget(this.context.widgetContext).build(DzSplitter)
46
+ splitter.orientation = this.context.orientation
47
+
48
+ this._items?.forEach((widget, index) => {
49
+ splitter.addWidget(widget)
50
+ splitter.setCollapsible(index, this.context.collapsible[index] ?? this.context.collapsible[0] ?? false)
51
+ splitter.setStretchFactor(index, this.context.strech[index] ?? this.context.strech[0] ?? 0)
52
+ })
53
+
54
+ restoreState(splitter, this.context.state?.value);
55
+ (splitter.getWidget() as QSplitter).splitterMoved.scriptConnect(() => {
56
+ this.context.state.value = getState(splitter)
57
+ })
58
+ this.context.state.connect((state) => {
59
+ restoreState(splitter, state)
60
+ })
61
+
62
+ this.context.add(splitter, (splitter) => {
63
+ then?.(splitter)
64
+ })
65
+
66
+ return splitter
67
+ }
68
+ }
69
+
70
+ export class SplitterBuilderContext {
71
+ private _current: DzSplitter
72
+
73
+ orientation: number = DzSplitter.Vertical
74
+ collapsible: boolean[] = []
75
+ strech: number[] = []
76
+ state = new Observable<string>()
77
+
78
+ get current(): DzSplitter | null {
79
+ return this._current
80
+ }
81
+
82
+ constructor(public readonly widgetContext: WidgetBuilderContext) { }
83
+
84
+ add(splitter: DzSplitter, content: (splitterWidget: DzSplitter) => void): DzSplitter {
85
+ this._current = splitter
86
+ content(splitter)
87
+ this._current = null
88
+ return splitter
89
+ }
90
+ }
@@ -0,0 +1,106 @@
1
+ import { Observable } from '@dsf/lib/observable';
2
+ import { IWidgetBuilder } from './widget-builder';
3
+ import LayoutBuilder from './layout-builder';
4
+ import { Direction } from '../shared';
5
+ import { WidgetBuilderContext } from './widgets-builder';
6
+
7
+ export class TabBuilder implements IWidgetBuilder<DzTabWidget> {
8
+ private direction: Direction = 'vertical';
9
+ private titleText: string;
10
+ private tabIndex_: Observable<number>;
11
+ private currentChanged: (index: number) => void;
12
+
13
+ constructor(private layoutBuilder: LayoutBuilder, private context: TabBuilderContext) {
14
+ }
15
+
16
+ visible(value: boolean | Observable<boolean>): this {
17
+ this.context.visible = typeof value === 'boolean'
18
+ ? new Observable(value)
19
+ : value
20
+ return this
21
+ }
22
+
23
+ static create(context: TabBuilderContext): TabBuilder {
24
+ return new TabBuilder(new LayoutBuilder(context.widgetContext), context)
25
+ }
26
+
27
+ horizontal(): this {
28
+ this.direction = 'horizontal'
29
+ return this
30
+ }
31
+
32
+ vertical(): this {
33
+ this.direction = 'vertical'
34
+ return this
35
+ }
36
+
37
+ title(text: string): this {
38
+ this.titleText = text;
39
+ return this;
40
+ }
41
+
42
+ bind(tabNumber: Observable<number>): this {
43
+ this.tabIndex_ = tabNumber;
44
+ return this;
45
+ }
46
+
47
+ onChanged(then: (index: number) => void): this {
48
+ this.currentChanged = then
49
+ return this
50
+ }
51
+
52
+ build(then?: (layout: DzVBoxLayout | DzHBoxLayout, tabWidget: DzTabWidget) => void): DzTabWidget {
53
+ return this.context.add((tabWidget) => {
54
+ let tab = new DzWidget(this.context.widgetContext.dialog)
55
+ tabWidget.addTab(tab, this.titleText)
56
+ this.context.widgetContext.layout.addWidget(tabWidget)
57
+
58
+ this.layoutBuilder
59
+ .parent(tab)
60
+ .direction(this.direction)
61
+ .build((layout) => {
62
+ then?.(layout, tabWidget)
63
+ })
64
+
65
+ if (this.context.visible) {
66
+ if (this.context.visible.value === false)
67
+ tab.hide()
68
+ this.context.visible.connect((visible) => {
69
+ if (visible)
70
+ tab.show()
71
+ else
72
+ tab.hide()
73
+ })
74
+ }
75
+
76
+ tabWidget["currentChanged(int)"].scriptConnect((index: number) => {
77
+ if (this.tabIndex_) this.tabIndex_.value = index
78
+ this.currentChanged?.(index)
79
+ })
80
+
81
+ tabWidget.setCurrentPage(this.tabIndex_?.value ?? 0)
82
+ });
83
+ }
84
+ }
85
+
86
+ export class TabBuilderContext {
87
+ private counter = 1;
88
+ private widgets: DzTabWidget[] = [];
89
+ visible: Observable<boolean>
90
+
91
+ constructor(public readonly widgetContext: WidgetBuilderContext) { }
92
+
93
+ add(content: (tabWidget: DzTabWidget) => void): DzTabWidget {
94
+ this.counter++
95
+ let tabWidget = this.getWidget()
96
+ content(tabWidget)
97
+ this.counter--
98
+ return tabWidget
99
+ }
100
+
101
+ private getWidget(): DzTabWidget {
102
+ if (this.widgets.length === 0 || this.counter >= this.widgets.length)
103
+ this.widgets[this.counter] = new DzTabWidget(this.widgetContext.dialog);
104
+ return this.widgets[this.counter];
105
+ }
106
+ }
@@ -0,0 +1,109 @@
1
+ import { createUID } from '@dsf/lib/guid';
2
+ import { Observable } from '@dsf/lib/observable';
3
+ import { WidgetBuilderContext } from './widgets-builder';
4
+
5
+ export abstract class WidgetBuilderBase<T extends DzWidget> implements IWidgetBuilder<T>{
6
+ constructor(protected readonly widget: T) { }
7
+
8
+ enabled<T>(when: boolean | Observable<T>): this {
9
+ if (typeof when === 'boolean') {
10
+ this.widget.enabled = when
11
+ }
12
+ else {
13
+ this.widget.enabled = Boolean(when.value)
14
+ when.connect((value) => {
15
+ this.widget.enabled = Boolean(value)
16
+ })
17
+ }
18
+ return this
19
+ }
20
+
21
+ focus(): this {
22
+ this.widget.getWidget().setFocus()
23
+ return this
24
+ }
25
+
26
+ toolTip(toolTip: string): this {
27
+ this.widget.toolTip = toolTip
28
+ this.widget.whatsThis = toolTip
29
+ return this
30
+ }
31
+
32
+ whatsThis(whatsThis: string): this {
33
+ this.widget.whatsThis = whatsThis
34
+ return this
35
+ }
36
+
37
+ visible(value: boolean | Observable<boolean>): this {
38
+ let observable = typeof value === 'boolean'
39
+ ? new Observable(value)
40
+ : value
41
+
42
+ if (observable.value)
43
+ this.widget.show()
44
+ else
45
+ this.widget.hide()
46
+ observable.connect((value) => {
47
+ if (value)
48
+ this.widget.show()
49
+ else
50
+ this.widget.hide()
51
+ })
52
+ return this
53
+ }
54
+
55
+ build(): T {
56
+ return this.widget
57
+ }
58
+ }
59
+
60
+ export interface IWidgetBuilder<T extends DzWidget> {
61
+ visible(value: boolean | Observable<boolean>): this
62
+ build(): T
63
+ }
64
+
65
+ export class WidgetBuilder {
66
+ private _parent: DzWidget | DzLayout;
67
+ private _args: any[] | null;
68
+
69
+ constructor(public readonly context: WidgetBuilderContext) { }
70
+
71
+ parent(parent: DzWidget | DzLayout): this {
72
+ this._parent = parent;
73
+ return this;
74
+ }
75
+
76
+ withArgs(widgetArgs: any[]): this {
77
+ this._args = widgetArgs;
78
+ return this;
79
+ }
80
+
81
+ build<T extends DzWidget>(type: { new(p0: any, p1?: any, p2?: any, p3?: any): T; }, then?: (widget: T) => void): T {
82
+ let parent = this._parent ?? this.context.parent;
83
+ let name = createUID();
84
+ let widget: T;
85
+
86
+ if (parent.inherits("DzLayout")) {
87
+ let args = this._args;
88
+ if (!args || args.length === 0) widget = new type(this.context.dialog);
89
+ else if (args.length === 1) widget = new type(this.context.dialog, args[0]);
90
+ else if (args.length === 2) widget = new type(this.context.dialog, args[0], args[1]);
91
+ else if (args.length === 3) widget = new type(this.context.dialog, args[0], args[1], args[2]);
92
+ else throw Error("DzWidget Arguments out of range");
93
+ (<DzLayout>parent).addWidget(widget);
94
+ }
95
+ else {
96
+ widget = new type(parent);
97
+ }
98
+
99
+ widget.name = name;
100
+ then?.(widget);
101
+
102
+ return widget;
103
+ }
104
+ }
105
+
106
+ export const createWidget = (context: WidgetBuilderContext): WidgetBuilder => {
107
+ return new WidgetBuilder(context)
108
+ }
109
+
@@ -0,0 +1,119 @@
1
+ import { Observable } from '@dsf/lib/observable'
2
+ import { ButtonBuilder } from './button-builder'
3
+ import CheckBoxBuilder from './checkbox-builder'
4
+ import { ComboBoxBuilder } from './combo-box-builder'
5
+ import { ComboEditBuilder } from './combo-edit-builder'
6
+ import GroupBoxBuilder from './groupbox-builder'
7
+ import LabelBuilder from './label-builder'
8
+ import LayoutBuilder from './layout-builder'
9
+ import LineEditBuilder from './line-edit-builder'
10
+ import { ListViewBuilder } from './list-view-builder'
11
+ import { NodeSelectionComboBoxBuilder } from './node-selection-builder'
12
+ import { PopupMenuBuilder } from './popup-menu-builder'
13
+ import RadioButtonBuilder from './radio-builder'
14
+ import { SplitterBuilder, SplitterBuilderContext } from './splitter-builder'
15
+ import { TabBuilder, TabBuilderContext } from './tab-builder'
16
+ import { createWidget } from './widget-builder'
17
+
18
+ export class WidgetBuilderContext {
19
+ layout: DzLayout | null
20
+
21
+ get parent(): DzWidget | DzLayout {
22
+ return this.layout ?? this.dialog
23
+ }
24
+
25
+ constructor(public readonly dialog: DzBasicDialog) {
26
+ this.layout = new LayoutBuilder(this).build()
27
+ }
28
+ }
29
+
30
+ export class WidgetsBuilder {
31
+ private readonly tabsContext: TabBuilderContext
32
+ private readonly splitterContext: SplitterBuilderContext
33
+
34
+ constructor(public readonly context: WidgetBuilderContext) {
35
+ this.tabsContext = new TabBuilderContext(this.context)
36
+ this.splitterContext = new SplitterBuilderContext(this.context)
37
+ }
38
+
39
+ vertical(then?: (layout: DzVBoxLayout) => void): DzVBoxLayout {
40
+ return LayoutBuilder
41
+ .create(this.context)
42
+ .direction('vertical')
43
+ .build(then)
44
+ }
45
+
46
+ horizontal(then?: (layout: DzHBoxLayout) => void): DzHBoxLayout {
47
+ return LayoutBuilder
48
+ .create(this.context)
49
+ .direction('horizontal')
50
+ .build(then)
51
+ }
52
+
53
+ widget<T extends DzWidget>(type: { new(p0: any, p1?: any, p2?: any, p3?: any): T }, then?: (widget: T) => void): T {
54
+ return createWidget(this.context).build(type, then)
55
+ }
56
+
57
+ label(text: string): LabelBuilder {
58
+ return new LabelBuilder(this.context).text(text)
59
+ }
60
+
61
+ button(text?: string): ButtonBuilder {
62
+ return new ButtonBuilder(this.context).text(text)
63
+ }
64
+
65
+ edit(): LineEditBuilder {
66
+ return new LineEditBuilder(this.context)
67
+ }
68
+
69
+ checkbox(label?: string): CheckBoxBuilder {
70
+ return new CheckBoxBuilder(this.context).label(label)
71
+ }
72
+
73
+ radio(label?: string): RadioButtonBuilder {
74
+ return new RadioButtonBuilder(this.context).label(label)
75
+ }
76
+
77
+ group(title?: string | Observable<string>): GroupBoxBuilder {
78
+ return new GroupBoxBuilder(this.context).title(title)
79
+ }
80
+
81
+ tab(title?: string): TabBuilder {
82
+ return TabBuilder.create(this.tabsContext).title(title)
83
+ }
84
+
85
+ splitter(...items: DzWidget[]): SplitterBuilder {
86
+ return new SplitterBuilder(this.splitterContext).items(...items)
87
+ }
88
+
89
+ contextMenu(): PopupMenuBuilder {
90
+ return new PopupMenuBuilder(this.context)
91
+ }
92
+
93
+ combo(): ComboBoxBuilder {
94
+ return new ComboBoxBuilder(this.context)
95
+ }
96
+
97
+ comboEdit(): ComboEditBuilder {
98
+ return new ComboEditBuilder(this.context)
99
+ }
100
+
101
+ /**
102
+ *
103
+ * @returns
104
+ * @deprecated use list
105
+ */
106
+ listView<TItem, TData = TItem>(): ListViewBuilder<TItem, TData> {
107
+ return new ListViewBuilder(this.context)
108
+ }
109
+
110
+ get list(): { view: <TItem, TData = TItem>() => ListViewBuilder<TItem, TData> } {
111
+ return {
112
+ view: <TItem, TData = TItem>() => new ListViewBuilder<TItem, TData>(this.context)
113
+ }
114
+ }
115
+
116
+ nodeSelection(): NodeSelectionComboBoxBuilder {
117
+ return new NodeSelectionComboBoxBuilder(this.context)
118
+ }
119
+ }
@@ -0,0 +1,28 @@
1
+ import { Observable } from '@dsf/lib/observable';
2
+ import { BasicDialog } from './basic-dialog';
3
+ import { InputValidator } from './input-validator';
4
+
5
+ export class InputDialogModel {
6
+ value$: Observable<string> = new Observable()
7
+ validator: InputValidator | null = null
8
+
9
+ getNumericValue(): number {
10
+ return parseFloat(this.value$.value).valueOf()
11
+ }
12
+
13
+ constructor(validator: InputValidator | null = null) {
14
+ this.validator = validator
15
+ }
16
+ }
17
+
18
+ export class InputDialog extends BasicDialog {
19
+ constructor(title: string, private readonly model: InputDialogModel) {
20
+ super(title);
21
+ }
22
+
23
+ protected build(): void {
24
+ let add = this.add
25
+
26
+ add.edit().text(this.model.value$).validator(this.model.validator).focus()
27
+ }
28
+ }
@@ -0,0 +1,9 @@
1
+ export enum InputValidator {
2
+ float,
3
+ int,
4
+ regexp,
5
+ subpath,
6
+ filename,
7
+ nodename,
8
+ nodelabel
9
+ }
@@ -0,0 +1,8 @@
1
+
2
+ export type Direction = 'vertical' | 'horizontal';
3
+
4
+ export class DialogProperties {
5
+ width?: number;
6
+ height?: number;
7
+ resizable?: boolean;
8
+ }
@@ -0,0 +1,81 @@
1
+ import { debug, warn } from '@dsf/common/log'
2
+ import { mainWindow } from '@dsf/lib/global'
3
+ import { isGUID } from './string-helper'
4
+
5
+ const actionMgr = mainWindow.getActionMgr()
6
+
7
+ export const isCustomAction = (action: string | DzAction): boolean => {
8
+ return typeof action === 'string'
9
+ ? isGUID(action)
10
+ : action.inherits('DzCustomAction')
11
+ }
12
+
13
+ export const findAction = (name: string): DzAction | null => {
14
+ return isCustomAction(name)
15
+ ? findCustomAction(name)
16
+ : actionMgr.findAction(name)
17
+ }
18
+
19
+ const findCustomAction = (name: string): DzCustomAction | null => {
20
+ let index = actionMgr.findCustomAction(name)
21
+ return index >= 0
22
+ ? actionMgr.getCustomActionByIndex(index)
23
+ : null
24
+ }
25
+
26
+ export const triggerAction = (name: string) => {
27
+ findAction(name)?.trigger()
28
+ }
29
+
30
+ export const setActionShortcut = (name: string, shortcut: string) => {
31
+ let action = findAction(name)
32
+ if (!action) return
33
+ if (isCustomAction(action)) {
34
+ actionMgr.setCustomActionShortcut(actionMgr.findCustomAction(name), shortcut)
35
+ debug(`Shortcut set for Custom Action ${action.text}: ${shortcut}`)
36
+ }
37
+ else {
38
+ actionMgr.setAccel(name, shortcut)
39
+ debug(`Shortcut set for Action ${action.text}: ${shortcut}`)
40
+ }
41
+
42
+ }
43
+
44
+ export const clearActionShorcut = (name: string) => {
45
+ let action = findAction(name)
46
+ if (!action) return
47
+ if (isCustomAction(action)) {
48
+ actionMgr.setCustomActionShortcut(actionMgr.findCustomAction(name), '')
49
+ }
50
+ else {
51
+ actionMgr.setAccel(name, '')
52
+ }
53
+ }
54
+
55
+ export const getActionPixmap = (action: string, icon: string, maxSize?: number): QPixmap | null => {
56
+ try {
57
+ if (!action) return null;
58
+ let isCustom = isCustomAction(action)
59
+
60
+ if (isCustom && icon && typeof icon === 'string' && icon) {
61
+ let image: DzImageTexture = (App.getImageMgr() as any)['getImage(QString)'](icon)
62
+ if (image) {
63
+ let size = image.getOriginalImageSize();
64
+ let pixmap = size.width > maxSize || size.height > maxSize
65
+ ? image.getPreviewPixmap(Math.min(size.width, maxSize), Math.min(size.height, maxSize))
66
+ : new Pixmap(image.getFilename())
67
+
68
+ return pixmap
69
+ }
70
+ }
71
+ else if (!isCustom) {
72
+ let pixmap = App.getStyle().actionPixmap(action, 0, 0)
73
+ return pixmap?.height === 0 ? null : pixmap
74
+ }
75
+ } catch (error) {
76
+ warn(`Error while trying to get icon pixmap: ${error}`)
77
+ }
78
+ return null
79
+ }
80
+
81
+