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