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_viewcontainer viewcontainer;
22 public Xcls_view view;
23 public Xcls_inspectorcontainer inspectorcontainer;
24 public Xcls_sourceview sourceview;
25 public Xcls_buffer buffer;
28 public Gtk.Widget lastObj;
30 public int last_search_end;
31 public Gtk.SourceSearchContext searchcontext;
32 public JsRender.JsRender file;
34 public Xcls_MainWindow main_window;
37 public Xcls_WindowRooView()
40 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
45 this.last_search_end = 0;
50 this.el.hexpand = true;
51 var child_0 = new Xcls_notebook( _this );
53 this.el.pack_start ( child_0.el , true,true,0 );
56 // user defined functions
57 public void scroll_to_line (int line) {
58 this.notebook.el.page = 1;// code preview...
60 GLib.Timeout.add(500, () => {
65 var buf = this.sourceview.el.get_buffer();
67 var sbuf = (Gtk.SourceBuffer) buf;
71 sbuf.get_iter_at_line(out iter, line);
72 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
78 public void createThumb () {
81 if (this.file == null) {
84 if (this.notebook.el.page > 0 ) {
88 var filename = this.file.getIconFileName(false);
90 var win = this.el.get_parent_window();
91 var width = win.get_width();
92 // var height = win.get_height();
94 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, this.paned.el.position);
95 screenshot.save(filename,"png");
105 public void loadFile (JsRender.JsRender file)
108 this.view.renderJS(true);
109 this.notebook.el.page = 0;// gtk preview
110 this.sourceview.loadFile();
113 public int search (string txt) {
114 this.notebook.el.page = 1;
115 var s = new Gtk.SourceSearchSettings();
116 var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
117 this.searchcontext = new Gtk.SourceSearchContext(buf,s);
118 this.searchcontext.set_highlight(true);
119 s.set_search_text(txt);
121 Gtk.TextIter beg, st,en;
123 buf.get_start_iter(out beg);
124 this.searchcontext.forward(beg, out st, out en);
125 this.last_search_end = 0;
126 return this.searchcontext.get_occurrences_count();
130 public void requestRedraw () {
131 this.view.renderJS(false);
132 this.sourceview.loadFile();
134 public void forwardSearch (bool change_focus) {
136 if (this.searchcontext == null) {
139 this.notebook.el.page = 1;
140 Gtk.TextIter beg, st,en, stl;
142 var buf = this.sourceview.el.get_buffer();
143 buf.get_iter_at_offset(out beg, this.last_search_end);
144 if (!this.searchcontext.forward(beg, out st, out en)) {
145 this.last_search_end = 0;
147 this.last_search_end = en.get_offset();
149 this.sourceview.el.grab_focus();
151 buf.place_cursor(st);
152 var ln = st.get_line();
153 buf.get_iter_at_line(out stl,ln);
155 this.sourceview.el.scroll_to_iter(stl, 0.0f, true, 0.0f, 0.5f);
159 public class Xcls_notebook : Object
161 public Gtk.Notebook el;
162 private Xcls_WindowRooView _this;
168 public Xcls_notebook(Xcls_WindowRooView _owner )
171 _this.notebook = this;
172 this.el = new Gtk.Notebook();
176 // set gobject values
177 var child_0 = new Xcls_label_preview( _this );
179 var child_1 = new Xcls_label_code( _this );
181 var child_2 = new Xcls_paned( _this );
183 this.el.add ( child_2.el );
184 var child_3 = new Xcls_ScrolledWindow14( _this );
186 this.el.append_page ( child_3.el , _this.label_code.el );
189 // user defined functions
191 public class Xcls_label_preview : Object
194 private Xcls_WindowRooView _this;
200 public Xcls_label_preview(Xcls_WindowRooView _owner )
203 _this.label_preview = this;
204 this.el = new Gtk.Label( "Preview" );
208 // set gobject values
211 // user defined functions
214 public class Xcls_label_code : Object
217 private Xcls_WindowRooView _this;
223 public Xcls_label_code(Xcls_WindowRooView _owner )
226 _this.label_code = this;
227 this.el = new Gtk.Label( "Preview Generated Code" );
231 // set gobject values
234 // user defined functions
237 public class Xcls_paned : Object
240 private Xcls_WindowRooView _this;
246 public Xcls_paned(Xcls_WindowRooView _owner )
250 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
254 // set gobject values
255 var child_0 = new Xcls_viewbox( _this );
257 this.el.pack1 ( child_0.el , true,true );
258 var child_1 = new Xcls_inspectorcontainer( _this );
260 this.el.pack2 ( child_1.el , true,true );
263 // user defined functions
265 public class Xcls_viewbox : Object
268 private Xcls_WindowRooView _this;
274 public Xcls_viewbox(Xcls_WindowRooView _owner )
277 _this.viewbox = this;
278 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
282 // set gobject values
283 this.el.homogeneous = false;
284 var child_0 = new Xcls_Box7( _this );
286 this.el.pack_start ( child_0.el , false,true,0 );
287 var child_1 = new Xcls_viewcontainer( _this );
289 this.el.pack_end ( child_1.el , true,true,0 );
292 // user defined functions
294 public class Xcls_Box7 : Object
297 private Xcls_WindowRooView _this;
303 public Xcls_Box7(Xcls_WindowRooView _owner )
306 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
310 // set gobject values
311 this.el.homogeneous = true;
312 this.el.height_request = 20;
313 this.el.vexpand = false;
314 var child_0 = new Xcls_Button8( _this );
316 this.el.pack_start ( child_0.el , false,false,0 );
317 var child_1 = new Xcls_AutoRedraw( _this );
319 this.el.pack_start ( child_1.el , false,false,0 );
320 var child_2 = new Xcls_Button10( _this );
322 this.el.pack_start ( child_2.el , false,false,0 );
325 // user defined functions
327 public class Xcls_Button8 : Object
329 public Gtk.Button el;
330 private Xcls_WindowRooView _this;
336 public Xcls_Button8(Xcls_WindowRooView _owner )
339 this.el = new Gtk.Button();
343 // set gobject values
344 this.el.label = "Redraw";
347 this.el.clicked.connect( ( ) => {
348 _this.view.renderJS( true);
352 // user defined functions
355 public class Xcls_AutoRedraw : Object
357 public Gtk.CheckButton el;
358 private Xcls_WindowRooView _this;
364 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
367 _this.AutoRedraw = this;
368 this.el = new Gtk.CheckButton();
372 // set gobject values
373 this.el.active = true;
374 this.el.label = "Auto Redraw On";
377 this.el.toggled.connect( (state) => {
378 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
382 // user defined functions
385 public class Xcls_Button10 : Object
387 public Gtk.Button el;
388 private Xcls_WindowRooView _this;
394 public Xcls_Button10(Xcls_WindowRooView _owner )
397 this.el = new Gtk.Button();
401 // set gobject values
402 this.el.label = "Full Redraw";
405 this.el.clicked.connect( () => {
406 _this.view.redraws = 99;
407 _this.view.el.web_context.clear_cache();
408 //_this.view.renderJS(true);
409 FakeServerCache.clear();
415 // user defined functions
419 public class Xcls_viewcontainer : Object
421 public Gtk.ScrolledWindow el;
422 private Xcls_WindowRooView _this;
428 public Xcls_viewcontainer(Xcls_WindowRooView _owner )
431 _this.viewcontainer = this;
432 this.el = new Gtk.ScrolledWindow( null, null );
436 // set gobject values
437 this.el.shadow_type = Gtk.ShadowType.IN;
438 var child_0 = new Xcls_view( _this );
440 this.el.add ( child_0.el );
444 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
447 // user defined functions
449 public class Xcls_view : Object
451 public WebKit.WebView el;
452 private Xcls_WindowRooView _this;
456 public string renderedData;
457 public bool refreshRequired;
458 public WebKit.WebInspector inspector;
461 public GLib.DateTime lastRedraw;
462 public string runhtml;
463 public bool pendingRedraw;
466 public Xcls_view(Xcls_WindowRooView _owner )
470 this.el = new WebKit.WebView();
473 this.renderedData = "";
474 this.refreshRequired = false;
477 this.lastRedraw = null;
479 this.pendingRedraw = false;
481 // set gobject values
486 // this may not work!?
487 var settings = this.el.get_settings();
488 settings.enable_developer_extras = true;
491 var fs= new FakeServer(this.el);
493 // this was an attempt to change the url perms.. did not work..
494 // settings.enable_file_access_from_file_uris = true;
495 // settings.enable_offline_web_application_cache - true;
496 // settings.enable_universal_access_from_file_uris = true;
503 // FIXME - base url of script..
504 // we need it so some of the database features work.
505 this.el.load_html( "Render not ready" ,
506 //fixme - should be a config option!
507 // or should we catch stuff and fix it up..
508 "http://localhost/app.Builder/"
512 //this.el.open('file:///' + __script_path__ + '/../builder.html');
517 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
518 null, // list of targets
519 Gdk.DragAction.COPY // what to do with data after dropped
522 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
523 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
525 GLib.Timeout.add_seconds(1, () =>{
526 //print("run refresh?");
527 if (this.el == null) {
538 this.el.script_dialog.connect( (dialog) => {
539 if (this.el == null) {
543 var msg = dialog.get_message();
544 if (msg.length < 4) {
547 if (msg.substring(0,4) != "IPC:") {
550 var ar = msg.split(":", 3);
556 _this.file.saveHTML(ar[2]);
563 this.el.show.connect( ( ) => {
564 this.initInspector();;
566 this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
569 print("TARGET: drag-drop");
570 var is_valid_drop_site = true;
575 w, // will receive 'drag-data-received' signal
576 ctx, /* represents the current state of the DnD
577 this.get('/Window').atoms["STRING"], /* the target type we want
582 /* No target offered by source => error
585 return is_valid_drop_site;
588 this.el.load_changed.connect( (le) => {
589 if (le != WebKit.LoadEvent.FINISHED) {
592 if (this.runjs.length < 1) {
595 // this.el.run_javascript(this.runjs, null);
596 FakeServerCache.remove( this.runjs);
601 // user defined functions
602 public void reInit () {
604 // if this happens destroy the webkit..
606 this.el.stop_loading();
608 if (_this.viewbox.el.get_parent() == null) {
613 _this.viewbox.el.remove(_this.viewcontainer.el);
614 _this.paned.el.remove(_this.inspectorcontainer.el);
616 // destory seems to cause problems.
618 //_this.viewcontainer.el.destroy();
619 //_this.inspectorcontainer.el.destroy();
620 var inv =new Xcls_inspectorcontainer(_this);
622 _this.paned.el.pack2(inv.el,true,true);
626 var nv =new Xcls_viewcontainer(_this);
628 _this.viewbox.el.pack_end(nv.el,true,true,0);
633 //while(Gtk.events_pending ()) Gtk.main_iteration ();
634 //_this.view.renderJS(true);
635 _this.view.refreshRequired = true;
637 public void runRefresh ()
639 // this is run every 2 seconds from the init..
643 if (!this.refreshRequired) {
644 // print("no refresh required");
648 if (this.lastRedraw != null) {
649 // do not redraw if last redraw was less that 5 seconds ago.
650 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
655 if (_this.file == null) {
660 this.refreshRequired = false;
661 // print("HTML RENDERING");
664 //this.get('/BottomPane').el.show();
665 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
666 _this.file.webkit_page_id = this.el.get_page_id();
668 var js = _this.file.toSourcePreview();
677 var project = _this.file.project;
679 //print (project.fn);
680 // set it to non-empty.
682 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
685 // this.runhtml = this.runhtml || '';
688 // then we need to reload the browser using
689 // load_html_string..
691 // then trigger a redraw once it's loaded..
692 this.pendingRedraw = true;
694 var runhtml = "<script type=\"text/javascript\">\n" ;
698 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
703 runhtml += builderhtml + "\n";
704 runhtml += "</script>\n" ;
706 // fix to make sure they are the same..
707 this.runhtml = project.runhtml;
708 // need to modify paths
711 var base_template = _this.file.project.base_template;
713 if (base_template.length > 0 && !FileUtils.test(
714 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
716 print("invalid base_template name - using default: %s\n", base_template);
721 GLib.FileUtils.get_contents(
722 BuilderApplication.configDirectory() + "/resources/" +
723 (base_template.length > 0 ? base_template : "roo.builder.html")
729 this.renderedData = js;
732 string js_src = js + "\n" +
733 "Roo.onReady(function() {\n" +
734 "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
735 "Roo.XComponent.build();\n" +
738 // print("render js: " + js);
740 // console.log('not loaded yet');
742 this.lastRedraw = new DateTime.now_local();
745 //this.runjs = js_src;
746 var fc = FakeServerCache.factory_with_data(js_src);
747 this.runjs = fc.fname;
749 var html = inhtml.replace("</head>", runhtml + this.runhtml +
750 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
751 // "<script type=\"text/javascript\">\n" +
756 //print("LOAD HTML " + html);
758 var rootURL = _this.file.project.rootURL;
762 this.el.load_html( html ,
763 //fixme - should be a config option!
764 (rootURL.length > 0 ? rootURL : "xhttp://localhost/app.Builder.js/")
767 // force the inspector...
768 // this.initInspector();
770 // - no need for this, the builder javascript will call it when build is complete
771 //GLib.Timeout.add_seconds(1, () => {
772 // this.el.run_javascript("Builder.saveHTML()",null);
775 // print( "before render" + this.lastRedraw);
776 // print( "after render" + (new Date()));
779 public void initInspector () {
781 /* if (this.inspector == this.el.get_inspector()) {
782 this.inspector.show();
783 this.inspector.open_window();
784 print("init inspecter called, and inspector is the same as existing\n");
787 print("new inspector?\n");
789 this.inspector = this.el.get_inspector();
790 this.inspector.ref();
792 // got a new inspector...
794 this.inspector.open_window.connect(() => {
795 this.inspector = this.el.get_inspector();
796 print("inspector attach\n");
797 var wv = this.inspector.get_web_view();
799 print("got inspector web view\n");
801 var cn = _this.inspectorcontainer.el.get_child();
803 _this.inspectorcontainer.el.remove(cn);
806 _this.inspectorcontainer.el.add(wv);
809 //this.inspector.close();
811 //this.inspector = null;
819 this.inspector.closed.connect(() => {
820 print("inspector closed?!?");
821 // if this happens destroy the webkit..
823 this.el.stop_loading();
825 if (_this.viewbox.el.get_parent() == null) {
830 _this.viewbox.el.remove(_this.viewcontainer.el);
831 _this.el.remove(_this.inspectorcontainer.el);
833 // destory seems to cause problems.
835 //_this.viewcontainer.el.destroy();
836 //_this.inspectorcontainer.el.destroy();
839 var nv =new Xcls_viewcontainer(_this);
841 _this.viewbox.el.pack_end(nv.el,true,true,0);
843 var inv =new Xcls_inspectorcontainer(_this);
845 _this.el.pack2(inv.el,true,true);
849 //while(Gtk.events_pending ()) Gtk.main_iteration ();
850 //_this.view.renderJS(true);
851 _this.view.refreshRequired = true;
856 this.inspector.show();
858 public void renderJS (bool force) {
860 // this is the public redraw call..
861 // we refresh in a loop privately..
862 var autodraw = _this.AutoRedraw.el.active;
863 if (!autodraw && !force) {
864 print("Skipping redraw - no force, and autodraw off");
868 this.refreshRequired = true;
874 public class Xcls_inspectorcontainer : Object
876 public Gtk.ScrolledWindow el;
877 private Xcls_WindowRooView _this;
883 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
886 _this.inspectorcontainer = this;
887 this.el = new Gtk.ScrolledWindow( null, null );
891 // set gobject values
892 this.el.shadow_type = Gtk.ShadowType.IN;
896 this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
899 // user defined functions
903 public class Xcls_ScrolledWindow14 : Object
905 public Gtk.ScrolledWindow el;
906 private Xcls_WindowRooView _this;
912 public Xcls_ScrolledWindow14(Xcls_WindowRooView _owner )
915 this.el = new Gtk.ScrolledWindow( null, null );
919 // set gobject values
920 var child_0 = new Xcls_sourceview( _this );
922 this.el.add ( child_0.el );
925 // user defined functions
927 public class Xcls_sourceview : Object
929 public Gtk.SourceView el;
930 private Xcls_WindowRooView _this;
935 public bool allow_node_scroll;
936 public string propSelected;
939 public Xcls_sourceview(Xcls_WindowRooView _owner )
942 _this.sourceview = this;
943 this.el = new Gtk.SourceView();
947 this.allow_node_scroll = true;
948 this.propSelected = "";
950 // set gobject values
951 this.el.editable = false;
952 this.el.show_line_marks = true;
953 this.el.show_line_numbers = true;
954 var child_0 = new Xcls_buffer( _this );
956 this.el.set_buffer ( child_0.el );
962 var description = Pango.FontDescription.from_string("monospace");
963 description.set_size(8000);
964 this.el.override_font(description);
967 //var buf = this.el.get_buffer();
968 //buf.notify.connect(this.onCursorChanged);
972 var attrs = new Gtk.SourceMarkAttributes();
973 var pink = Gdk.RGBA();
974 pink.parse ( "pink");
975 attrs.set_background ( pink);
976 attrs.set_icon_name ( "process-stop");
977 attrs.query_tooltip_text.connect(( mark) => {
978 //print("tooltip query? %s\n", mark.name);
982 this.el.set_mark_attributes ("ERR", attrs, 1);
984 var wattrs = new Gtk.SourceMarkAttributes();
985 var blue = Gdk.RGBA();
986 blue.parse ( "#ABF4EB");
987 wattrs.set_background ( blue);
988 wattrs.set_icon_name ( "process-stop");
989 wattrs.query_tooltip_text.connect(( mark) => {
990 //print("tooltip query? %s\n", mark.name);
994 this.el.set_mark_attributes ("WARN", wattrs, 1);
998 var dattrs = new Gtk.SourceMarkAttributes();
999 var purple = Gdk.RGBA();
1000 purple.parse ( "#EEA9FF");
1001 dattrs.set_background ( purple);
1002 dattrs.set_icon_name ( "process-stop");
1003 dattrs.query_tooltip_text.connect(( mark) => {
1004 //print("tooltip query? %s\n", mark.name);
1008 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1011 var gattrs = new Gtk.SourceMarkAttributes();
1012 var grey = Gdk.RGBA();
1013 grey.parse ( "#ccc");
1014 gattrs.set_background ( grey);
1017 this.el.set_mark_attributes ("grey", gattrs, 1);
1027 this.el.button_release_event.connect( () => {
1028 this.onCursorChanged();
1034 // user defined functions
1035 public void onCursorChanged (/*ParamSpec ps*/) {
1039 // if (ps.name != "cursor-position") {
1043 var buf = this.el.get_buffer();
1044 print("cursor changed : %d\n", buf.cursor_position);
1046 buf.get_iter_at_offset(out cpos, buf.cursor_position);
1048 var ln = cpos.get_line();
1049 print("cursor changed line : %d\n", ln);
1050 var node = _this.file.lineToNode(ln+1);
1053 print("can not find node\n");
1056 var prop = node.lineToProp(ln+1);
1057 print("prop : %s", prop == null ? "???" : prop);
1064 var ltree = _this.main_window.windowstate.left_tree;
1065 var tp = ltree.model.treePathFromNode(node);
1066 print("got tree path %s\n", tp);
1068 this.allow_node_scroll = false; /// block node scrolling..
1071 //print("changing cursor on tree..\n");
1075 // let's try allowing editing on the methods.
1076 // a little klunky at present..
1077 this.propSelected = "";
1079 //see if we can find it..
1080 var kv = prop.split(":");
1083 //var k = prop.get_key(kv[1]);
1084 // fixme -- need to determine if it's an editable property...
1085 this.propSelected = prop;
1087 } else if (kv[0] == "l") {
1088 this.propSelected = prop;
1092 ltree.view.setCursor(tp, "editor");
1093 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
1094 this.nodeSelected(node,false);
1096 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
1097 GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
1098 this.allow_node_scroll = true;
1103 // highlight the node..
1105 public void nodeSelected (JsRender.Node? sel, bool scroll ) {
1109 // this is connected in widnowstate
1110 print("node selected\n");
1111 var buf = this.el.get_buffer();
1113 var sbuf = (Gtk.SourceBuffer) buf;
1116 while(Gtk.events_pending()) {
1117 Gtk.main_iteration();
1121 // clear all the marks..
1125 sbuf.get_bounds (out start, out end);
1126 sbuf.remove_source_marks (start, end, "grey");
1130 print("no selected node\n");
1131 // no highlighting..
1135 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1137 sbuf.get_iter_at_line(out iter, sel.line_start);
1140 Gtk.TextIter cur_iter;
1141 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1143 //var cur_line = cur_iter.get_line();
1144 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1148 print("scrolling to node -- should occur on node picking.\n");
1149 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1152 var start_line = sel.line_start;
1153 var end_line = sel.line_end;
1156 this.el.editable = false;
1157 // now if we have selected a property...
1158 if (this.propSelected.length> 0 ) {
1161 if (sel.getPropertyRange(this.propSelected, out nstart, out nend) && nend > nstart) {
1162 start_line = nstart;
1164 this.el.editable = true;
1166 print("propSelected = %s range %d -> %d\n", this.propSelected, start_line, end_line);
1171 // check selection - if it's out of 'bounds'
1172 if (this.el.editable && sbuf.get_has_selection()) {
1173 Gtk.TextIter sel_start_iter, sel_end_iter;
1174 sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1176 if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1177 sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
1179 this.el.editable = false;
1187 for (var i = 0; i < buf.get_line_count();i++) {
1188 if (i < (start_line -1) || i > (end_line -1)) {
1190 sbuf.get_iter_at_line(out iter, i);
1191 sbuf.create_source_mark(null, "grey", iter);
1199 public string toString () {
1202 this.el.get_buffer().get_start_iter(out s);
1203 this.el.get_buffer().get_end_iter(out e);
1204 var ret = this.el.get_buffer().get_text(s,e,true);
1205 //print("TO STRING? " + ret);
1208 public void loadFile ( ) {
1209 this.loading = true;
1212 // get the cursor and scroll position....
1213 var buf = this.el.get_buffer();
1214 var cpos = buf.cursor_position;
1216 print("BEFORE LOAD cursor = %d\n", cpos);
1218 var vadj_pos = this.el.get_vadjustment().get_value();
1223 var sbuf = (Gtk.SourceBuffer) buf;
1227 if (_this.file == null || _this.file.xtype != "Roo") {
1228 print("xtype != Roo");
1229 this.loading = false;
1233 // get the string from the rendered tree...
1235 var str = _this.file.toSource();
1237 // print("setting str %d\n", str.length);
1238 buf.set_text(str, str.length);
1239 var lm = Gtk.SourceLanguageManager.get_default();
1241 //?? is javascript going to work as js?
1243 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
1249 sbuf.get_bounds (out start, out end);
1250 sbuf.remove_source_marks (start, end, null); // remove all marks..
1252 GLib.Timeout.add(500, () => {
1254 print("RESORTING cursor to = %d\n", cpos);
1255 Gtk.TextIter cpos_iter;
1256 buf.get_iter_at_offset(out cpos_iter, cpos);
1257 buf.place_cursor(cpos_iter);
1259 this.el.get_vadjustment().set_value(vadj_pos);;
1260 this.onCursorChanged();
1264 this.loading = false;
1265 _this.buffer.dirty = false;
1267 public void highlightErrorsJson (string type, Json.Object obj) {
1271 var buf = this.el.get_buffer();
1272 var sbuf = (Gtk.SourceBuffer)buf;
1273 buf.get_bounds (out start, out end);
1275 sbuf.remove_source_marks (start, end, type);
1278 // we should highlight other types of errors..
1280 if (!obj.has_member(type)) {
1281 print("Return has no errors\n");
1284 var err = obj.get_object_member(type);
1286 if (_this.file == null) {
1287 return; // just in case the file has not loaded yet?
1293 var regex = new Regex("\\.bjs$");
1296 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
1297 } catch (GLib.RegexError e) {
1301 if (!err.has_member(valafn)) {
1302 print("File path has no errors\n");
1305 var lines = err.get_object_member(valafn);
1309 var tlines = buf.get_line_count () +1;
1311 lines.foreach_member((obj, line, node) => {
1314 // print("get inter\n");
1315 var eline = int.parse(line) -1 ;
1316 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
1319 if (eline > tlines || eline < 0) {
1322 sbuf.get_iter_at_line( out iter, eline);
1323 //print("mark line\n");
1324 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
1325 var ar = lines.get_array_member(line);
1326 for (var i = 0 ; i < ar.get_length(); i++) {
1327 msg += (msg.length > 0) ? "\n" : "";
1328 msg += ar.get_string_element(i);
1332 sbuf.create_source_mark(msg, type, iter);
1341 public class Xcls_buffer : Object
1343 public Gtk.SourceBuffer el;
1344 private Xcls_WindowRooView _this;
1349 public int error_line;
1352 public Xcls_buffer(Xcls_WindowRooView _owner )
1355 _this.buffer = this;
1356 this.el = new Gtk.SourceBuffer( null );
1360 this.error_line = -1;
1362 // set gobject values
1365 this.el.changed.connect( () => {
1368 // _this.save_button.el.sensitive = true;
1369 ///?? has changed occured during loading?
1370 if (_this.sourceview.loading) {
1374 print("- PREVIEW EDITOR CHANGED--");
1377 //this.checkSyntax();
1386 // user defined functions
1387 public string toString () {
1391 this.el.get_start_iter(out s);
1392 this.el.get_end_iter(out e);
1393 var ret = this.el.get_text(s,e,true);
1394 //print("TO STRING? " + ret);
1397 public bool checkSyntax () {
1400 var str = this.toString();
1403 if (this.error_line > 0) {
1406 this.el.get_bounds (out start, out end);
1408 this.el.remove_source_marks (start, end, null);
1411 if (str.length < 1) {
1412 print("checkSyntax - empty string?\n");
1416 if (_this.file == null) {
1419 var p = Palete.factory(_this.file.xtype);
1423 this.check_running = true;
1426 if (_this.file.language == "js") {
1428 print("calling validate javascript\n");
1429 return this.highlightErrors(p.validateJavascript(
1440 print("calling validate vala\n");
1441 // clear the buttons.
1444 if (! _this.window.windowstate.valasource.checkFileWithNodePropChange(
1451 this.check_running = false;
1456 //print("done mark line\n");
1458 return true; // at present allow saving - even if it's invalid..