missing file assignment on compile test
[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 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                  
92                 BuilderApplication.valasource.compiled.connect(this.showCompileResult); 
93                 
94                 this.compile_results = new  Xcls_ValaCompileResults(); // the poup dialogs with results in.
95                 this.compile_results.window = this.win;
96                 BuilderApplication.valasource.compile_output.connect(this.compile_results.addLine);
97                 
98                 this.win.statusbar_compilestatus_label.el.hide();
99                 this.win.statusbar_run.el.hide();
100                 this.win.search_results.el.hide();
101                 
102                 this.popover_files = new Xcls_PopoverFiles();
103                 this.popover_files.setMainWindow(this.win);
104         }
105
106
107         // left tree
108
109         public void leftTreeInit()
110         {
111          
112                 this.left_tree = new Xcls_WindowLeftTree();
113                 this.left_tree.ref();
114                 this.left_tree.main_window = this.win;
115         
116                 this.win.leftpane.el.remove(this.win.editpane.el);
117         //this.win.tree.el.remove(this.left_tree.el);
118         this.win.leftpane.el.add(this.left_tree.el);
119             
120         
121                 //this.win.tree.el.pack_start(this.left_tree.el,true, true,0);
122                 this.left_tree.el.show_all();
123                    
124                 this.left_tree.before_node_change.connect(() => {
125                         // if the node change is caused by the editor (code preview)
126                         if (this.left_tree.view.lastEventSource == "editor") {
127                                 return true;
128                         }
129                         return this.leftTreeBeforeChange();
130
131                 });
132                 // node selected -- only by clicking?
133                 this.left_tree.node_selected.connect((sel, source) => {
134                         if (source == "editor") {
135                                 return;
136                         }
137                         if (this.file.xtype == "Roo") { 
138                                 this.window_rooview.sourceview.nodeSelected(sel,true); // foce scroll.
139                         } else {
140                                 this.window_gladeview.sourceview.nodeSelected(sel);
141                         }
142                 });
143                 
144                 this.left_tree.node_selected.connect((sel, source) => {
145                         this.leftTreeNodeSelected(sel, source);
146                 });
147          
148                 this.left_tree.changed.connect(() => {
149                         GLib.debug("LEFT TREE: Changed fired\n");
150                         this.file.save();
151                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
152                                    this.window_rooview.requestRedraw();
153                         } else {
154                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
155                         }
156                          
157                 });
158                  
159         }
160
161         public bool leftTreeBeforeChange()
162         {
163                 // in theory code editor has to hide before tree change occurs.
164                 //if (this.state != State.CODE) {
165                         this.left_props.finish_editing();
166                         
167                         if (this.state == State.CODE) {
168                                 this.code_editor_tab.saveContents();
169                                 this.switchState(State.PREVIEW);
170                         }
171                         
172                         return true;
173                 //}
174
175                 //if (!this.code_editor.saveContents()) {
176                 //      return false;
177                 //}
178                 //return false;
179         }
180         
181         int tree_width = 300;
182         int props_width = 300;
183         
184         public void leftTreeNodeSelected(JsRender.Node? sel, string source)
185         {
186                 
187                 // do we really want to flip paletes if differnt nodes are selected
188                 // showing palete should be deliberate thing..
189                  
190          
191                 print("node_selected called %s\n", (sel == null) ? "NULL" : "a value");
192
193                 this.add_props.hide(); // always hide add node/add listener if we change node.
194                 this.rightpalete.hide();
195                 
196                 this.left_props.load(this.left_tree.getActiveFile(), sel);
197                 
198                 var outerpane = this.win.mainpane.el;
199                 var innerpane = this.win.editpane.el;
200                 
201                  if (this.win.editpane.el.parent != null && sel != null) {
202                         // select another node... no change to show hide/resize
203                         return;
204                 }
205                                  
206                 if (sel == null) {
207                     // remove win.editpane from leftpane
208                     // remove lefttree from from win.tree 
209                     // add win.tree to leftpane
210                     if (this.win.editpane.el.parent != null) {
211                         this.props_width =  outerpane.get_position() - innerpane.get_position();
212                         this.tree_width = innerpane.get_position();
213                         GLib.debug("HIDE: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
214                         
215                         this.win.leftpane.el.remove(this.win.editpane.el);
216                         this.win.tree.el.remove(this.left_tree.el);
217                         this.win.leftpane.el.add(this.left_tree.el);
218                 }
219                     
220                 
221                         //GLib.debug("Hide Properties");
222                         outerpane.show_all(); // make sure it's visiable..
223                         this.left_props.el.hide();
224                         GLib.debug("set position: %d", this.tree_width);
225                         outerpane.set_position(this.tree_width);
226                         //outerpane.set_position(int.max(250,innerpane.get_position()));
227                         //this.left_props.el.width_request =  this.left_props.el.get_allocated_width();
228                         return;
229                 }
230                 
231                 // at this point we are showing the outer only,
232                 
233                 
234                 
235                 
236                 this.tree_width = outerpane.get_position();
237                 
238                 GLib.debug("SHOW: prop_w = %d, tree_w = %d", this.props_width, this.tree_width);
239                       
240                 // remove this.ldeftree from this.win.leftpane
241                 this.win.leftpane.el.remove(this.left_tree.el);
242                 this.win.tree.el.add(this.left_tree.el);
243                 this.win.leftpane.el.add(this.win.editpane.el);
244                 
245                 
246                 
247                 
248                 GLib.debug("left props is %s",  this.left_props.el.visible ? "shown" : "hidden");
249                 // at start (hidden) - outer  = 400 inner = 399
250                 // expanded out -> outer = 686, inner = 399 
251                 //this.win.props.el.pack_start(this.left_props.el,true, true,0);
252                 this.left_props.el.show_all();
253                 //if (!this.left_props.el.visible) {
254                  
255                         GLib.debug("outerpos : %d, innerpos : %d", outerpane.get_position(), innerpane.get_position());
256                         outerpane.set_position(this.tree_width + this.props_width);
257                         innerpane.set_position(this.tree_width);
258                         /* var cw = outerpane.el.get_position();
259                         var rw = int.min(this.left_props.el.width_request, 150);
260                         print("outerpos : %d, innerpos : %d", cw + rw, cw);
261                         
262                         innerpane.set_position(cw); */
263                         this.left_props.el.show();
264                 
265                 //}
266                 
267                  
268                 
269                 
270                 
271
272                 
273                 
274                 // if either of these are active.. then we should update them??
275                 
276                 
277                 
278    /**
279    
280    make outerpane = {current width of left pane} + width of props
281    make innerpane = {current width of left pane}
282    
283    
284    
285    
286    
287    var outerpane = _this.main_window.leftpane.el;
288    var pane = _this.main_window.editpane.el;
289    
290   
291    
292     var try_size = (i * 25) + 60; // est. 20px per line + 40px header
293     GLib.Timeout.add_seconds(1, () => { 
294                 // max 80%...
295                 pane.set_position( 
296                      ((try_size * 1.0f) /  (pane.max_position * 1.0f))  > 0.8f  ? 
297                     (int) (pane.max_position * 0.2f) :
298                     pane.max_position-try_size);
299             return GLib.Source.REMOVE;
300         });
301         */
302                 
303                 
304                 /*
305                 switch (this.state) {
306                  
307                         case State.CODE:
308                                  this.switchState(State.PREVIEW);
309                          
310                                 break;
311                            
312                                                         
313                 }
314                 */
315  
316                  
317
318         }
319
320
321
322
323         public void propsListInit()
324         {
325         
326                 this.left_props =new Xcls_LeftProps();
327                 this.left_props.ref();
328                 this.left_props.main_window = this.win;
329                 this.win.props.el.pack_start(this.left_props.el,true, true,0);
330                 this.left_props.el.show_all();
331         
332                 this.left_props.show_editor.connect( (file, node, prop) => {
333                         this.switchState(State.CODE);
334                         
335                         
336                         this.code_editor_tab.show(
337                                 file,
338                                 node,
339                                 prop
340                         );
341                         
342                         
343                         
344                 });
345
346                 // not sure if this is needed - as closing the popvoer should save it.
347                 this.left_props.stop_editor.connect( () => {
348                         var ret =  this.code_editor_tab.saveContents();
349                         if (!ret) {
350                                 return false;
351                         }
352                         this.switchState(State.PREVIEW);
353                          
354                         return ret;
355                 });
356         
357                 this.left_props.changed.connect(() => {
358                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
359                                    this.window_rooview.requestRedraw();
360                         } else {
361                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
362                         }
363                         this.left_tree.model.updateSelected();
364                         this.file.save();
365                         if (this.file.xtype=="Gtk") {
366                                 BuilderApplication.valasource.checkFileSpawn(this.file);
367                         }
368                 });
369          
370
371         }
372
373         //-------------  projects edit
374
375         public void projectEditInit()
376         {
377                 this.roo_projectsettings_pop  =new Xcls_RooProjectSettings();
378                 this.roo_projectsettings_pop.ref();  /// really?
379         
380                 this.vala_projectsettings_pop  =new  ValaProjectSettingsPopover();
381                 this.vala_projectsettings_pop.ref();
382                 this.vala_projectsettings_pop.window = this.win;
383         
384                 //((Gtk.Container)(this.win.projecteditview.el.get_widget())).add(this.projectsettings.el);
385  
386  
387                 this.roo_projectsettings_pop.buttonPressed.connect((btn) => {
388                         // in theory active file can only be rooo...
389                          if (this.left_tree.getActiveFile().xtype == "Roo" ) {
390                                 if (btn == "save") {
391                                         this.window_rooview.view.renderJS(true);
392                                         this.roo_projectsettings_pop.el.hide();
393                                 }
394                                 if (btn == "apply") {
395                                         this.window_rooview.view.renderJS(true);
396                                         return;
397                                 }
398                         } else {
399                                 // do nothing for gtk..
400                         }
401                         if (btn == "save" || btn == "apply") {
402                                 this.win.project.save();
403                  
404                         }
405                         //this.switchState (State.PREVIEW); 
406                          
407                  });
408
409         }
410         
411         public void projectPopoverShow(Gtk.Widget btn, Project.Project? pr) 
412         { 
413                 if (pr == null) {
414                     pr = this.project;
415             }
416           
417             /*
418         var active_file = this.left_tree.getActiveFile() ;
419         if (active_file != null) {
420             xtype = active_file.xtype;
421         } else {
422         
423                 return; // no active project
424             // we might be on the file brower..
425             //pr = this.left_projects.getSelectedProject();        
426             //if (pr != null) {
427             //    xtype = pr.xtype;
428             //}
429         } 
430         */
431         if (pr.xtype == "") {
432             return;
433         }
434         if (pr.xtype  == "Roo" ) {
435                         this.roo_projectsettings_pop.show(btn,pr);
436                         return;
437                 }
438
439                 // gtk..
440                 this.vala_projectsettings_pop.show(btn,(Project.Gtk)pr);
441         
442         }
443         
444         
445         // ----------- object adding
446         public void objectAddInit()
447         {
448
449                 this.rightpalete  = new Xcls_PopoverAddObject();
450                 this.rightpalete.mainwindow = this.win;
451                 this.rightpalete.ref();  /// really?
452                 /*((Gtk.Container)(this.win.objectview.el.get_widget())).add(this.rightpalete.el);
453  
454
455                 var stage = this.win.objectview.el.get_stage();
456                 stage.set_background_color(  Clutter.Color.from_string("#000"));
457                  */
458         }
459         
460         // -----------  properties adding list...
461         // listener uses the properties 
462         public void propsAddInit()
463         {
464         // Add properties
465                 this.add_props  = new Xcls_PopoverAddProp();
466                 this.add_props.mainwindow = this.win;
467                 this.add_props.ref();  /// really?
468                 // don't need to add it..
469                 //((Gtk.Container)(this.win.addpropsview.el.get_widget())).add(this.add_props.el);
470  
471
472                 //var  stage = this.win.addpropsview.el.get_stage();
473                 //stage.set_background_color(  Clutter.Color.from_string("#000"));
474
475
476                 this.add_props.select.connect( (prop) => {
477                          
478                         this.left_props.addProp(prop);
479                 });
480
481         }
482         public void propsAddShow()
483         {
484
485         }
486         public void propsAddHide()
487         {
488         
489         }
490
491  
492         // ----------- Add / Edit listener
493         // listener uses the properties 
494         //public void listenerInit()     { }
495         public void listenerShow()
496         {
497
498         }
499         public void listenerHide()
500         {
501         
502         }
503
504         // -------------- codeEditor
505
506         public void codeEditInit()
507         {
508                 this.code_editor_tab  = new  Editor();
509                 //this.code_editor.ref();  /// really?
510                 this.win.codeeditviewbox.el.add(this.code_editor_tab.el);
511                 
512                 this.win.codeeditviewbox.el.hide();
513                 this.code_editor_tab.window = this.win;
514  
515                 // editor.save...
516
517                 this.code_editor_tab.save.connect( () => {
518                         this.file.save();
519                         this.left_tree.model.updateSelected();
520                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
521                                    this.window_rooview.requestRedraw();
522                         } else {
523                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
524                         }
525                          // we do not need to call spawn... - as it's already called by the editor?
526                          
527                 });
528                 
529         }
530         /*
531         public void codePopoverEditInit()
532         {
533                 this.code_editor_popover  = new  Xcls_PopoverEditor();
534                 //this.code_editor.ref();  /// really?
535                  
536                 this.code_editor_popover.setMainWindow( this.win);
537   
538                 this.code_editor_popover.editor.save.connect( () => {
539                         this.file.save();
540                         this.left_tree.model.updateSelected();
541                         if (this.left_tree.getActiveFile().xtype == "Roo" ) {
542                                    this.window_rooview.requestRedraw();
543                         } else {
544                                   this.window_gladeview.loadFile(this.left_tree.getActiveFile());
545                         }
546                          // we do not need to call spawn... - as it's already called by the editor?
547                          
548                 });
549                 
550         }
551         */
552         // ----------- list of projects on left
553         /*
554         public void  projectListInit() 
555         {
556
557                 this.left_projects = new Xcls_WindowLeftProjects();
558                  this.left_projects.ref();
559                  this.win.leftpane.el.pack_start(this.left_projects.el,true, true,0);
560                  this.left_projects.el.show_all();
561                  this.left_projects.project_selected.connect((proj) => {
562                         this.buttonsShowHide();
563                         proj.scanDirs();
564                         this.clutterfiles.loadProject(proj);
565                 
566                  });
567
568         }
569         */
570         
571         
572         // ----------- file view
573         public void showPopoverFiles(Gtk.Widget btn, Project.Project? project, bool new_window)
574         {
575                 this.popover_files.show(btn, project, new_window);
576         
577         }
578         
579         
580  
581         public void fileDetailsInit()
582         {
583                 this.file_details = new Xcls_PopoverFileDetails();
584                 this.file_details.mainwindow = this.win;
585                 // force it modal to the main window..
586                 
587                 this.file_details.success.connect((project,file) =>
588                 {
589                         this.fileViewOpen(file, this.file_details.new_window,  -1);
590                 });
591
592         }
593         
594         
595         public void gotoLine(int line)
596         {
597         
598                 if (file.xtype == "PlainFile") {
599                     this.switchState (State.CODEONLY); 
600                         if (line> -1) {
601                                 this.code_editor_tab.scroll_to_line(line);
602                         }
603                 } else {
604                 
605                         this.switchState (State.PREVIEW); 
606                          
607                         if (file.project.xtype == "Gtk" && line> -1 ) {
608                                 // fixme - show the editing tab.
609                                 this.window_gladeview.scroll_to_line(line);
610                         } 
611                         // fixme - what about Roo?
612
613                 }
614         
615         }
616         
617         public void fileViewOpen(JsRender.JsRender file, bool new_window, int line = -1)
618         {
619                 var existing = BuilderApplication.getWindow(file);
620                 
621                 if (existing != null) {
622                         existing.el.present();
623                         existing.windowstate.gotoLine(line);
624                         return;
625                 }
626                 
627                 if (new_window) {
628                         BuilderApplication.newWindow(file, line);
629                         return;
630                 }
631                 
632                 
633                 this.win.project = file.project;
634                 this.project = file.project;
635                 this.file = file;
636                 BuilderApplication.updateWindows();
637                 
638                 if (file.xtype == "PlainFile") {
639                         this.win.codeeditviewbox.el.show();
640                         this.switchState (State.CODEONLY); 
641                         file.loadItems();
642                         this.code_editor_tab.show(file, null, null);
643                          
644                 } else {
645                 
646                         this.switchState (State.PREVIEW); 
647                         // this triggers loadItems..
648                         this.left_tree.model.loadFile(file);
649                          
650
651                 }
652                 this.gotoLine(line);
653         
654                 var ctr= this.win.rooviewbox.el;
655  
656         
657                 if (file.project.xtype == "Roo" ) { 
658                     // removes all the childe elemnts from rooviewbox
659                 
660                         ctr.foreach( (w) => { ctr.remove(w); });
661  
662                         ctr.add(this.window_rooview.el);
663  
664                         if (file.xtype != "PlainFile") {       
665  
666                                 this.window_rooview.loadFile(file);
667                                 this.window_rooview.el.show_all();
668                         }
669  
670                         
671
672                 } else {
673                         ctr.foreach( (w) => { ctr.remove(w); });
674
675                         ctr.add(this.window_gladeview.el);
676  
677                         if (file.xtype != "PlainFile") {    
678                                 
679                                 this.window_gladeview.loadFile(file);
680                                 this.window_gladeview.el.show_all();
681                         }
682  
683                 }
684                 print("OPEN : " + file.name);
685                 if (file.xtype != "PlainFile") { 
686                         // hide the file editor.
687                    this.win.codeeditviewbox.el.hide();
688                         //this.win.editpane.el.set_position(this.win.editpane.el.max_position);
689                 }
690                 this.win.setTitle(file.project.name + " : " + file.name);
691                          
692
693         }
694  
695  
696          /*
697         public void fileViewOpenPlain(string fname)
698         {
699                 
700                 this.switchState (State.CODEONLY); 
701                 this.code_editor.showPlainFile(fname);
702         }
703  */
704          
705         // ---------  webkit view
706         public void webkitViewInit()
707         {
708                 this.window_rooview  =new Xcls_WindowRooView();
709                 this.window_rooview.main_window = this.win;
710                 this.window_rooview.ref();
711                 this.win.rooviewbox.el.add(this.window_rooview.el);
712                 
713                 this.window_rooview.el.show_all();
714                 this.win.rooviewbox.el.hide();
715         
716         }
717
718         // ------ Gtk  - view
719
720         public void gtkViewInit()
721         {
722
723                 
724                 
725                 this.window_gladeview  =new Xcls_GtkView( );
726                 this.window_gladeview.ref();
727                 this.window_gladeview.main_window = this.win;
728  
729         }
730         
731
732         
733         
734         public void showProps(Gtk.Widget btn, JsRender.NodePropType sig_or_listen)
735         {
736                 var ae =  this.left_tree.getActiveElement();
737                 if (ae == null) {
738                                 return;
739                 }
740                 this.rightpalete.hide(); 
741                 
742                 this.add_props.el.show_all(); 
743                 this.add_props.show(
744                         this.win.project.palete, //Palete.factory(this.win.project.xtype), 
745                          sig_or_listen, //this.state == State.LISTENER ? "signals" : "props",
746                         ae.fqn(),
747                         btn
748                         
749                 );
750         }
751         
752         public void showAddObject(Gtk.Widget btn)
753         {
754          
755                  var n = this.left_tree.getActiveElement();
756                 this.add_props.hide();
757                 this.rightpalete.el.show_all();
758                 this.rightpalete.show(
759                         this.left_tree.getActiveFile().palete(), 
760                         n == null ? "*top" : n.fqn(),
761                         btn
762                 );
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  
921                         // stop the spinner...
922                         GLib.debug("vala compiled Built Project: %s    Window Project %s",
923                                 
924                         BuilderApplication.valasource.file == null ? "No file?" : (
925                         
926                                 BuilderApplication.valasource.file.project == null  ? "No Project" : BuilderApplication.valasource.file.project.fn
927                         ),
928                         this.project != null ? this.project.fn : "No Project?"
929                         );
930                                 
931                         
932                         
933                         if (this.project != null && 
934                         BuilderApplication.valasource.file != null &&   
935                         BuilderApplication.valasource.file.project != null &&                           
936                             this.project.fn != BuilderApplication.valasource.file.project.fn) {
937                                 GLib.debug("skip update - not our project");
938                                 return;
939                         }
940                         
941                         var generator = new Json.Generator ();
942                         var n  = new Json.Node(Json.NodeType.OBJECT);
943                         n.init_object(obj);
944                         generator.set_root (n);
945                         print("result :%s", generator.to_data (null));
946                         
947                         
948                         var buf = this.code_editor_tab.buffer;
949                         buf.check_running = false;
950                         var has_errors = false;
951                                       
952                         if (obj.has_member("ERR-TOTAL")) {
953                                 if (obj.get_int_member("ERR-TOTAL")> 0) {
954                                         has_errors = true;
955                                 }
956                                  this.win.statusbar_errors.setNotices( obj.get_object_member("ERR") , (int) obj.get_int_member("ERR-TOTAL"));
957                         } else {
958                                  this.win.statusbar_errors.setNotices( new Json.Object() , 0);
959                         }    
960                         
961                         if (obj.has_member("WARN-TOTAL")) {
962
963                                  this.win.statusbar_warnings.setNotices(obj.get_object_member("WARN"), (int) obj.get_int_member("WARN-TOTAL"));
964                         } else {
965                                  this.win.statusbar_warnings.setNotices( new Json.Object() , 0);
966                                  
967                         }
968                         if (obj.has_member("DEPR-TOTAL")) {
969                                 
970                                  this.win.statusbar_depricated.setNotices( obj.get_object_member("DEPR"),  (int) obj.get_int_member("DEPR-TOTAL"));
971                                  
972                         } else {
973                                 this.win.statusbar_depricated.setNotices( new Json.Object(),0);
974                         }
975                         //if (this.state == State.CODE || this.state == State.PROJECTCODEONLY) {
976                         if ( this.state == State.CODEONLY) {
977                                 buf.highlightErrorsJson("ERR", obj); 
978                                 buf.highlightErrorsJson("WARN", obj);
979                                 buf.highlightErrorsJson("DEPR", obj);
980                         }
981                         
982                         this.win.statusbar_compilestatus_label.el.hide();
983                         this.win.statusbar_run.el.hide();
984                         if (!has_errors) { 
985                                 this.win.statusbar_compilestatus_label.el.show();
986                                 this.win.statusbar_run.el.show();
987                         }
988                         if (this.file.xtype == "Gtk") {
989                                 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
990                                 var gbuf =   this.window_gladeview.sourceview;
991                                 gbuf.highlightErrorsJson("ERR", obj);
992                                 gbuf.highlightErrorsJson("WARN", obj);
993                                 gbuf.highlightErrorsJson("DEPR", obj);                  
994                                 
995                                 if (!has_errors) {
996                                         this.win.statusbar_run.el.show();
997                                 }
998                         
999                    }
1000                    
1001                    if (this.file.xtype == "Roo") {
1002                                 // not sure how this is working ok? - as highlighting is happening on the vala files at present..
1003                                 var gbuf =   this.window_rooview.sourceview;
1004                                 gbuf.highlightErrorsJson("ERR", obj);
1005                                 gbuf.highlightErrorsJson("WARN", obj);
1006                                 gbuf.highlightErrorsJson("DEPR", obj);                  
1007                         
1008                    }
1009                     
1010                         this.last_compile_result = obj;
1011                         
1012                         
1013                 }
1014         
1015 }
1016
1017