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_search_entry search_entry;
27 public Xcls_search_results search_results;
28 public Xcls_nextBtn nextBtn;
29 public Xcls_backBtn backBtn;
30 public Xcls_search_settings search_settings;
31 public Xcls_case_sensitive case_sensitive;
32 public Xcls_regex regex;
33 public Xcls_multiline multiline;
36 public Gtk.Widget lastObj;
37 public Xcls_MainWindow main_window;
38 public int last_error_counter;
39 public int last_search_end;
40 public GtkSource.SearchContext searchcontext;
41 public JsRender.JsRender file;
44 public Xcls_WindowRooView()
47 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
51 this.last_error_counter = 0;
52 this.last_search_end = 0;
56 this.el.hexpand = true;
57 this.el.vexpand = true;
58 new Xcls_notebook( _this );
59 this.el.append( _this.notebook.el );
62 // user defined functions
63 public void loadFile (JsRender.JsRender file)
66 this.view.renderJS(true);
67 this.notebook.el.page = 0;// gtk preview
68 this.sourceview.loadFile();
69 this.last_error_counter = -1;
70 this.updateErrorMarks();
72 public void highlightNodeAtLine (int ln) {
79 var node = _this.file.lineToNode(ln+1);
82 //print("can not find node\n");
85 var prop = node.lineToProp(ln+1);
86 print("prop : %s", prop == null ? "???" : prop.name);
89 // ---------- this selects the tree's node...
91 var ltree = _this.main_window.windowstate.left_tree;
92 ltree.model.selectNode(node);
94 //_this.sourceview.allow_node_scroll = false; /// block node scrolling..
97 //print("changing cursor on tree..\n");
101 // let's try allowing editing on the methods.
102 // a little klunky at present..
103 _this.sourceview.prop_selected = "";
106 //see if we can find it..
107 var kv = prop.split(":");
110 //var k = prop.get_key(kv[1]);
111 // fixme -- need to determine if it's an editable property...
112 _this.sourceview.prop_selected = prop;
114 } else if (kv[0] == "l") {
115 _this.sourceview.prop_selected = prop;
120 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
121 _this.sourceview.nodeSelected(node,false);
123 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
124 // GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
125 // this.allow_node_scroll = true;
141 public void requestRedraw () {
142 this.view.renderJS(false);
143 this.sourceview.loadFile();
145 public void forwardSearch (bool change_focus) {
147 if (this.searchcontext == null) {
150 this.notebook.el.page = 1;
151 Gtk.TextIter beg, st,en;
152 bool has_wrapped_around;
153 var buf = this.sourceview.el.get_buffer();
154 buf.get_iter_at_offset(out beg, this.last_search_end);
155 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
156 this.last_search_end = 0;
159 this.last_search_end = en.get_offset();
161 this.sourceview.el.grab_focus();
163 buf.place_cursor(st);
167 this.sourceview.el.scroll_to_iter(st, 0.0f, true, 0.0f, 0.5f);
170 var ln = st.get_line();
172 this.highlightNodeAtLine(ln);
174 public void backSearch (bool change_focus) {
176 if (this.searchcontext == null) {
180 Gtk.TextIter beg, st,en;
181 bool has_wrapped_around;
182 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
184 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
186 this.last_search_end = 0;
189 this.last_search_end = en.get_offset();
191 this.sourceview.el.grab_focus();
193 this.buffer.el.place_cursor(st);
194 this.sourceview.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
195 var ln = st.get_line();
196 this.highlightNodeAtLine(ln);
200 public int search (string in_txt) {
201 this.notebook.el.page = 1;
205 var s = new GtkSource.SearchSettings();
206 s.case_sensitive = _this.case_sensitive.el.active;
207 s.regex_enabled = _this.regex.el.active;
208 s.wrap_around = false;
210 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
211 this.searchcontext.set_highlight(true);
214 if (_this.multiline.el.active) {
215 txt = in_txt.replace("\\n", "\n");
218 s.set_search_text(txt);
219 Gtk.TextIter beg, st,en;
220 bool has_wrapped_around;
221 this.buffer.el.get_start_iter(out beg);
222 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
223 this.last_search_end = 0;
225 return this.searchcontext.get_occurrences_count();
231 public void createThumb () {
234 if (this.file == null) {
238 if (this.notebook.el.page > 0 ) {
242 this.file.widgetToIcon(this.view.el);
249 public void updateErrorMarks () {
253 var buf = _this.buffer.el;
256 buf.get_bounds (out start, out end);
260 GLib.debug("highlight errors");
262 // we should highlight other types of errors..
267 if (_this.file == null) {
268 GLib.debug("file is null?");
272 var ar = this.file.getErrors();
274 buf.remove_source_marks (start, end, null);
275 this.last_error_counter = file.error_counter ;
276 GLib.debug("higjlight has no errors");
279 if (this.last_error_counter == file.error_counter) {
287 var tlines = buf.get_line_count () +1;
291 buf.remove_source_marks (start, end, null);
292 foreach(var diag in ar) {
296 // print("get inter\n");
297 var eline = (int)diag.range.start.line + 1;
299 if (eline > tlines || eline < 0) {
304 buf.get_iter_at_line_offset( out iter, eline, (int)diag.range.start.character);
308 var msg = "Line: %d %s : %s".printf(eline+1, diag.category, diag.message);
309 buf.create_source_mark( msg, diag.category, iter);
310 GLib.debug("set line %d to %s", eline, msg);
311 //this.marks.set(eline, msg);
313 this.last_error_counter = file.error_counter ;
320 public void scroll_to_line (int line) {
323 GLib.Timeout.add(100, () => {
325 this.notebook.el.set_current_page( 1 );
328 var buf = this.sourceview.el.get_buffer();
330 var sbuf = (GtkSource.Buffer) buf;
334 sbuf.get_iter_at_line(out iter, line);
335 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
341 public class Xcls_notebook : Object
343 public Gtk.Notebook el;
344 private Xcls_WindowRooView _this;
350 public Xcls_notebook(Xcls_WindowRooView _owner )
353 _this.notebook = this;
354 this.el = new Gtk.Notebook();
358 // set gobject values
359 this.el.vexpand = true;
360 new Xcls_label_preview( _this );
361 new Xcls_label_code( _this );
362 new Xcls_paned( _this );
363 this.el.append_page ( _this.paned.el , _this.label_preview.el );
364 var child_4 = new Xcls_Box13( _this );
366 this.el.append_page ( child_4.el , _this.label_code.el );
369 // user defined functions
371 public class Xcls_label_preview : Object
374 private Xcls_WindowRooView _this;
380 public Xcls_label_preview(Xcls_WindowRooView _owner )
383 _this.label_preview = this;
384 this.el = new Gtk.Label( "Preview" );
388 // set gobject values
391 // user defined functions
394 public class Xcls_label_code : Object
397 private Xcls_WindowRooView _this;
403 public Xcls_label_code(Xcls_WindowRooView _owner )
406 _this.label_code = this;
407 this.el = new Gtk.Label( "Preview Generated Code" );
411 // set gobject values
414 // user defined functions
417 public class Xcls_paned : Object
420 private Xcls_WindowRooView _this;
426 public Xcls_paned(Xcls_WindowRooView _owner )
430 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
434 // set gobject values
435 this.el.vexpand = true;
436 new Xcls_viewbox( _this );
437 this.el.set_start_child ( _this.viewbox.el );
438 new Xcls_inspectorcontainer( _this );
439 this.el.set_end_child ( _this.inspectorcontainer.el );
442 // user defined functions
444 public class Xcls_viewbox : Object
447 private Xcls_WindowRooView _this;
453 public Xcls_viewbox(Xcls_WindowRooView _owner )
456 _this.viewbox = this;
457 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
461 // set gobject values
462 this.el.homogeneous = false;
463 this.el.vexpand = true;
464 var child_1 = new Xcls_Box7( _this );
466 this.el.append( child_1.el );
467 new Xcls_view( _this );
468 this.el.append( _this.view.el );
471 // user defined functions
473 public class Xcls_Box7 : Object
476 private Xcls_WindowRooView _this;
482 public Xcls_Box7(Xcls_WindowRooView _owner )
485 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
489 // set gobject values
490 this.el.homogeneous = true;
491 this.el.height_request = 20;
492 this.el.vexpand = false;
493 var child_1 = new Xcls_Button8( _this );
495 this.el.append( child_1.el );
496 new Xcls_AutoRedraw( _this );
497 this.el.append( _this.AutoRedraw.el );
498 var child_3 = new Xcls_Button10( _this );
500 this.el.append( child_3.el );
503 // user defined functions
505 public class Xcls_Button8 : Object
507 public Gtk.Button el;
508 private Xcls_WindowRooView _this;
514 public Xcls_Button8(Xcls_WindowRooView _owner )
517 this.el = new Gtk.Button();
521 // set gobject values
522 this.el.label = "Redraw";
525 this.el.clicked.connect( ( ) => {
526 _this.view.renderJS( true);
530 // user defined functions
533 public class Xcls_AutoRedraw : Object
535 public Gtk.CheckButton el;
536 private Xcls_WindowRooView _this;
542 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
545 _this.AutoRedraw = this;
546 this.el = new Gtk.CheckButton();
550 // set gobject values
551 this.el.active = true;
552 this.el.label = "Auto Redraw On";
555 this.el.toggled.connect( (state) => {
556 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
560 // user defined functions
563 public class Xcls_Button10 : Object
565 public Gtk.Button el;
566 private Xcls_WindowRooView _this;
572 public Xcls_Button10(Xcls_WindowRooView _owner )
575 this.el = new Gtk.Button();
579 // set gobject values
580 this.el.label = "Full Redraw";
583 this.el.clicked.connect( () => {
584 _this.view.redraws = 99;
585 // _this.view.el.web_context.clear_cache();
586 //_this.view.renderJS(true);
587 FakeServerCache.clear();
593 // user defined functions
597 public class Xcls_view : Object
599 public WebKit.WebView el;
600 private Xcls_WindowRooView _this;
604 public WebKit.WebInspector inspector;
605 public bool pendingRedraw;
607 public bool refreshRequired;
609 public string runhtml;
610 public string renderedData;
611 public GLib.DateTime lastRedraw;
614 public Xcls_view(Xcls_WindowRooView _owner )
618 this.el = new WebKit.WebView();
621 this.pendingRedraw = false;
623 this.refreshRequired = false;
626 this.renderedData = "";
627 this.lastRedraw = null;
629 // set gobject values
630 this.el.vexpand = true;
635 // this may not work!?
636 var settings = this.el.get_settings();
637 settings.enable_developer_extras = true;
640 var fs= new FakeServer(this.el);
642 // this was an attempt to change the url perms.. did not work..
643 // settings.enable_file_access_from_file_uris = true;
644 // settings.enable_offline_web_application_cache - true;
645 // settings.enable_universal_access_from_file_uris = true;
652 // FIXME - base url of script..
653 // we need it so some of the database features work.
654 this.el.load_html( "Render not ready" ,
655 //fixme - should be a config option!
656 // or should we catch stuff and fix it up..
657 "http://localhost/app.Builder/"
661 //this.el.open('file:///' + __script_path__ + '/../builder.html');
666 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
667 null, // list of targets
668 Gdk.DragAction.COPY // what to do with data after dropped
671 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
672 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
674 GLib.Timeout.add_seconds(1, () =>{
675 //print("run refresh?");
676 if (this.el == null) {
687 this.el.script_dialog.connect( (dialog) => {
690 if (this.el == null) {
694 var msg = dialog.get_message();
695 if (msg.length < 4) {
699 GLib.debug("script dialog got %s", msg);
701 if (msg.substring(0,4) != "IPC:") {
704 var ar = msg.split(":", 3);
711 GLib.debug("GOT saveHTML %d", ar[2].length);
712 _this.file.saveHTML(ar[2]);
720 this.el.ready_to_show.connect( ( ) => {
721 this.initInspector();
724 this.el.load_changed.connect( (le) => {
725 if (le != WebKit.LoadEvent.FINISHED) {
728 if (this.runjs.length < 1) {
731 // this.el.run_javascript(this.runjs, null);
732 FakeServerCache.remove( this.runjs);
737 // user defined functions
738 public void initInspector () {
742 // this.inspector.open_window.connect(() => {
743 this.inspector = this.el.get_inspector();
745 this.inspector.open_window.connect(() => {
746 print("inspector attach\n");
747 var wv = this.inspector.get_web_view();
749 print("got inspector web view\n");
751 var cn = _this.inspectorcontainer.el.get_first_child();
753 _this.inspectorcontainer.el.remove(cn);
756 _this.inspectorcontainer.el.append(wv);
759 print("got inspector web view FAILED\n");
760 //this.inspector.close();
762 //this.inspector = null;
769 this.inspector.show();
774 public void renderJS (bool force) {
776 // this is the public redraw call..
777 // we refresh in a loop privately..
778 var autodraw = _this.AutoRedraw.el.active;
779 if (!autodraw && !force) {
780 print("Skipping redraw - no force, and autodraw off");
784 this.refreshRequired = true;
786 public void reInit () {
788 // if this happens destroy the webkit..
790 this.el.stop_loading();
792 if (_this.viewbox.el.get_parent() == null) {
797 _this.viewbox.el.remove(_this.viewcontainer.el);
798 //_this.paned.el.remove(_this.inspectorcontainer.el);
800 // destory seems to cause problems.
802 //_this.viewcontainer.el.destroy();
803 //_this.inspectorcontainer.el.destroy();
804 var inv =new Xcls_inspectorcontainer(_this);
806 _this.paned.el.set_end_child(inv.el);
807 _this.inspectorcontainer = inv;
810 var nv =new Xcls_viewcontainer(_this);
812 _this.viewbox.el.append(nv.el);
814 _this.viewcontainer = nv;
817 //while(Gtk.events_pending ()) Gtk.main_iteration ();
818 //_this.view.renderJS(true);
819 _this.view.refreshRequired = true;
823 public void runRefresh ()
825 // this is run every 2 seconds from the init..
829 if (!this.refreshRequired) {
830 // print("no refresh required");
834 if (this.lastRedraw != null) {
835 // do not redraw if last redraw was less that 5 seconds ago.
836 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
841 if (_this.file == null) {
846 this.refreshRequired = false;
847 // print("HTML RENDERING");
850 //this.get('/BottomPane').el.show();
851 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
852 _this.file.webkit_page_id = this.el.get_page_id();
854 var js = _this.file.toSourcePreview();
863 var project = (Project.Roo) _this.file.project;
865 //print (project.fn);
866 // set it to non-empty.
868 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
871 // this.runhtml = this.runhtml || '';
874 // then we need to reload the browser using
875 // load_html_string..
877 // then trigger a redraw once it's loaded..
878 this.pendingRedraw = true;
880 var runhtml = "<script type=\"text/javascript\">\n" ;
884 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
889 runhtml += builderhtml + "\n";
890 runhtml += "</script>\n" ;
892 // fix to make sure they are the same..
893 this.runhtml = project.runhtml;
894 // need to modify paths
897 var base_template = project.base_template;
899 if (base_template.length > 0 && !FileUtils.test(
900 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
902 print("invalid base_template name - using default: %s\n", base_template);
907 GLib.FileUtils.get_contents(
908 BuilderApplication.configDirectory() + "/resources/" +
909 (base_template.length > 0 ? base_template : "roo.builder.html")
915 this.renderedData = js;
918 string js_src = js + "
919 Roo.onReady(function() {
920 if (" + _this.file.name +".show) {
921 " + _this.file.name +".show({});
923 Builder.saveHTML.defer(100, Builder);
926 Roo.XComponent.build();
929 // print("render js: " + js);
931 // console.log('not loaded yet');
933 this.lastRedraw = new DateTime.now_local();
936 //this.runjs = js_src;
937 var fc = FakeServerCache.factory_with_data(js_src);
938 this.runjs = fc.fname;
940 var html = inhtml.replace("</head>", runhtml + this.runhtml +
941 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
942 // "<script type=\"text/javascript\">\n" +
947 //print("LOAD HTML " + html);
949 var rootURL = project.rootURL;
953 this.el.load_html( html ,
954 //fixme - should be a config option!
955 (rootURL.length > 0 ? rootURL : "xhttp://localhost/roobuilder/")
957 this.initInspector();
958 // force the inspector...
959 // this.initInspector();
961 // - no need for this, the builder javascript will call it when build is complete
962 //GLib.Timeout.add_seconds(1, () => {
963 // this.el.run_javascript("Builder.saveHTML()",null);
966 // print( "before render" + this.lastRedraw);
967 // print( "after render" + (new Date()));
973 public class Xcls_inspectorcontainer : Object
976 private Xcls_WindowRooView _this;
982 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
985 _this.inspectorcontainer = this;
986 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
990 // set gobject values
991 this.el.vexpand = true;
994 // user defined functions
998 public class Xcls_Box13 : Object
1001 private Xcls_WindowRooView _this;
1007 public Xcls_Box13(Xcls_WindowRooView _owner )
1010 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1014 // set gobject values
1015 this.el.vexpand = true;
1016 new Xcls_sourceviewscroll( _this );
1017 this.el.append( _this.sourceviewscroll.el );
1018 var child_2 = new Xcls_Box18( _this );
1020 this.el.append( child_2.el );
1023 // user defined functions
1025 public class Xcls_sourceviewscroll : Object
1027 public Gtk.ScrolledWindow el;
1028 private Xcls_WindowRooView _this;
1034 public Xcls_sourceviewscroll(Xcls_WindowRooView _owner )
1037 _this.sourceviewscroll = this;
1038 this.el = new Gtk.ScrolledWindow();
1042 // set gobject values
1043 this.el.vexpand = true;
1044 new Xcls_sourceview( _this );
1045 this.el.set_child ( _this.sourceview.el );
1048 // user defined functions
1050 public class Xcls_sourceview : Object
1052 public GtkSource.View el;
1053 private Xcls_WindowRooView _this;
1057 public int editable_start_pos;
1058 public bool loading;
1059 public bool button_is_pressed;
1060 public string prop_selected;
1061 public bool key_is_pressed;
1062 public Gtk.CssProvider css;
1063 public JsRender.Node? node_selected;
1066 public Xcls_sourceview(Xcls_WindowRooView _owner )
1069 _this.sourceview = this;
1070 this.el = new GtkSource.View();
1073 this.editable_start_pos = -1;
1074 this.loading = true;
1075 this.button_is_pressed = false;
1076 this.prop_selected = "";
1077 this.key_is_pressed = false;
1078 this.node_selected = null;
1080 // set gobject values
1081 this.el.name = "roo-view";
1082 this.el.editable = false;
1083 this.el.show_line_marks = true;
1084 this.el.show_line_numbers = true;
1085 new Xcls_buffer( _this );
1086 this.el.set_buffer ( _this.buffer.el );
1087 var child_2 = new Xcls_EventControllerKey17( _this );
1089 this.el.add_controller ( child_2.el );
1095 this.css = new Gtk.CssProvider();
1097 this.css.load_from_string(
1098 "#roo-view { font: 10px monospace; }"
1101 Gtk.StyleContext.add_provider_for_display(
1102 this.el.get_display(),
1104 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1109 this.loading = true;
1110 //var buf = this.el.get_buffer();
1111 //buf.notify.connect(this.onCursorChanged);
1114 var attrs = new GtkSource.MarkAttributes();
1115 var pink = Gdk.RGBA();
1116 pink.parse ( "pink");
1117 attrs.set_background ( pink);
1118 attrs.set_icon_name ( "process-stop");
1119 attrs.query_tooltip_text.connect(( mark) => {
1120 //print("tooltip query? %s\n", mark.name);
1124 this.el.set_mark_attributes ("ERR", attrs, 1);
1126 var wattrs = new GtkSource.MarkAttributes();
1127 var blue = Gdk.RGBA();
1128 blue.parse ( "#ABF4EB");
1129 wattrs.set_background ( blue);
1130 wattrs.set_icon_name ( "process-stop");
1131 wattrs.query_tooltip_text.connect(( mark) => {
1132 //print("tooltip query? %s\n", mark.name);
1136 this.el.set_mark_attributes ("WARN", wattrs, 1);
1140 var dattrs = new GtkSource.MarkAttributes();
1141 var purple = Gdk.RGBA();
1142 purple.parse ( "#EEA9FF");
1143 dattrs.set_background ( purple);
1144 dattrs.set_icon_name ( "process-stop");
1145 dattrs.query_tooltip_text.connect(( mark) => {
1146 //print("tooltip query? %s\n", mark.name);
1150 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1153 var gattrs = new GtkSource.MarkAttributes();
1154 var grey = Gdk.RGBA();
1155 grey.parse ( "#ccc");
1156 gattrs.set_background ( grey);
1159 this.el.set_mark_attributes ("grey", gattrs, 1);
1169 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
1171 //GLib.debug("query tooltip");
1175 var yoff = (int) _this.sourceviewscroll.el.vadjustment.value;
1177 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
1179 var l = iter.get_line();
1180 //GLib.debug("query tooltip line %d", (int) l);
1181 var marks = _this.buffer.el.get_source_marks_at_line(l, null);
1182 //GLib.debug("query tooltip line marks %d", (int) marks.length());
1184 marks.@foreach((m) => {
1185 //GLib.debug("got mark %s", m.name);
1186 str += (str.length > 0 ? "\n" : "") + m.name;
1188 // true if there is a mark..
1189 if (str.length > 0 ) {
1190 tooltip.set_text( str);
1192 return str.length > 0 ? true : false;
1197 // user defined functions
1198 public void loadFile ( ) {
1199 this.loading = true;
1202 // get the cursor and scroll position....
1203 var buf = this.el.get_buffer();
1204 var cpos = buf.cursor_position;
1206 print("BEFORE LOAD cursor = %d\n", cpos);
1208 var vadj_pos = this.el.get_vadjustment().get_value();
1213 var sbuf = (GtkSource.Buffer) buf;
1217 if (_this.file == null || _this.file.xtype != "Roo") {
1218 print("xtype != Roo");
1219 this.loading = false;
1223 // get the string from the rendered tree...
1225 var str = _this.file.toSource();
1227 // print("setting str %d\n", str.length);
1228 buf.set_text(str, str.length);
1229 var lm = GtkSource.LanguageManager.get_default();
1231 //?? is javascript going to work as js?
1233 ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));
1236 _this.main_window.windowstate.updateErrorMarksAll();
1238 // restore the cursor position?
1239 // after reloading the contents.
1240 GLib.Timeout.add(500, () => {
1241 _this.buffer.in_cursor_change = true;
1242 print("RESORTING cursor to = %d\n", cpos);
1243 Gtk.TextIter cpos_iter;
1244 buf.get_iter_at_offset(out cpos_iter, cpos);
1245 buf.place_cursor(cpos_iter);
1247 this.el.get_vadjustment().set_value(vadj_pos);;
1248 _this.buffer.in_cursor_change = false;
1252 //_this.buffer.checkSyntax();
1256 this.loading = false;
1257 _this.buffer.dirty = false;
1259 public void nodeSelected (JsRender.Node? sel, bool scroll) {
1265 // this is connected in widnowstate
1266 print("Roo-view - node selected\n");
1267 var buf = this.el.get_buffer();
1269 var sbuf = (GtkSource.Buffer) buf;
1274 // clear all the marks..
1278 sbuf.get_bounds (out start, out end);
1279 sbuf.remove_source_marks (start, end, "grey");
1281 this.node_selected = sel;
1283 // no highlighting..
1287 sbuf.get_iter_at_line(out iter, sel.line_start);
1290 Gtk.TextIter cur_iter;
1291 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1293 //var cur_line = cur_iter.get_line();
1294 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1297 if (! _this.buffer.in_cursor_change) {
1298 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1303 for (var i = 0; i < buf.get_line_count();i++) {
1304 if (i < sel.line_start || i > sel.line_end) {
1306 sbuf.get_iter_at_line(out iter, i);
1307 sbuf.create_source_mark(null, "grey", iter);
1315 public void updateGreySelection (bool scroll) {
1316 var sel = this.node_selected;
1317 print("node selected\n");
1318 var buf = this.el.get_buffer();
1319 var sbuf = (GtkSource.Buffer) buf;
1322 this.clearGreySelection();
1327 print("no selected node\n");
1328 // no highlighting..
1332 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1334 sbuf.get_iter_at_line(out iter, sel.line_start);
1337 Gtk.TextIter cur_iter;
1338 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1340 var cursor_at_line = cur_iter.get_line();
1343 //var cur_line = cur_iter.get_line();
1344 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1348 print("scrolling to node -- should occur on node picking.\n");
1349 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1352 var start_line = sel.line_start;
1353 var end_line = sel.line_end;
1356 this.el.editable = false;
1358 //var colon_pos = 0;
1360 this.editable_start_pos = -1;
1362 // now if we have selected a property...
1363 if (this.prop_selected.length> 0 ) {
1366 if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1367 start_line = nstart;
1369 // this.el.editable = true; << cant do this!!?
1370 print("start line = %d, end line = %d\n", start_line, end_line);
1372 // see if we are 'right of ':'
1373 // get an iter for the start of the line.
1374 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1375 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1376 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1381 if (end_first_line_iter.forward_to_line_end()) {
1382 var first_line = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1384 print("first line = %s\n", first_line);
1385 if (first_line.contains(":")) {
1386 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1387 print("colon_pos = %d\n", this.editable_start_pos);
1391 //Gtk.TextIter colon_iter;
1392 //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1393 //sbuf.create_source_mark(null, "active_text", colon_iter);
1398 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1399 //if (start_line - 1 == cursor_at_line) {
1400 // should be ok - current_posssion can not be less than '-1'...
1401 if (sbuf.cursor_position < this.editable_start_pos) {
1403 print("cursor is before start pos.. - turn off editable...\n");
1404 //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1405 //print("before cursor string = %s\n", before_cursor_string);
1406 //if (!before_cursor_string.contains(":")) {
1407 this.el.editable = false;
1416 print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line);
1421 print("checking selection\n");
1424 // check selection - if it's out of 'bounds'
1425 if (this.el.editable && sbuf.get_has_selection()) {
1426 Gtk.TextIter sel_start_iter, sel_end_iter;
1427 sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1429 if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1430 sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
1432 this.el.editable = false;
1434 if (this.editable_start_pos > 0 &&
1435 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1438 this.el.editable = false;
1448 for (var i = 0; i < buf.get_line_count();i++) {
1449 if (i < (start_line -1) || i > (end_line -1)) {
1451 sbuf.get_iter_at_line(out iter, i);
1452 sbuf.create_source_mark(null, "grey", iter);
1457 if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1458 Gtk.TextIter cpos_iter;
1459 buf.get_iter_at_line(out cpos_iter, start_line);
1461 buf.place_cursor(cpos_iter);
1466 public void highlightErrorsJson (string type, Json.Object obj) {
1467 // this is a hook for the vala code - it has no value in javascript
1468 // as we only have one error ususally....
1475 public void clearGreySelection () {
1476 // clear all the marks..
1477 var sbuf = (GtkSource.Buffer)this.el.buffer;
1482 sbuf.get_bounds (out start, out end);
1483 sbuf.remove_source_marks (start, end, "grey");
1487 public string toString () {
1490 this.el.get_buffer().get_start_iter(out s);
1491 this.el.get_buffer().get_end_iter(out e);
1492 var ret = this.el.get_buffer().get_text(s,e,true);
1493 //print("TO STRING? " + ret);
1497 public class Xcls_buffer : Object
1499 public GtkSource.Buffer el;
1500 private Xcls_WindowRooView _this;
1504 public int error_line;
1505 public bool in_cursor_change;
1507 public int last_line;
1510 public Xcls_buffer(Xcls_WindowRooView _owner )
1513 _this.buffer = this;
1514 this.el = new GtkSource.Buffer( null );
1517 this.error_line = -1;
1518 this.in_cursor_change = false;
1520 this.last_line = -1;
1522 // set gobject values
1525 this.el.cursor_moved.connect( ( ) => {
1526 GLib.debug("cursor moved called");
1529 if (this.in_cursor_change ) {
1530 GLib.debug("cursor changed : %d [ignoring nested call)", this.el.cursor_position);
1534 GLib.debug("cursor changed : %d", this.el.cursor_position);
1536 this.el.get_iter_at_offset(out cpos, this.el.cursor_position);
1538 var ln = cpos.get_line();
1539 if (this.last_line == ln ){
1542 this.last_line = ln;
1543 var node = _this.file.lineToNode(ln);
1546 print("can not find node\n");
1549 this.in_cursor_change = true;
1550 var ltree = _this.main_window.windowstate.left_tree;
1551 ltree.model.selectNode(node);
1552 this.in_cursor_change = false;
1554 this.el.changed.connect( () => {
1558 // _this.save_button.el.sensitive = true;
1559 ///?? has changed occured during loading?
1561 // only trigger this if
1566 if (_this.sourceview.loading) {
1572 print("- PREVIEW EDITOR CHANGED--");
1575 // this.checkSyntax(); // this calls backs and highlights errors.. in theory...
1579 if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1580 print("button or key not pressed to generate change?!\n");
1585 // what are we editing??
1586 if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length < 1) {
1590 // find the colon on the first line...
1592 if (_this.sourceview.editable_start_pos > -1) {
1594 var buf = (GtkSource.Buffer)_this.sourceview.el.get_buffer();
1596 //print("cursor changed : %d\n", buf.cursor_position);
1597 Gtk.TextIter spos,epos;
1598 buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1599 buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1602 var line = spos.get_line();
1603 var endline = buf.get_line_count();
1604 while (line < endline) {
1606 buf.get_iter_at_line(out epos, line);
1607 if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1608 buf.get_iter_at_line(out epos, line);
1615 print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1617 // in theory the last char will be '}' or '},' .. or ','
1618 // we should chop the ',' of the end...
1619 var str = buf.get_text(spos, epos, false);
1620 print("got string\n%s\n", str);
1628 // user defined functions
1629 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1631 this.error_line = validate_res.size;
1633 if (this.error_line < 1) {
1636 var tlines = this.el.get_line_count ();
1638 var valiter = validate_res.map_iterator();
1639 while (valiter.next()) {
1641 // print("get inter\n");
1642 var eline = valiter.get_key();
1643 if (eline > tlines) {
1646 this.el.get_iter_at_line( out iter, eline);
1647 //print("mark line\n");
1648 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1652 public string toString () {
1656 this.el.get_start_iter(out s);
1657 this.el.get_end_iter(out e);
1658 var ret = this.el.get_text(s,e,true);
1659 //print("TO STRING? " + ret);
1664 public class Xcls_EventControllerKey17 : Object
1666 public Gtk.EventControllerKey el;
1667 private Xcls_WindowRooView _this;
1673 public Xcls_EventControllerKey17(Xcls_WindowRooView _owner )
1676 this.el = new Gtk.EventControllerKey();
1680 // set gobject values
1683 this.el.key_pressed.connect( (keyval, keycode, state) => {
1687 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1688 GLib.debug("SAVE: ctrl-g pressed");
1689 _this.forwardSearch(true);
1692 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1693 GLib.debug("SAVE: ctrl-f pressed");
1694 _this.search_entry.el.grab_focus();
1698 //this.button_is_pressed = true;
1700 // print(event.key.keyval)
1708 // user defined functions
1713 public class Xcls_Box18 : Object
1716 private Xcls_WindowRooView _this;
1722 public Xcls_Box18(Xcls_WindowRooView _owner )
1725 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1729 // set gobject values
1730 this.el.homogeneous = false;
1731 this.el.vexpand = false;
1732 new Xcls_search_entry( _this );
1733 this.el.append( _this.search_entry.el );
1734 new Xcls_search_results( _this );
1735 this.el.append( _this.search_results.el );
1736 new Xcls_nextBtn( _this );
1737 this.el.append( _this.nextBtn.el );
1738 new Xcls_backBtn( _this );
1739 this.el.append( _this.backBtn.el );
1740 var child_5 = new Xcls_MenuButton24( _this );
1742 this.el.append( child_5.el );
1745 // user defined functions
1747 public class Xcls_search_entry : Object
1749 public Gtk.SearchEntry el;
1750 private Xcls_WindowRooView _this;
1754 public Gtk.CssProvider css;
1757 public Xcls_search_entry(Xcls_WindowRooView _owner )
1760 _this.search_entry = this;
1761 this.el = new Gtk.SearchEntry();
1765 // set gobject values
1766 this.el.name = "roo-search-entry";
1767 this.el.hexpand = true;
1768 this.el.placeholder_text = "Press enter to search";
1769 var child_1 = new Xcls_EventControllerKey20( _this );
1771 this.el.add_controller( child_1.el );
1775 this.css = new Gtk.CssProvider();
1777 this.css.load_from_string(
1778 "#roo-search-entry { background-color: #ccc; }"
1781 Gtk.StyleContext.add_provider_for_display(
1782 this.el.get_display(),
1784 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1788 this.el.search_changed.connect( ( ) => {
1790 _this.search(_this.search_entry.el.text);
1791 _this.search_results.updateResults();
1793 GLib.Timeout.add_seconds(1,() => {
1794 _this.search_results.updateResults();
1800 // user defined functions
1801 public void forwardSearch (bool change_focus) {
1804 _this.forwardSearch(change_focus);
1808 switch(_this.windowstate.state) {
1809 case WindowState.State.CODEONLY:
1810 //case WindowState.State.CODE:
1811 // search the code being edited..
1812 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1815 case WindowState.State.PREVIEW:
1816 if (_this.windowstate.file.xtype == "Gtk") {
1817 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1819 _this.windowstate.window_rooview.forwardSearch(change_focus);
1828 public class Xcls_EventControllerKey20 : Object
1830 public Gtk.EventControllerKey el;
1831 private Xcls_WindowRooView _this;
1837 public Xcls_EventControllerKey20(Xcls_WindowRooView _owner )
1840 this.el = new Gtk.EventControllerKey();
1844 // set gobject values
1847 this.el.key_pressed.connect( (keyval, keycode, state) => {
1849 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1850 GLib.debug("SAVE: ctrl-g pressed");
1851 _this.forwardSearch(true);
1856 if (keyval == Gdk.Key.Return) {
1857 _this.forwardSearch(true);
1863 // print(event.key.keyval)
1869 // user defined functions
1873 public class Xcls_search_results : Object
1875 public Gtk.Label el;
1876 private Xcls_WindowRooView _this;
1882 public Xcls_search_results(Xcls_WindowRooView _owner )
1885 _this.search_results = this;
1886 this.el = new Gtk.Label( "No Results" );
1890 // set gobject values
1891 this.el.margin_end = 4;
1892 this.el.margin_start = 4;
1895 // user defined functions
1896 public void updateResults () {
1897 this.el.visible = true;
1899 var res = _this.searchcontext.get_occurrences_count();
1901 _this.search_results.el.label = "??? Matches";
1905 _this.nextBtn.el.sensitive = false;
1906 _this.backBtn.el.sensitive = false;
1909 _this.search_results.el.label = "%d Matches".printf(res);
1910 _this.nextBtn.el.sensitive = true;
1911 _this.backBtn.el.sensitive = true;
1914 _this.search_results.el.label = "No Matches";
1919 public class Xcls_nextBtn : Object
1921 public Gtk.Button el;
1922 private Xcls_WindowRooView _this;
1926 public bool always_show_image;
1929 public Xcls_nextBtn(Xcls_WindowRooView _owner )
1932 _this.nextBtn = this;
1933 this.el = new Gtk.Button();
1936 this.always_show_image = true;
1938 // set gobject values
1939 this.el.icon_name = "go-down";
1940 this.el.sensitive = false;
1943 this.el.clicked.connect( (event) => {
1945 _this.forwardSearch(true);
1950 // user defined functions
1953 public class Xcls_backBtn : Object
1955 public Gtk.Button el;
1956 private Xcls_WindowRooView _this;
1960 public bool always_show_image;
1963 public Xcls_backBtn(Xcls_WindowRooView _owner )
1966 _this.backBtn = this;
1967 this.el = new Gtk.Button();
1970 this.always_show_image = true;
1972 // set gobject values
1973 this.el.icon_name = "go-up";
1974 this.el.sensitive = false;
1977 this.el.clicked.connect( (event) => {
1979 _this.backSearch(true);
1985 // user defined functions
1988 public class Xcls_MenuButton24 : Object
1990 public Gtk.MenuButton el;
1991 private Xcls_WindowRooView _this;
1995 public bool always_show_image;
1998 public Xcls_MenuButton24(Xcls_WindowRooView _owner )
2001 this.el = new Gtk.MenuButton();
2004 this.always_show_image = true;
2006 // set gobject values
2007 this.el.icon_name = "emblem-system";
2008 new Xcls_search_settings( _this );
2009 this.el.popover = _this.search_settings.el;
2012 // user defined functions
2014 public class Xcls_search_settings : Object
2016 public Gtk.Popover el;
2017 private Xcls_WindowRooView _this;
2023 public Xcls_search_settings(Xcls_WindowRooView _owner )
2026 _this.search_settings = this;
2027 this.el = new Gtk.Popover();
2031 // set gobject values
2032 var child_1 = new Xcls_Box26( _this );
2033 this.el.child = child_1.el;
2036 // user defined functions
2038 public class Xcls_Box26 : Object
2041 private Xcls_WindowRooView _this;
2047 public Xcls_Box26(Xcls_WindowRooView _owner )
2050 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
2054 // set gobject values
2055 new Xcls_case_sensitive( _this );
2056 this.el.append( _this.case_sensitive.el );
2057 new Xcls_regex( _this );
2058 this.el.append( _this.regex.el );
2059 new Xcls_multiline( _this );
2060 this.el.append( _this.multiline.el );
2063 // user defined functions
2065 public class Xcls_case_sensitive : Object
2067 public Gtk.CheckButton el;
2068 private Xcls_WindowRooView _this;
2074 public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2077 _this.case_sensitive = this;
2078 this.el = new Gtk.CheckButton();
2082 // set gobject values
2083 this.el.label = "Case Sensitive";
2092 // user defined functions
2095 public class Xcls_regex : Object
2097 public Gtk.CheckButton el;
2098 private Xcls_WindowRooView _this;
2104 public Xcls_regex(Xcls_WindowRooView _owner )
2108 this.el = new Gtk.CheckButton();
2112 // set gobject values
2113 this.el.label = "Regex";
2122 // user defined functions
2125 public class Xcls_multiline : Object
2127 public Gtk.CheckButton el;
2128 private Xcls_WindowRooView _this;
2134 public Xcls_multiline(Xcls_WindowRooView _owner )
2137 _this.multiline = this;
2138 this.el = new Gtk.CheckButton();
2142 // set gobject values
2143 this.el.label = "Multi-line (add \\n)";
2152 // user defined functions