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