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