src/Builder4/WindowState.vala
[app.Builder.js] / src / Builder4 / WindowState.vala
1 /**
2  * as state management is a bit too complicated inside the builder
3  * it's better to seperate this into this class
4  * 
5  * This class has references to all the Class instances that make up the window..
6  * 
7  */
8 public class WindowState : Object 
9 {
10         public Xcls_MainWindow win;
11
12         public enum State {
13                 NONE,
14                 PREVIEW,
15                 OBJECT,
16                 PROP,
17                 LISTENER,
18                 CODE,
19                 CODEONLY,
20                 FILES,
21                 PROJECT // project settings..
22         }
23
24         public State state = State.NONE;
25
26         public bool children_loaded = false;
27
28         
29         
30         public Project.Project project;
31         public JsRender.JsRender file;
32         
33         
34         
35         public Xcls_WindowLeftTree  left_tree;
36         public Xcls_WindowAddProp   add_props;
37         public Xcls_LeftProps       left_props;
38         public Xcls_ProjectSettings projectsettings;
39         public ValaProjectSettings  vala_projectsettings;
40         public Xcls_RightPalete     rightpalete;
41         public Editor               code_editor;    
42         public Xcls_WindowRooView   window_rooview;
43         public Xcls_GtkView         window_gladeview;
44         
45         public Xcls_ClutterFiles     clutterfiles;
46
47         public Xcls_WindowLeftProjects left_projects; // can not see where this is initialized.. 
48         
49         public DialogTemplateSelect template_select; 
50         
51         public Xcls_PopoverFileDetails file_details;
52         
53         
54         public Xcls_ValaCompileResults compile_results;
55         
56         // dialogs??
57         public Xcls_DialogPluginWebkit webkit_plugin;
58         
59         
60         public Palete.ValaSource valasource; // the spawner that runs the vala compiler.
61         public Json.Object last_compile_result;
62         
63         // ctor 
64         public WindowState(Xcls_MainWindow win)
65         {
66                 this.win = win;
67                 // initialize
68
69                 // left elements..
70                 this.leftTreeInit();
71                 this.propsListInit();
72
73                 // on clutter space...
74                 this.projectEditInit();
75                 this.codeEditInit();
76                 this.projectListInit();
77                 this.fileViewInit();
78
79                 // adding stuff
80                 this.objectAddInit();
81                 this.propsAddInit();
82
83
84                 // previews...
85                 this.gtkViewInit();
86                 this.webkitViewInit();
87
88                 // dialogs
89
90                 this.fileDetailsInit();
91
92                 this.webkit_plugin = new Xcls_DialogPluginWebkit();
93                 this.template_select = new DialogTemplateSelect();
94                 this.children_loaded = true;
95                 
96                 this.left_tree.node_selected.connect((sel) => {
97                         this.window_gladeview.sourceview.nodeSelected(sel);
98                 });
99                 this.valasource = new Palete.ValaSource();
100                 this.valasource.compiled.connect(this.valaCompiled);
101                 
102                 this.compile_results = new  Xcls_ValaCompileResults();
103                 this.compile_results.window = this.win;
104         }
105
106
107         // left tree
108
109         public void leftTreeInit()
110         {
111          
112                 this.left_tree = new Xcls_WindowLeftTree();
113                 this.left_tree.ref();
114                 this.left_tree.main_window = this.win;
115         
116                 this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
117                 this.left_tree.el.show_all();
118                    
119                 this.left_tree.before_node_change.connect(() => {
120                         return this.leftTreeBeforeChange();
121
122                 });
123
124                 this.left_tree.node_selected.connect((sel) => {
125                         this.leftTreeNodeSelected(sel);
126                 });
127          
128                 this.left_tree.changed.connect(() => {
129                         
130                         this.file.save();
131                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
132                                    this.window_rooview.requestRedraw();
133                         } else {
134                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
135                         }
136                          
137                 });
138                  
139         }
140
141         public bool leftTreeBeforeChange()
142         {
143                 if (this.state != State.CODE) {
144                         this.left_props.finish_editing();
145                         return true;
146                 }
147                 if (!this.code_editor.saveContents()) {
148                         return false;
149                 }
150                 return false;
151         }
152         
153         public void leftTreeNodeSelected(JsRender.Node? sel)
154         {
155
156                 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
157
158                 if (sel == null) {
159                         this.left_props.el.hide();
160                 } 
161                 this.left_props.el.show();
162                 this.left_props.load(this.left_tree.getActiveFile(), sel);
163                 switch (this.state) {
164                         
165                         case State.OBJECT: 
166                                   
167                                  if (sel == null) {
168                                         this.rightpalete.clear();
169                                         break;
170                                 }
171                                 this.rightpalete.load(this.left_tree.getActiveFile().palete(), sel.fqn());
172                                 break;
173                                  
174                 
175                    case State.PROP:
176                                 if (sel == null) {
177                                         this.add_props.clear();
178                                         break;
179                                 }
180                                 this.add_props.show(this.left_tree.getActiveFile().palete(), "props", sel.fqn());
181                                 break;
182
183                         case State.LISTENER:
184                            
185                                 if (sel == null) {
186                                         this.add_props.clear();
187                                         break;
188                                 }
189                                 this.add_props.show(this.left_tree.getActiveFile().palete(), "signals", sel.fqn());
190                                 break;
191                                 
192                         case State.CODE:
193                                  this.switchState(State.PREVIEW);
194                          
195                                 break;
196                            
197                                                         
198                 }
199                  
200
201         }
202
203
204
205
206         public void propsListInit()
207         {
208         
209                 this.left_props =new Xcls_LeftProps();
210                 this.left_props.ref();
211                 this.left_props.main_window = this.win;
212                 this.win.props.el.pack_start(this.left_props.el,true, true,0);
213                 this.left_props.el.show_all();
214         
215                 this.left_props.show_editor.connect( (file, node, type,  key) => {
216                         this.switchState(State.CODE);
217                         this.code_editor.show(
218                                 file,
219                                 node,
220                                 type,
221                                 key
222                         );
223                         
224                         
225                 });
226
227    
228                 this.left_props.stop_editor.connect( () => {
229                         if (this.state != State.CODE) {
230                                 return true;
231                         }
232         
233                         var ret =  this.code_editor.saveContents();
234                         if (!ret) {
235                                 return false;
236                         }
237                         this.switchState(State.PREVIEW);
238                         return ret;
239                 });
240         
241                 this.left_props.changed.connect(() => {
242                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
243                                    this.window_rooview.requestRedraw();
244                         } else {
245                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
246                         }
247                         this.left_tree.model.updateSelected();
248                         this.file.save();
249                         if (this.file.xtype=="Gtk") {
250                                 this.valasource.checkFileSpawn(this.file);
251                         }
252                 });
253         
254
255
256         }
257
258         //-------------  projects edit
259
260         public void projectEditInit()
261         {
262                 this.projectsettings  =new Xcls_ProjectSettings();
263                 this.projectsettings.ref();  /// really?
264         
265                 this.vala_projectsettings  =new ValaProjectSettings();
266                 this.vala_projectsettings.ref();
267                 this.vala_projectsettings.window = this.win;
268         
269                 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
270                 //this.projectsettings.el.show_all();
271
272                 var stage = this.win.projecteditview.el.get_stage();
273                 stage.set_background_color(  Clutter.Color.from_string("#000"));
274         
275                 this.projectsettings.buttonPressed.connect((btn) => {
276                          if (this.left_tree.getActiveFile().xtype == "Roo" ) {
277                                 if (btn == "save") {
278                                         this.window_rooview.view.renderJS(true);
279                                 }
280                                 if (btn == "apply") {
281                                         this.window_rooview.view.renderJS(true);
282                                         return;
283                                 }
284                         } else {
285                                 // do nothing for gtk..
286                         }
287                         if (btn == "save" || btn == "apply") {
288                                 this.win.project.save();
289                  
290                         }
291                         this.switchState (State.PREVIEW); 
292                          
293                  });
294
295         }
296         // ----------- object adding
297         public void objectAddInit()
298         {
299
300                 this.rightpalete  = new Xcls_RightPalete();
301                 this.rightpalete.ref();  /// really?
302                 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
303                 //this.projectsettings.el.show_all();
304
305                 var stage = this.win.objectview.el.get_stage();
306                 stage.set_background_color(  Clutter.Color.from_string("#000"));
307                    
308         }
309         
310         // -----------  properties adding list...
311         // listener uses the properties 
312         public void propsAddInit()
313         {
314         // Add properties
315                 this.add_props  = new Xcls_WindowAddProp();
316                 this.add_props.ref();  /// really?
317                 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
318                 //this.projectsettings.el.show_all();
319
320                 var  stage = this.win.addpropsview.el.get_stage();
321                 stage.set_background_color(  Clutter.Color.from_string("#000"));
322
323
324                 this.add_props.select.connect( (key,type,skel, etype) => {
325                         this.left_props.addProp(etype, key, skel, type);
326                 });
327
328         }
329         public void propsAddShow()
330         {
331
332         }
333         public void propsAddHide()
334         {
335         
336         }
337
338
339
340         
341         // ----------- Add / Edit listener
342         // listener uses the properties 
343         //public void listenerInit()     { }
344         public void listenerShow()
345         {
346
347         }
348         public void listenerHide()
349         {
350         
351         }
352
353         // -------------- codeEditor
354
355         public void codeEditInit()
356         {
357                 this.code_editor  = new  Editor();
358                 //this.code_editor.ref();  /// really?
359                 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
360                 
361                 this.code_editor.window = this.win;
362                 //this.projectsettings.el.show_all();
363
364                 var stage = this.win.codeeditview.el.get_stage();
365                 stage.set_background_color(  Clutter.Color.from_string("#000"));
366                 // editor.save...
367
368                 this.code_editor.save.connect( () => {
369                         this.file.save();
370                         this.left_tree.model.updateSelected();
371                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
372                                    this.window_rooview.requestRedraw();
373                         } else {
374                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
375                         }
376                          // we do not need to call spawn... - as it's already called by the editor?
377                          
378                 });
379                 
380         }
381
382         // ----------- list of projects on left
383         public void  projectListInit() 
384         {
385
386                 this.left_projects = new Xcls_WindowLeftProjects();
387                  this.left_projects.ref();
388                  this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
389                  this.left_projects.el.show_all();
390                  this.left_projects.project_selected.connect((proj) => {
391                         this.buttonsShowHide();
392                         proj.scanDirs();
393                         this.clutterfiles.loadProject(proj);
394                 
395                  });
396
397         }
398         // ----------- file view
399
400         public void fileViewInit()
401         {
402                 var stage = this.win.rooview.el.get_stage(); // seems odd... 
403                 this.clutterfiles = new Xcls_ClutterFiles();
404                 this.clutterfiles.ref();
405                 stage.add_child(this.clutterfiles.el);
406                 this.clutterfiles.el.show();
407
408
409                 this.clutterfiles.open.connect((file) => { 
410                         this.fileViewOpen(file);
411                 });
412                 this.clutterfiles.el.transitions_completed.connect(() => {
413                         if (this.state == State.FILES) {
414                                 this.win.rooview.el.hide();
415                         } else {
416                                 this.clutterfiles.el.hide();
417                         }
418                         
419                         
420                 });
421
422         }
423  
424         public void fileDetailsInit()
425         {
426                 this.file_details = new Xcls_PopoverFileDetails();
427                 this.file_details.mainwindow = this.win;
428                 // force it modal to the main window..
429                 
430                 this.file_details.success.connect((project,file) =>
431                 {
432                         this.fileViewOpen(file);
433                 });
434
435         }
436         
437         public void fileViewOpen(JsRender.JsRender file)
438         {
439                 this.win.project = file.project;
440                 this.project = project;
441                 this.file = file;
442                 
443                 
444                 if (file.xtype == "PlainFile") {
445                         this.switchState (State.CODEONLY); 
446                         file.loadItems();
447                         this.code_editor.show(file, null, "", "");
448                 } else {
449                 
450                         this.switchState (State.PREVIEW); 
451                         // this triggers loadItems..
452                         this.left_tree.model.loadFile(file);
453
454                 }
455         
456         
457                 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
458                 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
459         
460                 if (file.project.xtype == "Roo" ) { 
461                         ctr.foreach( (w) => { ctr.remove(w); });
462                         ctr_p.foreach( (w) => { ctr_p.remove(w); });
463                         ctr.add(this.window_rooview.el);
464                         ctr_p.add(this.projectsettings.el);
465                         if (file.xtype != "PlainFile") {       
466                                 this.window_rooview.loadFile(file);
467                                 this.window_rooview.el.show_all();
468                         }
469                         this.projectsettings.el.show_all();            
470                         
471
472                 } else {
473                         ctr.foreach( (w) => { ctr.remove(w); });
474                         ctr_p.foreach( (w) => { ctr_p.remove(w); });            
475                         ctr.add(this.window_gladeview.el);
476                         ctr_p.add(this.vala_projectsettings.el);
477                         if (file.xtype != "PlainFile") {    
478                                 this.window_gladeview.loadFile(file);
479                                 this.window_gladeview.el.show_all();
480                         }
481                         this.vala_projectsettings.el.show_all();
482                 }
483                 print("OPEN : " + file.name);
484                 if (file.xtype != "PlainFile") {    
485                         this.win.editpane.el.set_position(this.win.editpane.el.max_position);
486                 }
487                 this.win.setTitle(file.project.name + " : " + file.name);
488                          
489
490         }
491          
492         
493         // ---------  webkit view
494         public void webkitViewInit()
495         {
496                 this.window_rooview  =new Xcls_WindowRooView();
497                 this.window_rooview.ref();
498                 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
499                 this.window_rooview.el.show_all();
500
501                 var stage = this.win.rooview.el.get_stage();
502                 stage.set_background_color(  Clutter.Color.from_string("#000"));
503         }
504
505         // ------ Gtk  - view
506
507         public void gtkViewInit()
508         {
509                 this.window_gladeview  =new Xcls_GtkView();
510                 this.window_gladeview.ref();
511                 this.window_gladeview.main_window = this.win;
512         }
513         
514         public void easingSaveAll()
515         {
516                 this.win.addpropsview.el.save_easing_state();
517                 this.win.codeeditview.el.save_easing_state();
518                 this.win.objectview.el.save_easing_state();
519                 this.win.projecteditview.el.save_easing_state();
520                 this.win.rooview.el.save_easing_state();
521                 this.clutterfiles.el.save_easing_state();
522                  
523         }
524         public void easingRestoreAll()
525         {
526                 this.win.addpropsview.el.restore_easing_state();
527                 this.win.codeeditview.el.restore_easing_state();
528                 this.win.objectview.el.restore_easing_state();
529                 this.win.projecteditview.el.restore_easing_state();
530                 this.win.rooview.el.restore_easing_state();
531                 this.clutterfiles.el.restore_easing_state();
532                 
533         }
534         public void switchState(State new_state)
535         {
536                 
537                 // if the new state and the old state are the same..
538                 
539                 if (new_state == this.state) {
540                         return;
541                 }
542                 
543                 // save the easing state of everything..
544                 this.easingSaveAll();
545                 
546                 switch (this.state) {
547
548                         case State.PREVIEW:
549                                 if (this.left_tree.getActiveFile() != null) {
550                                          if (this.left_tree.getActiveFile().xtype == "Roo" ) {
551                                                  this.window_rooview.createThumb();
552                                          } else {
553                                                   this.window_gladeview.createThumb();
554                                           }
555                                 }
556                                 // normally we are going from preview to another state.
557                                 // and different windows hide the preview in differnt ways..
558                                 
559                                 break;
560                         
561                    case State.LISTENER:
562                    case State.PROP:
563                                 
564                                 this.win.addpropsview.el.set_scale(0.0f,0.0f);
565                                  break;
566                                 
567                         case State.CODE:
568                                 this.code_editor.saveContents();
569                           
570                                 this.win.codeeditview.el.set_scale(0.0f,0.0f);
571                                 break;
572                                 
573                         case State.CODEONLY:
574                                 // going from codeonly..
575                                 this.win.leftpane.el.show();
576                                 // enable re-calc of canvas..
577                             while (Gtk.events_pending()) { 
578                                         Gtk.main_iteration();
579                                 }
580                                 //this.code_editor.saveContents(); << not yet...
581                                  
582                                 this.win.rooview.el.show(); 
583                                 this.win.codeeditview.el.set_scale(0.0f,0.0f);
584                                  
585                                 break;
586
587                          case State.OBJECT:
588                            
589                                 this.win.objectview.el.set_scale(0.0f,0.0f);
590                                  break;
591
592                    case State.PROJECT:
593                                 if (this.win.project.xtype == "Gtk") {
594                                         this.vala_projectsettings.save();
595                                 } 
596                                 
597                                 this.win.projecteditview.el.set_scale(0.0f,0.0f);
598                                  break;
599
600                   case State.FILES: // goes to preview or codeonly...
601                                 // hide files...
602                                 
603                                 if (new_state == State.CODEONLY) {
604                                         this.win.rooview.el.hide();
605                                 } else {
606                                         this.win.rooview.el.show();
607                                 }
608                                 
609                                 this.win.rooview.el.set_easing_duration(1000);
610                                 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
611                                 this.win.rooview.el.set_scale(1.0f,1.0f);
612                                 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
613                                 this.win.rooview.el.set_opacity(0xff);
614                                 
615                                 
616                            
617                                 this.clutterfiles.el.set_easing_duration(1000);
618                                 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
619                                 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
620                                 this.clutterfiles.el.set_opacity(0);
621  
622                                 //this.clutterfiles.el.hide();
623                                  
624
625                                 break;
626
627                                 
628                 }
629            
630                 var oldstate  =this.state;
631                 this.state = new_state;
632                 
633                 
634                                 
635                 this.buttonsShowHide();
636                 
637                 
638                 switch (this.state) {
639                         
640                         case State.PREVIEW:  // this is the default state when working...
641                                  this.win.editpane.el.show(); // holder for tree and properties..
642                                  
643                          
644                                  this.left_projects.el.hide(); 
645                                  if (oldstate != State.FILES) {
646                                         // it's handled above..
647                                         print ("changing state to preview from NOT files..");
648                                          
649  
650                                         this.win.rooview.el.set_scale(1.0f,1.0f);
651                                  }
652                            
653                                 break;
654
655
656                         case State.LISTENER:
657                 // same as prop?
658                         case State.PROP:
659                                 var ae =      this.left_tree.getActiveElement();
660                                 if (ae == null) {
661                                         this.state = oldstate;
662                                         this.buttonsShowHide();
663                                         this.resizeCanvasElements();
664                                         this.easingRestoreAll();
665                                         return;
666                                 }
667                                 this.add_props.el.show_all();
668                                 this.add_props.show(
669                                         Palete.factory(this.win.project.xtype), 
670                                         this.state == State.LISTENER ? "signals" : "props",
671                                         ae.fqn()
672                                 );
673  
674                                         
675  
676                                 
677                                 // -- FIXME? this needs to be State aware?
678                  
679                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
680                                   
681                                 this.win.addpropsview.el.set_scale(1.0f,1.0f);
682                                 break;
683                    
684                         case State.OBJECT:
685                                  var n = this.left_tree.getActiveElement();
686
687                                 if (this.file == null) {
688                                         this.state =oldstate;
689                                         this.buttonsShowHide();
690                                         this.resizeCanvasElements();
691                                         this.easingRestoreAll();
692                                         return;
693                                 }
694                                 
695                                 if (n == null && this.file.tree != null) {
696                                         this.state = oldstate;
697                                         this.buttonsShowHide();
698                                         this.resizeCanvasElements();
699                                         this.easingRestoreAll();
700                                         return;
701                                 }
702
703                                 this.rightpalete.el.show_all();
704                                 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
705
706                                 
707                           
708                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
709                                 this.win.objectview.el.set_scale(1.0f,1.0f);
710                                  
711                                 break;
712                    
713                    
714                         case State.CODE:
715                                 this.win.codeeditview.el.show();
716                                 this.code_editor.el.show_all();
717                                 // caller needs to call editor - show....
718                                 this.win.codeeditview.el.set_scale(1.0f,1.0f);
719                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
720
721                                 break;
722
723                         case State.CODEONLY:
724                                 // going to codeonly..
725                                 this.win.codeeditview.el.show();
726                                 // recalc canvas...
727                                 //while (Gtk.events_pending()) { 
728                                 //      Gtk.main_iteration();
729                                 //}
730                                 
731                                 this.win.leftpane.el.hide();
732                                 this.win.codeeditview.el.show();
733                                 //while (Gtk.events_pending()) { 
734                                 //      Gtk.main_iteration();
735                                 //}
736                                 
737                                 
738                                 this.code_editor.el.show_all();
739                             
740                                 this.win.codeeditview.el.set_scale(1.0f,1.0f);
741                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
742                                 break;
743
744                    case State.PROJECT:
745
746                            if (this.win.project.xtype == "Roo") {
747                                         this.projectsettings.el.show_all();
748                                         this.projectsettings.show(this.win.project);
749                                 } else {
750                                         this.vala_projectsettings.el.show_all();
751                                         this.vala_projectsettings.show((Project.Gtk)this.win.project);
752                                 }
753
754                                 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
755                                 
756                                 this.win.projecteditview.el.set_scale(1.0f,1.0f);
757                                 
758                            
759                                 break;
760                                 
761                    case State.FILES:  // can only get here from PREVIEW (or code-only) state.. in theory..
762                                 
763    
764                                 this.win.editpane.el.hide(); // holder for tree and properties..
765                                 
766                                 this.left_projects.el.show(); 
767                                 
768                                 // rotate the preview to hidden...
769                                 this.win.rooview.el.set_easing_duration(1000);
770                                 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
771                                 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
772                                 this.win.rooview.el.set_opacity(0);
773                          
774                                 
775                                 
776          
777                                 if (this.win.project != null) {
778                                         this.left_projects.selectProject(this.win.project);
779                                 }
780                          
781                                 
782                                 this.clutterfiles.el.show();
783                                  
784                                 this.clutterfiles.el.set_easing_duration(1000);
785                                 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
786                                 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
787                                 this.clutterfiles.el.set_opacity(0xff);
788                                 
789                                  
790                                 
791                                 break;
792
793
794                 }
795                 this.resizeCanvasElements();
796                 this.easingRestoreAll();
797                 
798                 // run the animation.. - then load files...
799                 
800                         
801         }
802         
803         public int redraw_count = 0;
804         public void resizeCanvas() // called by window resize .. delays redraw
805         {
806                 var rc = this.redraw_count;        
807                 this.redraw_count = 2;
808                 if (rc == 0) {
809                         GLib.Timeout.add(100,  ()  =>{
810                                  return this.resizeCanvasQueue();
811                         });
812                 }
813         }
814         public bool  resizeCanvasQueue()
815         {
816                 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);        
817
818                 if (this.redraw_count < 1) {
819                         return false; // should not really happen...
820                 }
821
822
823                 this.redraw_count--;
824
825                 if (this.redraw_count > 0) {
826                         return true; // do it again in 1 second...
827                 }
828                 // got down to 0 or -1....
829                 this.redraw_count = 0;
830                 this.resizeCanvasElements();
831                 return false;
832
833         }
834         public void resizeCanvasElements()
835         {
836                 Gtk.Allocation alloc;
837                 this.win.clutterembed.el.get_allocation(out alloc);
838
839            // print("WindowState.resizeCanvasElements\n");
840                 if (!this.children_loaded || this.win.clutterembed == null) {
841                         print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
842                         return; 
843                 }
844                 
845                 var avail = alloc.width < 50.0f ? 0 :  alloc.width - 50.0f;
846                 var palsize = avail < 300.0f ? avail : 300.0f;
847                    
848  
849                 // -------- code edit min 600
850                 
851                 var codesize = avail < 800.0f ? avail : 800.0f;
852                 
853                 
854                 //print("set code size %f\n", codesize);
855
856                         
857                 
858                 switch ( this.state) {
859                         case State.PREVIEW:
860                                  
861                                 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
862                                 break;
863         
864                         case State.FILES: 
865                                 this.clutterfiles.set_size(alloc.width-50, alloc.height);
866                                 break;
867
868                         case State.PROJECT:
869                  
870                                 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
871                 
872                            // this.win.rooview.el.save_easing_state();
873                                 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
874                                  
875                                 this.win.rooview.el.set_scale(0.5f, 0.5f);
876                                 //this.win.rooview.el.restore_easing_state();
877                                 break;
878
879                         case State.CODE: 
880                                 this.win.codeeditview.el.set_size(codesize, alloc.height);
881                                 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
882                                 //this.win.rooview.el.save_easing_state();
883                                  
884                                 this.win.rooview.el.set_scale(scale,scale);
885                            // this.win.rooview.el.restore_easing_state();
886                                 break;
887                                 
888                         case State.CODEONLY: 
889                                 this.win.codeeditview.el.set_size(codesize, alloc.height);
890                                 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
891                                 //this.win.rooview.el.save_easing_state();
892                                 this.win.rooview.el.hide(); 
893                                 this.win.rooview.el.set_scale(scale,scale);
894                            // this.win.rooview.el.restore_easing_state();
895                                 break;  
896                         case State.PROP:
897                         case State.LISTENER:
898                                  this.win.addpropsview.el.set_size(palsize, alloc.height);
899                                 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
900                                 this.win.rooview.el.set_scale(scale,scale);
901                                 break;
902                                 
903                         case State.OBJECT:  
904                                 this.win.objectview.el.set_size(palsize, alloc.height);    
905                                 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
906                                 //this.win.rooview.el.save_easing_state();
907                                 this.win.rooview.el.set_scale(scale,scale);
908                            // this.win.rooview.el.restore_easing_state();
909                                 break;
910                 }
911         }
912
913         // -- buttons show hide.....
914
915         public void buttonsShowHide()
916         {
917                 // basically hide everything, then show the relivant..
918
919                  this.win.backbutton.el.hide();
920         
921                 this.win.projectbutton.el.hide(); // show file nav...
922                 this.win.editfilebutton.el.hide();
923                 this.win.projecteditbutton.el.hide();
924                  
925                 
926                 this.win.objectshowbutton.el.hide(); // add objects
927                 this.win.addpropbutton.el.hide();  
928                 this.win.addlistenerbutton.el.hide(); 
929
930         
931         
932                 this.win.addprojectbutton.el.hide();
933                 this.win.addfilebutton.el.hide();
934                 this.win.delprojectbutton.el.hide();
935                   
936                 
937                 switch (this.state) {
938                         
939                         case State.PREVIEW:  // this is the default state when working...
940                            
941                                 this.win.projectbutton.el.show(); // show file nav...
942                                 this.win.editfilebutton.el.show();
943                                 this.win.projecteditbutton.el.show();
944                                  
945                                 
946                                 this.win.objectshowbutton.el.show(); // add objects
947                                 this.win.addpropbutton.el.show();  
948                                 this.win.addlistenerbutton.el.show(); 
949                                 break;
950                         
951                         case State.CODEONLY: 
952                                 this.win.projectbutton.el.show();
953                                 break;
954                    
955                         case State.CODE: 
956                         case State.PROP:
957                         case State.LISTENER:
958                         case State.OBJECT:
959                                 
960                                 this.win.backbutton.el.show();
961                                 this.win.objectshowbutton.el.show(); // add objects
962                                 this.win.addpropbutton.el.show();  
963                                 this.win.addlistenerbutton.el.show(); 
964                                 break;
965                         
966                         case State.PROJECT: 
967                                 // anything else?
968                                 this.win.backbutton.el.show();
969                                 break;
970                         
971         
972                         case State.FILES:
973                                 if (this.left_projects.getSelectedProject() != null ) {
974                                         if (this.left_tree.getActiveFile() != null) {
975                                                 this.win.backbutton.el.show();
976                                         }
977                                         this.win.addfilebutton.el.show();
978                                 }
979                                          
980                                 this.win.addprojectbutton.el.show();
981                                 this.win.delprojectbutton.el.show();
982                                 
983                                 break;
984                 }
985                 
986                 
987
988         }
989         
990         
991         public void valaCompiled(Json.Object obj)
992                 {
993                         // vala has finished compiling...
994                         print("vala compiled");
995                         
996                         var buf = this.code_editor.buffer;
997                         buf.check_running = false;
998                                       
999                         if (obj.has_member("ERR-TOTAL")) {
1000                                  this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
1001                         } else {
1002                                  this.win.statusbar_errors.setNotices( new Json.Object() , 0);
1003                         }    
1004                         
1005                         if (obj.has_member("WARN-TOTAL")) {
1006
1007                                  this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
1008                         } else {
1009                                  this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
1010                                  
1011                         }
1012                         if (obj.has_member("DEPR-TOTAL")) {
1013                                 
1014                                  this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"),  (int) obj.get_int_member("DEPR-TOTAL"));
1015                                  
1016                         } else {
1017                                 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
1018                         }
1019                         
1020                         buf.highlightErrorsJson("ERR", obj);
1021                         buf.highlightErrorsJson("WARN", obj);
1022                         buf.highlightErrorsJson("DEPR", obj);
1023                         
1024                         if (this.file.xtype == "Gtk") {
1025                                 var gbuf =   this.window_gladeview.sourceview;
1026                                 gbuf.highlightErrorsJson("ERR", obj);
1027                                 gbuf.highlightErrorsJson("WARN", obj);
1028                                 gbuf.highlightErrorsJson("DEPR", obj);                  
1029                         
1030                    }
1031                         this.last_compile_result = obj;
1032                         
1033                         
1034                 }
1035         
1036 }
1037
1038