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 Gtk.SourceSearchContext searchcontext;
26 public JsRender.JsRender file;
28 public Xcls_MainWindow main_window;
34 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
43 this.el.hexpand = true;
44 var child_0 = new Xcls_notebook( _this );
46 this.el.pack_start ( child_0.el , true,true,0 );
49 this.el.size_allocate.connect( (aloc) => {
51 this.width = aloc.width;
52 this.height =aloc.height;
56 // user defined functions
57 public void scroll_to_line (int line) {
58 this.notebook.el.page = 1;// code preview...
60 GLib.Timeout.add(500, () => {
65 var buf = this.sourceview.el.get_buffer();
67 var sbuf = (Gtk.SourceBuffer) buf;
71 sbuf.get_iter_at_line(out iter, line);
72 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
78 public void createThumb () {
81 if (this.file == null) {
84 // only screenshot the gtk preview..
85 if (this.notebook.el.page > 0 ) {
90 var filename = this.file.getIconFileName(false);
92 var win = this.el.get_parent_window();
93 var width = win.get_width();
94 var height = win.get_height();
96 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
97 screenshot.save(filename,"png");
109 // should we hold until it's printed...
120 public void loadFile (JsRender.JsRender file)
124 if (file.tree == null) {
127 this.notebook.el.page = 0;// gtk preview
132 this.sourceview.loadFile();
136 if (this.lastObj != null) {
137 this.container.el.remove(this.lastObj);
140 // hide the compile view at present..
146 print("ALLOC SET SIZES %d, %d\n", w,h);
148 // set the container size min to 500/500 or 20 px less than max..
149 w = int.max (w-20, 500);
150 h = int.max (h-20, 500);
152 print("SET SIZES %d, %d\n", w,h);
153 _this.container.el.set_size_request(w,h);
155 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
156 var rgba = Gdk.RGBA ();
158 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
161 var x = new JsRender.NodeToGtk(file.tree);
162 var obj = x.munge() as Gtk.Widget;
169 this.container.el.add(obj);
175 public int search (string txt) {
176 var s = new Gtk.SourceSearchSettings();
177 var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
178 this.searchcontext = new Gtk.SourceSearchContext(buf,s);
179 this.searchcontext.set_highlight(true);
180 s.set_search_text(txt);
182 Gtk.TextIter beg, st,en;
184 buf.get_start_iter(out beg);
185 this.searchcontext.forward(beg, out st, out en);
187 return this.searchcontext.get_occurrences_count();
191 public class Xcls_notebook : Object
193 public Gtk.Notebook el;
194 private Xcls_GtkView _this;
200 public Xcls_notebook(Xcls_GtkView _owner )
203 _this.notebook = this;
204 this.el = new Gtk.Notebook();
208 // set gobject values
209 var child_0 = new Xcls_label_preview( _this );
211 var child_1 = new Xcls_label_code( _this );
213 var child_2 = new Xcls_ScrolledWindow5( _this );
215 this.el.append_page ( child_2.el , _this.label_preview.el );
216 var child_3 = new Xcls_ScrolledWindow8( _this );
218 this.el.append_page ( child_3.el , _this.label_code.el );
221 // user defined functions
223 public class Xcls_label_preview : Object
226 private Xcls_GtkView _this;
232 public Xcls_label_preview(Xcls_GtkView _owner )
235 _this.label_preview = this;
236 this.el = new Gtk.Label( "Preview" );
240 // set gobject values
243 // user defined functions
246 public class Xcls_label_code : Object
249 private Xcls_GtkView _this;
255 public Xcls_label_code(Xcls_GtkView _owner )
258 _this.label_code = this;
259 this.el = new Gtk.Label( "Preview Generated Code" );
263 // set gobject values
266 // user defined functions
269 public class Xcls_ScrolledWindow5 : Object
271 public Gtk.ScrolledWindow el;
272 private Xcls_GtkView _this;
278 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
281 this.el = new Gtk.ScrolledWindow( null, null );
285 // set gobject values
286 var child_0 = new Xcls_view_layout( _this );
288 this.el.add ( child_0.el );
291 // user defined functions
293 public class Xcls_view_layout : Object
295 public Gtk.Layout el;
296 private Xcls_GtkView _this;
302 public Xcls_view_layout(Xcls_GtkView _owner )
305 _this.view_layout = this;
306 this.el = new Gtk.Layout( null, null );
310 // set gobject values
311 var child_0 = new Xcls_container( _this );
313 this.el.put ( child_0.el , 10,10 );
316 // user defined functions
318 public class Xcls_container : Object
321 private Xcls_GtkView _this;
327 public Xcls_container(Xcls_GtkView _owner )
330 _this.container = this;
331 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
335 // set gobject values
338 // user defined functions
343 public class Xcls_ScrolledWindow8 : Object
345 public Gtk.ScrolledWindow el;
346 private Xcls_GtkView _this;
352 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
355 this.el = new Gtk.ScrolledWindow( null, null );
359 // set gobject values
360 var child_0 = new Xcls_sourceview( _this );
362 this.el.add ( child_0.el );
365 // user defined functions
367 public class Xcls_sourceview : Object
369 public Gtk.SourceView el;
370 private Xcls_GtkView _this;
377 public Xcls_sourceview(Xcls_GtkView _owner )
380 _this.sourceview = this;
381 this.el = new Gtk.SourceView();
386 // set gobject values
387 this.el.editable = false;
388 this.el.show_line_marks = true;
389 this.el.show_line_numbers = true;
395 var description = Pango.FontDescription.from_string("monospace");
396 description.set_size(8000);
397 this.el.override_font(description);
400 var buf = this.el.get_buffer();
401 buf.notify.connect((ps) => {
405 if (ps.name != "cursor-position") {
408 print("cursor changed : %d\n", buf.cursor_position);
410 buf.get_iter_at_offset(out cpos, buf.cursor_position);
412 var ln = cpos.get_line();
414 var node = _this.file.lineToNode(ln);
416 print("can not find node\n");
419 var ltree = _this.main_window.windowstate.left_tree;
420 var tp = ltree.model.treePathFromNode(node);
421 print("got tree path %s\n", tp);
423 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
426 // highlight the node..
432 var attrs = new Gtk.SourceMarkAttributes();
433 var pink = Gdk.RGBA();
434 pink.parse ( "pink");
435 attrs.set_background ( pink);
436 attrs.set_icon_name ( "process-stop");
437 attrs.query_tooltip_text.connect(( mark) => {
438 //print("tooltip query? %s\n", mark.name);
442 this.el.set_mark_attributes ("ERR", attrs, 1);
444 var wattrs = new Gtk.SourceMarkAttributes();
445 var blue = Gdk.RGBA();
446 blue.parse ( "#ABF4EB");
447 wattrs.set_background ( blue);
448 wattrs.set_icon_name ( "process-stop");
449 wattrs.query_tooltip_text.connect(( mark) => {
450 //print("tooltip query? %s\n", mark.name);
454 this.el.set_mark_attributes ("WARN", wattrs, 1);
458 var dattrs = new Gtk.SourceMarkAttributes();
459 var purple = Gdk.RGBA();
460 purple.parse ( "#EEA9FF");
461 dattrs.set_background ( purple);
462 dattrs.set_icon_name ( "process-stop");
463 dattrs.query_tooltip_text.connect(( mark) => {
464 //print("tooltip query? %s\n", mark.name);
468 this.el.set_mark_attributes ("DEPR", dattrs, 1);
471 var gattrs = new Gtk.SourceMarkAttributes();
472 var grey = Gdk.RGBA();
473 grey.parse ( "#ccc");
474 gattrs.set_background ( grey);
477 this.el.set_mark_attributes ("grey", gattrs, 1);
487 // user defined functions
488 public void nodeSelected (JsRender.Node? sel) {
492 // this is connected in widnowstate
493 print("node selected");
494 var buf = this.el.get_buffer();
496 var sbuf = (Gtk.SourceBuffer) buf;
499 while(Gtk.events_pending()) {
500 Gtk.main_iteration();
504 // clear all the marks..
508 sbuf.get_bounds (out start, out end);
509 sbuf.remove_source_marks (start, end, "grey");
517 sbuf.get_iter_at_line(out iter, sel.line_start);
518 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
520 for (var i = 0; i < buf.get_line_count();i++) {
521 if (i < sel.line_start || i > sel.line_end) {
523 sbuf.get_iter_at_line(out iter, i);
524 sbuf.create_source_mark(null, "grey", iter);
532 public string toString () {
535 this.el.get_buffer().get_start_iter(out s);
536 this.el.get_buffer().get_end_iter(out e);
537 var ret = this.el.get_buffer().get_text(s,e,true);
538 //print("TO STRING? " + ret);
541 public void loadFile ( ) {
543 var buf = this.el.get_buffer();
545 var sbuf = (Gtk.SourceBuffer) buf;
549 if (_this.file == null || _this.file.xtype != "Gtk") {
550 print("xtype != Gtk");
551 this.loading = false;
557 var regex = new Regex("\\.bjs$");
560 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
561 } catch (GLib.RegexError e) {
562 this.loading = false;
567 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
568 print("File path has no errors\n");
569 this.loading = false;
576 GLib.FileUtils.get_contents (valafn, out str);
578 this.loading = false;
582 // print("setting str %d\n", str.length);
583 buf.set_text(str, str.length);
584 var lm = Gtk.SourceLanguageManager.get_default();
586 //?? is javascript going to work as js?
588 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
594 sbuf.get_bounds (out start, out end);
595 sbuf.remove_source_marks (start, end, null); // remove all marks..
598 if (_this.main_window.windowstate.last_compile_result != null) {
599 var obj = _this.main_window.windowstate.last_compile_result;
600 this.highlightErrorsJson("ERR", obj);
601 this.highlightErrorsJson("WARN", obj);
602 this.highlightErrorsJson("DEPR", obj);
604 //while (Gtk.events_pending()) {
605 // Gtk.main_iteration();
608 this.loading = false;
610 public void highlightErrorsJson (string type, Json.Object obj) {
614 var buf = this.el.get_buffer();
615 var sbuf = (Gtk.SourceBuffer)buf;
616 buf.get_bounds (out start, out end);
618 sbuf.remove_source_marks (start, end, type);
621 // we should highlight other types of errors..
623 if (!obj.has_member(type)) {
624 print("Return has no errors\n");
627 var err = obj.get_object_member(type);
629 if (_this.file == null) {
630 return; // just in case the file has not loaded yet?
636 var regex = new Regex("\\.bjs$");
639 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
640 } catch (GLib.RegexError e) {
644 if (!err.has_member(valafn)) {
645 print("File path has no errors\n");
648 var lines = err.get_object_member(valafn);
652 var tlines = buf.get_line_count () +1;
654 lines.foreach_member((obj, line, node) => {
657 // print("get inter\n");
658 var eline = int.parse(line) -1 ;
659 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
662 if (eline > tlines || eline < 0) {
665 sbuf.get_iter_at_line( out iter, eline);
666 //print("mark line\n");
667 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
668 var ar = lines.get_array_member(line);
669 for (var i = 0 ; i < ar.get_length(); i++) {
670 msg += (msg.length > 0) ? "\n" : "";
671 msg += ar.get_string_element(i);
675 sbuf.create_source_mark(msg, type, iter);