Fix #7438 - All comple warnings gone....
[roobuilder] / src / Builder4 / Editor.vala
1 static Editor  _Editor;
2
3 public class Editor : Object
4 {
5     public Gtk.Box el;
6     private Editor  _this;
7
8     public static Editor singleton()
9     {
10         if (_Editor == null) {
11             _Editor= new Editor();
12         }
13         return _Editor;
14     }
15     public Xcls_save_button save_button;
16     public Xcls_close_btn close_btn;
17     public Xcls_RightEditor RightEditor;
18     public Xcls_view view;
19     public Xcls_buffer buffer;
20     public Xcls_search_entry search_entry;
21     public Xcls_search_results search_results;
22     public Xcls_nextBtn nextBtn;
23     public Xcls_backBtn backBtn;
24     public Xcls_search_settings search_settings;
25     public Xcls_case_sensitive case_sensitive;
26     public Xcls_regex regex;
27     public Xcls_multiline multiline;
28
29         // my vars (def)
30     public Xcls_MainWindow window;
31     public int pos_root_x;
32     public bool dirty;
33     public int pos_root_y;
34     public bool pos;
35     public Gtk.SourceSearchContext searchcontext;
36     public int last_search_end;
37     public JsRender.NodeProp? prop;
38     public JsRender.JsRender? file;
39     public JsRender.Node node;
40     public signal void save ();
41     public string activeEditor;
42
43     // ctor
44     public Editor()
45     {
46         _this = this;
47         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
48
49         // my vars (dec)
50         this.window = null;
51         this.dirty = false;
52         this.pos = false;
53         this.searchcontext = null;
54         this.last_search_end = 0;
55         this.prop = null;
56         this.file = null;
57         this.node = null;
58         this.activeEditor = "";
59
60         // set gobject values
61         this.el.homogeneous = false;
62         this.el.hexpand = true;
63         this.el.vexpand = true;
64         var child_0 = new Xcls_Box2( _this );
65         child_0.ref();
66         this.el.pack_start (  child_0.el , false,true );
67         var child_1 = new Xcls_RightEditor( _this );
68         child_1.ref();
69         this.el.add(  child_1.el );
70         var child_2 = new Xcls_Box12( _this );
71         child_2.ref();
72         this.el.add(  child_2.el );
73     }
74
75     // user defined functions
76     public bool saveContents ()  {
77         
78         
79         if (_this.file == null) {
80             return true;
81         }
82         
83          
84          
85          var str = _this.buffer.toString();
86          
87          _this.buffer.checkSyntax();
88          
89          
90          
91          // LeftPanel.model.changed(  str , false);
92          _this.dirty = false;
93          _this.save_button.el.sensitive = false;
94          
95         // find the text for the node..
96         if (_this.file.xtype != "PlainFile") {
97            // in theory these properties have to exist!?!
98                 this.prop.val = str;
99             this.window.windowstate.left_props.reload();
100         } else {
101             _this.file.setSource(  str );
102          }
103         
104         // call the signal..
105         this.save();
106         
107         return true;
108     
109     }
110     public void forwardSearch (bool change_focus) {
111     
112         if (this.searchcontext == null) {
113                 return;
114         } 
115         
116         Gtk.TextIter beg, st,en;
117          bool has_wrapped_around;
118         this.buffer.el.get_iter_at_offset(out beg, this.last_search_end);
119         if (!this.searchcontext.forward2(beg, out st, out en, out has_wrapped_around)) {
120         
121                 this.last_search_end = 0; // not sure if this should happen
122         } else {
123                 if (has_wrapped_around) {
124                         return;
125                 }
126         
127                 this.last_search_end = en.get_offset();
128                 if (change_focus) {
129                         this.view.el.grab_focus();
130                 }
131                 this.buffer.el.place_cursor(st);
132                 this.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);
133         }
134      
135     }
136     public void show (JsRender.JsRender file, JsRender.Node? node, JsRender.NodeProp? prop)
137     {
138         this.reset();
139         this.file = file;    
140         
141         if (file.xtype != "PlainFile") {
142                 this.prop = prop;
143             this.node = node;
144     
145             // find the text for the node..
146             this.view.load( prop.val );
147             this.close_btn.el.show();       
148         
149         } else {
150             this.view.load(        file.toSource() );
151             this.close_btn.el.hide();
152         }
153      
154     }
155     public void backSearch (bool change_focus) {
156     
157         if (this.searchcontext == null) {
158                 return;
159         } 
160         
161         Gtk.TextIter beg, st,en;
162         bool has_wrapped_around;
163         this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
164         
165         if (!this.searchcontext.backward2(beg, out st, out en, out has_wrapped_around)) {
166         
167                 this.last_search_end = 0;
168         } else {
169                 this.last_search_end = en.get_offset();
170                 if (change_focus) {
171                         this.view.el.grab_focus();
172                 }
173                 this.buffer.el.place_cursor(st);
174                 this.view.el.scroll_to_iter(st,  0.1f, true, 0.0f, 0.5f);
175         }
176      
177     }
178     public int search (string in_txt) {
179     
180         var s = new Gtk.SourceSearchSettings();
181         s.case_sensitive = _this.case_sensitive.el.active;
182         s.regex_enabled = _this.regex.el.active;        
183         s.wrap_around = false;
184         
185         this.searchcontext = new Gtk.SourceSearchContext(this.buffer.el,s);
186         this.searchcontext.set_highlight(true);
187         var txt = in_txt;
188         
189         if (_this.multiline.el.active) {
190                 txt = in_txt.replace("\\n", "\n");
191         }
192         
193         s.set_search_text(txt);
194         Gtk.TextIter beg, st,en;
195          
196         this.buffer.el.get_start_iter(out beg);
197         bool has_wrapped_around;
198         this.searchcontext.forward2(beg, out st, out en, out has_wrapped_around);
199         this.last_search_end = 0;
200         
201         return this.searchcontext.get_occurrences_count();
202     
203      
204        
205     
206     }
207     public void reset () {
208          this.file = null;    
209          
210         this.node = null;
211         this.prop = null;
212         this.searchcontext = null;
213       
214     }
215     public void scroll_to_line (int line) {
216     
217         GLib.Timeout.add(500, () => {
218        
219                 var buf = this.view.el.get_buffer();
220     
221                 var sbuf = (Gtk.SourceBuffer) buf;
222     
223     
224                 Gtk.TextIter iter;   
225                 sbuf.get_iter_at_line(out iter,  line);
226                 this.view.el.scroll_to_iter(iter,  0.1f, true, 0.0f, 0.5f);
227                 return false;
228         });   
229     }
230     public class Xcls_Box2 : Object
231     {
232         public Gtk.Box el;
233         private Editor  _this;
234
235
236             // my vars (def)
237
238         // ctor
239         public Xcls_Box2(Editor _owner )
240         {
241             _this = _owner;
242             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
243
244             // my vars (dec)
245
246             // set gobject values
247             this.el.homogeneous = false;
248             var child_0 = new Xcls_save_button( _this );
249             child_0.ref();
250             this.el.add (  child_0.el  );
251             var child_1 = new Xcls_Label5( _this );
252             child_1.ref();
253             this.el.add (  child_1.el  );
254             var child_2 = new Xcls_Scale6( _this );
255             child_2.ref();
256             this.el.add (  child_2.el  );
257             var child_3 = new Xcls_close_btn( _this );
258             child_3.ref();
259             this.el.add (  child_3.el  );
260         }
261
262         // user defined functions
263     }
264     public class Xcls_save_button : Object
265     {
266         public Gtk.Button el;
267         private Editor  _this;
268
269
270             // my vars (def)
271
272         // ctor
273         public Xcls_save_button(Editor _owner )
274         {
275             _this = _owner;
276             _this.save_button = this;
277             this.el = new Gtk.Button();
278
279             // my vars (dec)
280
281             // set gobject values
282             this.el.always_show_image = true;
283             this.el.label = "Save";
284             var child_0 = new Xcls_Image4( _this );
285             child_0.ref();
286             this.el.image = child_0.el;
287
288             //listeners
289             this.el.clicked.connect( () => { 
290                 _this.saveContents();
291             });
292         }
293
294         // user defined functions
295     }
296     public class Xcls_Image4 : Object
297     {
298         public Gtk.Image el;
299         private Editor  _this;
300
301
302             // my vars (def)
303
304         // ctor
305         public Xcls_Image4(Editor _owner )
306         {
307             _this = _owner;
308             this.el = new Gtk.Image();
309
310             // my vars (dec)
311
312             // set gobject values
313             this.el.icon_name = "document-save";
314         }
315
316         // user defined functions
317     }
318
319
320     public class Xcls_Label5 : Object
321     {
322         public Gtk.Label el;
323         private Editor  _this;
324
325
326             // my vars (def)
327
328         // ctor
329         public Xcls_Label5(Editor _owner )
330         {
331             _this = _owner;
332             this.el = new Gtk.Label( null );
333
334             // my vars (dec)
335
336             // set gobject values
337             this.el.hexpand = true;
338         }
339
340         // user defined functions
341     }
342
343     public class Xcls_Scale6 : Object
344     {
345         public Gtk.Scale el;
346         private Editor  _this;
347
348
349             // my vars (def)
350
351         // ctor
352         public Xcls_Scale6(Editor _owner )
353         {
354             _this = _owner;
355             this.el = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL,6, 30, 1);
356
357             // my vars (dec)
358
359             // set gobject values
360             this.el.width_request = 200;
361             this.el.has_origin = true;
362             this.el.draw_value = true;
363             this.el.digits = 0;
364             this.el.sensitive = true;
365
366             // init method
367
368             {
369                 this.el.set_range(6,30);
370                 this.el.set_value(8);
371             }
372
373             //listeners
374             this.el.change_value.connect( (st, val ) => {
375                  
376                   try {
377                   _this.view.css.load_from_data(
378                                 "#editor-view { font: %dpx Monospace; }".printf((int)val)
379                                 );
380                   } catch (Error e) {}
381                 return false;
382             });
383         }
384
385         // user defined functions
386     }
387
388     public class Xcls_close_btn : Object
389     {
390         public Gtk.Button el;
391         private Editor  _this;
392
393
394             // my vars (def)
395
396         // ctor
397         public Xcls_close_btn(Editor _owner )
398         {
399             _this = _owner;
400             _this.close_btn = this;
401             this.el = new Gtk.Button();
402
403             // my vars (dec)
404
405             // set gobject values
406             this.el.always_show_image = true;
407             var child_0 = new Xcls_Image8( _this );
408             child_0.ref();
409             this.el.image = child_0.el;
410
411             //listeners
412             this.el.clicked.connect( () => { 
413                 _this.saveContents();
414                 _this.window.windowstate.switchState(WindowState.State.PREVIEW);
415             });
416         }
417
418         // user defined functions
419     }
420     public class Xcls_Image8 : Object
421     {
422         public Gtk.Image el;
423         private Editor  _this;
424
425
426             // my vars (def)
427
428         // ctor
429         public Xcls_Image8(Editor _owner )
430         {
431             _this = _owner;
432             this.el = new Gtk.Image();
433
434             // my vars (dec)
435
436             // set gobject values
437             this.el.icon_name = "window-close";
438         }
439
440         // user defined functions
441     }
442
443
444
445     public class Xcls_RightEditor : Object
446     {
447         public Gtk.ScrolledWindow el;
448         private Editor  _this;
449
450
451             // my vars (def)
452
453         // ctor
454         public Xcls_RightEditor(Editor _owner )
455         {
456             _this = _owner;
457             _this.RightEditor = this;
458             this.el = new Gtk.ScrolledWindow( null, null );
459
460             // my vars (dec)
461
462             // set gobject values
463             this.el.vexpand = true;
464             var child_0 = new Xcls_view( _this );
465             child_0.ref();
466             this.el.add (  child_0.el  );
467
468             // init method
469
470             this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
471         }
472
473         // user defined functions
474     }
475     public class Xcls_view : Object
476     {
477         public Gtk.SourceView el;
478         private Editor  _this;
479
480
481             // my vars (def)
482         public Gtk.CssProvider css;
483
484         // ctor
485         public Xcls_view(Editor _owner )
486         {
487             _this = _owner;
488             _this.view = this;
489             this.el = new Gtk.SourceView();
490
491             // my vars (dec)
492             this.css = null;
493
494             // set gobject values
495             this.el.auto_indent = true;
496             this.el.indent_width = 4;
497             this.el.name = "editor-view";
498             this.el.show_line_marks = true;
499             this.el.insert_spaces_instead_of_tabs = true;
500             this.el.show_line_numbers = true;
501             this.el.tab_width = 4;
502             this.el.highlight_current_line = true;
503             var child_0 = new Xcls_buffer( _this );
504             child_0.ref();
505             this.el.set_buffer (  child_0.el  );
506
507             // init method
508
509             this.css = new Gtk.CssProvider();
510                 try {
511                         this.css.load_from_data("#editor-view { font: 10px Monospace;}");
512                 } catch (Error e) {}
513                 this.el.get_style_context().add_provider(this.css,Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
514                  
515                          
516             
517                 try {        
518                         this.el.completion.add_provider(new Palete.CompletionProvider(_this));
519                 } catch (GLib.Error  e) {}
520                 
521                 this.el.completion.unblock_interactive();
522                 this.el.completion.select_on_show                       = true; // select
523                 this.el.completion.show_headers                 = false;
524                 this.el.completion.remember_info_visibility             = true;
525                 
526               
527                 var attrs = new Gtk.SourceMarkAttributes();
528                 var  pink =   Gdk.RGBA();
529                 pink.parse ( "pink");
530                 attrs.set_background ( pink);
531                 attrs.set_icon_name ( "process-stop");    
532                 attrs.query_tooltip_text.connect(( mark) => {
533                     //print("tooltip query? %s\n", mark.name);
534                     return mark.name;
535                 });
536                 
537                 this.el.set_mark_attributes ("ERR", attrs, 1);
538                 
539                  var wattrs = new Gtk.SourceMarkAttributes();
540                 var  blue =   Gdk.RGBA();
541                 blue.parse ( "#ABF4EB");
542                 wattrs.set_background ( blue);
543                 wattrs.set_icon_name ( "process-stop");    
544                 wattrs.query_tooltip_text.connect(( mark) => {
545                     //print("tooltip query? %s\n", mark.name);
546                     return mark.name;
547                 });
548                 
549                 this.el.set_mark_attributes ("WARN", wattrs, 1);
550                 
551              
552                 
553                  var dattrs = new Gtk.SourceMarkAttributes();
554                 var  purple =   Gdk.RGBA();
555                 purple.parse ( "#EEA9FF");
556                 dattrs.set_background ( purple);
557                 dattrs.set_icon_name ( "process-stop");    
558                 dattrs.query_tooltip_text.connect(( mark) => {
559                     //print("tooltip query? %s\n", mark.name);
560                     return mark.name;
561                 });
562                 
563                 this.el.set_mark_attributes ("DEPR", dattrs, 1);
564                 
565               
566                  this.el.get_space_drawer().set_matrix(null);
567                  this.el.get_space_drawer().set_types_for_locations( 
568                         Gtk.SourceSpaceLocationFlags.ALL,
569                         Gtk.SourceSpaceTypeFlags.ALL
570                 );
571                 this.el.get_space_drawer().set_enable_matrix(true);
572                 /*
573                 Gtk.SourceDrawSpacesFlags.LEADING + 
574             Gtk.SourceDrawSpacesFlags.TRAILING + 
575             Gtk.SourceDrawSpacesFlags.TAB + 
576             Gtk.SourceDrawSpacesFlags.SPACE
577                 */
578
579             //listeners
580             this.el.key_release_event.connect( (event) => {
581                 
582                 if (event.keyval == Gdk.Key.s && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
583                     GLib.debug("SAVE: ctrl-S  pressed");
584                     _this.saveContents();
585                     return false;
586                 }
587                 
588                 if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
589                     GLib.debug("SAVE: ctrl-g  pressed");
590                         _this.forwardSearch(true);
591                     return true;
592                 }
593                 if (event.keyval == Gdk.Key.f && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
594                     GLib.debug("SAVE: ctrl-f  pressed");
595                         _this.search_entry.el.grab_focus();
596                     return true;
597                 }
598                 
599                // print(event.key.keyval)
600                 
601                 return false;
602             
603             });
604         }
605
606         // user defined functions
607         public void load (string str) {
608         
609         // show the help page for the active node..
610            //this.get('/Help').show();
611         
612         
613           // this.get('/BottomPane').el.set_current_page(0);
614             var buf = (Gtk.SourceBuffer)this.el.get_buffer();
615             buf.set_text(str, str.length);
616             buf.set_undo_manager(null);
617             
618             var lm = Gtk.SourceLanguageManager.get_default();
619             var lang = "vala";
620             if (_this.file != null) {
621                  lang = _this.file.language;
622             }
623             print("lang=%s, content_type = %s\n", lang, _this.file.content_type);
624             var lg = _this.file.content_type.length > 0  ?
625                     lm.guess_language(_this.file.path, _this.file.content_type) :
626                     lm.get_language(lang);
627              
628            
629             ((Gtk.SourceBuffer)(this.el.get_buffer())) .set_language(lg); 
630         
631             this.el.insert_spaces_instead_of_tabs = true;
632             if (lg != null) {
633                         print("sourcelanguage  = %s\n", lg.name);
634                         if (lg.name == "Vala") {
635                             this.el.insert_spaces_instead_of_tabs = false;
636                         }
637              }
638             _this.dirty = false;
639             this.el.grab_focus();
640             _this.save_button.el.sensitive = false;
641         }
642     }
643     public class Xcls_buffer : Object
644     {
645         public Gtk.SourceBuffer el;
646         private Editor  _this;
647
648
649             // my vars (def)
650         public int error_line;
651         public bool check_queued;
652         public bool check_running;
653
654         // ctor
655         public Xcls_buffer(Editor _owner )
656         {
657             _this = _owner;
658             _this.buffer = this;
659             this.el = new Gtk.SourceBuffer( null );
660
661             // my vars (dec)
662             this.error_line = -1;
663             this.check_queued = false;
664             this.check_running = false;
665
666             // set gobject values
667
668             //listeners
669             this.el.changed.connect( () => {
670                 // check syntax??
671                 // ??needed..??
672                 _this.save_button.el.sensitive = true;
673                 print("EDITOR CHANGED");
674                 this.checkSyntax();
675                
676                 _this.dirty = true;
677             
678                 // this.get('/LeftPanel.model').changed(  str , false);
679                 return ;
680             });
681         }
682
683         // user defined functions
684         public bool checkSyntax () {
685          
686             if (this.check_running) {
687                 print("Check is running\n");
688                 if (this.check_queued) { 
689                     print("Check is already queued");
690                     return true;
691                 }
692                 this.check_queued = true;
693                 print("Adding queued Check ");
694                 GLib.Timeout.add_seconds(1, () => {
695                     this.check_queued = false;
696                     
697                     this.checkSyntax();
698                     return false;
699                 });
700             
701         
702                 return true;
703             }
704             var str = this.toString();
705             
706             // needed???
707             if (this.error_line > 0) {
708                  Gtk.TextIter start;
709                  Gtk.TextIter end;     
710                 this.el.get_bounds (out start, out end);
711         
712                 this.el.remove_source_marks (start, end, null);
713             }
714             if (str.length < 1) {
715                 print("checkSyntax - empty string?\n");
716                 return true;
717             }
718             
719             if (_this.file.xtype == "PlainFile") {
720             
721                 // assume it's gtk...
722                    this.check_running = true;
723          
724                  if (!BuilderApplication.valasource.checkPlainFileSpawn(
725                    _this.file,
726                     str
727                  )) {
728                     this.check_running = false;
729                 }
730                 
731                 return true;
732             
733             }
734            if (_this.file == null) {
735                return true;
736            }
737             var p = _this.file.project.palete;
738             
739         
740              
741             this.check_running = true;
742             
743             
744             if (_this.file.language == "js") {
745                 this.check_running = false;
746                 print("calling validate javascript\n"); 
747                 Gee.HashMap<int,string> errors;
748                 p.javascriptHasErrors(
749                         _this.window.windowstate,
750                     str, 
751                      _this.prop,
752                     _this.file,   // no reference not node?
753                     out errors
754                 );
755                 return this.highlightErrors(errors);    
756                 
757             }
758                 
759                 
760             print("calling validate vala\n");    
761             // clear the buttons.
762          
763             
764            if (! BuilderApplication.valasource.checkFileWithNodePropChange(
765                 _this.file,
766                 _this.node,
767                  _this.prop,        
768                     str
769                 )) {
770                 this.check_running = false;
771             } 
772              
773             
774             
775             //print("done mark line\n");
776              
777             return true; // at present allow saving - even if it's invalid..
778         }
779         public bool highlightErrorsJson (string type, Json.Object obj) {
780               Gtk.TextIter start;
781              Gtk.TextIter end;     
782                 this.el.get_bounds (out start, out end);
783                 
784                 this.el.remove_source_marks (start, end, type);
785                          
786              
787              // we should highlight other types of errors..
788             
789             if (!obj.has_member(type)) {
790                 print("Return has no errors\n");
791                 return true;
792             }
793             
794             if (_this.window.windowstate.state != WindowState.State.CODEONLY 
795               
796                 ) {
797                 return true;
798             } 
799             
800             
801             var err = obj.get_object_member(type);
802             
803             
804             if (_this.file == null) {
805                 return true;
806             
807             }
808             var valafn = _this.file.path;
809          
810             if (_this.file.xtype != "PlainFile") {
811         
812         
813                 
814                 
815                  valafn = "";
816                   try {             
817                        var  regex = new Regex("\\.bjs$");
818                        // should not happen
819                       
820                      
821                         valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
822                      } catch (GLib.RegexError e) {
823                         return true;
824                     }   
825         
826         
827         
828               }
829                if (!err.has_member(valafn)) {
830                     print("File path has no errors\n");
831                     return  true;
832                 }
833         
834                 var lines = err.get_object_member(valafn);
835                 
836                 var offset = 1;
837                 if (obj.has_member("line_offset")) {
838                     offset = (int)obj.get_int_member("line_offset") + 1;
839                 }
840             
841         
842              
843             
844             var tlines = this.el.get_line_count () +1;
845             
846             lines.foreach_member((obj, line, node) => {
847                 
848                      Gtk.TextIter iter;
849             //        print("get inter\n");
850                     var eline = int.parse(line) - offset;
851                     print("GOT ERROR on line %s -- converted to %d\n", line,eline);
852                     
853                     
854                     if (eline > tlines || eline < 0) {
855                         return;
856                     }
857                     this.el.get_iter_at_line( out iter, eline);
858                     //print("mark line\n");
859                     var msg  = "Line: %d".printf(eline+1);
860                     var ar = lines.get_array_member(line);
861                     for (var i = 0 ; i < ar.get_length(); i++) {
862                             msg += (msg.length > 0) ? "\n" : "";
863                             msg += ar.get_string_element(i);
864                     }
865                     
866                     
867                     this.el.create_source_mark(msg, type, iter);
868                 } );
869                 return false;
870             
871         
872         
873         
874         
875         }
876         public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
877                  
878                 this.error_line = validate_res.size;
879         
880                 if (this.error_line < 1) {
881                       return true;
882                 }
883                 var tlines = this.el.get_line_count ();
884                 Gtk.TextIter iter;
885                 var valiter = validate_res.map_iterator();
886                 while (valiter.next()) {
887                 
888             //        print("get inter\n");
889                     var eline = valiter.get_key();
890                     if (eline > tlines) {
891                         continue;
892                     }
893                     this.el.get_iter_at_line( out iter, eline);
894                     //print("mark line\n");
895                     this.el.create_source_mark(valiter.get_value(), "ERR", iter);
896                 }   
897                 return false;
898             }
899         public string toString () {
900             
901             Gtk.TextIter s;
902             Gtk.TextIter e;
903             this.el.get_start_iter(out s);
904             this.el.get_end_iter(out e);
905             var ret = this.el.get_text(s,e,true);
906             //print("TO STRING? " + ret);
907             return ret;
908         }
909     }
910
911
912
913     public class Xcls_Box12 : Object
914     {
915         public Gtk.Box el;
916         private Editor  _this;
917
918
919             // my vars (def)
920
921         // ctor
922         public Xcls_Box12(Editor _owner )
923         {
924             _this = _owner;
925             this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
926
927             // my vars (dec)
928
929             // set gobject values
930             this.el.homogeneous = false;
931             this.el.vexpand = false;
932             var child_0 = new Xcls_search_entry( _this );
933             child_0.ref();
934             this.el.add(  child_0.el );
935             var child_1 = new Xcls_MenuBar14( _this );
936             child_1.ref();
937             this.el.add (  child_1.el  );
938             var child_2 = new Xcls_nextBtn( _this );
939             child_2.ref();
940             this.el.add(  child_2.el );
941             var child_3 = new Xcls_backBtn( _this );
942             child_3.ref();
943             this.el.add(  child_3.el );
944             var child_4 = new Xcls_MenuButton20( _this );
945             child_4.ref();
946             this.el.add(  child_4.el );
947         }
948
949         // user defined functions
950     }
951     public class Xcls_search_entry : Object
952     {
953         public Gtk.SearchEntry el;
954         private Editor  _this;
955
956
957             // my vars (def)
958
959         // ctor
960         public Xcls_search_entry(Editor _owner )
961         {
962             _this = _owner;
963             _this.search_entry = this;
964             this.el = new Gtk.SearchEntry();
965
966             // my vars (dec)
967
968             // set gobject values
969             this.el.width_request = 300;
970             this.el.hexpand = true;
971             this.el.placeholder_text = "Press enter to search";
972
973             // init method
974
975             var description =   Pango.FontDescription.from_string("monospace");
976                 description.set_size(8000);
977                  this.el.set_property("font-desc",description);
978
979             //listeners
980             this.el.key_press_event.connect( (event) => {
981                  if (event.keyval == Gdk.Key.g && (event.state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
982                     GLib.debug("SAVE: ctrl-g  pressed");
983                         _this.forwardSearch(true);
984                     return true;
985                 }
986                 
987               
988                 if (event.keyval == Gdk.Key.Return && this.el.text.length > 0) {
989                         //var res =
990                          _this.search(this.el.text);
991                          _this.search_results.updateResults();
992             
993                         GLib.Timeout.add_seconds(2,() => {
994                                  _this.search_results.updateResults();
995                                  return false;
996                          });
997                  
998                         
999                     return true;
1000             
1001                 }    
1002                // print(event.key.keyval)
1003                
1004                 return false;
1005             
1006             });
1007             this.el.changed.connect( () => {
1008                 /*
1009                 if (this.el.text == "") {
1010                         _this.search_results.el.hide();
1011                         return;
1012                 }
1013                 var res = 0;
1014                 switch(_this.windowstate.state) {
1015                         case WindowState.State.CODEONLY:
1016                         ///case WindowState.State.CODE:
1017                                 // search the code being edited..
1018                                 res = _this.windowstate.code_editor_tab.search(this.el.text);
1019                                 
1020                                 break;
1021                         case WindowState.State.PREVIEW:
1022                                 if (_this.windowstate.file.xtype == "Gtk") {
1023                                          res = _this.windowstate.window_gladeview.search(this.el.text);
1024                                 } else { 
1025                                          res = _this.windowstate.window_rooview.search(this.el.text);                   
1026                                 }
1027                         
1028                         
1029                                 break;
1030                 }
1031                 _this.search_results.el.show();
1032                 if (res > 0) {
1033                         _this.search_results.el.label = "%d Matches".printf(res);
1034                 } else {
1035                         _this.search_results.el.label = "No Matches";
1036                 }
1037                         
1038                 */
1039                 
1040             });
1041         }
1042
1043         // user defined functions
1044         public void forwardSearch (bool change_focus) {
1045         
1046         
1047                 _this.forwardSearch(change_focus);
1048         
1049         /*
1050         
1051                 switch(_this.windowstate.state) {
1052                         case WindowState.State.CODEONLY:
1053                         //case WindowState.State.CODE:
1054                                 // search the code being edited..
1055                                 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1056                                  
1057                                 break;
1058                         case WindowState.State.PREVIEW:
1059                                 if (_this.windowstate.file.xtype == "Gtk") {
1060                                         _this.windowstate.window_gladeview.forwardSearch(change_focus);
1061                                 } else { 
1062                                          _this.windowstate.window_rooview.forwardSearch(change_focus);
1063                                 }
1064                         
1065                                 break;
1066                 }
1067                 */
1068                 
1069         }
1070     }
1071
1072     public class Xcls_MenuBar14 : Object
1073     {
1074         public Gtk.MenuBar el;
1075         private Editor  _this;
1076
1077
1078             // my vars (def)
1079
1080         // ctor
1081         public Xcls_MenuBar14(Editor _owner )
1082         {
1083             _this = _owner;
1084             this.el = new Gtk.MenuBar();
1085
1086             // my vars (dec)
1087
1088             // set gobject values
1089             var child_0 = new Xcls_search_results( _this );
1090             child_0.ref();
1091             this.el.add (  child_0.el  );
1092         }
1093
1094         // user defined functions
1095     }
1096     public class Xcls_search_results : Object
1097     {
1098         public Gtk.MenuItem el;
1099         private Editor  _this;
1100
1101
1102             // my vars (def)
1103         public bool always_show_image;
1104
1105         // ctor
1106         public Xcls_search_results(Editor _owner )
1107         {
1108             _this = _owner;
1109             _this.search_results = this;
1110             this.el = new Gtk.MenuItem();
1111
1112             // my vars (dec)
1113             this.always_show_image = true;
1114
1115             // set gobject values
1116             this.el.visible = false;
1117             this.el.show();
1118
1119             //listeners
1120             this.el.button_press_event.connect( () => {
1121             /*
1122                 if (this.popup == null) {
1123                     this.popup = new Xcls_ValaCompileErrors();
1124                     this.popup.window = _this;
1125                 }
1126                
1127                 
1128                 this.popup.show(this.notices, this.el);
1129                 */
1130                 return true;
1131             });
1132         }
1133
1134         // user defined functions
1135         public void updateResults () {
1136                 this.el.visible = true;
1137                 
1138                 var res = _this.searchcontext.get_occurrences_count();
1139                 if (res < 0) {
1140                         _this.search_results.el.label = "??? Matches";          
1141                         return;
1142                 }
1143         
1144                 _this.nextBtn.el.sensitive = false;
1145                 _this.backBtn.el.sensitive = false;     
1146         
1147                 if (res > 0) {
1148                         _this.search_results.el.label = "%d Matches".printf(res);
1149                         _this.nextBtn.el.sensitive = true;
1150                         _this.backBtn.el.sensitive = true;
1151                         return;
1152                 } 
1153                 _this.search_results.el.label = "No Matches";
1154                 
1155         }
1156     }
1157
1158
1159     public class Xcls_nextBtn : Object
1160     {
1161         public Gtk.Button el;
1162         private Editor  _this;
1163
1164
1165             // my vars (def)
1166
1167         // ctor
1168         public Xcls_nextBtn(Editor _owner )
1169         {
1170             _this = _owner;
1171             _this.nextBtn = this;
1172             this.el = new Gtk.Button();
1173
1174             // my vars (dec)
1175
1176             // set gobject values
1177             this.el.always_show_image = true;
1178             this.el.label = "Next";
1179             this.el.sensitive = false;
1180             var child_0 = new Xcls_Image17( _this );
1181             child_0.ref();
1182             this.el.image = child_0.el;
1183
1184             //listeners
1185             this.el.button_press_event.connect( (event) => {
1186             
1187                 _this.forwardSearch(true);
1188                 
1189                 return true;
1190             });
1191         }
1192
1193         // user defined functions
1194     }
1195     public class Xcls_Image17 : Object
1196     {
1197         public Gtk.Image el;
1198         private Editor  _this;
1199
1200
1201             // my vars (def)
1202
1203         // ctor
1204         public Xcls_Image17(Editor _owner )
1205         {
1206             _this = _owner;
1207             this.el = new Gtk.Image();
1208
1209             // my vars (dec)
1210
1211             // set gobject values
1212             this.el.icon_name = "go-down";
1213         }
1214
1215         // user defined functions
1216     }
1217
1218
1219     public class Xcls_backBtn : Object
1220     {
1221         public Gtk.Button el;
1222         private Editor  _this;
1223
1224
1225             // my vars (def)
1226
1227         // ctor
1228         public Xcls_backBtn(Editor _owner )
1229         {
1230             _this = _owner;
1231             _this.backBtn = this;
1232             this.el = new Gtk.Button();
1233
1234             // my vars (dec)
1235
1236             // set gobject values
1237             this.el.always_show_image = true;
1238             this.el.label = "Previous";
1239             this.el.sensitive = false;
1240             var child_0 = new Xcls_Image19( _this );
1241             child_0.ref();
1242             this.el.image = child_0.el;
1243
1244             //listeners
1245             this.el.button_press_event.connect( (event) => {
1246             
1247                 _this.backSearch(true);
1248                 
1249                 return true;
1250             });
1251         }
1252
1253         // user defined functions
1254     }
1255     public class Xcls_Image19 : Object
1256     {
1257         public Gtk.Image el;
1258         private Editor  _this;
1259
1260
1261             // my vars (def)
1262
1263         // ctor
1264         public Xcls_Image19(Editor _owner )
1265         {
1266             _this = _owner;
1267             this.el = new Gtk.Image();
1268
1269             // my vars (dec)
1270
1271             // set gobject values
1272             this.el.icon_name = "go-up";
1273         }
1274
1275         // user defined functions
1276     }
1277
1278
1279     public class Xcls_MenuButton20 : Object
1280     {
1281         public Gtk.MenuButton el;
1282         private Editor  _this;
1283
1284
1285             // my vars (def)
1286
1287         // ctor
1288         public Xcls_MenuButton20(Editor _owner )
1289         {
1290             _this = _owner;
1291             this.el = new Gtk.MenuButton();
1292
1293             // my vars (dec)
1294
1295             // set gobject values
1296             this.el.always_show_image = true;
1297             this.el.label = "Settings";
1298             var child_0 = new Xcls_Image21( _this );
1299             child_0.ref();
1300             this.el.image = child_0.el;
1301             var child_1 = new Xcls_search_settings( _this );
1302             child_1.ref();
1303             this.el.popup = child_1.el;
1304         }
1305
1306         // user defined functions
1307     }
1308     public class Xcls_Image21 : Object
1309     {
1310         public Gtk.Image el;
1311         private Editor  _this;
1312
1313
1314             // my vars (def)
1315
1316         // ctor
1317         public Xcls_Image21(Editor _owner )
1318         {
1319             _this = _owner;
1320             this.el = new Gtk.Image();
1321
1322             // my vars (dec)
1323
1324             // set gobject values
1325             this.el.icon_name = "emblem-system";
1326         }
1327
1328         // user defined functions
1329     }
1330
1331     public class Xcls_search_settings : Object
1332     {
1333         public Gtk.Menu el;
1334         private Editor  _this;
1335
1336
1337             // my vars (def)
1338
1339         // ctor
1340         public Xcls_search_settings(Editor _owner )
1341         {
1342             _this = _owner;
1343             _this.search_settings = this;
1344             this.el = new Gtk.Menu();
1345
1346             // my vars (dec)
1347
1348             // set gobject values
1349             var child_0 = new Xcls_case_sensitive( _this );
1350             child_0.ref();
1351             this.el.append(  child_0.el );
1352             var child_1 = new Xcls_regex( _this );
1353             child_1.ref();
1354             this.el.append(  child_1.el );
1355             var child_2 = new Xcls_multiline( _this );
1356             child_2.ref();
1357             this.el.append(  child_2.el );
1358         }
1359
1360         // user defined functions
1361     }
1362     public class Xcls_case_sensitive : Object
1363     {
1364         public Gtk.CheckMenuItem el;
1365         private Editor  _this;
1366
1367
1368             // my vars (def)
1369
1370         // ctor
1371         public Xcls_case_sensitive(Editor _owner )
1372         {
1373             _this = _owner;
1374             _this.case_sensitive = this;
1375             this.el = new Gtk.CheckMenuItem();
1376
1377             // my vars (dec)
1378
1379             // set gobject values
1380             this.el.label = "Case Sensitive";
1381             this.el.show();
1382
1383             // init method
1384
1385             {
1386                 this.el.show();
1387             }
1388         }
1389
1390         // user defined functions
1391     }
1392
1393     public class Xcls_regex : Object
1394     {
1395         public Gtk.CheckMenuItem el;
1396         private Editor  _this;
1397
1398
1399             // my vars (def)
1400
1401         // ctor
1402         public Xcls_regex(Editor _owner )
1403         {
1404             _this = _owner;
1405             _this.regex = this;
1406             this.el = new Gtk.CheckMenuItem();
1407
1408             // my vars (dec)
1409
1410             // set gobject values
1411             this.el.label = "Regex";
1412             this.el.show();
1413
1414             // init method
1415
1416             {
1417                 this.el.show();
1418             }
1419         }
1420
1421         // user defined functions
1422     }
1423
1424     public class Xcls_multiline : Object
1425     {
1426         public Gtk.CheckMenuItem el;
1427         private Editor  _this;
1428
1429
1430             // my vars (def)
1431
1432         // ctor
1433         public Xcls_multiline(Editor _owner )
1434         {
1435             _this = _owner;
1436             _this.multiline = this;
1437             this.el = new Gtk.CheckMenuItem();
1438
1439             // my vars (dec)
1440
1441             // set gobject values
1442             this.el.label = "Multi-line (add \\n)";
1443             this.el.show();
1444
1445             // init method
1446
1447             {
1448                 this.el.show();
1449             }
1450         }
1451
1452         // user defined functions
1453     }
1454
1455
1456
1457
1458 }