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