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