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