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