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