11namespace colibri . ui . controls . properties {
22
3- class PropertySectionPane extends Control {
4-
5- private _section : PropertySection < any > ;
6- private _titleArea : HTMLDivElement ;
7- private _formArea : HTMLDivElement ;
8- private _page : PropertyPage ;
9- private _menuIcon : IconControl ;
10- private _expandIconControl : IconControl ;
11-
12- constructor ( page : PropertyPage , section : PropertySection < any > ) {
13- super ( ) ;
14-
15- this . _page = page ;
16-
17- this . _section = section ;
18-
19- this . addClass ( "PropertySectionPane" ) ;
20- }
21-
22- createSection ( ) {
23-
24- if ( ! this . _formArea ) {
25-
26- this . _titleArea = document . createElement ( "div" ) ;
27- this . _titleArea . classList . add ( "PropertyTitleArea" ) ;
28- this . _titleArea . addEventListener ( "click" , ( ) => this . toggleSection ( ) ) ;
29-
30- this . _expandIconControl = new IconControl ( colibri . ColibriPlugin . getInstance ( ) . getIcon ( colibri . ICON_CONTROL_TREE_COLLAPSE ) ) ;
31-
32- this . _expandIconControl . getCanvas ( ) . classList . add ( "expanded" ) ;
33-
34- this . _expandIconControl . getCanvas ( ) . addEventListener ( "click" , e => {
35-
36- e . stopImmediatePropagation ( ) ;
37-
38- this . toggleSection ( )
39- } ) ;
40-
41- this . _titleArea . appendChild ( this . _expandIconControl . getCanvas ( ) ) ;
42-
43- const label = document . createElement ( "label" ) ;
44- label . innerText = this . _section . getTitle ( ) ;
45- this . _titleArea . appendChild ( label ) ;
46-
47- this . _menuIcon = new IconControl ( ColibriPlugin . getInstance ( ) . getIcon ( ICON_SMALL_MENU ) ) ;
48- this . _menuIcon . getCanvas ( ) . classList . add ( "IconButton" ) ;
49- this . _menuIcon . getCanvas ( ) . style . visibility = this . _section . hasMenu ( ) ? "visible" : "hidden" ;
50- this . _menuIcon . getCanvas ( ) . addEventListener ( "click" , e => {
51-
52- e . stopPropagation ( ) ;
53- e . stopImmediatePropagation ( ) ;
54-
55- if ( this . _section . hasMenu ( ) ) {
56-
57- const menu = new Menu ( ) ;
58- this . _section . createMenu ( menu ) ;
59- menu . createWithEvent ( e ) ;
60- }
61- } ) ;
62- this . _titleArea . appendChild ( this . _menuIcon . getCanvas ( ) ) ;
63-
64- this . _formArea = document . createElement ( "div" ) ;
65- this . _formArea . classList . add ( "PropertyFormArea" ) ;
66- this . _section . create ( this . _formArea ) ;
67-
68- this . getElement ( ) . appendChild ( this . _titleArea ) ;
69- this . getElement ( ) . appendChild ( this . _formArea ) ;
70-
71- this . updateExpandIcon ( ) ;
72-
73- let collapsed = this . getCollapsedStateInStorage ( ) ;
74-
75- if ( collapsed === undefined ) {
76-
77- this . setCollapsedStateInStorage ( this . _section . isCollapsedByDefault ( ) ) ;
78-
79- collapsed = this . getCollapsedStateInStorage ( ) ;
80- }
81-
82- if ( collapsed === "true" ) {
83-
84- this . toggleSection ( ) ;
85- }
86- }
87- }
88-
89- private getCollapsedStateInStorage ( ) {
90-
91- return window . localStorage [ this . getLocalStorageKey ( ) + ".collapsed" ] ;
92- }
93-
94- private setCollapsedStateInStorage ( collapsed : boolean ) {
95-
96- return window . localStorage [ this . getLocalStorageKey ( ) + ".collapsed" ] = collapsed ? "true" : "false" ;
97- }
98-
99- private getLocalStorageKey ( ) {
100-
101- return `colibri.ui.controls.properties.PropertySection[${ this . _section . getId ( ) } ]` ;
102- }
103-
104-
105- isExpanded ( ) {
106- return this . _expandIconControl . getCanvas ( ) . classList . contains ( "expanded" ) ;
107- }
108-
109- private toggleSection ( ) : void {
110-
111- if ( this . isExpanded ( ) ) {
112-
113- this . _formArea . style . display = "none" ;
114- this . _expandIconControl . getCanvas ( ) . classList . remove ( "expanded" ) ;
115-
116- } else {
117-
118- this . _formArea . style . display = "grid" ;
119- this . _expandIconControl . getCanvas ( ) . classList . add ( "expanded" ) ;
120- }
121-
122- this . _page . updateExpandStatus ( ) ;
123-
124- this . getContainer ( ) . dispatchLayoutEvent ( ) ;
125-
126- this . updateExpandIcon ( ) ;
127-
128- this . setCollapsedStateInStorage ( ! this . isExpanded ( ) ) ;
129- }
130-
131- private updateExpandIcon ( ) {
132-
133- const icon = this . isExpanded ( ) ? colibri . ICON_CONTROL_SECTION_COLLAPSE : colibri . ICON_CONTROL_SECTION_EXPAND ;
134-
135- const image = ColibriPlugin . getInstance ( ) . getIcon ( icon ) ;
136-
137- this . _expandIconControl . setIcon ( image ) ;
138- }
139-
140- getSection ( ) {
141- return this . _section ;
142- }
143-
144- getFormArea ( ) {
145- return this . _formArea ;
146- }
147- }
148-
1493 export class PropertyPage extends Control {
1504 private _sectionProvider : PropertySectionProvider ;
1515 private _sectionPanes : PropertySectionPane [ ] ;
@@ -186,6 +40,12 @@ namespace colibri.ui.controls.properties {
18640
18741 const pane = new PropertySectionPane ( this , section ) ;
18842
43+ if ( section . getTypeHash ( ) ) {
44+
45+ this . removePanesWithSameTypeHash ( section . getTypeHash ( ) ) ;
46+ }
47+
48+ console . log ( "PropertyPage: create pane for" , section . getTitle ( ) , section . getId ( ) ) ;
18949 this . add ( pane ) ;
19050
19151 this . _sectionPaneMap . set ( section . getId ( ) , pane ) ;
@@ -197,7 +57,9 @@ namespace colibri.ui.controls.properties {
19757 const sectionIdList = list . map ( section => section . getId ( ) ) ;
19858
19959 for ( const pane of this . _sectionPanes ) {
60+
20061 const index = sectionIdList . indexOf ( pane . getSection ( ) . getId ( ) ) ;
62+
20163 pane . getElement ( ) . style . order = index . toString ( ) ;
20264 }
20365
@@ -206,12 +68,29 @@ namespace colibri.ui.controls.properties {
20668 } else {
20769
20870 for ( const pane of this . _sectionPanes ) {
209-
71+
21072 pane . getElement ( ) . style . display = "none" ;
21173 }
21274 }
21375 }
21476
77+ private removePanesWithSameTypeHash ( typeHash : string ) {
78+
79+ for ( const pane of this . _sectionPanes ) {
80+
81+ const section = pane . getSection ( ) ;
82+
83+ if ( section . getTypeHash ( ) === typeHash ) {
84+
85+ console . log ( "PropertyPage: remove dynamic pane" , section . getTitle ( ) , section . getId ( ) ) ;
86+ this . remove ( pane ) ;
87+ }
88+ }
89+
90+ this . _sectionPanes = this . _sectionPanes
91+ . filter ( pane => pane . getSection ( ) . getTypeHash ( ) !== typeHash ) ;
92+ }
93+
21594 public updateWithSelection ( ) : void {
21695
21796 if ( ! this . _sectionProvider ) {
@@ -288,6 +167,11 @@ namespace colibri.ui.controls.properties {
288167 pane . createSection ( ) ;
289168 section . updateWithSelection ( ) ;
290169
170+ if ( section . isDynamicTitle ( ) ) {
171+
172+ pane . updateTitle ( ) ;
173+ }
174+
291175 } else {
292176
293177 pane . getElement ( ) . style . display = "none" ;
@@ -357,6 +241,7 @@ namespace colibri.ui.controls.properties {
357241 }
358242
359243 getSectionProvider ( ) {
244+
360245 return this . _sectionProvider ;
361246 }
362247 }
0 commit comments