1 static Xcls_GtkView _GtkView;
3 public class Xcls_GtkView : Object
6 private Xcls_GtkView _this;
8 public static Xcls_GtkView singleton()
10 if (_GtkView == null) {
11 _GtkView= new Xcls_GtkView();
15 public Xcls_notebook notebook;
16 public Xcls_label_preview label_preview;
17 public Xcls_label_code label_code;
18 public Xcls_view_layout view_layout;
19 public Xcls_container container;
20 public Xcls_sourceview sourceview;
23 public Gtk.Widget lastObj;
25 public int last_search_end;
26 public Gtk.SourceSearchContext searchcontext;
27 public JsRender.JsRender file;
29 public Xcls_MainWindow main_window;
35 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
40 this.last_search_end = 0;
45 this.el.hexpand = true;
46 this.el.vexpand = true;
47 var child_0 = new Xcls_notebook( _this );
49 this.el.pack_start ( child_0.el , true,true,0 );
52 this.el.size_allocate.connect( (aloc) => {
54 this.width = aloc.width;
55 this.height =aloc.height;
59 // user defined functions
60 public void scroll_to_line (int line) {
61 this.notebook.el.page = 1;// code preview...
63 GLib.Timeout.add(500, () => {
68 var buf = this.sourceview.el.get_buffer();
70 var sbuf = (Gtk.SourceBuffer) buf;
74 sbuf.get_iter_at_line(out iter, line);
75 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
81 public void createThumb () {
84 if (this.file == null) {
87 // only screenshot the gtk preview..
88 if (this.notebook.el.page > 0 ) {
93 var filename = this.file.getIconFileName(false);
95 var win = this.el.get_parent_window();
96 var width = win.get_width();
97 var height = win.get_height();
99 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
100 screenshot.save(filename,"png");
112 // should we hold until it's printed...
123 public void loadFile (JsRender.JsRender file)
127 if (file.tree == null) {
130 this.notebook.el.page = 0;// gtk preview
135 this.sourceview.loadFile();
136 this.searchcontext = null;
139 if (this.lastObj != null) {
140 this.container.el.remove(this.lastObj);
143 // hide the compile view at present..
149 print("ALLOC SET SIZES %d, %d\n", w,h);
151 // set the container size min to 500/500 or 20 px less than max..
152 w = int.max (w-20, 500);
153 h = int.max (h-20, 500);
155 print("SET SIZES %d, %d\n", w,h);
156 _this.container.el.set_size_request(w,h);
158 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
159 var rgba = Gdk.RGBA ();
161 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
164 var x = new JsRender.NodeToGtk((Project.Gtk) file.project, file.tree);
165 var obj = x.munge() as Gtk.Widget;
172 this.container.el.add(obj);
178 public int search (string txt) {
179 this.notebook.el.page = 1;
180 var s = new Gtk.SourceSearchSettings();
181 var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
182 this.searchcontext = new Gtk.SourceSearchContext(buf,s);
183 this.searchcontext.set_highlight(true);
184 s.set_search_text(txt);
186 Gtk.TextIter beg, st,en;
188 buf.get_start_iter(out beg);
189 this.searchcontext.forward(beg, out st, out en);
190 this.last_search_end = 0;
191 return this.searchcontext.get_occurrences_count();
195 public void forwardSearch (bool change_focus) {
197 if (this.searchcontext == null) {
200 this.notebook.el.page = 1;
201 Gtk.TextIter beg, st,en, stl;
203 var buf = this.sourceview.el.get_buffer();
204 buf.get_iter_at_offset(out beg, this.last_search_end);
205 if (!this.searchcontext.forward(beg, out st, out en)) {
206 this.last_search_end = 0;
208 this.last_search_end = en.get_offset();
210 this.sourceview.el.grab_focus();
212 buf.place_cursor(st);
213 var ln = st.get_line();
214 buf.get_iter_at_line(out stl,ln);
216 this.sourceview.el.scroll_to_iter(stl, 0.0f, true, 0.0f, 0.5f);
220 public class Xcls_notebook : Object
222 public Gtk.Notebook el;
223 private Xcls_GtkView _this;
229 public Xcls_notebook(Xcls_GtkView _owner )
232 _this.notebook = this;
233 this.el = new Gtk.Notebook();
237 // set gobject values
238 var child_0 = new Xcls_label_preview( _this );
240 var child_1 = new Xcls_label_code( _this );
242 var child_2 = new Xcls_ScrolledWindow5( _this );
244 this.el.append_page ( child_2.el , _this.label_preview.el );
245 var child_3 = new Xcls_ScrolledWindow8( _this );
247 this.el.append_page ( child_3.el , _this.label_code.el );
250 // user defined functions
252 public class Xcls_label_preview : Object
255 private Xcls_GtkView _this;
261 public Xcls_label_preview(Xcls_GtkView _owner )
264 _this.label_preview = this;
265 this.el = new Gtk.Label( "Preview" );
269 // set gobject values
272 // user defined functions
275 public class Xcls_label_code : Object
278 private Xcls_GtkView _this;
284 public Xcls_label_code(Xcls_GtkView _owner )
287 _this.label_code = this;
288 this.el = new Gtk.Label( "Preview Generated Code" );
292 // set gobject values
295 // user defined functions
298 public class Xcls_ScrolledWindow5 : Object
300 public Gtk.ScrolledWindow el;
301 private Xcls_GtkView _this;
307 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
310 this.el = new Gtk.ScrolledWindow( null, null );
314 // set gobject values
315 var child_0 = new Xcls_view_layout( _this );
317 this.el.add ( child_0.el );
320 // user defined functions
322 public class Xcls_view_layout : Object
324 public Gtk.Layout el;
325 private Xcls_GtkView _this;
331 public Xcls_view_layout(Xcls_GtkView _owner )
334 _this.view_layout = this;
335 this.el = new Gtk.Layout( null, null );
339 // set gobject values
340 var child_0 = new Xcls_container( _this );
342 this.el.put ( child_0.el , 10,10 );
345 // user defined functions
347 public class Xcls_container : Object
350 private Xcls_GtkView _this;
356 public Xcls_container(Xcls_GtkView _owner )
359 _this.container = this;
360 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
364 // set gobject values
367 // user defined functions
372 public class Xcls_ScrolledWindow8 : Object
374 public Gtk.ScrolledWindow el;
375 private Xcls_GtkView _this;
381 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
384 this.el = new Gtk.ScrolledWindow( null, null );
388 // set gobject values
389 var child_0 = new Xcls_sourceview( _this );
391 this.el.add ( child_0.el );
394 // user defined functions
396 public class Xcls_sourceview : Object
398 public Gtk.SourceView el;
399 private Xcls_GtkView _this;
404 public bool allow_node_scroll;
407 public Xcls_sourceview(Xcls_GtkView _owner )
410 _this.sourceview = this;
411 this.el = new Gtk.SourceView();
415 this.allow_node_scroll = true;
417 // set gobject values
418 this.el.editable = false;
419 this.el.show_line_marks = true;
420 this.el.show_line_numbers = true;
426 var description = Pango.FontDescription.from_string("monospace");
427 description.set_size(8000);
428 this.el.override_font(description);
431 var buf = this.el.get_buffer();
432 buf.notify.connect((ps) => {
436 if (ps.name != "cursor-position") {
439 print("cursor changed : %d\n", buf.cursor_position);
441 buf.get_iter_at_offset(out cpos, buf.cursor_position);
443 var ln = cpos.get_line();
445 var node = _this.file.lineToNode(ln);
448 print("can not find node\n");
451 var ltree = _this.main_window.windowstate.left_tree;
452 var tp = ltree.model.treePathFromNode(node);
453 print("got tree path %s\n", tp);
455 this.allow_node_scroll = false;
456 print("changing cursor on tree..\n");
457 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
458 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
459 GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
460 this.allow_node_scroll = true;
465 // highlight the node..
471 var attrs = new Gtk.SourceMarkAttributes();
472 var pink = Gdk.RGBA();
473 pink.parse ( "pink");
474 attrs.set_background ( pink);
475 attrs.set_icon_name ( "process-stop");
476 attrs.query_tooltip_text.connect(( mark) => {
477 //print("tooltip query? %s\n", mark.name);
481 this.el.set_mark_attributes ("ERR", attrs, 1);
483 var wattrs = new Gtk.SourceMarkAttributes();
484 var blue = Gdk.RGBA();
485 blue.parse ( "#ABF4EB");
486 wattrs.set_background ( blue);
487 wattrs.set_icon_name ( "process-stop");
488 wattrs.query_tooltip_text.connect(( mark) => {
489 //print("tooltip query? %s\n", mark.name);
493 this.el.set_mark_attributes ("WARN", wattrs, 1);
497 var dattrs = new Gtk.SourceMarkAttributes();
498 var purple = Gdk.RGBA();
499 purple.parse ( "#EEA9FF");
500 dattrs.set_background ( purple);
501 dattrs.set_icon_name ( "process-stop");
502 dattrs.query_tooltip_text.connect(( mark) => {
503 //print("tooltip query? %s\n", mark.name);
507 this.el.set_mark_attributes ("DEPR", dattrs, 1);
510 var gattrs = new Gtk.SourceMarkAttributes();
511 var grey = Gdk.RGBA();
512 grey.parse ( "#ccc");
513 gattrs.set_background ( grey);
516 this.el.set_mark_attributes ("grey", gattrs, 1);
526 // user defined functions
527 public void nodeSelected (JsRender.Node? sel) {
531 // this is connected in widnowstate
532 print("Roo-view - node selected\n");
533 var buf = this.el.get_buffer();
535 var sbuf = (Gtk.SourceBuffer) buf;
538 while(Gtk.events_pending()) {
539 Gtk.main_iteration();
543 // clear all the marks..
547 sbuf.get_bounds (out start, out end);
548 sbuf.remove_source_marks (start, end, "grey");
556 sbuf.get_iter_at_line(out iter, sel.line_start);
559 Gtk.TextIter cur_iter;
560 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
562 //var cur_line = cur_iter.get_line();
563 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
566 if (this.allow_node_scroll) {
568 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
573 for (var i = 0; i < buf.get_line_count();i++) {
574 if (i < sel.line_start || i > sel.line_end) {
576 sbuf.get_iter_at_line(out iter, i);
577 sbuf.create_source_mark(null, "grey", iter);
585 public string toString () {
588 this.el.get_buffer().get_start_iter(out s);
589 this.el.get_buffer().get_end_iter(out e);
590 var ret = this.el.get_buffer().get_text(s,e,true);
591 //print("TO STRING? " + ret);
594 public void loadFile ( ) {
596 var buf = this.el.get_buffer();
598 var sbuf = (Gtk.SourceBuffer) buf;
602 if (_this.file == null || _this.file.xtype != "Gtk") {
603 print("xtype != Gtk");
604 this.loading = false;
610 var regex = new Regex("\\.bjs$");
613 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
614 } catch (GLib.RegexError e) {
615 this.loading = false;
620 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
621 print("File path has no errors\n");
622 this.loading = false;
629 GLib.FileUtils.get_contents (valafn, out str);
631 this.loading = false;
635 // print("setting str %d\n", str.length);
636 buf.set_text(str, str.length);
637 var lm = Gtk.SourceLanguageManager.get_default();
639 //?? is javascript going to work as js?
641 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
647 sbuf.get_bounds (out start, out end);
648 sbuf.remove_source_marks (start, end, null); // remove all marks..
651 if (_this.main_window.windowstate.last_compile_result != null) {
652 var obj = _this.main_window.windowstate.last_compile_result;
653 this.highlightErrorsJson("ERR", obj);
654 this.highlightErrorsJson("WARN", obj);
655 this.highlightErrorsJson("DEPR", obj);
657 //while (Gtk.events_pending()) {
658 // Gtk.main_iteration();
661 this.loading = false;
663 public void highlightErrorsJson (string type, Json.Object obj) {
667 var buf = this.el.get_buffer();
668 var sbuf = (Gtk.SourceBuffer)buf;
669 buf.get_bounds (out start, out end);
671 sbuf.remove_source_marks (start, end, type);
674 // we should highlight other types of errors..
676 if (!obj.has_member(type)) {
677 print("Return has no errors\n");
680 var err = obj.get_object_member(type);
682 if (_this.file == null) {
683 return; // just in case the file has not loaded yet?
689 var regex = new Regex("\\.bjs$");
692 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
693 } catch (GLib.RegexError e) {
697 if (!err.has_member(valafn)) {
698 print("File path has no errors\n");
701 var lines = err.get_object_member(valafn);
705 var tlines = buf.get_line_count () +1;
707 lines.foreach_member((obj, line, node) => {
710 // print("get inter\n");
711 var eline = int.parse(line) -1 ;
712 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
715 if (eline > tlines || eline < 0) {
718 sbuf.get_iter_at_line( out iter, eline);
719 //print("mark line\n");
720 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
721 var ar = lines.get_array_member(line);
722 for (var i = 0 ; i < ar.get_length(); i++) {
723 msg += (msg.length > 0) ? "\n" : "";
724 msg += ar.get_string_element(i);
728 sbuf.create_source_mark(msg, type, iter);