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 scroll_to_line (int line) {
248 GLib.Timeout.add(100, () => {
250 this.notebook.el.set_current_page( 1 );
253 var buf = this.sourceview.el.get_buffer();
255 var sbuf = (GtkSource.Buffer) buf;
259 sbuf.get_iter_at_line(out iter, line);
260 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
266 public class Xcls_notebook : Object
268 public Gtk.Notebook el;
269 private Xcls_WindowRooView _this;
275 public Xcls_notebook(Xcls_WindowRooView _owner )
278 _this.notebook = this;
279 this.el = new Gtk.Notebook();
283 // set gobject values
284 this.el.vexpand = true;
285 new Xcls_label_preview( _this );
286 new Xcls_label_code( _this );
287 new Xcls_paned( _this );
288 this.el.append_page ( _this.paned.el , _this.label_preview.el );
289 var child_4 = new Xcls_Box13( _this );
291 this.el.append_page ( child_4.el , _this.label_code.el );
294 // user defined functions
296 public class Xcls_label_preview : Object
299 private Xcls_WindowRooView _this;
305 public Xcls_label_preview(Xcls_WindowRooView _owner )
308 _this.label_preview = this;
309 this.el = new Gtk.Label( "Preview" );
313 // set gobject values
316 // user defined functions
319 public class Xcls_label_code : Object
322 private Xcls_WindowRooView _this;
328 public Xcls_label_code(Xcls_WindowRooView _owner )
331 _this.label_code = this;
332 this.el = new Gtk.Label( "Preview Generated Code" );
336 // set gobject values
339 // user defined functions
342 public class Xcls_paned : Object
345 private Xcls_WindowRooView _this;
351 public Xcls_paned(Xcls_WindowRooView _owner )
355 this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
359 // set gobject values
360 this.el.vexpand = true;
361 new Xcls_viewbox( _this );
362 this.el.set_start_child ( _this.viewbox.el );
363 new Xcls_inspectorcontainer( _this );
364 this.el.set_end_child ( _this.inspectorcontainer.el );
367 // user defined functions
369 public class Xcls_viewbox : Object
372 private Xcls_WindowRooView _this;
378 public Xcls_viewbox(Xcls_WindowRooView _owner )
381 _this.viewbox = this;
382 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
386 // set gobject values
387 this.el.homogeneous = false;
388 this.el.vexpand = true;
389 var child_1 = new Xcls_Box7( _this );
391 this.el.append( child_1.el );
392 new Xcls_view( _this );
393 this.el.append( _this.view.el );
396 // user defined functions
398 public class Xcls_Box7 : Object
401 private Xcls_WindowRooView _this;
407 public Xcls_Box7(Xcls_WindowRooView _owner )
410 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
414 // set gobject values
415 this.el.homogeneous = true;
416 this.el.height_request = 20;
417 this.el.vexpand = false;
418 var child_1 = new Xcls_Button8( _this );
420 this.el.append( child_1.el );
421 new Xcls_AutoRedraw( _this );
422 this.el.append( _this.AutoRedraw.el );
423 var child_3 = new Xcls_Button10( _this );
425 this.el.append( child_3.el );
428 // user defined functions
430 public class Xcls_Button8 : Object
432 public Gtk.Button el;
433 private Xcls_WindowRooView _this;
439 public Xcls_Button8(Xcls_WindowRooView _owner )
442 this.el = new Gtk.Button();
446 // set gobject values
447 this.el.label = "Redraw";
450 this.el.clicked.connect( ( ) => {
451 _this.view.renderJS( true);
455 // user defined functions
458 public class Xcls_AutoRedraw : Object
460 public Gtk.CheckButton el;
461 private Xcls_WindowRooView _this;
467 public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
470 _this.AutoRedraw = this;
471 this.el = new Gtk.CheckButton();
475 // set gobject values
476 this.el.active = true;
477 this.el.label = "Auto Redraw On";
480 this.el.toggled.connect( (state) => {
481 this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
485 // user defined functions
488 public class Xcls_Button10 : Object
490 public Gtk.Button el;
491 private Xcls_WindowRooView _this;
497 public Xcls_Button10(Xcls_WindowRooView _owner )
500 this.el = new Gtk.Button();
504 // set gobject values
505 this.el.label = "Full Redraw";
508 this.el.clicked.connect( () => {
509 _this.view.redraws = 99;
510 // _this.view.el.web_context.clear_cache();
511 //_this.view.renderJS(true);
512 FakeServerCache.clear();
518 // user defined functions
522 public class Xcls_view : Object
524 public WebKit.WebView el;
525 private Xcls_WindowRooView _this;
529 public WebKit.WebInspector inspector;
530 public bool pendingRedraw;
532 public bool refreshRequired;
534 public string runhtml;
535 public string renderedData;
536 public GLib.DateTime lastRedraw;
539 public Xcls_view(Xcls_WindowRooView _owner )
543 this.el = new WebKit.WebView();
546 this.pendingRedraw = false;
548 this.refreshRequired = false;
551 this.renderedData = "";
552 this.lastRedraw = null;
554 // set gobject values
555 this.el.vexpand = true;
560 // this may not work!?
561 var settings = this.el.get_settings();
562 settings.enable_developer_extras = true;
565 var fs= new FakeServer(this.el);
567 // this was an attempt to change the url perms.. did not work..
568 // settings.enable_file_access_from_file_uris = true;
569 // settings.enable_offline_web_application_cache - true;
570 // settings.enable_universal_access_from_file_uris = true;
577 // FIXME - base url of script..
578 // we need it so some of the database features work.
579 this.el.load_html( "Render not ready" ,
580 //fixme - should be a config option!
581 // or should we catch stuff and fix it up..
582 "http://localhost/app.Builder/"
586 //this.el.open('file:///' + __script_path__ + '/../builder.html');
591 Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
592 null, // list of targets
593 Gdk.DragAction.COPY // what to do with data after dropped
596 // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
597 Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
599 GLib.Timeout.add_seconds(1, () =>{
600 //print("run refresh?");
601 if (this.el == null) {
612 this.el.script_dialog.connect( (dialog) => {
615 if (this.el == null) {
619 var msg = dialog.get_message();
620 if (msg.length < 4) {
624 GLib.debug("script dialog got %s", msg);
626 if (msg.substring(0,4) != "IPC:") {
629 var ar = msg.split(":", 3);
636 GLib.debug("GOT saveHTML %d", ar[2].length);
637 _this.file.saveHTML(ar[2]);
645 this.el.ready_to_show.connect( ( ) => {
646 this.initInspector();
649 this.el.load_changed.connect( (le) => {
650 if (le != WebKit.LoadEvent.FINISHED) {
653 if (this.runjs.length < 1) {
656 // this.el.run_javascript(this.runjs, null);
657 FakeServerCache.remove( this.runjs);
662 // user defined functions
663 public void initInspector () {
667 // this.inspector.open_window.connect(() => {
668 this.inspector = this.el.get_inspector();
670 this.inspector.open_window.connect(() => {
671 print("inspector attach\n");
672 var wv = this.inspector.get_web_view();
674 print("got inspector web view\n");
676 var cn = _this.inspectorcontainer.el.get_first_child();
678 _this.inspectorcontainer.el.remove(cn);
681 _this.inspectorcontainer.el.append(wv);
684 print("got inspector web view FAILED\n");
685 //this.inspector.close();
687 //this.inspector = null;
694 this.inspector.show();
699 public void renderJS (bool force) {
701 // this is the public redraw call..
702 // we refresh in a loop privately..
703 var autodraw = _this.AutoRedraw.el.active;
704 if (!autodraw && !force) {
705 print("Skipping redraw - no force, and autodraw off");
709 this.refreshRequired = true;
711 public void reInit () {
713 // if this happens destroy the webkit..
715 this.el.stop_loading();
717 if (_this.viewbox.el.get_parent() == null) {
722 _this.viewbox.el.remove(_this.viewcontainer.el);
723 //_this.paned.el.remove(_this.inspectorcontainer.el);
725 // destory seems to cause problems.
727 //_this.viewcontainer.el.destroy();
728 //_this.inspectorcontainer.el.destroy();
729 var inv =new Xcls_inspectorcontainer(_this);
731 _this.paned.el.set_end_child(inv.el);
732 _this.inspectorcontainer = inv;
735 var nv =new Xcls_viewcontainer(_this);
737 _this.viewbox.el.append(nv.el);
739 _this.viewcontainer = nv;
742 //while(Gtk.events_pending ()) Gtk.main_iteration ();
743 //_this.view.renderJS(true);
744 _this.view.refreshRequired = true;
748 public void runRefresh ()
750 // this is run every 2 seconds from the init..
754 if (!this.refreshRequired) {
755 // print("no refresh required");
759 if (this.lastRedraw != null) {
760 // do not redraw if last redraw was less that 5 seconds ago.
761 if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
766 if (_this.file == null) {
771 this.refreshRequired = false;
772 // print("HTML RENDERING");
775 //this.get('/BottomPane').el.show();
776 //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
777 _this.file.webkit_page_id = this.el.get_page_id();
779 var js = _this.file.toSourcePreview();
788 var project = (Project.Roo) _this.file.project;
790 //print (project.fn);
791 // set it to non-empty.
793 // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
796 // this.runhtml = this.runhtml || '';
799 // then we need to reload the browser using
800 // load_html_string..
802 // then trigger a redraw once it's loaded..
803 this.pendingRedraw = true;
805 var runhtml = "<script type=\"text/javascript\">\n" ;
809 GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
814 runhtml += builderhtml + "\n";
815 runhtml += "</script>\n" ;
817 // fix to make sure they are the same..
818 this.runhtml = project.runhtml;
819 // need to modify paths
822 var base_template = project.base_template;
824 if (base_template.length > 0 && !FileUtils.test(
825 BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
827 print("invalid base_template name - using default: %s\n", base_template);
832 GLib.FileUtils.get_contents(
833 BuilderApplication.configDirectory() + "/resources/" +
834 (base_template.length > 0 ? base_template : "roo.builder.html")
840 this.renderedData = js;
843 string js_src = js + "
844 Roo.onReady(function() {
845 if (" + _this.file.name +".show) {
846 " + _this.file.name +".show({});
848 Builder.saveHTML.defer(100, Builder);
851 Roo.XComponent.build();
854 // print("render js: " + js);
856 // console.log('not loaded yet');
858 this.lastRedraw = new DateTime.now_local();
861 //this.runjs = js_src;
862 var fc = FakeServerCache.factory_with_data(js_src);
863 this.runjs = fc.fname;
865 var html = inhtml.replace("</head>", runhtml + this.runhtml +
866 "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
867 // "<script type=\"text/javascript\">\n" +
872 //print("LOAD HTML " + html);
874 var rootURL = project.rootURL;
878 this.el.load_html( html ,
879 //fixme - should be a config option!
880 (rootURL.length > 0 ? rootURL : "xhttp://localhost/roobuilder/")
882 this.initInspector();
883 // force the inspector...
884 // this.initInspector();
886 // - no need for this, the builder javascript will call it when build is complete
887 //GLib.Timeout.add_seconds(1, () => {
888 // this.el.run_javascript("Builder.saveHTML()",null);
891 // print( "before render" + this.lastRedraw);
892 // print( "after render" + (new Date()));
898 public class Xcls_inspectorcontainer : Object
901 private Xcls_WindowRooView _this;
907 public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
910 _this.inspectorcontainer = this;
911 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
915 // set gobject values
916 this.el.vexpand = true;
919 // user defined functions
923 public class Xcls_Box13 : Object
926 private Xcls_WindowRooView _this;
932 public Xcls_Box13(Xcls_WindowRooView _owner )
935 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
939 // set gobject values
940 this.el.vexpand = true;
941 new Xcls_sourceviewscroll( _this );
942 this.el.append( _this.sourceviewscroll.el );
943 var child_2 = new Xcls_Box19( _this );
945 this.el.append( child_2.el );
948 // user defined functions
950 public class Xcls_sourceviewscroll : Object
952 public Gtk.ScrolledWindow el;
953 private Xcls_WindowRooView _this;
959 public Xcls_sourceviewscroll(Xcls_WindowRooView _owner )
962 _this.sourceviewscroll = this;
963 this.el = new Gtk.ScrolledWindow();
967 // set gobject values
968 this.el.vexpand = true;
969 new Xcls_sourceview( _this );
970 this.el.set_child ( _this.sourceview.el );
973 // user defined functions
975 public class Xcls_sourceview : Object
977 public GtkSource.View el;
978 private Xcls_WindowRooView _this;
982 public int editable_start_pos;
984 public bool button_is_pressed;
985 public string prop_selected;
986 public bool key_is_pressed;
987 public Gtk.CssProvider css;
988 public JsRender.Node? node_selected;
991 public Xcls_sourceview(Xcls_WindowRooView _owner )
994 _this.sourceview = this;
995 this.el = new GtkSource.View();
998 this.editable_start_pos = -1;
1000 this.button_is_pressed = false;
1001 this.prop_selected = "";
1002 this.key_is_pressed = false;
1003 this.node_selected = null;
1005 // set gobject values
1006 this.el.name = "roo-view";
1007 this.el.editable = false;
1008 this.el.show_line_marks = true;
1009 this.el.show_line_numbers = true;
1010 new Xcls_buffer( _this );
1011 this.el.set_buffer ( _this.buffer.el );
1012 var child_2 = new Xcls_EventControllerKey17( _this );
1014 this.el.add_controller ( child_2.el );
1015 var child_3 = new Xcls_GestureClick18( _this );
1017 this.el.add_controller( child_3.el );
1023 this.css = new Gtk.CssProvider();
1025 this.css.load_from_string(
1026 "#roo-view { font: 10px monospace; }"
1029 Gtk.StyleContext.add_provider_for_display(
1030 this.el.get_display(),
1032 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1037 this.loading = true;
1038 //var buf = this.el.get_buffer();
1039 //buf.notify.connect(this.onCursorChanged);
1042 var attrs = new GtkSource.MarkAttributes();
1043 var pink = Gdk.RGBA();
1044 pink.parse ( "pink");
1045 attrs.set_background ( pink);
1046 attrs.set_icon_name ( "process-stop");
1047 attrs.query_tooltip_text.connect(( mark) => {
1048 //print("tooltip query? %s\n", mark.name);
1052 this.el.set_mark_attributes ("ERR", attrs, 1);
1054 var wattrs = new GtkSource.MarkAttributes();
1055 var blue = Gdk.RGBA();
1056 blue.parse ( "#ABF4EB");
1057 wattrs.set_background ( blue);
1058 wattrs.set_icon_name ( "process-stop");
1059 wattrs.query_tooltip_text.connect(( mark) => {
1060 //print("tooltip query? %s\n", mark.name);
1064 this.el.set_mark_attributes ("WARN", wattrs, 1);
1068 var dattrs = new GtkSource.MarkAttributes();
1069 var purple = Gdk.RGBA();
1070 purple.parse ( "#EEA9FF");
1071 dattrs.set_background ( purple);
1072 dattrs.set_icon_name ( "process-stop");
1073 dattrs.query_tooltip_text.connect(( mark) => {
1074 //print("tooltip query? %s\n", mark.name);
1078 this.el.set_mark_attributes ("DEPR", dattrs, 1);
1081 var gattrs = new GtkSource.MarkAttributes();
1082 var grey = Gdk.RGBA();
1083 grey.parse ( "#ccc");
1084 gattrs.set_background ( grey);
1087 this.el.set_mark_attributes ("grey", gattrs, 1);
1097 this.el.query_tooltip.connect( (x, y, keyboard_tooltip, tooltip) => {
1099 //GLib.debug("query tooltip");
1103 var yoff = (int) _this.sourceviewscroll.el.vadjustment.value;
1105 this.el.get_iter_at_position (out iter, out trailing, x, y + yoff);
1107 var l = iter.get_line();
1108 //GLib.debug("query tooltip line %d", (int) l);
1109 var marks = _this.buffer.el.get_source_marks_at_line(l, null);
1110 //GLib.debug("query tooltip line marks %d", (int) marks.length());
1112 marks.@foreach((m) => {
1113 //GLib.debug("got mark %s", m.name);
1114 str += (str.length > 0 ? "\n" : "") + m.name;
1116 // true if there is a mark..
1117 if (str.length > 0 ) {
1118 tooltip.set_text( str);
1120 return str.length > 0 ? true : false;
1125 // user defined functions
1126 public void loadFile ( ) {
1127 this.loading = true;
1130 // get the cursor and scroll position....
1131 var buf = this.el.get_buffer();
1132 var cpos = buf.cursor_position;
1134 print("BEFORE LOAD cursor = %d\n", cpos);
1136 var vadj_pos = this.el.get_vadjustment().get_value();
1141 var sbuf = (GtkSource.Buffer) buf;
1145 if (_this.file == null || _this.file.xtype != "Roo") {
1146 print("xtype != Roo");
1147 this.loading = false;
1151 // get the string from the rendered tree...
1153 var str = _this.file.toSource();
1155 // print("setting str %d\n", str.length);
1156 buf.set_text(str, str.length);
1157 var lm = GtkSource.LanguageManager.get_default();
1159 //?? is javascript going to work as js?
1161 ((GtkSource.Buffer)(buf)) .set_language(lm.get_language(_this.file.language));
1167 sbuf.get_bounds (out start, out end);
1168 sbuf.remove_source_marks (start, end, null); // remove all marks..
1170 GLib.Timeout.add(500, () => {
1172 print("RESORTING cursor to = %d\n", cpos);
1173 Gtk.TextIter cpos_iter;
1174 buf.get_iter_at_offset(out cpos_iter, cpos);
1175 buf.place_cursor(cpos_iter);
1177 this.el.get_vadjustment().set_value(vadj_pos);;
1180 this.onCursorChanged();
1183 //_this.buffer.checkSyntax();
1187 this.loading = false;
1188 _this.buffer.dirty = false;
1190 public void onCursorChanged (/*ParamSpec ps*/) {
1192 if (!this.key_is_pressed && !this.button_is_pressed) {
1199 // if (ps.name != "cursor-position") {
1203 var buf = this.el.get_buffer();
1204 //print("cursor changed : %d\n", buf.cursor_position);
1206 buf.get_iter_at_offset(out cpos, buf.cursor_position);
1208 var ln = cpos.get_line();
1211 // --- select node at line....
1213 var node = _this.file.lineToNode(ln+1);
1216 print("can not find node\n");
1219 var prop = node.lineToProp(ln+1);
1220 print("prop : %s", prop == null ? "???" : prop.name);
1223 // ---------- this selects the tree's node...
1225 var ltree = _this.main_window.windowstate.left_tree;
1226 ltree.model.selectNode(node);
1229 //print("changing cursor on tree..\n");
1233 // let's try allowing editing on the methods.
1234 // a little klunky at present..
1235 this.prop_selected = "";
1238 //see if we can find it..
1239 var kv = prop.split(":");
1242 //var k = prop.get_key(kv[1]);
1243 // fixme -- need to determine if it's an editable property...
1244 this.prop_selected = prop;
1246 } else if (kv[0] == "l") {
1247 this.prop_selected = prop;
1252 // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
1253 //this.nodeSelected(node,false);
1255 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
1258 // highlight the node..
1260 public void nodeSelected (JsRender.Node? sel, bool scroll ) {
1264 // this is connected in widnowstate
1268 // while(Gtk.events_pending()) {
1269 // Gtk.main_iteration();
1272 this.node_selected = sel;
1274 // this.updateGreySelection(scroll);
1279 public void updateGreySelection (bool scroll) {
1280 var sel = this.node_selected;
1281 print("node selected\n");
1282 var buf = this.el.get_buffer();
1283 var sbuf = (GtkSource.Buffer) buf;
1286 this.clearGreySelection();
1291 print("no selected node\n");
1292 // no highlighting..
1296 print("highlight region %d to %d\n", sel.line_start,sel.line_end);
1298 sbuf.get_iter_at_line(out iter, sel.line_start);
1301 Gtk.TextIter cur_iter;
1302 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
1304 var cursor_at_line = cur_iter.get_line();
1307 //var cur_line = cur_iter.get_line();
1308 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
1312 print("scrolling to node -- should occur on node picking.\n");
1313 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
1316 var start_line = sel.line_start;
1317 var end_line = sel.line_end;
1320 this.el.editable = false;
1322 //var colon_pos = 0;
1324 this.editable_start_pos = -1;
1326 // now if we have selected a property...
1327 if (this.prop_selected.length> 0 ) {
1330 if (sel.getPropertyRange(this.prop_selected, out nstart, out nend) && nend > nstart) {
1331 start_line = nstart;
1333 // this.el.editable = true; << cant do this!!?
1334 print("start line = %d, end line = %d\n", start_line, end_line);
1336 // see if we are 'right of ':'
1337 // get an iter for the start of the line.
1338 Gtk.TextIter start_first_line_iter,end_first_line_iter;
1339 this.el.buffer.get_iter_at_line(out start_first_line_iter, start_line -1);
1340 this.el.buffer.get_iter_at_line(out end_first_line_iter, start_line -1);
1345 if (end_first_line_iter.forward_to_line_end()) {
1346 var first_line = this.el.buffer.get_text(start_first_line_iter, end_first_line_iter, false);
1348 print("first line = %s\n", first_line);
1349 if (first_line.contains(":")) {
1350 this.editable_start_pos = start_first_line_iter.get_offset() + first_line.index_of(":") + 1;
1351 print("colon_pos = %d\n", this.editable_start_pos);
1355 //Gtk.TextIter colon_iter;
1356 //sbuf.get_iter_at_offset (out colon_iter, colon_pos);
1357 //sbuf.create_source_mark(null, "active_text", colon_iter);
1362 //print("is cursor at line? %d ?= %d\n", start_line -1 , cursor_at_line);
1363 //if (start_line - 1 == cursor_at_line) {
1364 // should be ok - current_posssion can not be less than '-1'...
1365 if (sbuf.cursor_position < this.editable_start_pos) {
1367 print("cursor is before start pos.. - turn off editable...\n");
1368 //var before_cursor_string = this.el.buffer.get_text(start_line_iter, cur_iter, false);
1369 //print("before cursor string = %s\n", before_cursor_string);
1370 //if (!before_cursor_string.contains(":")) {
1371 this.el.editable = false;
1380 print("propSelected = %s range %d -> %d\n", this.prop_selected, start_line, end_line);
1385 print("checking selection\n");
1388 // check selection - if it's out of 'bounds'
1389 if (this.el.editable && sbuf.get_has_selection()) {
1390 Gtk.TextIter sel_start_iter, sel_end_iter;
1391 sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
1393 if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
1394 sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
1396 this.el.editable = false;
1398 if (this.editable_start_pos > 0 &&
1399 (sel_start_iter.get_offset() < this.editable_start_pos || sel_end_iter.get_offset() < this.editable_start_pos)
1402 this.el.editable = false;
1412 for (var i = 0; i < buf.get_line_count();i++) {
1413 if (i < (start_line -1) || i > (end_line -1)) {
1415 sbuf.get_iter_at_line(out iter, i);
1416 sbuf.create_source_mark(null, "grey", iter);
1421 if (scroll && (cursor_at_line > end_line || cursor_at_line < start_line)) {
1422 Gtk.TextIter cpos_iter;
1423 buf.get_iter_at_line(out cpos_iter, start_line);
1425 buf.place_cursor(cpos_iter);
1430 public void highlightErrorsJson (string type, Json.Object obj) {
1431 // this is a hook for the vala code - it has no value in javascript
1432 // as we only have one error ususally....
1439 public void clearGreySelection () {
1440 // clear all the marks..
1441 var sbuf = (GtkSource.Buffer)this.el.buffer;
1446 sbuf.get_bounds (out start, out end);
1447 sbuf.remove_source_marks (start, end, "grey");
1451 public string toString () {
1454 this.el.get_buffer().get_start_iter(out s);
1455 this.el.get_buffer().get_end_iter(out e);
1456 var ret = this.el.get_buffer().get_text(s,e,true);
1457 //print("TO STRING? " + ret);
1461 public class Xcls_buffer : Object
1463 public GtkSource.Buffer el;
1464 private Xcls_WindowRooView _this;
1468 public int error_line;
1472 public Xcls_buffer(Xcls_WindowRooView _owner )
1475 _this.buffer = this;
1476 this.el = new GtkSource.Buffer( null );
1479 this.error_line = -1;
1482 // set gobject values
1485 this.el.changed.connect( () => {
1489 // _this.save_button.el.sensitive = true;
1490 ///?? has changed occured during loading?
1492 // only trigger this if
1497 if (_this.sourceview.loading) {
1503 print("- PREVIEW EDITOR CHANGED--");
1506 // this.checkSyntax(); // this calls backs and highlights errors.. in theory...
1510 if (!_this.sourceview.button_is_pressed && !_this.sourceview.key_is_pressed) {
1511 print("button or key not pressed to generate change?!\n");
1516 // what are we editing??
1517 if (null == _this.sourceview.node_selected || _this.sourceview.prop_selected.length < 1) {
1521 // find the colon on the first line...
1523 if (_this.sourceview.editable_start_pos > -1) {
1525 var buf = (GtkSource.Buffer)_this.sourceview.el.get_buffer();
1527 //print("cursor changed : %d\n", buf.cursor_position);
1528 Gtk.TextIter spos,epos;
1529 buf.get_iter_at_offset(out spos, _this.sourceview.editable_start_pos);
1530 buf.get_iter_at_offset(out epos, _this.sourceview.editable_start_pos); // initialize epos..
1533 var line = spos.get_line();
1534 var endline = buf.get_line_count();
1535 while (line < endline) {
1537 buf.get_iter_at_line(out epos, line);
1538 if (buf.get_source_marks_at_line(line, "grey").length() > 0) {
1539 buf.get_iter_at_line(out epos, line);
1546 print("End Offset = %d/%d\n", epos.get_line(), epos.get_offset());
1548 // in theory the last char will be '}' or '},' .. or ','
1549 // we should chop the ',' of the end...
1550 var str = buf.get_text(spos, epos, false);
1551 print("got string\n%s\n", str);
1559 // user defined functions
1560 public bool highlightErrors ( Gee.HashMap<int,string> validate_res) {
1562 this.error_line = validate_res.size;
1564 if (this.error_line < 1) {
1567 var tlines = this.el.get_line_count ();
1569 var valiter = validate_res.map_iterator();
1570 while (valiter.next()) {
1572 // print("get inter\n");
1573 var eline = valiter.get_key();
1574 if (eline > tlines) {
1577 this.el.get_iter_at_line( out iter, eline);
1578 //print("mark line\n");
1579 this.el.create_source_mark(valiter.get_value(), "ERR", iter);
1583 public string toString () {
1587 this.el.get_start_iter(out s);
1588 this.el.get_end_iter(out e);
1589 var ret = this.el.get_text(s,e,true);
1590 //print("TO STRING? " + ret);
1595 public class Xcls_EventControllerKey17 : Object
1597 public Gtk.EventControllerKey el;
1598 private Xcls_WindowRooView _this;
1604 public Xcls_EventControllerKey17(Xcls_WindowRooView _owner )
1607 this.el = new Gtk.EventControllerKey();
1611 // set gobject values
1614 this.el.key_pressed.connect( (keyval, keycode, state) => {
1618 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1619 GLib.debug("SAVE: ctrl-g pressed");
1620 _this.forwardSearch(true);
1623 if (keyval == Gdk.Key.f && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1624 GLib.debug("SAVE: ctrl-f pressed");
1625 _this.search_entry.el.grab_focus();
1629 //this.button_is_pressed = true;
1631 // print(event.key.keyval)
1639 // user defined functions
1642 public class Xcls_GestureClick18 : Object
1644 public Gtk.GestureClick el;
1645 private Xcls_WindowRooView _this;
1651 public Xcls_GestureClick18(Xcls_WindowRooView _owner )
1654 this.el = new Gtk.GestureClick();
1658 // set gobject values
1661 this.el.released.connect( (n_press, x, y) => {
1663 print("BUTTON RELEASE EVENT\n");
1664 _this.sourceview.onCursorChanged();
1665 //this.button_is_pressed = false;
1670 // user defined functions
1675 public class Xcls_Box19 : Object
1678 private Xcls_WindowRooView _this;
1684 public Xcls_Box19(Xcls_WindowRooView _owner )
1687 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
1691 // set gobject values
1692 this.el.homogeneous = false;
1693 this.el.vexpand = false;
1694 new Xcls_search_entry( _this );
1695 this.el.append( _this.search_entry.el );
1696 new Xcls_search_results( _this );
1697 this.el.append( _this.search_results.el );
1698 new Xcls_nextBtn( _this );
1699 this.el.append( _this.nextBtn.el );
1700 new Xcls_backBtn( _this );
1701 this.el.append( _this.backBtn.el );
1702 var child_5 = new Xcls_MenuButton25( _this );
1704 this.el.append( child_5.el );
1707 // user defined functions
1709 public class Xcls_search_entry : Object
1711 public Gtk.SearchEntry el;
1712 private Xcls_WindowRooView _this;
1716 public Gtk.CssProvider css;
1719 public Xcls_search_entry(Xcls_WindowRooView _owner )
1722 _this.search_entry = this;
1723 this.el = new Gtk.SearchEntry();
1727 // set gobject values
1728 this.el.name = "roo-search-entry";
1729 this.el.hexpand = true;
1730 this.el.placeholder_text = "Press enter to search";
1731 var child_1 = new Xcls_EventControllerKey21( _this );
1733 this.el.add_controller( child_1.el );
1737 this.css = new Gtk.CssProvider();
1739 this.css.load_from_string(
1740 "#roo-search-entry { background-color: #ccc; }"
1743 Gtk.StyleContext.add_provider_for_display(
1744 this.el.get_display(),
1746 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
1750 this.el.search_changed.connect( ( ) => {
1752 _this.search(_this.search_entry.el.text);
1753 _this.search_results.updateResults();
1755 GLib.Timeout.add_seconds(1,() => {
1756 _this.search_results.updateResults();
1762 // user defined functions
1763 public void forwardSearch (bool change_focus) {
1766 _this.forwardSearch(change_focus);
1770 switch(_this.windowstate.state) {
1771 case WindowState.State.CODEONLY:
1772 //case WindowState.State.CODE:
1773 // search the code being edited..
1774 _this.windowstate.code_editor_tab.forwardSearch(change_focus);
1777 case WindowState.State.PREVIEW:
1778 if (_this.windowstate.file.xtype == "Gtk") {
1779 _this.windowstate.window_gladeview.forwardSearch(change_focus);
1781 _this.windowstate.window_rooview.forwardSearch(change_focus);
1790 public class Xcls_EventControllerKey21 : Object
1792 public Gtk.EventControllerKey el;
1793 private Xcls_WindowRooView _this;
1799 public Xcls_EventControllerKey21(Xcls_WindowRooView _owner )
1802 this.el = new Gtk.EventControllerKey();
1806 // set gobject values
1809 this.el.key_pressed.connect( (keyval, keycode, state) => {
1811 if (keyval == Gdk.Key.g && (state & Gdk.ModifierType.CONTROL_MASK ) > 0 ) {
1812 GLib.debug("SAVE: ctrl-g pressed");
1813 _this.forwardSearch(true);
1818 if (keyval == Gdk.Key.Return) {
1819 _this.forwardSearch(true);
1825 // print(event.key.keyval)
1831 // user defined functions
1835 public class Xcls_search_results : Object
1837 public Gtk.Label el;
1838 private Xcls_WindowRooView _this;
1844 public Xcls_search_results(Xcls_WindowRooView _owner )
1847 _this.search_results = this;
1848 this.el = new Gtk.Label( "No Results" );
1852 // set gobject values
1853 this.el.margin_end = 4;
1854 this.el.margin_start = 4;
1857 // user defined functions
1858 public void updateResults () {
1859 this.el.visible = true;
1861 var res = _this.searchcontext.get_occurrences_count();
1863 _this.search_results.el.label = "??? Matches";
1867 _this.nextBtn.el.sensitive = false;
1868 _this.backBtn.el.sensitive = false;
1871 _this.search_results.el.label = "%d Matches".printf(res);
1872 _this.nextBtn.el.sensitive = true;
1873 _this.backBtn.el.sensitive = true;
1876 _this.search_results.el.label = "No Matches";
1881 public class Xcls_nextBtn : Object
1883 public Gtk.Button el;
1884 private Xcls_WindowRooView _this;
1888 public bool always_show_image;
1891 public Xcls_nextBtn(Xcls_WindowRooView _owner )
1894 _this.nextBtn = this;
1895 this.el = new Gtk.Button();
1898 this.always_show_image = true;
1900 // set gobject values
1901 this.el.icon_name = "go-down";
1902 this.el.sensitive = false;
1905 this.el.clicked.connect( (event) => {
1907 _this.forwardSearch(true);
1912 // user defined functions
1915 public class Xcls_backBtn : Object
1917 public Gtk.Button el;
1918 private Xcls_WindowRooView _this;
1922 public bool always_show_image;
1925 public Xcls_backBtn(Xcls_WindowRooView _owner )
1928 _this.backBtn = this;
1929 this.el = new Gtk.Button();
1932 this.always_show_image = true;
1934 // set gobject values
1935 this.el.icon_name = "go-up";
1936 this.el.sensitive = false;
1939 this.el.clicked.connect( (event) => {
1941 _this.backSearch(true);
1947 // user defined functions
1950 public class Xcls_MenuButton25 : Object
1952 public Gtk.MenuButton el;
1953 private Xcls_WindowRooView _this;
1957 public bool always_show_image;
1960 public Xcls_MenuButton25(Xcls_WindowRooView _owner )
1963 this.el = new Gtk.MenuButton();
1966 this.always_show_image = true;
1968 // set gobject values
1969 this.el.icon_name = "emblem-system";
1970 new Xcls_search_settings( _this );
1971 this.el.popover = _this.search_settings.el;
1974 // user defined functions
1976 public class Xcls_search_settings : Object
1978 public Gtk.Popover el;
1979 private Xcls_WindowRooView _this;
1985 public Xcls_search_settings(Xcls_WindowRooView _owner )
1988 _this.search_settings = this;
1989 this.el = new Gtk.Popover();
1993 // set gobject values
1994 var child_1 = new Xcls_Box27( _this );
1995 this.el.child = child_1.el;
1998 // user defined functions
2000 public class Xcls_Box27 : Object
2003 private Xcls_WindowRooView _this;
2009 public Xcls_Box27(Xcls_WindowRooView _owner )
2012 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
2016 // set gobject values
2017 new Xcls_case_sensitive( _this );
2018 this.el.append( _this.case_sensitive.el );
2019 new Xcls_regex( _this );
2020 this.el.append( _this.regex.el );
2021 new Xcls_multiline( _this );
2022 this.el.append( _this.multiline.el );
2025 // user defined functions
2027 public class Xcls_case_sensitive : Object
2029 public Gtk.CheckButton el;
2030 private Xcls_WindowRooView _this;
2036 public Xcls_case_sensitive(Xcls_WindowRooView _owner )
2039 _this.case_sensitive = this;
2040 this.el = new Gtk.CheckButton();
2044 // set gobject values
2045 this.el.label = "Case Sensitive";
2054 // user defined functions
2057 public class Xcls_regex : Object
2059 public Gtk.CheckButton el;
2060 private Xcls_WindowRooView _this;
2066 public Xcls_regex(Xcls_WindowRooView _owner )
2070 this.el = new Gtk.CheckButton();
2074 // set gobject values
2075 this.el.label = "Regex";
2084 // user defined functions
2087 public class Xcls_multiline : Object
2089 public Gtk.CheckButton el;
2090 private Xcls_WindowRooView _this;
2096 public Xcls_multiline(Xcls_WindowRooView _owner )
2099 _this.multiline = this;
2100 this.el = new Gtk.CheckButton();
2104 // set gobject values
2105 this.el.label = "Multi-line (add \\n)";
2114 // user defined functions