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_search_end;
39 public GtkSource.SearchContext searchcontext;
40 public JsRender.JsRender file;
43 public Xcls_WindowRooView()
46 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
50 this.last_search_end = 0;
54 this.el.hexpand = true;
55 this.el.vexpand = true;
56 new Xcls_notebook( _this );
57 this.el.append( _this.notebook.el );
60 // user defined functions
61 public void loadFile (JsRender.JsRender file)
64 this.view.renderJS(true);
65 this.notebook.el.page = 0;// gtk preview
66 this.sourceview.loadFile();
68 public void highlightNodeAtLine (int ln) {
75 var node = _this.file.lineToNode(ln+1);
78 //print("can not find node\n");
81 var prop = node.lineToProp(ln+1);
82 print("prop : %s", prop == null ? "???" : prop.name);
85 // ---------- this selects the tree's node...
87 var ltree = _this.main_window.windowstate.left_tree;
88 ltree.model.selectNode(node);
90 //_this.sourceview.allow_node_scroll = false; /// block node scrolling..
93 //print("changing cursor on tree..\n");
97 // let's try allowing editing on the methods.
98 // a little klunky at present..
99 _this.sourceview.prop_selected = "";
102 //see if we can find it..
103 var kv = prop.split(":");
106 //var k = prop.get_key(kv[1]);
107 // fixme -- need to determine if it's an editable property...
108 _this.sourceview.prop_selected = prop;
110 } else if (kv[0] == "l") {
111 _this.sourceview.prop_selected = prop;
116 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
117 _this.sourceview.nodeSelected(node,false);
119 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
120 // GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
121 // this.allow_node_scroll = true;
137 public void requestRedraw () {
138 this.view.renderJS(false);
139 this.sourceview.loadFile();
141 public void forwardSearch (bool change_focus) {
143 if (this.searchcontext == null) {
146 this.notebook.el.page = 1;
147 Gtk.TextIter beg, st,en;
148 bool has_wrapped_around;
149 var buf = this.sourceview.el.get_buffer();
150 buf.get_iter_at_offset(out beg, this.last_search_end);
151 if (!this.searchcontext.forward(beg, out st, out en, out has_wrapped_around)) {
152 this.last_search_end = 0;
155 this.last_search_end = en.get_offset();
157 this.sourceview.el.grab_focus();
159 buf.place_cursor(st);
163 this.sourceview.el.scroll_to_iter(st, 0.0f, true, 0.0f, 0.5f);
166 var ln = st.get_line();
168 this.highlightNodeAtLine(ln);
170 public void backSearch (bool change_focus) {
172 if (this.searchcontext == null) {
176 Gtk.TextIter beg, st,en;
177 bool has_wrapped_around;
178 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end -1 );
180 if (!this.searchcontext.backward(beg, out st, out en, out has_wrapped_around)) {
182 this.last_search_end = 0;
185 this.last_search_end = en.get_offset();
187 this.sourceview.el.grab_focus();
189 this.buffer.el.place_cursor(st);
190 this.sourceview.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
191 var ln = st.get_line();
192 this.highlightNodeAtLine(ln);
196 public int search (string in_txt) {
197 this.notebook.el.page = 1;
201 var s = new GtkSource.SearchSettings();
202 s.case_sensitive = _this.case_sensitive.el.active;
203 s.regex_enabled = _this.regex.el.active;
204 s.wrap_around = false;
206 this.searchcontext = new GtkSource.SearchContext(this.buffer.el,s);
207 this.searchcontext.set_highlight(true);
210 if (_this.multiline.el.active) {
211 txt = in_txt.replace("\\n", "\n");
214 s.set_search_text(txt);
215 Gtk.TextIter beg, st,en;
216 bool has_wrapped_around;
217 this.buffer.el.get_start_iter(out beg);
218 this.searchcontext.forward(beg, out st, out en, out has_wrapped_around);
219 this.last_search_end = 0;
221 return this.searchcontext.get_occurrences_count();
227 public void createThumb () {
230 if (this.file == null) {
234 if (this.notebook.el.page > 0 ) {
238 this.file.widgetToIcon(this.view.el);
245 public void updateErrorMarks (string category) {
249 var buf = _this.buffer.el;
252 buf.get_bounds (out start, out end);
254 buf.remove_source_marks (start, end, category);
256 GLib.debug("highlight errors");
258 // we should highlight other types of errors..
263 if (_this.file == null) {
264 GLib.debug("file is null?");
268 var ar = this.file.getErrors(category);
269 if (ar == null || ar.get_n_items() < 1) {
270 GLib.debug("higjlight %s has no errors", category);
280 var tlines = buf.get_line_count () +1;
284 for (var i = 0; i < ar.get_n_items();i++) {
285 var err = (Palete.CompileError) ar.get_item(i);
288 // print("get inter\n");
289 var eline = err.line - offset;
290 GLib.debug("GOT ERROR on line %d -- converted to %d (offset = %d)",
291 err.line ,eline, offset);
294 if (eline > tlines || eline < 0) {
299 buf.get_iter_at_line( out iter, eline);
302 var msg = "Line: %d %s : %s".printf(eline+1, err.category, err.msg);
303 buf.create_source_mark( msg, err.category, iter);
304 GLib.debug("set line %d to %s", eline, msg);
305 //this.marks.set(eline, msg);
314 public void scroll_to_line (int line) {
317 GLib.Timeout.add(100, () => {
319 this.notebook.el.set_current_page( 1 );
322 var buf = this.sourceview.el.get_buffer();
324 var sbuf = (GtkSource.Buffer) buf;
328 sbuf.get_iter_at_line(out iter, line);
329 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
335 public class Xcls_notebook : Object
337 public Gtk.Notebook el;
338 private Xcls_WindowRooView _this;
344 public Xcls_notebook(Xcls_WindowRooView _owner )
347 _this.notebook = this;
348 this.el = new Gtk.Notebook();
352 // set gobject values
353 this.el.vexpand = true;
354 new Xcls_label_preview( _this );
355 new Xcls_label_code( _this );
356 new Xcls_paned( _this );
357 this.el.append_page ( _this.paned.el , _this.label_preview.el );
358 var child_4 = new Xcls_Box13( _this );
360 this.el.append_page ( child_4.el , _this.label_code.el );
363 // user defined functions
365 public class Xcls_label_preview : Object
368 private Xcls_WindowRooView _this;
374 public Xcls_label_preview(Xcls_WindowRooView _owner )
377 _this.label_preview = this;
378 this.el = new Gtk.Label( "Preview" );
382 // set gobject values
385 // user defined functions
388 public class Xcls_label_code : Object
391 private Xcls_WindowRooView _this;
397 public Xcls_label_code(Xcls_WindowRooView _owner )
400 _this.label_code = this;
401 this.el = new Gtk.Label( "Preview Generated Code" );
405 // set gobject values
408 // user defined functions
411 public class Xcls_paned : Object
414 private Xcls_WindowRooView _this;
420 public Xcls_paned(Xcls_WindowRooView _owner )
424 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
428 // set gobject values
429 this.el.vexpand = true;
430 new Xcls_viewbox( _this );
431 this.el.set_start_child ( _this.viewbox.el );
432 new Xcls_inspectorcontainer( _this );
433 this.el.set_end_child ( _this.inspectorcontainer.el );
436 // user defined functions
438 public class Xcls_viewbox : Object
441 private Xcls_WindowRooView _this;
447 public Xcls_viewbox(Xcls_WindowRooView _owner )
450 _this.viewbox = this;
451 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
455 // set gobject values
456 this.el.homogeneous = false;
457 this.el.vexpand = true;
458 var child_1 = new Xcls_Box7( _this );
460 this.el.append( child_1.el );
461 new Xcls_view( _this );
462 this.el.append( _this.view.el );
465 // user defined functions
467 public class Xcls_Box7 : Object
470 private Xcls_WindowRooView _this;
476 public Xcls_Box7(Xcls_WindowRooView _owner )
479 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
483 // set gobject values
484 this.el.homogeneous = true;
485 this.el.height_request = 20;
486 this.el.vexpand = false;
487 var child_1 = new Xcls_Button8( _this );
489 this.el.append( child_1.el );
490 new Xcls_AutoRedraw( _this );
491 this.el.append( _this.AutoRedraw.el );
492 var child_3 = new Xcls_Button10( _this );
494 this.el.append( child_3.el );
497 // user defined functions
499 public class Xcls_Button8 : Object
501 public Gtk.Button el;
502 private Xcls_WindowRooView _this;
508 public Xcls_Button8(Xcls_WindowRooView _owner )
511 this.el = new Gtk.Button();
515 // set gobject values
516 this.el.label = "Redraw";
519 this.el.clicked.connect( ( ) => {
520 _this.view.renderJS( true);
524 // user defined functions
527 public class Xcls_AutoRedraw : Object
529 public Gtk.CheckButton el;
530 private Xcls_WindowRooView _this;
536 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
539 _this.AutoRedraw = this;
540 this.el = new Gtk.CheckButton();
544 // set gobject values
545 this.el.active = true;
546 this.el.label = "Auto Redraw On";
549 this.el.toggled.connect( (state) => {
550 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
554 // user defined functions
557 public class Xcls_Button10 : Object
559 public Gtk.Button el;
560 private Xcls_WindowRooView _this;
566 public Xcls_Button10(Xcls_WindowRooView _owner )
569 this.el = new Gtk.Button();
573 // set gobject values
574 this.el.label = "Full Redraw";
577 this.el.clicked.connect( () => {
578 _this.view.redraws = 99;
579 // _this.view.el.web_context.clear_cache();
580 //_this.view.renderJS(true);
581 FakeServerCache.clear();
587 // user defined functions
591 public class Xcls_view : Object
593 public WebKit.WebView el;
594 private Xcls_WindowRooView _this;
598 public WebKit.WebInspector inspector;
599 public bool pendingRedraw;
601 public bool refreshRequired;
603 public string runhtml;
604 public string renderedData;
605 public GLib.DateTime lastRedraw;
608 public Xcls_view(Xcls_WindowRooView _owner )
612 this.el = new WebKit.WebView();
615 this.pendingRedraw = false;
617 this.refreshRequired = false;
620 this.renderedData = "";
621 this.lastRedraw = null;
623 // set gobject values
624 this.el.vexpand = true;
629 // this may not work!?
630 var settings = this.el.get_settings();
631 settings.enable_developer_extras = true;
634 var fs= new FakeServer(this.el);
636 // this was an attempt to change the url perms.. did not work..
637 // settings.enable_file_access_from_file_uris = true;
638 // settings.enable_offline_web_application_cache - true;
639 // settings.enable_universal_access_from_file_uris = true;
646 // FIXME - base url of script..
647 // we need it so some of the database features work.
648 this.el.load_html( "Render not ready" ,
649 //fixme - should be a config option!
650 // or should we catch stuff and fix it up..
651 "http://localhost/app.Builder/"
655 //this.el.open('file:///' + __script_path__ + '/../builder.html');
660 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
661 null, // list of targets
662 Gdk.DragAction.COPY // what to do with data after dropped
665 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
666 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
668 GLib.Timeout.add_seconds(1, () =>{
669 //print("run refresh?");
670 if (this.el == null) {
681 this.el.script_dialog.connect( (dialog) => {
684 if (this.el == null) {
688 var msg = dialog.get_message();
689 if (msg.length < 4) {
693 GLib.debug("script dialog got %s", msg);
695 if (msg.substring(0,4) != "IPC:") {
698 var ar = msg.split(":", 3);
705 GLib.debug("GOT saveHTML %d", ar[2].length);
706 _this.file.saveHTML(ar[2]);
714 this.el.ready_to_show.connect( ( ) => {
715 this.initInspector();
718 this.el.load_changed.connect( (le) => {
719 if (le != WebKit.LoadEvent.FINISHED) {
722 if (this.runjs.length < 1) {
725 // this.el.run_javascript(this.runjs, null);
726 FakeServerCache.remove( this.runjs);
731 // user defined functions
732 public void initInspector () {
736 // this.inspector.open_window.connect(() => {
737 this.inspector = this.el.get_inspector();
739 this.inspector.open_window.connect(() => {
740 print("inspector attach\n");
741 var wv = this.inspector.get_web_view();
743 print("got inspector web view\n");
745 var cn = _this.inspectorcontainer.el.get_first_child();
747 _this.inspectorcontainer.el.remove(cn);
750 _this.inspectorcontainer.el.append(wv);
753 print("got inspector web view FAILED\n");
754 //this.inspector.close();
756 //this.inspector = null;
763 this.inspector.show();
768 public void renderJS (bool force) {
770 // this is the public redraw call..
771 // we refresh in a loop privately..
772 var autodraw = _this.AutoRedraw.el.active;
773 if (!autodraw && !force) {
774 print("Skipping redraw - no force, and autodraw off");
778 this.refreshRequired = true;
780 public void reInit () {
782 // if this happens destroy the webkit..
784 this.el.stop_loading();
786 if (_this.viewbox.el.get_parent() == null) {
791 _this.viewbox.el.remove(_this.viewcontainer.el);
792 //_this.paned.el.remove(_this.inspectorcontainer.el);
794 // destory seems to cause problems.
796 //_this.viewcontainer.el.destroy();
797 //_this.inspectorcontainer.el.destroy();
798 var inv =new Xcls_inspectorcontainer(_this);
800 _this.paned.el.set_end_child(inv.el);
801 _this.inspectorcontainer = inv;
804 var nv =new Xcls_viewcontainer(_this);
806 _this.viewbox.el.append(nv.el);
808 _this.viewcontainer = nv;
811 //while(Gtk.events_pending ()) Gtk.main_iteration ();
812 //_this.view.renderJS(true);
813 _this.view.refreshRequired = true;
817 public void runRefresh ()
819 // this is run every 2 seconds from the init..
823 if (!this.refreshRequired) {
824 // print("no refresh required");
828 if (this.lastRedraw != null) {
829 // do not redraw if last redraw was less that 5 seconds ago.
830 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
835 if (_this.file == null) {
840 this.refreshRequired = false;
841 // print("HTML RENDERING");
844 //this.get('/BottomPane').el.show();
845 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
846 _this.file.webkit_page_id = this.el.get_page_id();
848 var js = _this.file.toSourcePreview();
857 var project = (Project.Roo) _this.file.project;
859 //print (project.fn);
860 // set it to non-empty.
862 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
865 // this.runhtml = this.runhtml || '';
868 // then we need to reload the browser using
869 // load_html_string..
871 // then trigger a redraw once it's loaded..
872 this.pendingRedraw = true;
874 var runhtml = "<script type=\"text/javascript\">\n" ;
878 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
883 runhtml += builderhtml + "\n";
884 runhtml += "</script>\n" ;
886 // fix to make sure they are the same..
887 this.runhtml = project.runhtml;
888 // need to modify paths
891 var base_template = project.base_template;
893 if (base_template.length > 0 && !FileUtils.test(
894 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
896 print("invalid base_template name - using default: %s\n", base_template);
901 GLib.FileUtils.get_contents(
902 BuilderApplication.configDirectory() + "/resources/" +
903 (base_template.length > 0 ? base_template : "roo.builder.html")
909 this.renderedData = js;
912 string js_src = js + "
913 Roo.onReady(function() {
914 if (" + _this.file.name +".show) {
915 " + _this.file.name +".show({});
917 Builder.saveHTML.defer(100, Builder);
920 Roo.XComponent.build();
923 // print("render js: " + js);
925 // console.log('not loaded yet');
927 this.lastRedraw = new DateTime.now_local();
930 //this.runjs = js_src;
931 var fc = FakeServerCache.factory_with_data(js_src);
932 this.runjs = fc.fname;
934 var html = inhtml.replace("</head>", runhtml + this.runhtml +
935 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
936 // "<script type=\"text/javascript\">\n" +
941 //print("LOAD HTML " + html);
943 var rootURL = project.rootURL;
947 this.el.load_html( html ,
948 //fixme - should be a config option!
949 (rootURL.length > 0 ? rootURL : "xhttp://localhost/roobuilder/")
951 this.initInspector();
952 // force the inspector...
953 // this.initInspector();
955 // - no need for this, the builder javascript will call it when build is complete
956 //GLib.Timeout.add_seconds(1, () => {
957 // this.el.run_javascript("Builder.saveHTML()",null);
960 // print( "before render" + this.lastRedraw);
961 // print( "after render" + (new Date()));
967 public class Xcls_inspectorcontainer : Object
970 private Xcls_WindowRooView _this;
976 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
979 _this.inspectorcontainer = this;
980 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
984 // set gobject values
985 this.el.vexpand = true;
988 // user defined functions
992 public class Xcls_Box13 : Object
995 private Xcls_WindowRooView _this;
1001 public Xcls_Box13(Xcls_WindowRooView _owner )
1004 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
1008 // set gobject values
1009 this.el.vexpand = true;
1010 new Xcls_sourceviewscroll( _this );
1011 this.el.append( _this.sourceviewscroll.el );
1012 var child_2 = new Xcls_Box19( _this );
1014 this.el.append( child_2.el );
1017 // user defined functions
1019 public class Xcls_sourceviewscroll : Object
1021 public Gtk.ScrolledWindow el;
1022 private Xcls_WindowRooView _this;
1028 public Xcls_sourceviewscroll(Xcls_WindowRooView _owner )
1031 _this.sourceviewscroll = this;
1032 this.el = new Gtk.ScrolledWindow();
1036 // set gobject values
1037 this.el.vexpand = true;
1038 new Xcls_sourceview( _this );
1039 this.el.set_child ( _this.sourceview.el );
1042 // user defined functions
1044 public class Xcls_sourceview : Object
1046 public GtkSource.View el;
1047 private Xcls_WindowRooView _this;
1051 public int editable_start_pos;
1052 public bool loading;
1053 public bool button_is_pressed;
1054 public string prop_selected;
1055 public bool key_is_pressed;
1056 public Gtk.CssProvider css;
1057 public JsRender.Node? node_selected;
1060 public Xcls_sourceview(Xcls_WindowRooView _owner )
1063 _this.sourceview = this;
1064 this.el = new GtkSource.View();
1067 this.editable_start_pos = -1;
1068 this.loading = true;
1069 this.button_is_pressed = false;
1070 this.prop_selected = "";
1071 this.key_is_pressed = false;
1072 this.node_selected = null;
1074 // set gobject values
1075 this.el.name = "roo-view";
1076 this.el.editable = false;
1077 this.el.show_line_marks = true;
1078 this.el.show_line_numbers = true;
1079 new Xcls_buffer( _this );
1080 this.el.set_buffer ( _this.buffer.el );
1081 var child_2 = new Xcls_EventControllerKey17( _this );
1083 this.el.add_controller ( child_2.el );
1084 var child_3 = new Xcls_GestureClick18( _this );
1086 this.el.add_controller( child_3.el );
1092 this.css = new Gtk.CssProvider();
1094 this.css.load_from_string(
1095 "#roo-view { font: 10px monospace; }"
1098 Gtk.StyleContext.add_provider_for_display(
1099 this.el.get_display(),
1101 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1106 this.loading = true;
1107 //var buf = this.el.get_buffer();
1108 //buf.notify.connect(this.onCursorChanged);
1111 var attrs = new GtkSource.MarkAttributes();
1112 var pink = Gdk.RGBA();
1113 pink.parse ( "pink");
1114 attrs.set_background ( pink);
1115 attrs.set_icon_name ( "process-stop");
1116 attrs.query_tooltip_text.connect(( mark) => {
1117 //print("tooltip query? %s\n", mark.name);
1121 this.el.set_mark_attributes ("ERR", attrs, 1);
1123 var wattrs = new GtkSource.MarkAttributes();
1124 var blue = Gdk.RGBA();
1125 blue.parse ( "#ABF4EB");
1126 wattrs.set_background ( blue);
1127 wattrs.set_icon_name ( "process-stop");
1128 wattrs.query_tooltip_text.connect(( mark) => {
1129 //print("tooltip query? %s\n", mark.name);
1133 this.el.set_mark_attributes ("WARN", wattrs, 1);
1137 var dattrs = new GtkSource.MarkAttributes();
1138 var purple = Gdk.RGBA();
1139 purple.parse ( "#EEA9FF");
1140 dattrs.set_background ( purple);
1141 dattrs.set_icon_name ( "process-stop");
1142 dattrs.query_tooltip_text.connect(( mark) => {
1143 //print("tooltip query? %s\n", mark.name);
1147 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1150 var gattrs = new GtkSource.MarkAttributes();
1151 var grey = Gdk.RGBA();
1152 grey.parse ( "#ccc");
1153 gattrs.set_background ( grey);
1156 this.el.set_mark_attributes ("grey", gattrs, 1);
1166 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
1168 //GLib.debug("query tooltip");
1172 var yoff = (int) _this.sourceviewscroll.el.vadjustment.value;
1174 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
1176 var l = iter.get_line();
1177 //GLib.debug("query tooltip line %d", (int) l);
1178 var marks = _this.buffer.el.get_source_marks_at_line(l, null);
1179 //GLib.debug("query tooltip line marks %d", (int) marks.length());
1181 marks.@foreach((m) => {
1182 //GLib.debug("got mark %s", m.name);
1183 str += (str.length > 0 ? "\n" : "") + m.name;
1185 // true if there is a mark..
1186 if (str.length > 0 ) {
1187 tooltip.set_text( str);
1189 return str.length > 0 ? true : false;
1194 // user defined functions
1195 public void loadFile ( ) {
1196 this.loading = true;
1199 // get the cursor and scroll position....
1200 var buf = this.el.get_buffer();
1201 var cpos = buf.cursor_position;
1203 print("BEFORE LOAD cursor = %d\n", cpos);
1205 var vadj_pos = this.el.get_vadjustment().get_value();
1210 var sbuf = (GtkSource.Buffer) buf;
1214 if (_this.file == null || _this.file.xtype != "Roo") {
1215 print("xtype != Roo");
1216 this.loading = false;
1220 // get the string from the rendered tree...
1222 var str = _this.file.toSource();
1224 // print("setting str %d\n", str.length);
1225 buf.set_text(str, str.length);
1226 var lm = GtkSource.LanguageManager.get_default();
1228 //?? is javascript going to work as js?
1230 ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));
1233 _this.main_window.windowstate.updateErrorMarksAll();
1235 // what does this do?
1236 GLib.Timeout.add(500, () => {
1238 print("RESORTING cursor to = %d\n", cpos);
1239 Gtk.TextIter cpos_iter;
1240 buf.get_iter_at_offset(out cpos_iter, cpos);
1241 buf.place_cursor(cpos_iter);
1243 this.el.get_vadjustment().set_value(vadj_pos);;
1246 this.onCursorChanged();
1249 //_this.buffer.checkSyntax();
1253 this.loading = false;
1254 _this.buffer.dirty = false;
1256 public void onCursorChanged (/*ParamSpec ps*/) {
1258 if (!this.key_is_pressed && !this.button_is_pressed) {
1265 // if (ps.name != "cursor-position") {
1269 var buf = this.el.get_buffer();
1270 //print("cursor changed : %d\n", buf.cursor_position);
1272 buf.get_iter_at_offset(out cpos, buf.cursor_position);
1274 var ln = cpos.get_line();
1277 // --- select node at line....
1279 var node = _this.file.lineToNode(ln+1);
1282 print("can not find node\n");
1285 var prop = node.lineToProp(ln+1);
1286 print("prop : %s", prop == null ? "???" : prop.name);
1289 // ---------- this selects the tree's node...
1291 var ltree = _this.main_window.windowstate.left_tree;
1292 ltree.model.selectNode(node);
1295 //print("changing cursor on tree..\n");
1299 // let's try allowing editing on the methods.
1300 // a little klunky at present..
1301 this.prop_selected = "";
1304 //see if we can find it..
1305 var kv = prop.split(":");
1308 //var k = prop.get_key(kv[1]);
1309 // fixme -- need to determine if it's an editable property...
1310 this.prop_selected = prop;
1312 } else if (kv[0] == "l") {
1313 this.prop_selected = prop;
1318 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
1319 //this.nodeSelected(node,false);
1321 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
1324 // highlight the node..
1326 public void nodeSelected (JsRender.Node? sel, bool scroll ) {
1330 // this is connected in widnowstate
1334 // while(Gtk.events_pending()) {
1335 // Gtk.main_iteration();
1338 this.node_selected = sel;
1340 // this.updateGreySelection(scroll);
1345 public void updateGreySelection (bool scroll) {
1346 var sel = this.node_selected;
1347 print("node selected\n");
1348 var buf = this.el.get_buffer();
1349 var sbuf = (GtkSource.Buffer) buf;
1352 this.clearGreySelection();
1357 print("no selected node\n");
1358 // no highlighting..
1362 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1364 sbuf.get_iter_at_line(out iter, sel.line_start);
1367 Gtk.TextIter cur_iter;
1368 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1370 var cursor_at_line = cur_iter.get_line();
1373 //var cur_line = cur_iter.get_line();
1374 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1378 print("scrolling to node -- should occur on node picking.\n");
1379 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1382 var start_line = sel.line_start;
1383 var end_line = sel.line_end;
1386 this.el.editable = false;
1388 //var colon_pos = 0;
1390 this.editable_start_pos = -1;
1392 // now if we have selected a property...
1393 if (this.prop_selected.length> 0 ) {
1396 if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1397 start_line = nstart;
1399 // this.el.editable = true; << cant do this!!?
1400 print("start line = %d, end line = %d\n", start_line, end_line);
1402 // see if we are 'right of ':'
1403 // get an iter for the start of the line.
1404 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1405 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1406 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1411 if (end_first_line_iter.forward_to_line_end()) {
1412 var first_line = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1414 print("first line = %s\n", first_line);
1415 if (first_line.contains(":")) {
1416 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1417 print("colon_pos = %d\n", this.editable_start_pos);
1421 //Gtk.TextIter colon_iter;
1422 //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1423 //sbuf.create_source_mark(null, "active_text", colon_iter);
1428 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1429 //if (start_line - 1 == cursor_at_line) {
1430 // should be ok - current_posssion can not be less than '-1'...
1431 if (sbuf.cursor_position < this.editable_start_pos) {
1433 print("cursor is before start pos.. - turn off editable...\n");
1434 //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1435 //print("before cursor string = %s\n", before_cursor_string);
1436 //if (!before_cursor_string.contains(":")) {
1437 this.el.editable = false;
1446 print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line);
1451 print("checking selection\n");
1454 // check selection - if it's out of 'bounds'
1455 if (this.el.editable && sbuf.get_has_selection()) {
1456 Gtk.TextIter sel_start_iter, sel_end_iter;
1457 sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1459 if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1460 sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
1462 this.el.editable = false;
1464 if (this.editable_start_pos > 0 &&
1465 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1468 this.el.editable = false;
1478 for (var i = 0; i < buf.get_line_count();i++) {
1479 if (i < (start_line -1) || i > (end_line -1)) {
1481 sbuf.get_iter_at_line(out iter, i);
1482 sbuf.create_source_mark(null, "grey", iter);
1487 if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1488 Gtk.TextIter cpos_iter;
1489 buf.get_iter_at_line(out cpos_iter, start_line);
1491 buf.place_cursor(cpos_iter);
1496 public void highlightErrorsJson (string type, Json.Object obj) {
1497 // this is a hook for the vala code - it has no value in javascript
1498 // as we only have one error ususally....
1505 public void clearGreySelection () {
1506 // clear all the marks..
1507 var sbuf = (GtkSource.Buffer)this.el.buffer;
1512 sbuf.get_bounds (out start, out end);
1513 sbuf.remove_source_marks (start, end, "grey");
1517 public string toString () {
1520 this.el.get_buffer().get_start_iter(out s);
1521 this.el.get_buffer().get_end_iter(out e);
1522 var ret = this.el.get_buffer().get_text(s,e,true);
1523 //print("TO STRING? " + ret);
1527 public class Xcls_buffer : Object
1529 public GtkSource.Buffer el;
1530 private Xcls_WindowRooView _this;
1534 public int error_line;
1538 public Xcls_buffer(Xcls_WindowRooView _owner )
1541 _this.buffer = this;
1542 this.el = new GtkSource.Buffer( null );
1545 this.error_line = -1;
1548 // set gobject values
1551 this.el.changed.connect( () => {
1555 // _this.save_button.el.sensitive = true;
1556 ///?? has changed occured during loading?
1558 // only trigger this if
1563 if (_this.sourceview.loading) {
1569 print("- PREVIEW EDITOR CHANGED--");
1572 // this.checkSyntax(); // this calls backs and highlights errors.. in theory...
1576 if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1577 print("button or key not pressed to generate change?!\n");
1582 // what are we editing??
1583 if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length < 1) {
1587 // find the colon on the first line...
1589 if (_this.sourceview.editable_start_pos > -1) {
1591 var buf = (GtkSource.Buffer)_this.sourceview.el.get_buffer();
1593 //print("cursor changed : %d\n", buf.cursor_position);
1594 Gtk.TextIter spos,epos;
1595 buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1596 buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1599 var line = spos.get_line();
1600 var endline = buf.get_line_count();
1601 while (line < endline) {
1603 buf.get_iter_at_line(out epos, line);
1604 if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1605 buf.get_iter_at_line(out epos, line);
1612 print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1614 // in theory the last char will be '}' or '},' .. or ','
1615 // we should chop the ',' of the end...
1616 var str = buf.get_text(spos, epos, false);
1617 print("got string\n%s\n", str);
1625 // user defined functions
1626 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1628 this.error_line = validate_res.size;
1630 if (this.error_line < 1) {
1633 var tlines = this.el.get_line_count ();
1635 var valiter = validate_res.map_iterator();
1636 while (valiter.next()) {
1638 // print("get inter\n");
1639 var eline = valiter.get_key();
1640 if (eline > tlines) {
1643 this.el.get_iter_at_line( out iter, eline);
1644 //print("mark line\n");
1645 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1649 public string toString () {
1653 this.el.get_start_iter(out s);
1654 this.el.get_end_iter(out e);
1655 var ret = this.el.get_text(s,e,true);
1656 //print("TO STRING? " + ret);
1661 public class Xcls_EventControllerKey17 : Object
1663 public Gtk.EventControllerKey el;
1664 private Xcls_WindowRooView _this;
1670 public Xcls_EventControllerKey17(Xcls_WindowRooView _owner )
1673 this.el = new Gtk.EventControllerKey();
1677 // set gobject values
1680 this.el.key_pressed.connect( (keyval, keycode, state) => {
1684 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1685 GLib.debug("SAVE: ctrl-g pressed");
1686 _this.forwardSearch(true);
1689 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1690 GLib.debug("SAVE: ctrl-f pressed");
1691 _this.search_entry.el.grab_focus();
1695 //this.button_is_pressed = true;
1697 // print(event.key.keyval)
1705 // user defined functions
1708 public class Xcls_GestureClick18 : Object
1710 public Gtk.GestureClick el;
1711 private Xcls_WindowRooView _this;
1717 public Xcls_GestureClick18(Xcls_WindowRooView _owner )
1720 this.el = new Gtk.GestureClick();
1724 // set gobject values
1727 this.el.released.connect( (n_press, x, y) => {
1729 print("BUTTON RELEASE EVENT\n");
1730 _this.sourceview.onCursorChanged();
1731 //this.button_is_pressed = false;
1736 // user defined functions
1741 public class Xcls_Box19 : Object
1744 private Xcls_WindowRooView _this;
1750 public Xcls_Box19(Xcls_WindowRooView _owner )
1753 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1757 // set gobject values
1758 this.el.homogeneous = false;
1759 this.el.vexpand = false;
1760 new Xcls_search_entry( _this );
1761 this.el.append( _this.search_entry.el );
1762 new Xcls_search_results( _this );
1763 this.el.append( _this.search_results.el );
1764 new Xcls_nextBtn( _this );
1765 this.el.append( _this.nextBtn.el );
1766 new Xcls_backBtn( _this );
1767 this.el.append( _this.backBtn.el );
1768 var child_5 = new Xcls_MenuButton25( _this );
1770 this.el.append( child_5.el );
1773 // user defined functions
1775 public class Xcls_search_entry : Object
1777 public Gtk.SearchEntry el;
1778 private Xcls_WindowRooView _this;
1782 public Gtk.CssProvider css;
1785 public Xcls_search_entry(Xcls_WindowRooView _owner )
1788 _this.search_entry = this;
1789 this.el = new Gtk.SearchEntry();
1793 // set gobject values
1794 this.el.name = "roo-search-entry";
1795 this.el.hexpand = true;
1796 this.el.placeholder_text = "Press enter to search";
1797 var child_1 = new Xcls_EventControllerKey21( _this );
1799 this.el.add_controller( child_1.el );
1803 this.css = new Gtk.CssProvider();
1805 this.css.load_from_string(
1806 "#roo-search-entry { background-color: #ccc; }"
1809 Gtk.StyleContext.add_provider_for_display(
1810 this.el.get_display(),
1812 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1816 this.el.search_changed.connect( ( ) => {
1818 _this.search(_this.search_entry.el.text);
1819 _this.search_results.updateResults();
1821 GLib.Timeout.add_seconds(1,() => {
1822 _this.search_results.updateResults();
1828 // user defined functions
1829 public void forwardSearch (bool change_focus) {
1832 _this.forwardSearch(change_focus);
1836 switch(_this.windowstate.state) {
1837 case WindowState.State.CODEONLY:
1838 //case WindowState.State.CODE:
1839 // search the code being edited..
1840 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1843 case WindowState.State.PREVIEW:
1844 if (_this.windowstate.file.xtype == "Gtk") {
1845 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1847 _this.windowstate.window_rooview.forwardSearch(change_focus);
1856 public class Xcls_EventControllerKey21 : Object
1858 public Gtk.EventControllerKey el;
1859 private Xcls_WindowRooView _this;
1865 public Xcls_EventControllerKey21(Xcls_WindowRooView _owner )
1868 this.el = new Gtk.EventControllerKey();
1872 // set gobject values
1875 this.el.key_pressed.connect( (keyval, keycode, state) => {
1877 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1878 GLib.debug("SAVE: ctrl-g pressed");
1879 _this.forwardSearch(true);
1884 if (keyval == Gdk.Key.Return) {
1885 _this.forwardSearch(true);
1891 // print(event.key.keyval)
1897 // user defined functions
1901 public class Xcls_search_results : Object
1903 public Gtk.Label el;
1904 private Xcls_WindowRooView _this;
1910 public Xcls_search_results(Xcls_WindowRooView _owner )
1913 _this.search_results = this;
1914 this.el = new Gtk.Label( "No Results" );
1918 // set gobject values
1919 this.el.margin_end = 4;
1920 this.el.margin_start = 4;
1923 // user defined functions
1924 public void updateResults () {
1925 this.el.visible = true;
1927 var res = _this.searchcontext.get_occurrences_count();
1929 _this.search_results.el.label = "??? Matches";
1933 _this.nextBtn.el.sensitive = false;
1934 _this.backBtn.el.sensitive = false;
1937 _this.search_results.el.label = "%d Matches".printf(res);
1938 _this.nextBtn.el.sensitive = true;
1939 _this.backBtn.el.sensitive = true;
1942 _this.search_results.el.label = "No Matches";
1947 public class Xcls_nextBtn : Object
1949 public Gtk.Button el;
1950 private Xcls_WindowRooView _this;
1954 public bool always_show_image;
1957 public Xcls_nextBtn(Xcls_WindowRooView _owner )
1960 _this.nextBtn = this;
1961 this.el = new Gtk.Button();
1964 this.always_show_image = true;
1966 // set gobject values
1967 this.el.icon_name = "go-down";
1968 this.el.sensitive = false;
1971 this.el.clicked.connect( (event) => {
1973 _this.forwardSearch(true);
1978 // user defined functions
1981 public class Xcls_backBtn : Object
1983 public Gtk.Button el;
1984 private Xcls_WindowRooView _this;
1988 public bool always_show_image;
1991 public Xcls_backBtn(Xcls_WindowRooView _owner )
1994 _this.backBtn = this;
1995 this.el = new Gtk.Button();
1998 this.always_show_image = true;
2000 // set gobject values
2001 this.el.icon_name = "go-up";
2002 this.el.sensitive = false;
2005 this.el.clicked.connect( (event) => {
2007 _this.backSearch(true);
2013 // user defined functions
2016 public class Xcls_MenuButton25 : Object
2018 public Gtk.MenuButton el;
2019 private Xcls_WindowRooView _this;
2023 public bool always_show_image;
2026 public Xcls_MenuButton25(Xcls_WindowRooView _owner )
2029 this.el = new Gtk.MenuButton();
2032 this.always_show_image = true;
2034 // set gobject values
2035 this.el.icon_name = "emblem-system";
2036 new Xcls_search_settings( _this );
2037 this.el.popover = _this.search_settings.el;
2040 // user defined functions
2042 public class Xcls_search_settings : Object
2044 public Gtk.Popover el;
2045 private Xcls_WindowRooView _this;
2051 public Xcls_search_settings(Xcls_WindowRooView _owner )
2054 _this.search_settings = this;
2055 this.el = new Gtk.Popover();
2059 // set gobject values
2060 var child_1 = new Xcls_Box27( _this );
2061 this.el.child = child_1.el;
2064 // user defined functions
2066 public class Xcls_Box27 : Object
2069 private Xcls_WindowRooView _this;
2075 public Xcls_Box27(Xcls_WindowRooView _owner )
2078 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
2082 // set gobject values
2083 new Xcls_case_sensitive( _this );
2084 this.el.append( _this.case_sensitive.el );
2085 new Xcls_regex( _this );
2086 this.el.append( _this.regex.el );
2087 new Xcls_multiline( _this );
2088 this.el.append( _this.multiline.el );
2091 // user defined functions
2093 public class Xcls_case_sensitive : Object
2095 public Gtk.CheckButton el;
2096 private Xcls_WindowRooView _this;
2102 public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2105 _this.case_sensitive = this;
2106 this.el = new Gtk.CheckButton();
2110 // set gobject values
2111 this.el.label = "Case Sensitive";
2120 // user defined functions
2123 public class Xcls_regex : Object
2125 public Gtk.CheckButton el;
2126 private Xcls_WindowRooView _this;
2132 public Xcls_regex(Xcls_WindowRooView _owner )
2136 this.el = new Gtk.CheckButton();
2140 // set gobject values
2141 this.el.label = "Regex";
2150 // user defined functions
2153 public class Xcls_multiline : Object
2155 public Gtk.CheckButton el;
2156 private Xcls_WindowRooView _this;
2162 public Xcls_multiline(Xcls_WindowRooView _owner )
2165 _this.multiline = this;
2166 this.el = new Gtk.CheckButton();
2170 // set gobject values
2171 this.el.label = "Multi-line (add \\n)";
2180 // user defined functions