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 var child_0 = new Xcls_notebook( _this );
48 this.el.pack_start ( child_0.el , true,true,0 );
51 this.el.size_allocate.connect( (aloc) => {
53 this.width = aloc.width;
54 this.height =aloc.height;
58 // user defined functions
59 public void scroll_to_line (int line) {
60 this.notebook.el.page = 1;// code preview...
62 GLib.Timeout.add(500, () => {
67 var buf = this.sourceview.el.get_buffer();
69 var sbuf = (Gtk.SourceBuffer) buf;
73 sbuf.get_iter_at_line(out iter, line);
74 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
80 public void createThumb () {
83 if (this.file == null) {
86 // only screenshot the gtk preview..
87 if (this.notebook.el.page > 0 ) {
92 var filename = this.file.getIconFileName(false);
94 var win = this.el.get_parent_window();
95 var width = win.get_width();
96 var height = win.get_height();
98 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
99 screenshot.save(filename,"png");
111 // should we hold until it's printed...
122 public void loadFile (JsRender.JsRender file)
126 if (file.tree == null) {
129 this.notebook.el.page = 0;// gtk preview
134 this.sourceview.loadFile();
135 this.searchcontext = null;
138 if (this.lastObj != null) {
139 this.container.el.remove(this.lastObj);
142 // hide the compile view at present..
148 print("ALLOC SET SIZES %d, %d\n", w,h);
150 // set the container size min to 500/500 or 20 px less than max..
151 w = int.max (w-20, 500);
152 h = int.max (h-20, 500);
154 print("SET SIZES %d, %d\n", w,h);
155 _this.container.el.set_size_request(w,h);
157 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
158 var rgba = Gdk.RGBA ();
160 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
163 var x = new JsRender.NodeToGtk(file.tree);
164 var obj = x.munge() as Gtk.Widget;
171 this.container.el.add(obj);
177 public int search (string txt) {
178 var s = new Gtk.SourceSearchSettings();
179 var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
180 this.searchcontext = new Gtk.SourceSearchContext(buf,s);
181 this.searchcontext.set_highlight(true);
182 s.set_search_text(txt);
184 Gtk.TextIter beg, st,en;
186 buf.get_start_iter(out beg);
187 this.searchcontext.forward(beg, out st, out en);
188 this.last_search_end = 0;
189 return this.searchcontext.get_occurrences_count();
193 public void forwardSearch () {
195 if (this.searchcontext == null) {
199 Gtk.TextIter beg, st,en;
201 var buf = this.sourceview.el.get_buffer();
202 buf.get_iter_at_offset(out beg, this.last_search_end);
203 if (!this.searchcontext.forward(beg, out st, out en)) {
204 this.last_search_end = 0;
206 this.last_search_end = en.get_offset();
208 this.sourceview.el.grab_focus();
210 buf.place_cursor(st);
212 this.sourceview.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
216 public class Xcls_notebook : Object
218 public Gtk.Notebook el;
219 private Xcls_GtkView _this;
225 public Xcls_notebook(Xcls_GtkView _owner )
228 _this.notebook = this;
229 this.el = new Gtk.Notebook();
233 // set gobject values
234 var child_0 = new Xcls_label_preview( _this );
236 var child_1 = new Xcls_label_code( _this );
238 var child_2 = new Xcls_ScrolledWindow5( _this );
240 this.el.append_page ( child_2.el , _this.label_preview.el );
241 var child_3 = new Xcls_ScrolledWindow8( _this );
243 this.el.append_page ( child_3.el , _this.label_code.el );
246 // user defined functions
248 public class Xcls_label_preview : Object
251 private Xcls_GtkView _this;
257 public Xcls_label_preview(Xcls_GtkView _owner )
260 _this.label_preview = this;
261 this.el = new Gtk.Label( "Preview" );
265 // set gobject values
268 // user defined functions
271 public class Xcls_label_code : Object
274 private Xcls_GtkView _this;
280 public Xcls_label_code(Xcls_GtkView _owner )
283 _this.label_code = this;
284 this.el = new Gtk.Label( "Preview Generated Code" );
288 // set gobject values
291 // user defined functions
294 public class Xcls_ScrolledWindow5 : Object
296 public Gtk.ScrolledWindow el;
297 private Xcls_GtkView _this;
303 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
306 this.el = new Gtk.ScrolledWindow( null, null );
310 // set gobject values
311 var child_0 = new Xcls_view_layout( _this );
313 this.el.add ( child_0.el );
316 // user defined functions
318 public class Xcls_view_layout : Object
320 public Gtk.Layout el;
321 private Xcls_GtkView _this;
327 public Xcls_view_layout(Xcls_GtkView _owner )
330 _this.view_layout = this;
331 this.el = new Gtk.Layout( null, null );
335 // set gobject values
336 var child_0 = new Xcls_container( _this );
338 this.el.put ( child_0.el , 10,10 );
341 // user defined functions
343 public class Xcls_container : Object
346 private Xcls_GtkView _this;
352 public Xcls_container(Xcls_GtkView _owner )
355 _this.container = this;
356 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
360 // set gobject values
363 // user defined functions
368 public class Xcls_ScrolledWindow8 : Object
370 public Gtk.ScrolledWindow el;
371 private Xcls_GtkView _this;
377 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
380 this.el = new Gtk.ScrolledWindow( null, null );
384 // set gobject values
385 var child_0 = new Xcls_sourceview( _this );
387 this.el.add ( child_0.el );
390 // user defined functions
392 public class Xcls_sourceview : Object
394 public Gtk.SourceView el;
395 private Xcls_GtkView _this;
400 public bool allow_node_scroll;
403 public Xcls_sourceview(Xcls_GtkView _owner )
406 _this.sourceview = this;
407 this.el = new Gtk.SourceView();
411 this.allow_node_scroll = true;
413 // set gobject values
414 this.el.editable = false;
415 this.el.show_line_marks = true;
416 this.el.show_line_numbers = true;
422 var description = Pango.FontDescription.from_string("monospace");
423 description.set_size(8000);
424 this.el.override_font(description);
427 var buf = this.el.get_buffer();
428 buf.notify.connect((ps) => {
432 if (ps.name != "cursor-position") {
435 print("cursor changed : %d\n", buf.cursor_position);
437 buf.get_iter_at_offset(out cpos, buf.cursor_position);
439 var ln = cpos.get_line();
440 this.allow_node_scroll = false;
441 var node = _this.file.lineToNode(ln);
442 this.allow_node_scroll = false;
444 print("can not find node\n");
447 var ltree = _this.main_window.windowstate.left_tree;
448 var tp = ltree.model.treePathFromNode(node);
449 print("got tree path %s\n", tp);
451 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
454 // highlight the node..
460 var attrs = new Gtk.SourceMarkAttributes();
461 var pink = Gdk.RGBA();
462 pink.parse ( "pink");
463 attrs.set_background ( pink);
464 attrs.set_icon_name ( "process-stop");
465 attrs.query_tooltip_text.connect(( mark) => {
466 //print("tooltip query? %s\n", mark.name);
470 this.el.set_mark_attributes ("ERR", attrs, 1);
472 var wattrs = new Gtk.SourceMarkAttributes();
473 var blue = Gdk.RGBA();
474 blue.parse ( "#ABF4EB");
475 wattrs.set_background ( blue);
476 wattrs.set_icon_name ( "process-stop");
477 wattrs.query_tooltip_text.connect(( mark) => {
478 //print("tooltip query? %s\n", mark.name);
482 this.el.set_mark_attributes ("WARN", wattrs, 1);
486 var dattrs = new Gtk.SourceMarkAttributes();
487 var purple = Gdk.RGBA();
488 purple.parse ( "#EEA9FF");
489 dattrs.set_background ( purple);
490 dattrs.set_icon_name ( "process-stop");
491 dattrs.query_tooltip_text.connect(( mark) => {
492 //print("tooltip query? %s\n", mark.name);
496 this.el.set_mark_attributes ("DEPR", dattrs, 1);
499 var gattrs = new Gtk.SourceMarkAttributes();
500 var grey = Gdk.RGBA();
501 grey.parse ( "#ccc");
502 gattrs.set_background ( grey);
505 this.el.set_mark_attributes ("grey", gattrs, 1);
515 // user defined functions
516 public void nodeSelected (JsRender.Node? sel) {
520 // this is connected in widnowstate
521 print("node selected");
522 var buf = this.el.get_buffer();
524 var sbuf = (Gtk.SourceBuffer) buf;
527 while(Gtk.events_pending()) {
528 Gtk.main_iteration();
532 // clear all the marks..
536 sbuf.get_bounds (out start, out end);
537 sbuf.remove_source_marks (start, end, "grey");
545 sbuf.get_iter_at_line(out iter, sel.line_start);
548 Gtk.TextIter cur_iter;
549 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
551 //var cur_line = cur_iter.get_line();
552 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
555 if (this.allow_node_scroll) {
556 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
560 is the cursor is between start+end...
561 then assume we do not need to scroll..
565 Gdk.Rectangle rect, target_rect, inter_rect;
566 this.el.get_visible_rect(out rect);
567 this.el.get_iter_location(iter, out target_rect);
569 if (!rect.intersect(target_rect, out inter_rect)) {
573 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
575 for (var i = 0; i < buf.get_line_count();i++) {
576 if (i < sel.line_start || i > sel.line_end) {
578 sbuf.get_iter_at_line(out iter, i);
579 sbuf.create_source_mark(null, "grey", iter);
587 public string toString () {
590 this.el.get_buffer().get_start_iter(out s);
591 this.el.get_buffer().get_end_iter(out e);
592 var ret = this.el.get_buffer().get_text(s,e,true);
593 //print("TO STRING? " + ret);
596 public void loadFile ( ) {
598 var buf = this.el.get_buffer();
600 var sbuf = (Gtk.SourceBuffer) buf;
604 if (_this.file == null || _this.file.xtype != "Gtk") {
605 print("xtype != Gtk");
606 this.loading = false;
612 var regex = new Regex("\\.bjs$");
615 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
616 } catch (GLib.RegexError e) {
617 this.loading = false;
622 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
623 print("File path has no errors\n");
624 this.loading = false;
631 GLib.FileUtils.get_contents (valafn, out str);
633 this.loading = false;
637 // print("setting str %d\n", str.length);
638 buf.set_text(str, str.length);
639 var lm = Gtk.SourceLanguageManager.get_default();
641 //?? is javascript going to work as js?
643 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
649 sbuf.get_bounds (out start, out end);
650 sbuf.remove_source_marks (start, end, null); // remove all marks..
653 if (_this.main_window.windowstate.last_compile_result != null) {
654 var obj = _this.main_window.windowstate.last_compile_result;
655 this.highlightErrorsJson("ERR", obj);
656 this.highlightErrorsJson("WARN", obj);
657 this.highlightErrorsJson("DEPR", obj);
659 //while (Gtk.events_pending()) {
660 // Gtk.main_iteration();
663 this.loading = false;
665 public void highlightErrorsJson (string type, Json.Object obj) {
669 var buf = this.el.get_buffer();
670 var sbuf = (Gtk.SourceBuffer)buf;
671 buf.get_bounds (out start, out end);
673 sbuf.remove_source_marks (start, end, type);
676 // we should highlight other types of errors..
678 if (!obj.has_member(type)) {
679 print("Return has no errors\n");
682 var err = obj.get_object_member(type);
684 if (_this.file == null) {
685 return; // just in case the file has not loaded yet?
691 var regex = new Regex("\\.bjs$");
694 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
695 } catch (GLib.RegexError e) {
699 if (!err.has_member(valafn)) {
700 print("File path has no errors\n");
703 var lines = err.get_object_member(valafn);
707 var tlines = buf.get_line_count () +1;
709 lines.foreach_member((obj, line, node) => {
712 // print("get inter\n");
713 var eline = int.parse(line) -1 ;
714 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
717 if (eline > tlines || eline < 0) {
720 sbuf.get_iter_at_line( out iter, eline);
721 //print("mark line\n");
722 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
723 var ar = lines.get_array_member(line);
724 for (var i = 0 ; i < ar.get_length(); i++) {
725 msg += (msg.length > 0) ? "\n" : "";
726 msg += ar.get_string_element(i);
730 sbuf.create_source_mark(msg, type, iter);