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