@@ -40,8 +40,8 @@ qx.Class.define("osparc.widget.Renamer", {
4040 construct : function ( oldLabel = "" , subtitle = "" , winTitle ) {
4141 this . base ( arguments , winTitle || this . tr ( "Rename" ) ) ;
4242
43- const maxWidth = 350 ;
44- const minWidth = 200 ;
43+ const maxWidth = 400 ;
44+ const minWidth = 250 ;
4545 const labelWidth = oldLabel ? Math . min ( Math . max ( parseInt ( oldLabel . length * 4 ) , minWidth ) , maxWidth ) : minWidth ;
4646 this . set ( {
4747 layout : new qx . ui . layout . VBox ( 5 ) ,
@@ -63,66 +63,93 @@ qx.Class.define("osparc.widget.Renamer", {
6363 "labelChanged" : "qx.event.type.Data"
6464 } ,
6565
66+ properties : {
67+ maxChars : {
68+ check : "Number" ,
69+ init : 50 ,
70+ apply : "__applyMaxChars" ,
71+ }
72+ } ,
73+
6674 members : {
67- __save : null ,
75+ _createChildControlImpl : function ( id ) {
76+ let control ;
77+ switch ( id ) {
78+ case "main-layout" :
79+ control = new qx . ui . container . Composite ( new qx . ui . layout . HBox ( 10 ) ) ;
80+ this . add ( control ) ;
81+ break ;
82+ case "text-field" :
83+ control = new qx . ui . form . TextField ( ) . set ( {
84+ placeholder : this . tr ( "Type text" ) ,
85+ allowGrowX : true
86+ } ) ;
87+ this . getChildControl ( "main-layout" ) . add ( control , {
88+ flex : 1
89+ } ) ;
90+ break ;
91+ case "save-button" :
92+ control = new qx . ui . form . Button ( this . tr ( "Save" ) ) . set ( {
93+ appearance : "form-button" ,
94+ padding : [ 1 , 5 ]
95+ } ) ;
96+ this . getChildControl ( "main-layout" ) . add ( control ) ;
97+ break ;
98+ case "subtitle" :
99+ control = new qx . ui . basic . Label ( ) . set ( {
100+ font : "text-12"
101+ } ) ;
102+ this . add ( control ) ;
103+ break ;
104+ }
105+ return control || this . base ( arguments , id ) ;
106+ } ,
68107
69108 __populateNodeLabelEditor : function ( oldLabel , labelWidth ) {
70- const nodeLabelEditor = new qx . ui . container . Composite ( new qx . ui . layout . HBox ( 10 ) ) ;
71-
72- // Create a text field in which to edit the data
73- const labelEditor = new qx . ui . form . TextField ( oldLabel ) . set ( {
74- placeholder : this . tr ( "Type text" ) ,
75- allowGrowX : true ,
76- minWidth : labelWidth
109+ const textField = this . getChildControl ( "text-field" ) . set ( {
110+ value : oldLabel ,
111+ minWidth : labelWidth ,
77112 } ) ;
78- nodeLabelEditor . add ( labelEditor , {
79- flex : 1
80- } ) ;
81-
82- this . addListener ( "appear" , e => {
83- labelEditor . focus ( ) ;
84- if ( labelEditor . getValue ( ) ) {
85- labelEditor . setTextSelection ( 0 , labelEditor . getValue ( ) . length ) ;
86- }
87- } , this ) ;
88113
89- // Create the "Save" button to close the cell editor
90- const save = this . __save = new qx . ui . form . Button ( this . tr ( "Save" ) ) ;
91- save . set ( {
92- appearance : "form-button" ,
93- padding : [ 1 , 5 ]
94- } ) ;
95- save . addListener ( "execute" , e => {
96- const newLabel = labelEditor . getValue ( ) ;
114+ const saveButton = this . getChildControl ( "save-button" ) ;
115+ saveButton . addListener ( "execute" , ( ) => {
116+ const newLabel = textField . getValue ( ) ;
97117 const data = {
98118 newLabel
99119 } ;
100120 this . fireDataEvent ( "labelChanged" , data ) ;
101121 } , this ) ;
102- nodeLabelEditor . add ( save ) ;
103122
104- this . add ( nodeLabelEditor ) ;
123+ this . addListener ( "appear" , ( ) => {
124+ textField . focus ( ) ;
125+ if ( textField . getValue ( ) ) {
126+ textField . setTextSelection ( 0 , textField . getValue ( ) . length ) ;
127+ }
128+ } , this ) ;
129+ } ,
130+
131+ __applyMaxChars : function ( value ) {
132+ this . getChildControl ( "text-field" ) . setMaxLength ( value ) ;
133+
134+ this . __addSubtitle ( this . tr ( "%1 characters max" , value ) ) ;
105135 } ,
106136
107- __addSubtitle : function ( subtitleLabel ) {
108- if ( subtitleLabel ) {
109- const subtitle = new qx . ui . basic . Label ( subtitleLabel ) . set ( {
110- font : "text-12"
111- } ) ;
112- this . add ( subtitle ) ;
137+ __addSubtitle : function ( subtitleText ) {
138+ if ( subtitleText ) {
139+ this . getChildControl ( "subtitle" ) . setValue ( subtitleText ) ;
113140 }
114141 } ,
115142
116143 __attachEventHandlers : function ( ) {
117144 let command = new qx . ui . command . Command ( "Enter" ) ;
118- command . addListener ( "execute" , e => {
119- this . __save . execute ( ) ;
145+ command . addListener ( "execute" , ( ) => {
146+ this . getChildControl ( "save-button" ) . execute ( ) ;
120147 command . dispose ( ) ;
121148 command = null ;
122149 } ) ;
123150
124151 let commandEsc = new qx . ui . command . Command ( "Esc" ) ;
125- commandEsc . addListener ( "execute" , e => {
152+ commandEsc . addListener ( "execute" , ( ) => {
126153 this . close ( ) ;
127154 commandEsc . dispose ( ) ;
128155 commandEsc = null ;
0 commit comments