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