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