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