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