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