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_view_layout view_layout;
25 public Xcls_container container;
26 public Xcls_sourceview sourceview;
29 public Gtk.Widget lastObj;
31 public int last_search_end;
32 public Gtk.SourceSearchContext searchcontext;
33 public JsRender.JsRender file;
35 public Xcls_MainWindow main_window;
41 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
46 this.last_search_end = 0;
51 this.el.hexpand = true;
52 var child_0 = new Xcls_notebook( _this );
54 this.el.pack_start ( child_0.el , true,true,0 );
57 this.el.size_allocate.connect( (aloc) => {
59 this.width = aloc.width;
60 this.height =aloc.height;
64 // user defined functions
65 public void scroll_to_line (int line) {
66 this.notebook.el.page = 1;// code preview...
68 GLib.Timeout.add(500, () => {
73 var buf = this.sourceview.el.get_buffer();
75 var sbuf = (Gtk.SourceBuffer) buf;
79 sbuf.get_iter_at_line(out iter, line);
80 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
86 public void createThumb () {
89 if (this.file == null) {
92 // only screenshot the gtk preview..
93 if (this.notebook.el.page > 0 ) {
98 var filename = this.file.getIconFileName(false);
100 var win = this.el.get_parent_window();
101 var width = win.get_width();
102 var height = win.get_height();
104 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
105 screenshot.save(filename,"png");
117 // should we hold until it's printed...
128 public void loadFile (JsRender.JsRender file)
132 if (file.tree == null) {
135 this.notebook.el.page = 0;// gtk preview
140 this.sourceview.loadFile();
141 this.searchcontext = null;
144 if (this.lastObj != null) {
145 this.container.el.remove(this.lastObj);
148 // hide the compile view at present..
154 print("ALLOC SET SIZES %d, %d\n", w,h);
156 // set the container size min to 500/500 or 20 px less than max..
157 w = int.max (w-20, 500);
158 h = int.max (h-20, 500);
160 print("SET SIZES %d, %d\n", w,h);
161 _this.container.el.set_size_request(w,h);
163 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
164 var rgba = Gdk.RGBA ();
166 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
169 var x = new JsRender.NodeToGtk(file.tree);
170 var obj = x.munge() as Gtk.Widget;
177 this.container.el.add(obj);
183 public int search (string txt) {
184 this.notebook.el.page = 1;
185 var s = new Gtk.SourceSearchSettings();
186 var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
187 this.searchcontext = new Gtk.SourceSearchContext(buf,s);
188 this.searchcontext.set_highlight(true);
189 s.set_search_text(txt);
191 Gtk.TextIter beg, st,en;
193 buf.get_start_iter(out beg);
194 this.searchcontext.forward(beg, out st, out en);
195 this.last_search_end = 0;
196 return this.searchcontext.get_occurrences_count();
200 public void forwardSearch () {
202 if (this.searchcontext == null) {
205 this.notebook.el.page = 1;
206 Gtk.TextIter beg, st,en, stl;
208 var buf = this.sourceview.el.get_buffer();
209 buf.get_iter_at_offset(out beg, this.last_search_end);
210 if (!this.searchcontext.forward(beg, out st, out en)) {
211 this.last_search_end = 0;
213 this.last_search_end = en.get_offset();
215 this.sourceview.el.grab_focus();
217 buf.place_cursor(st);
218 var ln = st.get_line();
219 buf.get_iter_at_line(out stl,ln);
221 this.sourceview.el.scroll_to_iter(stl, 0.0f, true, 0.0f, 0.5f);
225 public class Xcls_notebook : Object
227 public Gtk.Notebook el;
228 private Xcls_GtkView _this;
234 public Xcls_notebook(Xcls_GtkView _owner )
237 _this.notebook = this;
238 this.el = new Gtk.Notebook();
242 // set gobject values
243 var child_0 = new Xcls_label_preview( _this );
245 var child_1 = new Xcls_label_code( _this );
247 var child_2 = new Xcls_WindowRooView( _this );
249 this.el.add ( child_2.el );
250 var child_3 = new Xcls_ScrolledWindow14( _this );
252 this.el.append_page ( child_3.el , _this.label_preview.el );
253 var child_4 = new Xcls_ScrolledWindow17( _this );
255 this.el.append_page ( child_4.el , _this.label_code.el );
258 // user defined functions
260 public class Xcls_label_preview : Object
263 private Xcls_GtkView _this;
269 public Xcls_label_preview(Xcls_GtkView _owner )
272 _this.label_preview = this;
273 this.el = new Gtk.Label( "Preview" );
277 // set gobject values
280 // user defined functions
283 public class Xcls_label_code : Object
286 private Xcls_GtkView _this;
292 public Xcls_label_code(Xcls_GtkView _owner )
295 _this.label_code = this;
296 this.el = new Gtk.Label( "Preview Generated Code" );
300 // set gobject values
303 // user defined functions
306 public class Xcls_WindowRooView : Object
309 private Xcls_GtkView _this;
313 public JsRender.JsRender file;
316 public Xcls_WindowRooView(Xcls_GtkView _owner )
319 _this.WindowRooView = this;
320 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
324 // set gobject values
325 var child_0 = new Xcls_viewbox( _this );
327 this.el.pack1 ( child_0.el , true,true );
328 var child_1 = new Xcls_inspectorcontainer( _this );
330 this.el.pack2 ( child_1.el , true,true );
333 // user defined functions
334 public void createThumb () {
337 if (this.file == null) {
340 var filename = this.file.getIconFileName(false);
342 var win = this.el.get_parent_window();
343 var width = win.get_width();
344 // var height = win.get_height();
346 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, this.el.position);
347 screenshot.save(filename,"png");
358 public void loadFile (JsRender.JsRender file)
361 this.view.renderJS(true);
363 public void requestRedraw () {
364 this.view.renderJS(false);
367 public class Xcls_viewbox : Object
370 private Xcls_GtkView _this;
376 public Xcls_viewbox(Xcls_GtkView _owner )
379 _this.viewbox = this;
380 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
384 // set gobject values
385 this.el.homogeneous = false;
386 var child_0 = new Xcls_Box7( _this );
388 this.el.pack_start ( child_0.el , false,true,0 );
389 var child_1 = new Xcls_viewcontainer( _this );
391 this.el.pack_end ( child_1.el , true,true,0 );
394 // user defined functions
396 public class Xcls_Box7 : Object
399 private Xcls_GtkView _this;
405 public Xcls_Box7(Xcls_GtkView _owner )
408 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
412 // set gobject values
413 this.el.homogeneous = true;
414 this.el.height_request = 20;
415 this.el.vexpand = false;
416 var child_0 = new Xcls_Button8( _this );
418 this.el.pack_start ( child_0.el , false,false,0 );
419 var child_1 = new Xcls_AutoRedraw( _this );
421 this.el.pack_start ( child_1.el , false,false,0 );
422 var child_2 = new Xcls_Button10( _this );
424 this.el.pack_start ( child_2.el , false,false,0 );
427 // user defined functions
429 public class Xcls_Button8 : Object
431 public Gtk.Button el;
432 private Xcls_GtkView _this;
438 public Xcls_Button8(Xcls_GtkView _owner )
441 this.el = new Gtk.Button();
445 // set gobject values
446 this.el.label = "Redraw";
449 this.el.clicked.connect( ( ) => {
450 _this.view.renderJS( true);
454 // user defined functions
457 public class Xcls_AutoRedraw : Object
459 public Gtk.CheckButton el;
460 private Xcls_GtkView _this;
466 public Xcls_AutoRedraw(Xcls_GtkView _owner )
469 _this.AutoRedraw = this;
470 this.el = new Gtk.CheckButton();
474 // set gobject values
475 this.el.active = true;
476 this.el.label = "Auto Redraw On";
479 this.el.toggled.connect( (state) => {
480 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
484 // user defined functions
487 public class Xcls_Button10 : Object
489 public Gtk.Button el;
490 private Xcls_GtkView _this;
496 public Xcls_Button10(Xcls_GtkView _owner )
499 this.el = new Gtk.Button();
503 // set gobject values
504 this.el.label = "Full Redraw";
507 this.el.clicked.connect( () => {
508 _this.view.redraws = 99;
509 _this.view.el.web_context.clear_cache();
510 //_this.view.renderJS(true);
511 FakeServerCache.clear();
517 // user defined functions
521 public class Xcls_viewcontainer : Object
523 public Gtk.ScrolledWindow el;
524 private Xcls_GtkView _this;
530 public Xcls_viewcontainer(Xcls_GtkView _owner )
533 _this.viewcontainer = this;
534 this.el = new Gtk.ScrolledWindow( null, null );
538 // set gobject values
539 this.el.shadow_type = Gtk.ShadowType.IN;
540 var child_0 = new Xcls_view( _this );
542 this.el.add ( child_0.el );
546 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
549 // user defined functions
551 public class Xcls_view : Object
553 public WebKit.WebView el;
554 private Xcls_GtkView _this;
558 public string renderedData;
559 public bool refreshRequired;
560 public WebKit.WebInspector inspector;
563 public GLib.DateTime lastRedraw;
564 public string runhtml;
565 public bool pendingRedraw;
568 public Xcls_view(Xcls_GtkView _owner )
572 this.el = new WebKit.WebView();
575 this.renderedData = "";
576 this.refreshRequired = false;
579 this.lastRedraw = null;
581 this.pendingRedraw = false;
583 // set gobject values
588 // this may not work!?
589 var settings = this.el.get_settings();
590 settings.enable_developer_extras = true;
593 var fs= new FakeServer(this.el);
595 // this was an attempt to change the url perms.. did not work..
596 // settings.enable_file_access_from_file_uris = true;
597 // settings.enable_offline_web_application_cache - true;
598 // settings.enable_universal_access_from_file_uris = true;
605 // FIXME - base url of script..
606 // we need it so some of the database features work.
607 this.el.load_html( "Render not ready" ,
608 //fixme - should be a config option!
609 // or should we catch stuff and fix it up..
610 "http://localhost/app.Builder/"
614 //this.el.open('file:///' + __script_path__ + '/../builder.html');
619 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
620 null, // list of targets
621 Gdk.DragAction.COPY // what to do with data after dropped
624 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
625 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
627 GLib.Timeout.add_seconds(1, () =>{
628 //print("run refresh?");
629 if (this.el == null) {
640 this.el.script_dialog.connect( (dialog) => {
641 if (this.el == null) {
645 var msg = dialog.get_message();
646 if (msg.length < 4) {
649 if (msg.substring(0,4) != "IPC:") {
652 var ar = msg.split(":", 3);
658 _this.file.saveHTML(ar[2]);
665 this.el.show.connect( ( ) => {
666 this.initInspector();;
668 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
671 print("TARGET: drag-drop");
672 var is_valid_drop_site = true;
677 w, // will receive 'drag-data-received' signal
678 ctx, /* represents the current state of the DnD
679 this.get('/Window').atoms["STRING"], /* the target type we want
684 /* No target offered by source => error
687 return is_valid_drop_site;
690 this.el.load_changed.connect( (le) => {
691 if (le != WebKit.LoadEvent.FINISHED) {
694 if (this.runjs.length < 1) {
697 // this.el.run_javascript(this.runjs, null);
698 FakeServerCache.remove( this.runjs);
703 // user defined functions
704 public void reInit () {
706 // if this happens destroy the webkit..
708 this.el.stop_loading();
710 if (_this.viewbox.el.get_parent() == null) {
715 _this.viewbox.el.remove(_this.viewcontainer.el);
716 _this.el.remove(_this.inspectorcontainer.el);
718 // destory seems to cause problems.
720 //_this.viewcontainer.el.destroy();
721 //_this.inspectorcontainer.el.destroy();
722 var inv =new Xcls_inspectorcontainer(_this);
724 _this.el.pack2(inv.el,true,true);
728 var nv =new Xcls_viewcontainer(_this);
730 _this.viewbox.el.pack_end(nv.el,true,true,0);
735 //while(Gtk.events_pending ()) Gtk.main_iteration ();
736 //_this.view.renderJS(true);
737 _this.view.refreshRequired = true;
739 public void runRefresh ()
741 // this is run every 2 seconds from the init..
745 if (!this.refreshRequired) {
746 // print("no refresh required");
750 if (this.lastRedraw != null) {
751 // do not redraw if last redraw was less that 5 seconds ago.
752 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
757 if (_this.file == null) {
762 this.refreshRequired = false;
763 // print("HTML RENDERING");
766 //this.get('/BottomPane').el.show();
767 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
768 _this.file.webkit_page_id = this.el.get_page_id();
770 var js = _this.file.toSourcePreview();
779 var project = _this.file.project;
781 //print (project.fn);
782 // set it to non-empty.
784 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
787 // this.runhtml = this.runhtml || '';
790 // then we need to reload the browser using
791 // load_html_string..
793 // then trigger a redraw once it's loaded..
794 this.pendingRedraw = true;
796 var runhtml = "<script type=\"text/javascript\">\n" ;
800 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
805 runhtml += builderhtml + "\n";
806 runhtml += "</script>\n" ;
808 // fix to make sure they are the same..
809 this.runhtml = project.runhtml;
810 // need to modify paths
813 var base_template = _this.file.project.base_template;
815 if (base_template.length > 0 && !FileUtils.test(
816 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
818 print("invalid base_template name - using default: %s\n", base_template);
823 GLib.FileUtils.get_contents(
824 BuilderApplication.configDirectory() + "/resources/" +
825 (base_template.length > 0 ? base_template : "roo.builder.html")
831 this.renderedData = js;
834 string js_src = js + "\n" +
835 "Roo.onReady(function() {\n" +
836 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
837 "Roo.XComponent.build();\n" +
840 // print("render js: " + js);
842 // console.log('not loaded yet');
844 this.lastRedraw = new DateTime.now_local();
847 //this.runjs = js_src;
848 var fc = FakeServerCache.factory_with_data(js_src);
849 this.runjs = fc.fname;
851 var html = inhtml.replace("</head>", runhtml + this.runhtml +
852 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
853 // "<script type=\"text/javascript\">\n" +
858 //print("LOAD HTML " + html);
860 var rootURL = _this.file.project.rootURL;
864 this.el.load_html( html ,
865 //fixme - should be a config option!
866 (rootURL.length > 0 ? rootURL : "xhttp://localhost/app.Builder.js/")
869 // force the inspector...
870 // this.initInspector();
872 // - no need for this, the builder javascript will call it when build is complete
873 //GLib.Timeout.add_seconds(1, () => {
874 // this.el.run_javascript("Builder.saveHTML()",null);
877 // print( "before render" + this.lastRedraw);
878 // print( "after render" + (new Date()));
881 public void initInspector () {
883 /* if (this.inspector == this.el.get_inspector()) {
884 this.inspector.show();
885 this.inspector.open_window();
886 print("init inspecter called, and inspector is the same as existing\n");
889 print("new inspector?\n");
891 this.inspector = this.el.get_inspector();
892 this.inspector.ref();
894 // got a new inspector...
896 this.inspector.open_window.connect(() => {
897 this.inspector = this.el.get_inspector();
898 print("inspector attach\n");
899 var wv = this.inspector.get_web_view();
901 print("got inspector web view\n");
903 var cn = _this.inspectorcontainer.el.get_child();
905 _this.inspectorcontainer.el.remove(cn);
908 _this.inspectorcontainer.el.add(wv);
911 //this.inspector.close();
913 //this.inspector = null;
921 this.inspector.closed.connect(() => {
922 print("inspector closed?!?");
923 // if this happens destroy the webkit..
925 this.el.stop_loading();
927 if (_this.viewbox.el.get_parent() == null) {
932 _this.viewbox.el.remove(_this.viewcontainer.el);
933 _this.el.remove(_this.inspectorcontainer.el);
935 // destory seems to cause problems.
937 //_this.viewcontainer.el.destroy();
938 //_this.inspectorcontainer.el.destroy();
941 var nv =new Xcls_viewcontainer(_this);
943 _this.viewbox.el.pack_end(nv.el,true,true,0);
945 var inv =new Xcls_inspectorcontainer(_this);
947 _this.el.pack2(inv.el,true,true);
951 //while(Gtk.events_pending ()) Gtk.main_iteration ();
952 //_this.view.renderJS(true);
953 _this.view.refreshRequired = true;
958 this.inspector.show();
960 public void renderJS (bool force) {
962 // this is the public redraw call..
963 // we refresh in a loop privately..
964 var autodraw = _this.AutoRedraw.el.active;
965 if (!autodraw && !force) {
966 print("Skipping redraw - no force, and autodraw off");
970 this.refreshRequired = true;
976 public class Xcls_inspectorcontainer : Object
978 public Gtk.ScrolledWindow el;
979 private Xcls_GtkView _this;
985 public Xcls_inspectorcontainer(Xcls_GtkView _owner )
988 _this.inspectorcontainer = this;
989 this.el = new Gtk.ScrolledWindow( null, null );
993 // set gobject values
994 this.el.shadow_type = Gtk.ShadowType.IN;
998 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
1001 // user defined functions
1005 public class Xcls_ScrolledWindow14 : Object
1007 public Gtk.ScrolledWindow el;
1008 private Xcls_GtkView _this;
1014 public Xcls_ScrolledWindow14(Xcls_GtkView _owner )
1017 this.el = new Gtk.ScrolledWindow( null, null );
1021 // set gobject values
1022 var child_0 = new Xcls_view_layout( _this );
1024 this.el.add ( child_0.el );
1027 // user defined functions
1029 public class Xcls_view_layout : Object
1031 public Gtk.Layout el;
1032 private Xcls_GtkView _this;
1038 public Xcls_view_layout(Xcls_GtkView _owner )
1041 _this.view_layout = this;
1042 this.el = new Gtk.Layout( null, null );
1046 // set gobject values
1047 var child_0 = new Xcls_container( _this );
1049 this.el.put ( child_0.el , 10,10 );
1052 // user defined functions
1054 public class Xcls_container : Object
1057 private Xcls_GtkView _this;
1063 public Xcls_container(Xcls_GtkView _owner )
1066 _this.container = this;
1067 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1071 // set gobject values
1074 // user defined functions
1079 public class Xcls_ScrolledWindow17 : Object
1081 public Gtk.ScrolledWindow el;
1082 private Xcls_GtkView _this;
1088 public Xcls_ScrolledWindow17(Xcls_GtkView _owner )
1091 this.el = new Gtk.ScrolledWindow( null, null );
1095 // set gobject values
1096 var child_0 = new Xcls_sourceview( _this );
1098 this.el.add ( child_0.el );
1101 // user defined functions
1103 public class Xcls_sourceview : Object
1105 public Gtk.SourceView el;
1106 private Xcls_GtkView _this;
1110 public bool loading;
1111 public bool allow_node_scroll;
1114 public Xcls_sourceview(Xcls_GtkView _owner )
1117 _this.sourceview = this;
1118 this.el = new Gtk.SourceView();
1121 this.loading = true;
1122 this.allow_node_scroll = true;
1124 // set gobject values
1125 this.el.editable = false;
1126 this.el.show_line_marks = true;
1127 this.el.show_line_numbers = true;
1133 var description = Pango.FontDescription.from_string("monospace");
1134 description.set_size(8000);
1135 this.el.override_font(description);
1137 this.loading = true;
1138 var buf = this.el.get_buffer();
1139 buf.notify.connect((ps) => {
1143 if (ps.name != "cursor-position") {
1146 print("cursor changed : %d\n", buf.cursor_position);
1148 buf.get_iter_at_offset(out cpos, buf.cursor_position);
1150 var ln = cpos.get_line();
1152 var node = _this.file.lineToNode(ln);
1155 print("can not find node\n");
1158 var ltree = _this.main_window.windowstate.left_tree;
1159 var tp = ltree.model.treePathFromNode(node);
1160 print("got tree path %s\n", tp);
1162 this.allow_node_scroll = false;
1163 print("changing cursor on tree..\n");
1164 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
1165 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
1166 GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
1167 this.allow_node_scroll = true;
1172 // highlight the node..
1178 var attrs = new Gtk.SourceMarkAttributes();
1179 var pink = Gdk.RGBA();
1180 pink.parse ( "pink");
1181 attrs.set_background ( pink);
1182 attrs.set_icon_name ( "process-stop");
1183 attrs.query_tooltip_text.connect(( mark) => {
1184 //print("tooltip query? %s\n", mark.name);
1188 this.el.set_mark_attributes ("ERR", attrs, 1);
1190 var wattrs = new Gtk.SourceMarkAttributes();
1191 var blue = Gdk.RGBA();
1192 blue.parse ( "#ABF4EB");
1193 wattrs.set_background ( blue);
1194 wattrs.set_icon_name ( "process-stop");
1195 wattrs.query_tooltip_text.connect(( mark) => {
1196 //print("tooltip query? %s\n", mark.name);
1200 this.el.set_mark_attributes ("WARN", wattrs, 1);
1204 var dattrs = new Gtk.SourceMarkAttributes();
1205 var purple = Gdk.RGBA();
1206 purple.parse ( "#EEA9FF");
1207 dattrs.set_background ( purple);
1208 dattrs.set_icon_name ( "process-stop");
1209 dattrs.query_tooltip_text.connect(( mark) => {
1210 //print("tooltip query? %s\n", mark.name);
1214 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1217 var gattrs = new Gtk.SourceMarkAttributes();
1218 var grey = Gdk.RGBA();
1219 grey.parse ( "#ccc");
1220 gattrs.set_background ( grey);
1223 this.el.set_mark_attributes ("grey", gattrs, 1);
1233 // user defined functions
1234 public void nodeSelected (JsRender.Node? sel) {
1238 // this is connected in widnowstate
1239 print("node selected\n");
1240 var buf = this.el.get_buffer();
1242 var sbuf = (Gtk.SourceBuffer) buf;
1245 while(Gtk.events_pending()) {
1246 Gtk.main_iteration();
1250 // clear all the marks..
1254 sbuf.get_bounds (out start, out end);
1255 sbuf.remove_source_marks (start, end, "grey");
1259 // no highlighting..
1263 sbuf.get_iter_at_line(out iter, sel.line_start);
1266 Gtk.TextIter cur_iter;
1267 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1269 //var cur_line = cur_iter.get_line();
1270 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1273 if (this.allow_node_scroll) {
1275 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1280 for (var i = 0; i < buf.get_line_count();i++) {
1281 if (i < sel.line_start || i > sel.line_end) {
1283 sbuf.get_iter_at_line(out iter, i);
1284 sbuf.create_source_mark(null, "grey", iter);
1292 public string toString () {
1295 this.el.get_buffer().get_start_iter(out s);
1296 this.el.get_buffer().get_end_iter(out e);
1297 var ret = this.el.get_buffer().get_text(s,e,true);
1298 //print("TO STRING? " + ret);
1301 public void loadFile ( ) {
1302 this.loading = true;
1303 var buf = this.el.get_buffer();
1305 var sbuf = (Gtk.SourceBuffer) buf;
1309 if (_this.file == null || _this.file.xtype != "Gtk") {
1310 print("xtype != Gtk");
1311 this.loading = false;
1317 var regex = new Regex("\\.bjs$");
1320 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
1321 } catch (GLib.RegexError e) {
1322 this.loading = false;
1327 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
1328 print("File path has no errors\n");
1329 this.loading = false;
1336 GLib.FileUtils.get_contents (valafn, out str);
1338 this.loading = false;
1342 // print("setting str %d\n", str.length);
1343 buf.set_text(str, str.length);
1344 var lm = Gtk.SourceLanguageManager.get_default();
1346 //?? is javascript going to work as js?
1348 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
1354 sbuf.get_bounds (out start, out end);
1355 sbuf.remove_source_marks (start, end, null); // remove all marks..
1358 if (_this.main_window.windowstate.last_compile_result != null) {
1359 var obj = _this.main_window.windowstate.last_compile_result;
1360 this.highlightErrorsJson("ERR", obj);
1361 this.highlightErrorsJson("WARN", obj);
1362 this.highlightErrorsJson("DEPR", obj);
1364 //while (Gtk.events_pending()) {
1365 // Gtk.main_iteration();
1368 this.loading = false;
1370 public void highlightErrorsJson (string type, Json.Object obj) {
1374 var buf = this.el.get_buffer();
1375 var sbuf = (Gtk.SourceBuffer)buf;
1376 buf.get_bounds (out start, out end);
1378 sbuf.remove_source_marks (start, end, type);
1381 // we should highlight other types of errors..
1383 if (!obj.has_member(type)) {
1384 print("Return has no errors\n");
1387 var err = obj.get_object_member(type);
1389 if (_this.file == null) {
1390 return; // just in case the file has not loaded yet?
1396 var regex = new Regex("\\.bjs$");
1399 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
1400 } catch (GLib.RegexError e) {
1404 if (!err.has_member(valafn)) {
1405 print("File path has no errors\n");
1408 var lines = err.get_object_member(valafn);
1412 var tlines = buf.get_line_count () +1;
1414 lines.foreach_member((obj, line, node) => {
1417 // print("get inter\n");
1418 var eline = int.parse(line) -1 ;
1419 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
1422 if (eline > tlines || eline < 0) {
1425 sbuf.get_iter_at_line( out iter, eline);
1426 //print("mark line\n");
1427 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
1428 var ar = lines.get_array_member(line);
1429 for (var i = 0 ; i < ar.get_length(); i++) {
1430 msg += (msg.length > 0) ? "\n" : "";
1431 msg += ar.get_string_element(i);
1435 sbuf.create_source_mark(msg, type, iter);