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                           this.valasource.spawnFile(this.left_tree.model.file);
235                 });
236         
237
238
239         }
240
241         //-------------  projects edit
242
243         public void projectEditInit()
244         {
245                 this.projectsettings  =new Xcls_ProjectSettings();
246                 this.projectsettings.ref();  /// really?
247         
248                 this.vala_projectsettings  =new ValaProjectSettings();
249                 this.vala_projectsettings.ref();
250                 this.vala_projectsettings.window = this.win;
251         
252                 ((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
253                 //this.projectsettings.el.show_all();
254
255                 var stage = this.win.projecteditview.el.get_stage();
256                 stage.set_background_color(  Clutter.Color.from_string("#000"));
257         
258                 this.projectsettings.buttonPressed.connect((btn) => {
259                          if (this.left_tree.getActiveFile().xtype == "Roo" ) {
260                                 if (btn == "save") {
261                                         this.window_rooview.view.renderJS(true);
262                                 }
263                                 if (btn == "apply") {
264                                         this.window_rooview.view.renderJS(true);
265                                         return;
266                                 }
267                         } else {
268                                 // do nothing for gtk..
269                         }
270                         if (btn == "save" || btn == "apply") {
271                                 this.win.project.save();
272                  
273                         }
274                         this.switchState (State.PREVIEW); 
275                          
276                  });
277
278         }
279         // ----------- object adding
280         public void objectAddInit()
281         {
282
283                 this.rightpalete  = new Xcls_RightPalete();
284                 this.rightpalete.ref();  /// really?
285                 ((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
286                 //this.projectsettings.el.show_all();
287
288                 var stage = this.win.objectview.el.get_stage();
289                 stage.set_background_color(  Clutter.Color.from_string("#000"));
290                    
291         }
292         
293         // -----------  properties adding list...
294         // listener uses the properties 
295         public void propsAddInit()
296         {
297         // Add properties
298                 this.add_props  = new Xcls_WindowAddProp();
299                 this.add_props.ref();  /// really?
300                 ((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
301                 //this.projectsettings.el.show_all();
302
303                 var  stage = this.win.addpropsview.el.get_stage();
304                 stage.set_background_color(  Clutter.Color.from_string("#000"));
305
306
307                 this.add_props.select.connect( (key,type,skel, etype) => {
308                         this.left_props.addProp(etype, key, skel, type);
309                 });
310
311         }
312         public void propsAddShow()
313         {
314
315         }
316         public void propsAddHide()
317         {
318         
319         }
320
321
322
323         
324         // ----------- Add / Edit listener
325         // listener uses the properties 
326         //public void listenerInit()     { }
327         public void listenerShow()
328         {
329
330         }
331         public void listenerHide()
332         {
333         
334         }
335
336         // -------------- codeEditor
337
338         public void codeEditInit()
339         {
340                 this.code_editor  = new  Editor();
341                 //this.code_editor.ref();  /// really?
342                 ((Gtk.Container)(this.win.codeeditview.el.get_widget())).add(this.code_editor.el);
343                 
344                 this.code_editor.window = this.win;
345                 //this.projectsettings.el.show_all();
346
347                 var stage = this.win.codeeditview.el.get_stage();
348                 stage.set_background_color(  Clutter.Color.from_string("#000"));
349                 // editor.save...
350
351                 this.code_editor.save.connect( () => {
352                          this.left_tree.model.file.save();
353                          this.left_tree.model.updateSelected();
354                          // we do not need to call spawn... - as it's already called by the editor?
355                          
356                 });
357                 
358         }
359
360         // ----------- list of projects on left
361         public void  projectListInit() 
362         {
363
364                 this.left_projects = new Xcls_WindowLeftProjects();
365                  this.left_projects.ref();
366                  this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
367                  this.left_projects.el.show_all();
368                  this.left_projects.project_selected.connect((proj) => {
369                         this.buttonsShowHide();
370                         proj.scanDirs();
371                         this.clutterfiles.loadProject(proj);
372                 
373                  });
374
375         }
376         // ----------- file view
377
378         public void fileViewInit()
379         {
380                 var stage = this.win.rooview.el.get_stage(); // seems odd... 
381                 this.clutterfiles = new Xcls_ClutterFiles();
382                 this.clutterfiles.ref();
383                 stage.add_child(this.clutterfiles.el);
384                 this.clutterfiles.el.show_all();
385
386
387                 this.clutterfiles.open.connect((file) => { 
388                         this.fileViewOpen(file);
389                 });
390                 this.clutterfiles.el.transitions_completed.connect(() => {
391                         if (this.state == State.FILES) {
392                                 this.win.rooview.el.hide();
393                         } else {
394                                 this.clutterfiles.el.hide();
395                         }
396                         
397                         
398                 });
399
400         }
401  
402         public void fileDetailsInit()
403         {
404                 this.file_details = new Xcls_PopoverFileDetails();
405                 this.file_details.mainwindow = this.win;
406                 // force it modal to the main window..
407                 
408                 this.file_details.success.connect((project,file) =>
409                 {
410                         this.fileViewOpen(file);
411                 });
412
413         }
414         
415         public void fileViewOpen(JsRender.JsRender file)
416         {
417                 this.win.project = file.project;
418                 this.switchState (State.PREVIEW); 
419         
420                 this.left_tree.model.loadFile(file);
421         
422                 var ctr= ((Gtk.Container)(this.win.rooview.el.get_widget()));
423                 var ctr_p= ((Gtk.Container)(this.win.projecteditview.el.get_widget()));
424         
425                 if (file.xtype == "Roo" ) { 
426                         ctr.foreach( (w) => { ctr.remove(w); });
427                         ctr_p.foreach( (w) => { ctr_p.remove(w); });
428                         ctr.add(this.window_rooview.el);
429                         ctr_p.add(this.projectsettings.el);            
430                         this.window_rooview.loadFile(file);
431                         this.window_rooview.el.show_all();
432                         this.projectsettings.el.show_all();            
433
434                 } else {
435                         ctr.foreach( (w) => { ctr.remove(w); });
436                         ctr_p.foreach( (w) => { ctr_p.remove(w); });            
437                         ctr.add(this.window_gladeview.el);
438                         ctr_p.add(this.vala_projectsettings.el);
439                         this.window_gladeview.loadFile(file);
440                         this.window_gladeview.el.show_all();
441                         this.vala_projectsettings.el.show_all();
442                 }
443                 print("OPEN : " + file.name);
444                 this.win.editpane.el.set_position(this.win.editpane.el.max_position);
445                 this.win.setTitle(file.project.name + " : " +file.name);
446                          
447
448                 }
449
450         
451         // ---------  webkit view
452         public void webkitViewInit()
453         {
454                 this.window_rooview  =new Xcls_WindowRooView();
455                 this.window_rooview.ref();
456                 ((Gtk.Container)(this.win.rooview.el.get_widget())).add(this.window_rooview.el);
457                 this.window_rooview.el.show_all();
458
459                 var stage = this.win.rooview.el.get_stage();
460                 stage.set_background_color(  Clutter.Color.from_string("#000"));
461         }
462
463         // ------ Gtk  - view
464
465         public void gtkViewInit()
466         {
467                 this.window_gladeview  =new Xcls_GtkView();
468                 this.window_gladeview.ref();
469                 this.window_gladeview.main_window = this.win;
470         }
471         
472         public void easingSaveAll()
473         {
474                 this.win.addpropsview.el.save_easing_state();
475                 this.win.codeeditview.el.save_easing_state();
476                 this.win.objectview.el.save_easing_state();
477                 this.win.projecteditview.el.save_easing_state();
478                 this.win.rooview.el.save_easing_state();
479                 this.clutterfiles.el.save_easing_state();
480                  
481         }
482         public void easingRestoreAll()
483         {
484                 this.win.addpropsview.el.restore_easing_state();
485                 this.win.codeeditview.el.restore_easing_state();
486                 this.win.objectview.el.restore_easing_state();
487                 this.win.projecteditview.el.restore_easing_state();
488                 this.win.rooview.el.restore_easing_state();
489                 this.clutterfiles.el.restore_easing_state();
490                 
491         }
492         public void switchState(State new_state)
493         {
494                 
495                 // save the easing state of everything..
496                 this.easingSaveAll();
497                 
498                 switch (this.state) {
499
500                         case State.PREVIEW:
501                                 if (this.left_tree.getActiveFile() != null) {
502                                          if (this.left_tree.getActiveFile().xtype == "Roo" ) {
503                                                  this.window_rooview.createThumb();
504                                          } else {
505                                                   this.window_gladeview.createThumb();
506                                           }
507                                 }
508                                 // normally we are going from preview to another state.
509                                 // and different windows hide the preview in differnt ways..
510                                 
511                                 break;
512                         
513                    case State.LISTENER:
514                    case State.PROP:
515                                 
516                                 this.win.addpropsview.el.set_scale(0.0f,0.0f);
517                                  break;
518                                 
519                         case State.CODE:
520
521
522                                 this.code_editor.saveContents();
523                           
524                                 this.win.codeeditview.el.set_scale(0.0f,0.0f);
525                                  break;
526
527
528                          case State.OBJECT:
529                            
530                                 this.win.objectview.el.set_scale(0.0f,0.0f);
531                                  break;
532
533                    case State.PROJECT:
534                                 if (this.win.project.xtype == "Gtk") {
535                                         this.vala_projectsettings.save();
536                                 } 
537                                 
538                                 this.win.projecteditview.el.set_scale(0.0f,0.0f);
539                                  break;
540
541                   case State.FILES:
542                                 // hide files...
543                                 
544                                 this.win.rooview.el.show_all();
545                                 this.win.rooview.el.set_easing_duration(1000);
546                                 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
547                                 this.win.rooview.el.set_scale(1.0f,1.0f);
548                                 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
549                                 this.win.rooview.el.set_opacity(0xff);
550                            
551                                 
552                            
553                                  this.clutterfiles.el.set_easing_duration(1000);
554                                 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
555                                 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, -180.0f);
556                                 this.clutterfiles.el.set_opacity(0);
557  
558                                 //this.clutterfiles.el.hide();
559                                  
560
561                                 break;
562
563                                 
564                 }
565            
566                 var oldstate  =this.state;
567                 this.state = new_state;
568                 
569                 
570                                 
571                 this.buttonsShowHide();
572                 
573                 
574                 switch (this.state) {
575                         
576                         case State.PREVIEW:  // this is the default state when working...
577                                  this.win.editpane.el.show(); // holder for tree and properties..
578                                  
579                          
580                                  this.left_projects.el.hide(); 
581                                  if (oldstate != State.FILES) {
582                                         // it's handled above..
583                                         print ("changing state to preview from NOT files..");
584                                          
585  
586                                         this.win.rooview.el.set_scale(1.0f,1.0f);
587                                  }
588                            
589                                 break;
590
591
592                         case State.LISTENER:
593                 // same as prop?
594                         case State.PROP:
595                                 var ae =      this.left_tree.getActiveElement();
596                                 if (ae == null) {
597                                         this.state = oldstate;
598                                         this.buttonsShowHide();
599                                         this.resizeCanvasElements();
600                                         this.easingRestoreAll();
601                                         return;
602                                 }
603                                 this.add_props.el.show_all();
604                                 this.add_props.show(
605                                         Palete.factory(this.win.project.xtype), 
606                                         this.state == State.LISTENER ? "signals" : "props",
607                                         ae.fqn()
608                                 );
609  
610                                         
611  
612                                 
613                                 // -- FIXME? this needs to be State aware?
614                  
615                                 this.win.rooview.el.set_pivot_point(1.0f,0.5f);
616                                   
617                                 this.win.addpropsview.el.set_scale(1.0f,1.0f);
618                                  break;
619                    
620                         case State.OBJECT:
621                                  var n = this.left_tree.getActiveElement();
622
623                                 if (this.left_tree.model.file == null) {
624                                         this.state =oldstate;
625                                         this.buttonsShowHide();
626                                         this.resizeCanvasElements();
627                                         this.easingRestoreAll();
628                                         return;
629                                 }
630                                 
631                                 if (n == null && this.left_tree.model.file.tree != null) {
632                                         this.state = oldstate;
633                                         this.buttonsShowHide();
634                                         this.resizeCanvasElements();
635                                         this.easingRestoreAll();
636                                         return;
637                                 }
638
639                                 this.rightpalete.el.show_all();
640                                 this.rightpalete.load(this.left_tree.getActiveFile().palete(), n == null ? "*top" : n.fqn());
641
642                                 
643                           
644                         
645                                 this.win.objectview.el.set_scale(1.0f,1.0f);
646                                  
647                                 break;
648                    
649                    
650                         case State.CODE:
651
652                                 this.code_editor.el.show_all();
653                                 
654                                 // caller needs to call editor - show....
655                                   
656  
657                                  this.win.codeeditview.el.set_scale(1.0f,1.0f);
658                                  break;
659
660
661
662                    case State.PROJECT:
663
664                            if (this.win.project.xtype == "Roo") {
665                                         this.projectsettings.el.show_all();
666                                         this.projectsettings.show(this.win.project);
667                                 } else {
668                                         this.vala_projectsettings.el.show_all();
669                                         this.vala_projectsettings.show((Project.Gtk)this.win.project);
670                                 }
671
672                                 this.win.rooview.el.set_pivot_point(1.0f,1.0f); // bottom right..
673                                 
674                                 this.win.projecteditview.el.set_scale(1.0f,1.0f);
675                                 
676                            
677                                 break;
678                                 
679                    case State.FILES:  // can only get here from PREVIEW state.. in theory..
680                                 
681    
682                                 this.win.editpane.el.hide(); // holder for tree and properties..
683                          
684                                 this.left_projects.el.show(); 
685                         
686                                  this.win.rooview.el.set_easing_duration(1000);
687                                 this.win.rooview.el.set_pivot_point(0.5f,0.5f);
688                                 this.win.rooview.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 180.0f);
689                                 this.win.rooview.el.set_opacity(0);
690                                 //el.set_scale(0.0f,0.0f);
691
692  
693                                 if (this.win.project != null) {
694                                         this.left_projects.selectProject(this.win.project);
695                                 }
696                          
697                                 
698                                 this.clutterfiles.el.show_all();
699                                  
700                                 this.clutterfiles.el.set_easing_duration(1000);
701                                 this.clutterfiles.el.set_pivot_point(0.5f,0.5f);
702                                 this.clutterfiles.el.set_rotation_angle(Clutter.RotateAxis.Y_AXIS, 0.0f);
703                                 this.clutterfiles.el.set_opacity(0xff);
704                                 
705                                 
706                                 
707                                 break;
708
709
710                 }
711                 this.resizeCanvasElements();
712                 this.easingRestoreAll();
713                 
714                         
715         }
716         
717         public int redraw_count = 0;
718         public void resizeCanvas() // called by window resize .. delays redraw
719         {
720                 var rc = this.redraw_count;        
721                 this.redraw_count = 2;
722                 if (rc == 0) {
723                         GLib.Timeout.add(100,  ()  =>{
724                                  return this.resizeCanvasQueue();
725                         });
726                 }
727         }
728         public bool  resizeCanvasQueue()
729         {
730                 //print("WindowState.resizeCanvasQueue %d\n", this.redraw_count);        
731
732                 if (this.redraw_count < 1) {
733                         return false; // should not really happen...
734                 }
735
736
737                 this.redraw_count--;
738
739                 if (this.redraw_count > 0) {
740                         return true; // do it again in 1 second...
741                 }
742                 // got down to 0 or -1....
743                 this.redraw_count = 0;
744                 this.resizeCanvasElements();
745                 return false;
746
747         }
748         public void resizeCanvasElements()
749         {
750                 Gtk.Allocation alloc;
751                 this.win.clutterembed.el.get_allocation(out alloc);
752
753            // print("WindowState.resizeCanvasElements\n");
754                 if (!this.children_loaded || this.win.clutterembed == null) {
755                         print("WindowState.resizeCanvasElements = ingnore not loaded or no clutterfiles\n");
756                         return; 
757                 }
758                 
759                 var avail = alloc.width < 50.0f ? 0 :  alloc.width - 50.0f;
760                 var palsize = avail < 300.0f ? avail : 300.0f;
761                    
762  
763                 // -------- code edit min 600
764                 
765                 var codesize = avail < 800.0f ? avail : 800.0f;
766                 
767                 
768                 //print("set code size %f\n", codesize);
769
770                         
771                 
772                 switch ( this.state) {
773                         case State.PREVIEW:
774                                 this.win.rooview.el.set_size(alloc.width-50, alloc.height);
775                                 break;
776         
777                         case State.FILES: 
778                                 this.clutterfiles.set_size(alloc.width-50, alloc.height);
779                                 break;
780
781                         case State.PROJECT:
782                  
783                                 this.win.projecteditview.el.set_size(alloc.width-50, alloc.height / 2.0f);
784                 
785                            // this.win.rooview.el.save_easing_state();
786                                 //this.win.rooview.el.set_size(alloc.width / 2.0f, alloc.height / 2.0f);
787                                 this.win.rooview.el.set_scale(0.5f, 0.5f);
788                                 //this.win.rooview.el.restore_easing_state();
789                                 break;
790
791                         case State.CODE: 
792                                 this.win.codeeditview.el.set_size(codesize, alloc.height);
793                                 var scale = avail > 0.0f ? (avail - codesize -10 ) / avail : 0.0f;
794                                 //this.win.rooview.el.save_easing_state();
795                                  
796                                 this.win.rooview.el.set_scale(scale,scale);
797                            // this.win.rooview.el.restore_easing_state();
798                                 break;
799                                 
800                         case State.PROP:
801                         case State.LISTENER:
802                                  this.win.addpropsview.el.set_size(palsize, alloc.height);
803                                 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
804                                 this.win.rooview.el.set_scale(scale,scale);
805                                 break;
806                                 
807                         case State.OBJECT:  
808                                 this.win.objectview.el.set_size(palsize, alloc.height);    
809                                 var scale = avail > 0.0f ? (avail - palsize -10 ) / avail : 0.0f;
810                                 //this.win.rooview.el.save_easing_state();
811                                 this.win.rooview.el.set_scale(scale,scale);
812                            // this.win.rooview.el.restore_easing_state();
813                                 break;
814                 }
815         }
816
817         // -- buttons show hide.....
818
819         public void buttonsShowHide()
820         {
821                 // basically hide everything, then show the relivant..
822
823                  this.win.backbutton.el.hide();
824         
825                 this.win.projectbutton.el.hide(); // show file nav...
826                 this.win.editfilebutton.el.hide();
827                 this.win.projecteditbutton.el.hide();
828                  
829                 
830                 this.win.objectshowbutton.el.hide(); // add objects
831                 this.win.addpropbutton.el.hide();  
832                 this.win.addlistenerbutton.el.hide(); 
833
834         
835         
836                 this.win.addprojectbutton.el.hide();
837                 this.win.addfilebutton.el.hide();
838                 this.win.delprojectbutton.el.hide();
839                   
840                 
841                 switch (this.state) {
842                         
843                         case State.PREVIEW:  // this is the default state when working...
844                            
845                                 this.win.projectbutton.el.show(); // show file nav...
846                                 this.win.editfilebutton.el.show();
847                                 this.win.projecteditbutton.el.show();
848                                  
849                                 
850                                 this.win.objectshowbutton.el.show(); // add objects
851                                 this.win.addpropbutton.el.show();  
852                                 this.win.addlistenerbutton.el.show(); 
853                                 break;
854                         
855                    
856                         case State.CODE: 
857                         case State.PROP:
858                         case State.LISTENER:
859                         case State.OBJECT:
860                                 
861                                 this.win.backbutton.el.show();
862                                 this.win.objectshowbutton.el.show(); // add objects
863                                 this.win.addpropbutton.el.show();  
864                                 this.win.addlistenerbutton.el.show(); 
865                                 break;
866                         
867                         case State.PROJECT: 
868                                 // anything else?
869                                 this.win.backbutton.el.show();
870                                 break;
871                         
872         
873                         case State.FILES:
874                                 if (this.left_projects.getSelectedProject() != null ) {
875                                         if (this.left_tree.getActiveFile() != null) {
876                                                 this.win.backbutton.el.show();
877                                         }
878                                         this.win.addfilebutton.el.show();
879                                 }
880                                          
881                                 this.win.addprojectbutton.el.show();
882                                 this.win.delprojectbutton.el.show();
883                                 
884                                 break;
885                 }
886                 
887                 
888
889         }
890         
891         
892         public void valaCompiled(Json.Object obj)
893                 {
894                         // vala has finished compiling...
895                         print("vala compiled");
896                         
897                         var buf = this.code_editor.buffer;
898                         buf.check_running = false;
899                                       
900                         if (obj.has_member("ERR-TOTAL")) {
901                                  this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
902                         } else {
903                                  this.win.statusbar_errors.setNotices( new Json.Object() , 0);
904                         }    
905                         
906                         if (obj.has_member("WARN-TOTAL")) {
907
908                                  this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
909                         } else {
910                                  this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
911                                  
912                         }
913                         if (obj.has_member("DEPR-TOTAL")) {
914                                 
915                                  this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"),  (int) obj.get_int_member("DEPR-TOTAL"));
916                                  
917                         } else {
918                                 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
919                         }
920                         
921                         buf.highlightErrorsJson("ERR", obj);
922                         buf.highlightErrorsJson("WARN", obj);
923                         buf.highlightErrorsJson("DEPR", obj);
924                         
925                         var gbuf =   this.window_gladeview.sourceview;
926                         gbuf.highlightErrorsJson("ERR", obj);
927                         gbuf.highlightErrorsJson("WARN", obj);
928                         gbuf.highlightErrorsJson("DEPR", obj);                  
929                         
930                         this.last_compile_result = obj;
931                         
932                         
933                 }
934         
935 }
936
937