1 static Xcls_WindowRooView _WindowRooView;
3 public class Xcls_WindowRooView : Object
6 private Xcls_WindowRooView _this;
8 public static Xcls_WindowRooView singleton()
10 if (_WindowRooView == null) {
11 _WindowRooView= new Xcls_WindowRooView();
13 return _WindowRooView;
15 public Xcls_notebook notebook;
16 public Xcls_label_preview label_preview;
17 public Xcls_label_code label_code;
18 public Xcls_paned paned;
19 public Xcls_viewbox viewbox;
20 public Xcls_AutoRedraw AutoRedraw;
21 public Xcls_view view;
22 public Xcls_inspectorcontainer inspectorcontainer;
23 public Xcls_sourceviewscroll sourceviewscroll;
24 public Xcls_sourceview sourceview;
25 public Xcls_buffer buffer;
26 public Xcls_keystate keystate;
27 public Xcls_search_entry search_entry;
28 public Xcls_search_results search_results;
29 public Xcls_nextBtn nextBtn;
30 public Xcls_backBtn backBtn;
31 public Xcls_search_settings search_settings;
32 public Xcls_case_sensitive case_sensitive;
33 public Xcls_regex regex;
34 public Xcls_multiline multiline;
37 public Gtk.Widget lastObj;
38 public Xcls_MainWindow main_window;
39 public int last_error_counter;
40 public int last_search_end;
41 public GtkSource.SearchContext searchcontext;
42 public JsRender.JsRender file;
45 public Xcls_WindowRooView()
48 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
52 this.last_error_counter = 0;
53 this.last_search_end = 0;
57 this.el.hexpand = true;
58 this.el.vexpand = true;
59 new Xcls_notebook( _this );
60 this.el.append( _this.notebook.el );
63 // user defined functions
64 public void loadFile (JsRender.JsRender file)
67 this.view.renderJS(true);
68 this.notebook.el.page = 0;// gtk preview
69 this.sourceview.loadFile();
70 this.last_error_counter = -1;
71 this.updateErrorMarks();
73 public void highlightNodeAtLine (int ln) {
80 var node = _this.file.lineToNode(ln+1);
83 //print("can not find node\n");
86 var prop = node.lineToProp(ln+1);
87 print("prop : %s", prop == null ? "???" : prop.name);
90 // ---------- this selects the tree's node...
92 var ltree = _this.main_window.windowstate.left_tree;
93 ltree.model.selectNode(node);
95 //_this.sourceview.allow_node_scroll = false; /// block node scrolling..
98 //print("changing cursor on tree..\n");
102 // let's try allowing editing on the methods.
103 // a little klunky at present..
104 _this.sourceview.prop_selected = "";
107 //see if we can find it..
108 var kv = prop.split(":");
111 //var k = prop.get_key(kv[1]);
112 // fixme -- need to determine if it's an editable property...
113 _this.sourceview.prop_selected = prop;
115 } else if (kv[0] == "l") {
116 _this.sourceview.prop_selected = prop;
121 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
122 _this.sourceview.nodeSelected(node,false);
124 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
125 // GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
126 // this.allow_node_scroll = true;
142 public void requestRedraw () {
143 this.view.renderJS(false);
144 this.sourceview.loadFile();
146 public void forwardSearch (bool change_focus) {
148 if (this.searchcontext == null) {
151 this.notebook.el.page = 1;
152 Gtk.TextIter beg, st,en;
153 bool has_wrapped_around;
154 var buf = this.sourceview.el.get_buffer();
155 buf.get_iter_at_offset(out beg, this.last_search_end);
156 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
157 this.last_search_end = 0;
160 this.last_search_end = en.get_offset();
162 this.sourceview.el.grab_focus();
164 buf.place_cursor(st);
168 this.sourceview.el.scroll_to_iter(st, 0.0f, true, 0.0f, 0.5f);
171 var ln = st.get_line();
173 this.highlightNodeAtLine(ln);
175 public void backSearch (bool change_focus) {
177 if (this.searchcontext == null) {
181 Gtk.TextIter beg, st,en;
182 bool has_wrapped_around;
183 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
185 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
187 this.last_search_end = 0;
190 this.last_search_end = en.get_offset();
192 this.sourceview.el.grab_focus();
194 this.buffer.el.place_cursor(st);
195 this.sourceview.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
196 var ln = st.get_line();
197 this.highlightNodeAtLine(ln);
201 public int search (string in_txt) {
202 this.notebook.el.page = 1;
206 var s = new GtkSource.SearchSettings();
207 s.case_sensitive = _this.case_sensitive.el.active;
208 s.regex_enabled = _this.regex.el.active;
209 s.wrap_around = false;
211 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
212 this.searchcontext.set_highlight(true);
215 if (_this.multiline.el.active) {
216 txt = in_txt.replace("\\n", "\n");
219 s.set_search_text(txt);
220 Gtk.TextIter beg, st,en;
221 bool has_wrapped_around;
222 this.buffer.el.get_start_iter(out beg);
223 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
224 this.last_search_end = 0;
226 return this.searchcontext.get_occurrences_count();
232 public void createThumb () {
235 if (this.file == null) {
239 if (this.notebook.el.page > 0 ) {
243 this.file.widgetToIcon(this.view.el);
250 public void updateErrorMarks () {
254 var buf = _this.buffer.el;
257 buf.get_bounds (out start, out end);
261 GLib.debug("highlight errors");
263 // we should highlight other types of errors..
268 if (_this.file == null) {
269 GLib.debug("file is null?");
273 var ar = this.file.getErrors();
275 buf.remove_tag_by_name ("ERR", start, end);
276 buf.remove_tag_by_name ("WARN", start, end);
277 buf.remove_tag_by_name ("DEPR", start, end);
278 buf.remove_source_marks (start, end, "ERR");
279 buf.remove_source_marks (start, end, "WARN");
280 buf.remove_source_marks (start, end, "DEPR");
281 this.last_error_counter = file.error_counter ;
282 GLib.debug("higjlight has no errors");
285 if (this.last_error_counter == file.error_counter) {
289 var tlines = buf.get_line_count () +1;
293 buf.remove_source_marks (start, end, "ERR");
294 buf.remove_source_marks (start, end, "WARN");
295 buf.remove_source_marks (start, end, "DEPR");
296 buf.remove_tag_by_name ("ERR", start, end);
297 buf.remove_tag_by_name ("WARN", start, end);
298 buf.remove_tag_by_name ("DEPR", start, end);
299 foreach(var diag in ar) {
303 // print("get inter\n");
304 var eline = (int)diag.range.start.line ;
305 var eline_to = (int)diag.range.end.line;
306 if (eline > tlines || eline < 0) {
311 buf.get_iter_at_line( out iter, eline);
313 buf.get_iter_at_line_offset( out start,
314 eline, (int)diag.range.start.character);
315 buf.get_iter_at_line_offset( out end,
316 eline_to, (int)diag.range.end.character);
318 buf.apply_tag_by_name(diag.category, start, end);
321 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
322 buf.create_source_mark( msg, diag.category, iter);
323 GLib.debug("set line %d to %s", eline, msg);
324 //this.marks.set(eline, msg);
326 this.last_error_counter = file.error_counter ;
333 public void scroll_to_line (int line) {
336 GLib.Timeout.add(100, () => {
338 this.notebook.el.set_current_page( 1 );
341 var buf = this.sourceview.el.get_buffer();
343 var sbuf = (GtkSource.Buffer) buf;
347 sbuf.get_iter_at_line(out iter, line);
348 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
354 public class Xcls_notebook : Object
356 public Gtk.Notebook el;
357 private Xcls_WindowRooView _this;
363 public Xcls_notebook(Xcls_WindowRooView _owner )
366 _this.notebook = this;
367 this.el = new Gtk.Notebook();
371 // set gobject values
372 this.el.vexpand = true;
373 new Xcls_label_preview( _this );
374 new Xcls_label_code( _this );
375 new Xcls_paned( _this );
376 this.el.append_page ( _this.paned.el , _this.label_preview.el );
377 var child_4 = new Xcls_Box12( _this );
379 this.el.append_page ( child_4.el , _this.label_code.el );
382 // user defined functions
384 public class Xcls_label_preview : Object
387 private Xcls_WindowRooView _this;
393 public Xcls_label_preview(Xcls_WindowRooView _owner )
396 _this.label_preview = this;
397 this.el = new Gtk.Label( "Preview" );
401 // set gobject values
404 // user defined functions
407 public class Xcls_label_code : Object
410 private Xcls_WindowRooView _this;
416 public Xcls_label_code(Xcls_WindowRooView _owner )
419 _this.label_code = this;
420 this.el = new Gtk.Label( "Preview Generated Code" );
424 // set gobject values
427 // user defined functions
430 public class Xcls_paned : Object
433 private Xcls_WindowRooView _this;
439 public Xcls_paned(Xcls_WindowRooView _owner )
443 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
447 // set gobject values
448 this.el.vexpand = true;
449 new Xcls_viewbox( _this );
450 this.el.set_start_child ( _this.viewbox.el );
451 new Xcls_inspectorcontainer( _this );
452 this.el.set_end_child ( _this.inspectorcontainer.el );
455 // user defined functions
457 public class Xcls_viewbox : Object
460 private Xcls_WindowRooView _this;
466 public Xcls_viewbox(Xcls_WindowRooView _owner )
469 _this.viewbox = this;
470 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
474 // set gobject values
475 this.el.homogeneous = false;
476 this.el.vexpand = true;
477 var child_1 = new Xcls_Box6( _this );
479 this.el.append( child_1.el );
480 new Xcls_view( _this );
481 this.el.append( _this.view.el );
484 // user defined functions
486 public class Xcls_Box6 : Object
489 private Xcls_WindowRooView _this;
495 public Xcls_Box6(Xcls_WindowRooView _owner )
498 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
502 // set gobject values
503 this.el.homogeneous = true;
504 this.el.height_request = 20;
505 this.el.vexpand = false;
506 var child_1 = new Xcls_Button7( _this );
508 this.el.append( child_1.el );
509 new Xcls_AutoRedraw( _this );
510 this.el.append( _this.AutoRedraw.el );
511 var child_3 = new Xcls_Button9( _this );
513 this.el.append( child_3.el );
516 // user defined functions
518 public class Xcls_Button7 : Object
520 public Gtk.Button el;
521 private Xcls_WindowRooView _this;
527 public Xcls_Button7(Xcls_WindowRooView _owner )
530 this.el = new Gtk.Button();
534 // set gobject values
535 this.el.label = "Redraw";
538 this.el.clicked.connect( ( ) => {
539 _this.view.renderJS( true);
543 // user defined functions
546 public class Xcls_AutoRedraw : Object
548 public Gtk.CheckButton el;
549 private Xcls_WindowRooView _this;
555 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
558 _this.AutoRedraw = this;
559 this.el = new Gtk.CheckButton();
563 // set gobject values
564 this.el.active = true;
565 this.el.label = "Auto Redraw On";
568 this.el.toggled.connect( (state) => {
569 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
573 // user defined functions
576 public class Xcls_Button9 : Object
578 public Gtk.Button el;
579 private Xcls_WindowRooView _this;
585 public Xcls_Button9(Xcls_WindowRooView _owner )
588 this.el = new Gtk.Button();
592 // set gobject values
593 this.el.label = "Full Redraw";
596 this.el.clicked.connect( () => {
597 _this.view.redraws = 99;
598 // _this.view.el.web_context.clear_cache();
599 //_this.view.renderJS(true);
600 FakeServerCache.clear();
606 // user defined functions
610 public class Xcls_view : Object
612 public WebKit.WebView el;
613 private Xcls_WindowRooView _this;
617 public WebKit.WebInspector inspector;
618 public bool pendingRedraw;
620 public bool refreshRequired;
622 public string runhtml;
623 public string renderedData;
624 public GLib.DateTime lastRedraw;
627 public Xcls_view(Xcls_WindowRooView _owner )
631 this.el = new WebKit.WebView();
634 this.pendingRedraw = false;
636 this.refreshRequired = false;
639 this.renderedData = "";
640 this.lastRedraw = null;
642 // set gobject values
643 this.el.vexpand = true;
648 // this may not work!?
649 var settings = this.el.get_settings();
650 settings.enable_developer_extras = true;
653 var fs= new FakeServer(this.el);
655 // this was an attempt to change the url perms.. did not work..
656 // settings.enable_file_access_from_file_uris = true;
657 // settings.enable_offline_web_application_cache - true;
658 // settings.enable_universal_access_from_file_uris = true;
665 // FIXME - base url of script..
666 // we need it so some of the database features work.
667 this.el.load_html( "Render not ready" ,
668 //fixme - should be a config option!
669 // or should we catch stuff and fix it up..
670 "http://localhost/app.Builder/"
674 //this.el.open('file:///' + __script_path__ + '/../builder.html');
679 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
680 null, // list of targets
681 Gdk.DragAction.COPY // what to do with data after dropped
684 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
685 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
687 GLib.Timeout.add_seconds(1, () =>{
688 //print("run refresh?");
689 if (this.el == null) {
700 this.el.script_dialog.connect( (dialog) => {
702 if (this.el == null) {
706 var msg = dialog.get_message();
707 if (msg.length < 4) {
711 //GLib.debug("script dialog got %s", msg);
713 if (msg.substring(0,4) != "IPC:") {
716 var ar = msg.split(":", 3);
724 // GLib.debug("GOT saveHTML %d", ar[2].length);
725 _this.file.saveHTML(ar[2]);
734 this.el.ready_to_show.connect( ( ) => {
735 this.initInspector();
738 this.el.load_changed.connect( (le) => {
739 if (le != WebKit.LoadEvent.FINISHED) {
742 if (this.runjs.length < 1) {
745 // this.el.run_javascript(this.runjs, null);
746 FakeServerCache.remove( this.runjs);
751 // user defined functions
752 public void initInspector () {
756 // this.inspector.open_window.connect(() => {
757 this.inspector = this.el.get_inspector();
759 this.inspector.open_window.connect(() => {
760 print("inspector attach\n");
761 var wv = this.inspector.get_web_view();
763 print("got inspector web view\n");
765 var cn = _this.inspectorcontainer.el.get_first_child();
767 _this.inspectorcontainer.el.remove(cn);
770 _this.inspectorcontainer.el.append(wv);
773 print("got inspector web view FAILED\n");
774 //this.inspector.close();
776 //this.inspector = null;
783 this.inspector.show();
788 public void renderJS (bool force) {
790 // this is the public redraw call..
791 // we refresh in a loop privately..
792 var autodraw = _this.AutoRedraw.el.active;
793 if (!autodraw && !force) {
794 print("Skipping redraw - no force, and autodraw off");
798 this.refreshRequired = true;
801 public void reInit () {
803 // if this happens destroy the webkit..
805 this.el.stop_loading();
807 if (_this.viewbox.el.get_parent() == null) {
812 _this.viewbox.el.remove(_this.viewcontainer.el);
813 //_this.paned.el.remove(_this.inspectorcontainer.el);
815 // destory seems to cause problems.
817 //_this.viewcontainer.el.destroy();
818 //_this.inspectorcontainer.el.destroy();
819 var inv =new Xcls_inspectorcontainer(_this);
821 _this.paned.el.set_end_child(inv.el);
822 _this.inspectorcontainer = inv;
825 var nv =new Xcls_viewcontainer(_this);
827 _this.viewbox.el.append(nv.el);
829 _this.viewcontainer = nv;
832 //while(Gtk.events_pending ()) Gtk.main_iteration ();
833 //_this.view.renderJS(true);
834 _this.view.refreshRequired = true;
838 public void runRefresh ()
840 // this is run every 2 seconds from the init..
843 if (!this.refreshRequired) {
844 // print("no refresh required");
848 if (this.lastRedraw != null) {
849 // do not redraw if last redraw was less that 5 seconds ago.
850 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
855 if (_this.file == null) {
860 this.refreshRequired = false;
861 // print("HTML RENDERING");
864 //this.get('/BottomPane').el.show();
865 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
866 _this.file.webkit_page_id = this.el.get_page_id();
868 var js = _this.file.toSourcePreview();
877 var project = (Project.Roo) _this.file.project;
879 //print (project.fn);
880 // set it to non-empty.
882 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
885 // this.runhtml = this.runhtml || '';
888 // then we need to reload the browser using
889 // load_html_string..
891 // then trigger a redraw once it's loaded..
892 this.pendingRedraw = true;
894 var runhtml = "<script type=\"text/javascript\">\n" ;
898 GLib. File.new_for_uri("resource:///html/roo.builder.js").load_contents(null, out builderhtml, null);
903 runhtml += (string) builderhtml + "\n";
904 runhtml += "</script>\n" ;
906 // fix to make sure they are the same..
907 this.runhtml = project.runhtml;
908 // need to modify paths
911 var base_template = project.base_template;
912 var f = GLib. File.new_for_uri("resource:///html/" + base_template);
914 if (base_template.length > 0 && !f.query_exists(null)) {
916 GLib.debug("invalid base_template name - using default: %s", base_template);
917 f = GLib. File.new_for_uri("resource:///html/roo.builder.html");
921 f.load_contents(null, out inhtml, null);
927 this.renderedData = js;
930 string js_src = js + "
931 Roo.onReady(function() {
932 if (" + _this.file.name +".show) {
933 " + _this.file.name +".show({});
935 Builder.saveHTML.defer(100, Builder);
938 Roo.XComponent.build();
941 // print("render js: " + js);
943 // console.log('not loaded yet');
945 this.lastRedraw = new DateTime.now_local();
948 //this.runjs = js_src;
949 var fc = FakeServerCache.factory_with_data(js_src);
950 this.runjs = fc.fname;
951 var html = (string) inhtml;
952 html = html.replace("</head>", runhtml + this.runhtml +
953 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
954 // "<script type=\"text/javascript\">\n" +
959 //print("LOAD HTML " + html);
961 var rootURL = project.rootURL;
965 this.el.load_html( html ,
966 //fixme - should be a config option!
967 (rootURL.length > 0 ? rootURL : "xhttp://localhost/roobuilder/")
969 this.initInspector();
970 // force the inspector...
971 // this.initInspector();
973 // - no need for this, the builder javascript will call it when build is complete
974 //GLib.Timeout.add_seconds(1, () => {
975 // this.el.run_javascript("Builder.saveHTML()",null);
978 // print( "before render" + this.lastRedraw);
979 // print( "after render" + (new Date()));
985 public class Xcls_inspectorcontainer : Object
988 private Xcls_WindowRooView _this;
994 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
997 _this.inspectorcontainer = this;
998 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1002 // set gobject values
1003 this.el.vexpand = true;
1006 // user defined functions
1010 public class Xcls_Box12 : Object
1013 private Xcls_WindowRooView _this;
1019 public Xcls_Box12(Xcls_WindowRooView _owner )
1022 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1026 // set gobject values
1027 this.el.vexpand = true;
1028 new Xcls_sourceviewscroll( _this );
1029 this.el.append( _this.sourceviewscroll.el );
1030 var child_2 = new Xcls_Box18( _this );
1032 this.el.append( child_2.el );
1035 // user defined functions
1037 public class Xcls_sourceviewscroll : Object
1039 public Gtk.ScrolledWindow el;
1040 private Xcls_WindowRooView _this;
1046 public Xcls_sourceviewscroll(Xcls_WindowRooView _owner )
1049 _this.sourceviewscroll = this;
1050 this.el = new Gtk.ScrolledWindow();
1054 // set gobject values
1055 this.el.vexpand = true;
1056 new Xcls_sourceview( _this );
1057 this.el.set_child ( _this.sourceview.el );
1060 // user defined functions
1062 public class Xcls_sourceview : Object
1064 public GtkSource.View el;
1065 private Xcls_WindowRooView _this;
1069 public int editable_start_pos;
1070 public bool loading;
1071 public bool button_is_pressed;
1072 public string prop_selected;
1073 public Gtk.CssProvider? css;
1074 public bool key_is_pressed;
1075 public JsRender.Node? node_selected;
1078 public Xcls_sourceview(Xcls_WindowRooView _owner )
1081 _this.sourceview = this;
1082 this.el = new GtkSource.View();
1085 this.editable_start_pos = -1;
1086 this.loading = true;
1087 this.button_is_pressed = false;
1088 this.prop_selected = "";
1090 this.key_is_pressed = false;
1091 this.node_selected = null;
1093 // set gobject values
1094 this.el.name = "roo-view";
1095 this.el.editable = false;
1096 this.el.show_line_marks = true;
1097 this.el.show_line_numbers = true;
1098 this.el.css_classes = { "code-editor" };
1099 new Xcls_buffer( _this );
1100 this.el.set_buffer ( _this.buffer.el );
1101 new Xcls_keystate( _this );
1102 this.el.add_controller ( _this.keystate.el );
1103 var child_3 = new Xcls_EventControllerScroll17( _this );
1105 this.el.add_controller( child_3.el );
1113 this.loading = true;
1114 //var buf = this.el.get_buffer();
1115 //buf.notify.connect(this.onCursorChanged);
1118 var attrs = new GtkSource.MarkAttributes();
1119 attrs.set_icon_name ( "process-stop");
1120 attrs.query_tooltip_text.connect(( mark) => {
1121 //print("tooltip query? %s\n", mark.name);
1125 this.el.set_mark_attributes ("ERR", attrs, 1);
1127 var wattrs = new GtkSource.MarkAttributes();
1128 wattrs.set_icon_name ( "process-stop");
1129 wattrs.query_tooltip_text.connect(( mark) => {
1130 //print("tooltip query? %s\n", mark.name);
1134 this.el.set_mark_attributes ("WARN", wattrs, 1);
1138 var dattrs = new GtkSource.MarkAttributes();
1139 dattrs.set_icon_name ( "process-stop");
1140 dattrs.query_tooltip_text.connect(( mark) => {
1141 //print("tooltip query? %s\n", mark.name);
1145 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1148 var gattrs = new GtkSource.MarkAttributes();
1149 var grey = Gdk.RGBA();
1150 grey.parse ( "#ccc");
1151 gattrs.set_background ( grey);
1154 this.el.set_mark_attributes ("grey", gattrs, 1);
1163 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
1165 //GLib.debug("query tooltip");
1169 var yoff = (int) _this.sourceviewscroll.el.vadjustment.value;
1171 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
1173 var l = iter.get_line();
1174 //GLib.debug("query tooltip line %d", (int) l);
1175 var marks = _this.buffer.el.get_source_marks_at_line(l, null);
1176 //GLib.debug("query tooltip line marks %d", (int) marks.length());
1178 marks.@foreach((m) => {
1179 //GLib.debug("got mark %s", m.name);
1180 str += (str.length > 0 ? "\n" : "") + m.name;
1182 // true if there is a mark..
1183 if (str.length > 0 ) {
1184 tooltip.set_text( str);
1186 return str.length > 0 ? true : false;
1191 // user defined functions
1192 public void loadFile ( ) {
1193 this.loading = true;
1196 // get the cursor and scroll position....
1197 var buf = this.el.get_buffer();
1198 var cpos = buf.cursor_position;
1200 print("BEFORE LOAD cursor = %d\n", cpos);
1202 var vadj_pos = this.el.get_vadjustment().get_value();
1211 if (_this.file == null || _this.file.xtype != "Roo") {
1212 print("xtype != Roo");
1213 this.loading = false;
1217 // get the string from the rendered tree...
1219 var str = _this.file.toSource();
1221 // print("setting str %d\n", str.length);
1222 buf.set_text(str, str.length);
1223 var lm = GtkSource.LanguageManager.get_default();
1225 //?? is javascript going to work as js?
1227 ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));
1230 _this.main_window.windowstate.updateErrorMarksAll();
1232 // restore the cursor position?
1233 // after reloading the contents.
1234 GLib.Timeout.add(500, () => {
1235 _this.buffer.in_cursor_change = true;
1236 print("RESORTING cursor to = %d\n", cpos);
1237 Gtk.TextIter cpos_iter;
1238 buf.get_iter_at_offset(out cpos_iter, cpos);
1239 buf.place_cursor(cpos_iter);
1241 this.el.get_vadjustment().set_value(vadj_pos);;
1242 _this.buffer.in_cursor_change = false;
1246 //_this.buffer.checkSyntax();
1250 this.loading = false;
1251 _this.buffer.dirty = false;
1253 public void nodeSelected (JsRender.Node? sel, bool scroll) {
1259 // this is connected in widnowstate
1260 print("Roo-view - node selected\n");
1261 var buf = this.el.get_buffer();
1263 var sbuf = (GtkSource.Buffer) buf;
1268 // clear all the marks..
1272 sbuf.get_bounds (out start, out end);
1273 sbuf.remove_source_marks (start, end, "grey");
1275 this.node_selected = sel;
1277 // no highlighting..
1281 sbuf.get_iter_at_line(out iter, sel.line_start);
1284 Gtk.TextIter cur_iter;
1285 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1287 //var cur_line = cur_iter.get_line();
1288 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1291 if (! _this.buffer.in_cursor_change) {
1292 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1297 for (var i = 0; i < buf.get_line_count();i++) {
1298 if (i < sel.line_start || i > sel.line_end) {
1300 sbuf.get_iter_at_line(out iter, i);
1301 sbuf.create_source_mark(null, "grey", iter);
1309 public void updateGreySelection (bool scroll) {
1310 var sel = this.node_selected;
1311 print("node selected\n");
1312 var buf = this.el.get_buffer();
1313 var sbuf = (GtkSource.Buffer) buf;
1316 this.clearGreySelection();
1321 print("no selected node\n");
1322 // no highlighting..
1326 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1328 sbuf.get_iter_at_line(out iter, sel.line_start);
1331 Gtk.TextIter cur_iter;
1332 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1334 var cursor_at_line = cur_iter.get_line();
1337 //var cur_line = cur_iter.get_line();
1338 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1342 print("scrolling to node -- should occur on node picking.\n");
1343 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1346 var start_line = sel.line_start;
1347 var end_line = sel.line_end;
1350 this.el.editable = false;
1352 //var colon_pos = 0;
1354 this.editable_start_pos = -1;
1356 // now if we have selected a property...
1357 if (this.prop_selected.length> 0 ) {
1360 if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1361 start_line = nstart;
1363 // this.el.editable = true; << cant do this!!?
1364 print("start line = %d, end line = %d\n", start_line, end_line);
1366 // see if we are 'right of ':'
1367 // get an iter for the start of the line.
1368 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1369 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1370 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1375 if (end_first_line_iter.forward_to_line_end()) {
1376 var first_line = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1378 print("first line = %s\n", first_line);
1379 if (first_line.contains(":")) {
1380 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1381 print("colon_pos = %d\n", this.editable_start_pos);
1385 //Gtk.TextIter colon_iter;
1386 //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1387 //sbuf.create_source_mark(null, "active_text", colon_iter);
1392 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1393 //if (start_line - 1 == cursor_at_line) {
1394 // should be ok - current_posssion can not be less than '-1'...
1395 if (sbuf.cursor_position < this.editable_start_pos) {
1397 print("cursor is before start pos.. - turn off editable...\n");
1398 //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1399 //print("before cursor string = %s\n", before_cursor_string);
1400 //if (!before_cursor_string.contains(":")) {
1401 this.el.editable = false;
1410 print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line);
1415 print("checking selection\n");
1418 // check selection - if it's out of 'bounds'
1419 if (this.el.editable && sbuf.get_has_selection()) {
1420 Gtk.TextIter sel_start_iter, sel_end_iter;
1421 sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1423 if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1424 sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
1426 this.el.editable = false;
1428 if (this.editable_start_pos > 0 &&
1429 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1432 this.el.editable = false;
1442 for (var i = 0; i < buf.get_line_count();i++) {
1443 if (i < (start_line -1) || i > (end_line -1)) {
1445 sbuf.get_iter_at_line(out iter, i);
1446 sbuf.create_source_mark(null, "grey", iter);
1451 if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1452 Gtk.TextIter cpos_iter;
1453 buf.get_iter_at_line(out cpos_iter, start_line);
1455 buf.place_cursor(cpos_iter);
1460 public void clearGreySelection () {
1461 // clear all the marks..
1462 var sbuf = (GtkSource.Buffer)this.el.buffer;
1467 sbuf.get_bounds (out start, out end);
1468 sbuf.remove_source_marks (start, end, "grey");
1472 public string toString () {
1475 this.el.get_buffer().get_start_iter(out s);
1476 this.el.get_buffer().get_end_iter(out e);
1477 var ret = this.el.get_buffer().get_text(s,e,true);
1478 //print("TO STRING? " + ret);
1482 public class Xcls_buffer : Object
1484 public GtkSource.Buffer el;
1485 private Xcls_WindowRooView _this;
1489 public int error_line;
1490 public bool in_cursor_change;
1492 public int last_line;
1495 public Xcls_buffer(Xcls_WindowRooView _owner )
1498 _this.buffer = this;
1499 this.el = new GtkSource.Buffer( null );
1502 this.error_line = -1;
1503 this.in_cursor_change = false;
1505 this.last_line = -1;
1507 // set gobject values
1513 buf.create_tag ("bold", "weight", Pango.Weight.BOLD);
1514 buf.create_tag ("type", "weight", Pango.Weight.BOLD, "foreground", "#204a87");
1515 buf.create_tag ("keyword", "weight", Pango.Weight.BOLD, "foreground", "#a40000");
1516 buf.create_tag ("text", "weight", Pango.Weight.NORMAL, "foreground", "#729fcf");
1517 buf.create_tag ("number", "weight", Pango.Weight.BOLD, "foreground", "#ad7fa8");
1518 buf.create_tag ("method", "weight", Pango.Weight.BOLD, "foreground", "#729fcf");
1519 buf.create_tag ("property", "weight", Pango.Weight.BOLD, "foreground", "#BC1F51");
1520 buf.create_tag ("variable", "weight", Pango.Weight.BOLD, "foreground", "#A518B5");
1523 buf.create_tag ("ERR", "weight", Pango.Weight.BOLD, "background", "pink");
1524 buf.create_tag ("WARN", "weight", Pango.Weight.BOLD, "background", "#ABF4EB");
1525 buf.create_tag ("DEPR", "weight", Pango.Weight.BOLD, "background", "#EEA9FF");
1529 this.el.cursor_moved.connect( ( ) => {
1530 GLib.debug("cursor moved called");
1533 if (this.in_cursor_change ) {
1534 GLib.debug("cursor changed : %d [ignoring nested call)", this.el.cursor_position);
1538 GLib.debug("cursor changed : %d", this.el.cursor_position);
1540 this.el.get_iter_at_offset(out cpos, this.el.cursor_position);
1542 var ln = cpos.get_line();
1543 if (this.last_line == ln ){
1546 this.last_line = ln;
1547 var node = _this.file.lineToNode(ln);
1550 print("can not find node\n");
1553 this.in_cursor_change = true;
1554 var ltree = _this.main_window.windowstate.left_tree;
1555 ltree.model.selectNode(node);
1556 this.in_cursor_change = false;
1558 this.el.changed.connect( () => {
1562 // _this.save_button.el.sensitive = true;
1563 ///?? has changed occured during loading?
1565 // only trigger this if
1570 if (_this.sourceview.loading) {
1576 print("- PREVIEW EDITOR CHANGED--");
1579 // this.checkSyntax(); // this calls backs and highlights errors.. in theory...
1583 if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1584 print("button or key not pressed to generate change?!\n");
1589 // what are we editing??
1590 if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length < 1) {
1594 // find the colon on the first line...
1596 if (_this.sourceview.editable_start_pos > -1) {
1598 var buf = (GtkSource.Buffer)_this.sourceview.el.get_buffer();
1600 //print("cursor changed : %d\n", buf.cursor_position);
1601 Gtk.TextIter spos,epos;
1602 buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1603 buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1606 var line = spos.get_line();
1607 var endline = buf.get_line_count();
1608 while (line < endline) {
1610 buf.get_iter_at_line(out epos, line);
1611 if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1612 buf.get_iter_at_line(out epos, line);
1619 print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1621 // in theory the last char will be '}' or '},' .. or ','
1622 // we should chop the ',' of the end...
1623 var str = buf.get_text(spos, epos, false);
1624 print("got string\n%s\n", str);
1632 // user defined functions
1633 public string toString () {
1637 this.el.get_start_iter(out s);
1638 this.el.get_end_iter(out e);
1639 var ret = this.el.get_text(s,e,true);
1640 //print("TO STRING? " + ret);
1645 public class Xcls_keystate : Object
1647 public Gtk.EventControllerKey el;
1648 private Xcls_WindowRooView _this;
1652 public bool is_control;
1655 public Xcls_keystate(Xcls_WindowRooView _owner )
1658 _this.keystate = this;
1659 this.el = new Gtk.EventControllerKey();
1662 this.is_control = false;
1664 // set gobject values
1667 this.el.key_released.connect( (keyval, keycode, state) => {
1670 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1671 this.is_control = false;
1674 this.el.key_pressed.connect( (keyval, keycode, state) => {
1676 if (keyval == Gdk.Key.Control_L || keyval == Gdk.Key.Control_R) {
1677 this.is_control = true;
1680 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1681 GLib.debug("SAVE: ctrl-g pressed");
1682 _this.forwardSearch(true);
1685 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1686 GLib.debug("SAVE: ctrl-f pressed");
1687 _this.search_entry.el.grab_focus();
1691 //this.button_is_pressed = true;
1693 // print(event.key.keyval)
1701 // user defined functions
1704 public class Xcls_EventControllerScroll17 : Object
1706 public Gtk.EventControllerScroll el;
1707 private Xcls_WindowRooView _this;
1711 public double distance;
1714 public Xcls_EventControllerScroll17(Xcls_WindowRooView _owner )
1717 this.el = new Gtk.EventControllerScroll( Gtk.EventControllerScrollFlags.VERTICAL );
1720 this.distance = 0.0f;
1722 // set gobject values
1725 this.el.scroll.connect( (dx, dy) => {
1726 if (!_this.keystate.is_control) {
1729 //GLib.debug("scroll %f", dy);
1731 this.distance += dy;
1732 if (this.distance < -1) {
1734 BuilderApplication.settings.editor_font_size ++;
1737 if (this.distance > 1) {
1738 BuilderApplication.settings.editor_font_size --;
1746 // user defined functions
1751 public class Xcls_Box18 : Object
1754 private Xcls_WindowRooView _this;
1760 public Xcls_Box18(Xcls_WindowRooView _owner )
1763 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1767 // set gobject values
1768 this.el.homogeneous = false;
1769 this.el.vexpand = false;
1770 new Xcls_search_entry( _this );
1771 this.el.append( _this.search_entry.el );
1772 new Xcls_search_results( _this );
1773 this.el.append( _this.search_results.el );
1774 new Xcls_nextBtn( _this );
1775 this.el.append( _this.nextBtn.el );
1776 new Xcls_backBtn( _this );
1777 this.el.append( _this.backBtn.el );
1778 var child_5 = new Xcls_MenuButton24( _this );
1780 this.el.append( child_5.el );
1783 // user defined functions
1785 public class Xcls_search_entry : Object
1787 public Gtk.SearchEntry el;
1788 private Xcls_WindowRooView _this;
1794 public Xcls_search_entry(Xcls_WindowRooView _owner )
1797 _this.search_entry = this;
1798 this.el = new Gtk.SearchEntry();
1802 // set gobject values
1803 this.el.name = "roo-search-entry";
1804 this.el.hexpand = true;
1805 this.el.placeholder_text = "Press enter to search";
1806 var child_1 = new Xcls_EventControllerKey20( _this );
1808 this.el.add_controller( child_1.el );
1811 this.el.search_changed.connect( ( ) => {
1813 _this.search(_this.search_entry.el.text);
1814 _this.search_results.updateResults();
1816 GLib.Timeout.add_seconds(1,() => {
1817 _this.search_results.updateResults();
1823 // user defined functions
1824 public void forwardSearch (bool change_focus) {
1827 _this.forwardSearch(change_focus);
1831 switch(_this.windowstate.state) {
1832 case WindowState.State.CODEONLY:
1833 //case WindowState.State.CODE:
1834 // search the code being edited..
1835 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1838 case WindowState.State.PREVIEW:
1839 if (_this.windowstate.file.xtype == "Gtk") {
1840 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1842 _this.windowstate.window_rooview.forwardSearch(change_focus);
1851 public class Xcls_EventControllerKey20 : Object
1853 public Gtk.EventControllerKey el;
1854 private Xcls_WindowRooView _this;
1860 public Xcls_EventControllerKey20(Xcls_WindowRooView _owner )
1863 this.el = new Gtk.EventControllerKey();
1867 // set gobject values
1870 this.el.key_pressed.connect( (keyval, keycode, state) => {
1872 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1873 GLib.debug("SAVE: ctrl-g pressed");
1874 _this.forwardSearch(true);
1879 if (keyval == Gdk.Key.Return) {
1880 _this.forwardSearch(true);
1886 // print(event.key.keyval)
1892 // user defined functions
1896 public class Xcls_search_results : Object
1898 public Gtk.Label el;
1899 private Xcls_WindowRooView _this;
1905 public Xcls_search_results(Xcls_WindowRooView _owner )
1908 _this.search_results = this;
1909 this.el = new Gtk.Label( "No Results" );
1913 // set gobject values
1914 this.el.margin_end = 4;
1915 this.el.margin_start = 4;
1918 // user defined functions
1919 public void updateResults () {
1920 this.el.visible = true;
1922 var res = _this.searchcontext.get_occurrences_count();
1924 _this.search_results.el.label = "??? Matches";
1928 _this.nextBtn.el.sensitive = false;
1929 _this.backBtn.el.sensitive = false;
1932 _this.search_results.el.label = "%d Matches".printf(res);
1933 _this.nextBtn.el.sensitive = true;
1934 _this.backBtn.el.sensitive = true;
1937 _this.search_results.el.label = "No Matches";
1942 public class Xcls_nextBtn : Object
1944 public Gtk.Button el;
1945 private Xcls_WindowRooView _this;
1949 public bool always_show_image;
1952 public Xcls_nextBtn(Xcls_WindowRooView _owner )
1955 _this.nextBtn = this;
1956 this.el = new Gtk.Button();
1959 this.always_show_image = true;
1961 // set gobject values
1962 this.el.icon_name = "go-down";
1963 this.el.sensitive = false;
1966 this.el.clicked.connect( (event) => {
1968 _this.forwardSearch(true);
1973 // user defined functions
1976 public class Xcls_backBtn : Object
1978 public Gtk.Button el;
1979 private Xcls_WindowRooView _this;
1983 public bool always_show_image;
1986 public Xcls_backBtn(Xcls_WindowRooView _owner )
1989 _this.backBtn = this;
1990 this.el = new Gtk.Button();
1993 this.always_show_image = true;
1995 // set gobject values
1996 this.el.icon_name = "go-up";
1997 this.el.sensitive = false;
2000 this.el.clicked.connect( (event) => {
2002 _this.backSearch(true);
2008 // user defined functions
2011 public class Xcls_MenuButton24 : Object
2013 public Gtk.MenuButton el;
2014 private Xcls_WindowRooView _this;
2018 public bool always_show_image;
2021 public Xcls_MenuButton24(Xcls_WindowRooView _owner )
2024 this.el = new Gtk.MenuButton();
2027 this.always_show_image = true;
2029 // set gobject values
2030 this.el.icon_name = "emblem-system";
2031 new Xcls_search_settings( _this );
2032 this.el.popover = _this.search_settings.el;
2035 // user defined functions
2037 public class Xcls_search_settings : Object
2039 public Gtk.Popover el;
2040 private Xcls_WindowRooView _this;
2046 public Xcls_search_settings(Xcls_WindowRooView _owner )
2049 _this.search_settings = this;
2050 this.el = new Gtk.Popover();
2054 // set gobject values
2055 var child_1 = new Xcls_Box26( _this );
2057 this.el.child = child_1.el;
2060 // user defined functions
2062 public class Xcls_Box26 : Object
2065 private Xcls_WindowRooView _this;
2071 public Xcls_Box26(Xcls_WindowRooView _owner )
2074 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
2078 // set gobject values
2079 new Xcls_case_sensitive( _this );
2080 this.el.append( _this.case_sensitive.el );
2081 new Xcls_regex( _this );
2082 this.el.append( _this.regex.el );
2083 new Xcls_multiline( _this );
2084 this.el.append( _this.multiline.el );
2087 // user defined functions
2089 public class Xcls_case_sensitive : Object
2091 public Gtk.CheckButton el;
2092 private Xcls_WindowRooView _this;
2098 public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2101 _this.case_sensitive = this;
2102 this.el = new Gtk.CheckButton();
2106 // set gobject values
2107 this.el.label = "Case Sensitive";
2116 // user defined functions
2119 public class Xcls_regex : Object
2121 public Gtk.CheckButton el;
2122 private Xcls_WindowRooView _this;
2128 public Xcls_regex(Xcls_WindowRooView _owner )
2132 this.el = new Gtk.CheckButton();
2136 // set gobject values
2137 this.el.label = "Regex";
2146 // user defined functions
2149 public class Xcls_multiline : Object
2151 public Gtk.CheckButton el;
2152 private Xcls_WindowRooView _this;
2158 public Xcls_multiline(Xcls_WindowRooView _owner )
2161 _this.multiline = this;
2162 this.el = new Gtk.CheckButton();
2166 // set gobject values
2167 this.el.label = "Multi-line (add \\n)";
2176 // user defined functions