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