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