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