1 static Xcls_GtkView _GtkView;
3 public class Xcls_GtkView : Object
6 private Xcls_GtkView _this;
8 public static Xcls_GtkView singleton()
10 if (_GtkView == null) {
11 _GtkView= new Xcls_GtkView();
15 public Xcls_notebook notebook;
16 public Xcls_label_preview label_preview;
17 public Xcls_label_code label_code;
18 public Xcls_WindowRooView WindowRooView;
19 public Xcls_viewbox viewbox;
20 public Xcls_AutoRedraw AutoRedraw;
21 public Xcls_viewcontainer viewcontainer;
22 public Xcls_view view;
23 public Xcls_inspectorcontainer inspectorcontainer;
24 public Xcls_sourceview sourceview;
27 public Gtk.Widget lastObj;
29 public int last_search_end;
30 public Gtk.SourceSearchContext searchcontext;
31 public JsRender.JsRender file;
33 public Xcls_MainWindow main_window;
39 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
44 this.last_search_end = 0;
49 this.el.hexpand = true;
50 var child_0 = new Xcls_notebook( _this );
52 this.el.pack_start ( child_0.el , true,true,0 );
55 this.el.size_allocate.connect( (aloc) => {
57 this.width = aloc.width;
58 this.height =aloc.height;
62 // user defined functions
63 public void scroll_to_line (int line) {
64 this.notebook.el.page = 1;// code preview...
66 GLib.Timeout.add(500, () => {
71 var buf = this.sourceview.el.get_buffer();
73 var sbuf = (Gtk.SourceBuffer) buf;
77 sbuf.get_iter_at_line(out iter, line);
78 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
84 public void createThumb () {
87 if (this.file == null) {
90 // only screenshot the gtk preview..
91 if (this.notebook.el.page > 0 ) {
96 var filename = this.file.getIconFileName(false);
98 var win = this.el.get_parent_window();
99 var width = win.get_width();
100 var height = win.get_height();
102 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
103 screenshot.save(filename,"png");
115 // should we hold until it's printed...
126 public void loadFile (JsRender.JsRender file)
130 if (file.tree == null) {
133 this.notebook.el.page = 0;// gtk preview
138 this.sourceview.loadFile();
139 this.searchcontext = null;
142 if (this.lastObj != null) {
143 this.container.el.remove(this.lastObj);
146 // hide the compile view at present..
152 print("ALLOC SET SIZES %d, %d\n", w,h);
154 // set the container size min to 500/500 or 20 px less than max..
155 w = int.max (w-20, 500);
156 h = int.max (h-20, 500);
158 print("SET SIZES %d, %d\n", w,h);
159 _this.container.el.set_size_request(w,h);
161 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
162 var rgba = Gdk.RGBA ();
164 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
167 var x = new JsRender.NodeToGtk(file.tree);
168 var obj = x.munge() as Gtk.Widget;
175 this.container.el.add(obj);
181 public int search (string txt) {
182 this.notebook.el.page = 1;
183 var s = new Gtk.SourceSearchSettings();
184 var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
185 this.searchcontext = new Gtk.SourceSearchContext(buf,s);
186 this.searchcontext.set_highlight(true);
187 s.set_search_text(txt);
189 Gtk.TextIter beg, st,en;
191 buf.get_start_iter(out beg);
192 this.searchcontext.forward(beg, out st, out en);
193 this.last_search_end = 0;
194 return this.searchcontext.get_occurrences_count();
198 public void forwardSearch () {
200 if (this.searchcontext == null) {
203 this.notebook.el.page = 1;
204 Gtk.TextIter beg, st,en, stl;
206 var buf = this.sourceview.el.get_buffer();
207 buf.get_iter_at_offset(out beg, this.last_search_end);
208 if (!this.searchcontext.forward(beg, out st, out en)) {
209 this.last_search_end = 0;
211 this.last_search_end = en.get_offset();
213 this.sourceview.el.grab_focus();
215 buf.place_cursor(st);
216 var ln = st.get_line();
217 buf.get_iter_at_line(out stl,ln);
219 this.sourceview.el.scroll_to_iter(stl, 0.0f, true, 0.0f, 0.5f);
223 public class Xcls_notebook : Object
225 public Gtk.Notebook el;
226 private Xcls_GtkView _this;
232 public Xcls_notebook(Xcls_GtkView _owner )
235 _this.notebook = this;
236 this.el = new Gtk.Notebook();
240 // set gobject values
241 var child_0 = new Xcls_label_preview( _this );
243 var child_1 = new Xcls_label_code( _this );
245 var child_2 = new Xcls_WindowRooView( _this );
247 this.el.add ( child_2.el );
248 var child_3 = new Xcls_ScrolledWindow14( _this );
250 this.el.append_page ( child_3.el , _this.label_code.el );
253 // user defined functions
255 public class Xcls_label_preview : Object
258 private Xcls_GtkView _this;
264 public Xcls_label_preview(Xcls_GtkView _owner )
267 _this.label_preview = this;
268 this.el = new Gtk.Label( "Preview" );
272 // set gobject values
275 // user defined functions
278 public class Xcls_label_code : Object
281 private Xcls_GtkView _this;
287 public Xcls_label_code(Xcls_GtkView _owner )
290 _this.label_code = this;
291 this.el = new Gtk.Label( "Preview Generated Code" );
295 // set gobject values
298 // user defined functions
301 public class Xcls_WindowRooView : Object
304 private Xcls_GtkView _this;
308 public JsRender.JsRender file;
311 public Xcls_WindowRooView(Xcls_GtkView _owner )
314 _this.WindowRooView = this;
315 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
319 // set gobject values
320 var child_0 = new Xcls_viewbox( _this );
322 this.el.pack1 ( child_0.el , true,true );
323 var child_1 = new Xcls_inspectorcontainer( _this );
325 this.el.pack2 ( child_1.el , true,true );
328 // user defined functions
329 public void createThumb () {
332 if (this.file == null) {
335 var filename = this.file.getIconFileName(false);
337 var win = this.el.get_parent_window();
338 var width = win.get_width();
339 // var height = win.get_height();
341 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, this.el.position);
342 screenshot.save(filename,"png");
352 public void loadFile (JsRender.JsRender file)
355 this.view.renderJS(true);
357 public void requestRedraw () {
358 this.view.renderJS(false);
361 public class Xcls_viewbox : Object
364 private Xcls_GtkView _this;
370 public Xcls_viewbox(Xcls_GtkView _owner )
373 _this.viewbox = this;
374 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
378 // set gobject values
379 this.el.homogeneous = false;
380 var child_0 = new Xcls_Box7( _this );
382 this.el.pack_start ( child_0.el , false,true,0 );
383 var child_1 = new Xcls_viewcontainer( _this );
385 this.el.pack_end ( child_1.el , true,true,0 );
388 // user defined functions
390 public class Xcls_Box7 : Object
393 private Xcls_GtkView _this;
399 public Xcls_Box7(Xcls_GtkView _owner )
402 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
406 // set gobject values
407 this.el.homogeneous = true;
408 this.el.height_request = 20;
409 this.el.vexpand = false;
410 var child_0 = new Xcls_Button8( _this );
412 this.el.pack_start ( child_0.el , false,false,0 );
413 var child_1 = new Xcls_AutoRedraw( _this );
415 this.el.pack_start ( child_1.el , false,false,0 );
416 var child_2 = new Xcls_Button10( _this );
418 this.el.pack_start ( child_2.el , false,false,0 );
421 // user defined functions
423 public class Xcls_Button8 : Object
425 public Gtk.Button el;
426 private Xcls_GtkView _this;
432 public Xcls_Button8(Xcls_GtkView _owner )
435 this.el = new Gtk.Button();
439 // set gobject values
440 this.el.label = "Redraw";
443 this.el.clicked.connect( ( ) => {
444 _this.view.renderJS( true);
448 // user defined functions
451 public class Xcls_AutoRedraw : Object
453 public Gtk.CheckButton el;
454 private Xcls_GtkView _this;
460 public Xcls_AutoRedraw(Xcls_GtkView _owner )
463 _this.AutoRedraw = this;
464 this.el = new Gtk.CheckButton();
468 // set gobject values
469 this.el.active = true;
470 this.el.label = "Auto Redraw On";
473 this.el.toggled.connect( (state) => {
474 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
478 // user defined functions
481 public class Xcls_Button10 : Object
483 public Gtk.Button el;
484 private Xcls_GtkView _this;
490 public Xcls_Button10(Xcls_GtkView _owner )
493 this.el = new Gtk.Button();
497 // set gobject values
498 this.el.label = "Full Redraw";
501 this.el.clicked.connect( () => {
502 _this.view.redraws = 99;
503 _this.view.el.web_context.clear_cache();
504 //_this.view.renderJS(true);
505 FakeServerCache.clear();
511 // user defined functions
515 public class Xcls_viewcontainer : Object
517 public Gtk.ScrolledWindow el;
518 private Xcls_GtkView _this;
524 public Xcls_viewcontainer(Xcls_GtkView _owner )
527 _this.viewcontainer = this;
528 this.el = new Gtk.ScrolledWindow( null, null );
532 // set gobject values
533 this.el.shadow_type = Gtk.ShadowType.IN;
534 var child_0 = new Xcls_view( _this );
536 this.el.add ( child_0.el );
540 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
543 // user defined functions
545 public class Xcls_view : Object
547 public WebKit.WebView el;
548 private Xcls_GtkView _this;
552 public string renderedData;
553 public bool refreshRequired;
554 public WebKit.WebInspector inspector;
557 public GLib.DateTime lastRedraw;
558 public string runhtml;
559 public bool pendingRedraw;
562 public Xcls_view(Xcls_GtkView _owner )
566 this.el = new WebKit.WebView();
569 this.renderedData = "";
570 this.refreshRequired = false;
573 this.lastRedraw = null;
575 this.pendingRedraw = false;
577 // set gobject values
582 // this may not work!?
583 var settings = this.el.get_settings();
584 settings.enable_developer_extras = true;
587 var fs= new FakeServer(this.el);
589 // this was an attempt to change the url perms.. did not work..
590 // settings.enable_file_access_from_file_uris = true;
591 // settings.enable_offline_web_application_cache - true;
592 // settings.enable_universal_access_from_file_uris = true;
599 // FIXME - base url of script..
600 // we need it so some of the database features work.
601 this.el.load_html( "Render not ready" ,
602 //fixme - should be a config option!
603 // or should we catch stuff and fix it up..
604 "http://localhost/app.Builder/"
608 //this.el.open('file:///' + __script_path__ + '/../builder.html');
613 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
614 null, // list of targets
615 Gdk.DragAction.COPY // what to do with data after dropped
618 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
619 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
621 GLib.Timeout.add_seconds(1, () =>{
622 //print("run refresh?");
623 if (this.el == null) {
634 this.el.script_dialog.connect( (dialog) => {
635 if (this.el == null) {
639 var msg = dialog.get_message();
640 if (msg.length < 4) {
643 if (msg.substring(0,4) != "IPC:") {
646 var ar = msg.split(":", 3);
652 _this.file.saveHTML(ar[2]);
659 this.el.show.connect( ( ) => {
660 this.initInspector();;
662 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
665 print("TARGET: drag-drop");
666 var is_valid_drop_site = true;
671 w, // will receive 'drag-data-received' signal
672 ctx, /* represents the current state of the DnD
673 this.get('/Window').atoms["STRING"], /* the target type we want
678 /* No target offered by source => error
681 return is_valid_drop_site;
684 this.el.load_changed.connect( (le) => {
685 if (le != WebKit.LoadEvent.FINISHED) {
688 if (this.runjs.length < 1) {
691 // this.el.run_javascript(this.runjs, null);
692 FakeServerCache.remove( this.runjs);
697 // user defined functions
698 public void reInit () {
700 // if this happens destroy the webkit..
702 this.el.stop_loading();
704 if (_this.viewbox.el.get_parent() == null) {
709 _this.viewbox.el.remove(_this.viewcontainer.el);
710 _this.el.remove(_this.inspectorcontainer.el);
712 // destory seems to cause problems.
714 //_this.viewcontainer.el.destroy();
715 //_this.inspectorcontainer.el.destroy();
716 var inv =new Xcls_inspectorcontainer(_this);
718 _this.el.pack2(inv.el,true,true);
722 var nv =new Xcls_viewcontainer(_this);
724 _this.viewbox.el.pack_end(nv.el,true,true,0);
729 //while(Gtk.events_pending ()) Gtk.main_iteration ();
730 //_this.view.renderJS(true);
731 _this.view.refreshRequired = true;
733 public void runRefresh ()
735 // this is run every 2 seconds from the init..
739 if (!this.refreshRequired) {
740 // print("no refresh required");
744 if (this.lastRedraw != null) {
745 // do not redraw if last redraw was less that 5 seconds ago.
746 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
751 if (_this.file == null) {
756 this.refreshRequired = false;
757 // print("HTML RENDERING");
760 //this.get('/BottomPane').el.show();
761 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
762 _this.file.webkit_page_id = this.el.get_page_id();
764 var js = _this.file.toSourcePreview();
773 var project = _this.file.project;
775 //print (project.fn);
776 // set it to non-empty.
778 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
781 // this.runhtml = this.runhtml || '';
784 // then we need to reload the browser using
785 // load_html_string..
787 // then trigger a redraw once it's loaded..
788 this.pendingRedraw = true;
790 var runhtml = "<script type=\"text/javascript\">\n" ;
794 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
799 runhtml += builderhtml + "\n";
800 runhtml += "</script>\n" ;
802 // fix to make sure they are the same..
803 this.runhtml = project.runhtml;
804 // need to modify paths
807 var base_template = _this.file.project.base_template;
809 if (base_template.length > 0 && !FileUtils.test(
810 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
812 print("invalid base_template name - using default: %s\n", base_template);
817 GLib.FileUtils.get_contents(
818 BuilderApplication.configDirectory() + "/resources/" +
819 (base_template.length > 0 ? base_template : "roo.builder.html")
825 this.renderedData = js;
828 string js_src = js + "\n" +
829 "Roo.onReady(function() {\n" +
830 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
831 "Roo.XComponent.build();\n" +
834 // print("render js: " + js);
836 // console.log('not loaded yet');
838 this.lastRedraw = new DateTime.now_local();
841 //this.runjs = js_src;
842 var fc = FakeServerCache.factory_with_data(js_src);
843 this.runjs = fc.fname;
845 var html = inhtml.replace("</head>", runhtml + this.runhtml +
846 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
847 // "<script type=\"text/javascript\">\n" +
852 //print("LOAD HTML " + html);
854 var rootURL = _this.file.project.rootURL;
858 this.el.load_html( html ,
859 //fixme - should be a config option!
860 (rootURL.length > 0 ? rootURL : "xhttp://localhost/app.Builder.js/")
863 // force the inspector...
864 // this.initInspector();
866 // - no need for this, the builder javascript will call it when build is complete
867 //GLib.Timeout.add_seconds(1, () => {
868 // this.el.run_javascript("Builder.saveHTML()",null);
871 // print( "before render" + this.lastRedraw);
872 // print( "after render" + (new Date()));
875 public void initInspector () {
877 /* if (this.inspector == this.el.get_inspector()) {
878 this.inspector.show();
879 this.inspector.open_window();
880 print("init inspecter called, and inspector is the same as existing\n");
883 print("new inspector?\n");
885 this.inspector = this.el.get_inspector();
886 this.inspector.ref();
888 // got a new inspector...
890 this.inspector.open_window.connect(() => {
891 this.inspector = this.el.get_inspector();
892 print("inspector attach\n");
893 var wv = this.inspector.get_web_view();
895 print("got inspector web view\n");
897 var cn = _this.inspectorcontainer.el.get_child();
899 _this.inspectorcontainer.el.remove(cn);
902 _this.inspectorcontainer.el.add(wv);
905 //this.inspector.close();
907 //this.inspector = null;
915 this.inspector.closed.connect(() => {
916 print("inspector closed?!?");
917 // if this happens destroy the webkit..
919 this.el.stop_loading();
921 if (_this.viewbox.el.get_parent() == null) {
926 _this.viewbox.el.remove(_this.viewcontainer.el);
927 _this.el.remove(_this.inspectorcontainer.el);
929 // destory seems to cause problems.
931 //_this.viewcontainer.el.destroy();
932 //_this.inspectorcontainer.el.destroy();
935 var nv =new Xcls_viewcontainer(_this);
937 _this.viewbox.el.pack_end(nv.el,true,true,0);
939 var inv =new Xcls_inspectorcontainer(_this);
941 _this.el.pack2(inv.el,true,true);
945 //while(Gtk.events_pending ()) Gtk.main_iteration ();
946 //_this.view.renderJS(true);
947 _this.view.refreshRequired = true;
952 this.inspector.show();
954 public void renderJS (bool force) {
956 // this is the public redraw call..
957 // we refresh in a loop privately..
958 var autodraw = _this.AutoRedraw.el.active;
959 if (!autodraw && !force) {
960 print("Skipping redraw - no force, and autodraw off");
964 this.refreshRequired = true;
970 public class Xcls_inspectorcontainer : Object
972 public Gtk.ScrolledWindow el;
973 private Xcls_GtkView _this;
979 public Xcls_inspectorcontainer(Xcls_GtkView _owner )
982 _this.inspectorcontainer = this;
983 this.el = new Gtk.ScrolledWindow( null, null );
987 // set gobject values
988 this.el.shadow_type = Gtk.ShadowType.IN;
992 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
995 // user defined functions
999 public class Xcls_ScrolledWindow14 : Object
1001 public Gtk.ScrolledWindow el;
1002 private Xcls_GtkView _this;
1008 public Xcls_ScrolledWindow14(Xcls_GtkView _owner )
1011 this.el = new Gtk.ScrolledWindow( null, null );
1015 // set gobject values
1016 var child_0 = new Xcls_sourceview( _this );
1018 this.el.add ( child_0.el );
1021 // user defined functions
1023 public class Xcls_sourceview : Object
1025 public Gtk.SourceView el;
1026 private Xcls_GtkView _this;
1030 public bool loading;
1031 public bool allow_node_scroll;
1034 public Xcls_sourceview(Xcls_GtkView _owner )
1037 _this.sourceview = this;
1038 this.el = new Gtk.SourceView();
1041 this.loading = true;
1042 this.allow_node_scroll = true;
1044 // set gobject values
1045 this.el.editable = false;
1046 this.el.show_line_marks = true;
1047 this.el.show_line_numbers = true;
1053 var description = Pango.FontDescription.from_string("monospace");
1054 description.set_size(8000);
1055 this.el.override_font(description);
1057 this.loading = true;
1058 var buf = this.el.get_buffer();
1059 buf.notify.connect((ps) => {
1063 if (ps.name != "cursor-position") {
1066 print("cursor changed : %d\n", buf.cursor_position);
1068 buf.get_iter_at_offset(out cpos, buf.cursor_position);
1070 var ln = cpos.get_line();
1072 var node = _this.file.lineToNode(ln);
1075 print("can not find node\n");
1078 var ltree = _this.main_window.windowstate.left_tree;
1079 var tp = ltree.model.treePathFromNode(node);
1080 print("got tree path %s\n", tp);
1082 this.allow_node_scroll = false;
1083 print("changing cursor on tree..\n");
1084 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
1085 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
1086 GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
1087 this.allow_node_scroll = true;
1092 // highlight the node..
1098 var attrs = new Gtk.SourceMarkAttributes();
1099 var pink = Gdk.RGBA();
1100 pink.parse ( "pink");
1101 attrs.set_background ( pink);
1102 attrs.set_icon_name ( "process-stop");
1103 attrs.query_tooltip_text.connect(( mark) => {
1104 //print("tooltip query? %s\n", mark.name);
1108 this.el.set_mark_attributes ("ERR", attrs, 1);
1110 var wattrs = new Gtk.SourceMarkAttributes();
1111 var blue = Gdk.RGBA();
1112 blue.parse ( "#ABF4EB");
1113 wattrs.set_background ( blue);
1114 wattrs.set_icon_name ( "process-stop");
1115 wattrs.query_tooltip_text.connect(( mark) => {
1116 //print("tooltip query? %s\n", mark.name);
1120 this.el.set_mark_attributes ("WARN", wattrs, 1);
1124 var dattrs = new Gtk.SourceMarkAttributes();
1125 var purple = Gdk.RGBA();
1126 purple.parse ( "#EEA9FF");
1127 dattrs.set_background ( purple);
1128 dattrs.set_icon_name ( "process-stop");
1129 dattrs.query_tooltip_text.connect(( mark) => {
1130 //print("tooltip query? %s\n", mark.name);
1134 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1137 var gattrs = new Gtk.SourceMarkAttributes();
1138 var grey = Gdk.RGBA();
1139 grey.parse ( "#ccc");
1140 gattrs.set_background ( grey);
1143 this.el.set_mark_attributes ("grey", gattrs, 1);
1153 // user defined functions
1154 public void nodeSelected (JsRender.Node? sel) {
1158 // this is connected in widnowstate
1159 print("node selected\n");
1160 var buf = this.el.get_buffer();
1162 var sbuf = (Gtk.SourceBuffer) buf;
1165 while(Gtk.events_pending()) {
1166 Gtk.main_iteration();
1170 // clear all the marks..
1174 sbuf.get_bounds (out start, out end);
1175 sbuf.remove_source_marks (start, end, "grey");
1179 // no highlighting..
1183 sbuf.get_iter_at_line(out iter, sel.line_start);
1186 Gtk.TextIter cur_iter;
1187 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1189 //var cur_line = cur_iter.get_line();
1190 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1193 if (this.allow_node_scroll) {
1195 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1200 for (var i = 0; i < buf.get_line_count();i++) {
1201 if (i < sel.line_start || i > sel.line_end) {
1203 sbuf.get_iter_at_line(out iter, i);
1204 sbuf.create_source_mark(null, "grey", iter);
1212 public string toString () {
1215 this.el.get_buffer().get_start_iter(out s);
1216 this.el.get_buffer().get_end_iter(out e);
1217 var ret = this.el.get_buffer().get_text(s,e,true);
1218 //print("TO STRING? " + ret);
1221 public void loadFile ( ) {
1222 this.loading = true;
1223 var buf = this.el.get_buffer();
1225 var sbuf = (Gtk.SourceBuffer) buf;
1229 if (_this.file == null || _this.file.xtype != "Gtk") {
1230 print("xtype != Gtk");
1231 this.loading = false;
1237 var regex = new Regex("\\.bjs$");
1240 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
1241 } catch (GLib.RegexError e) {
1242 this.loading = false;
1247 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
1248 print("File path has no errors\n");
1249 this.loading = false;
1256 GLib.FileUtils.get_contents (valafn, out str);
1258 this.loading = false;
1262 // print("setting str %d\n", str.length);
1263 buf.set_text(str, str.length);
1264 var lm = Gtk.SourceLanguageManager.get_default();
1266 //?? is javascript going to work as js?
1268 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
1274 sbuf.get_bounds (out start, out end);
1275 sbuf.remove_source_marks (start, end, null); // remove all marks..
1278 if (_this.main_window.windowstate.last_compile_result != null) {
1279 var obj = _this.main_window.windowstate.last_compile_result;
1280 this.highlightErrorsJson("ERR", obj);
1281 this.highlightErrorsJson("WARN", obj);
1282 this.highlightErrorsJson("DEPR", obj);
1284 //while (Gtk.events_pending()) {
1285 // Gtk.main_iteration();
1288 this.loading = false;
1290 public void highlightErrorsJson (string type, Json.Object obj) {
1294 var buf = this.el.get_buffer();
1295 var sbuf = (Gtk.SourceBuffer)buf;
1296 buf.get_bounds (out start, out end);
1298 sbuf.remove_source_marks (start, end, type);
1301 // we should highlight other types of errors..
1303 if (!obj.has_member(type)) {
1304 print("Return has no errors\n");
1307 var err = obj.get_object_member(type);
1309 if (_this.file == null) {
1310 return; // just in case the file has not loaded yet?
1316 var regex = new Regex("\\.bjs$");
1319 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
1320 } catch (GLib.RegexError e) {
1324 if (!err.has_member(valafn)) {
1325 print("File path has no errors\n");
1328 var lines = err.get_object_member(valafn);
1332 var tlines = buf.get_line_count () +1;
1334 lines.foreach_member((obj, line, node) => {
1337 // print("get inter\n");
1338 var eline = int.parse(line) -1 ;
1339 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
1342 if (eline > tlines || eline < 0) {
1345 sbuf.get_iter_at_line( out iter, eline);
1346 //print("mark line\n");
1347 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
1348 var ar = lines.get_array_member(line);
1349 for (var i = 0 ; i < ar.get_length(); i++) {
1350 msg += (msg.length > 0) ? "\n" : "";
1351 msg += ar.get_string_element(i);
1355 sbuf.create_source_mark(msg, type, iter);