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 JsRender.JsRender file;
27 public Xcls_MainWindow main_window;
33 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
42 this.el.hexpand = true;
43 var child_0 = new Xcls_notebook( _this );
45 this.el.pack_start ( child_0.el , true,true,0 );
48 this.el.size_allocate.connect( (aloc) => {
50 this.width = aloc.width;
51 this.height =aloc.height;
55 // user defined functions
56 public void scroll_to_line (int line) {
57 this.notebook.el.page = 1;// code preview...
59 GLib.Timeout.add(500, () => {
64 var buf = this.sourceview.el.get_buffer();
66 var sbuf = (Gtk.SourceBuffer) buf;
70 sbuf.get_iter_at_line(out iter, line);
71 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
77 public void createThumb () {
80 if (this.file == null) {
83 // only screenshot the gtk preview..
84 if (this.notebook.el.page > 0 ) {
89 var filename = this.file.getIconFileName(false);
91 var win = this.el.get_parent_window();
92 var width = win.get_width();
93 var height = win.get_height();
95 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
96 screenshot.save(filename,"png");
108 // should we hold until it's printed...
119 public void loadFile (JsRender.JsRender file)
123 if (file.tree == null) {
126 this.notebook.el.page = 0;// gtk preview
131 this.sourceview.loadFile();
135 if (this.lastObj != null) {
136 this.container.el.remove(this.lastObj);
139 // hide the compile view at present..
145 print("ALLOC SET SIZES %d, %d\n", w,h);
147 // set the container size min to 500/500 or 20 px less than max..
148 w = int.max (w-20, 500);
149 h = int.max (h-20, 500);
151 print("SET SIZES %d, %d\n", w,h);
152 _this.container.el.set_size_request(w,h);
154 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
155 var rgba = Gdk.RGBA ();
157 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
160 var x = new JsRender.NodeToGtk(file.tree);
161 var obj = x.munge() as Gtk.Widget;
168 this.container.el.add(obj);
174 public class Xcls_notebook : Object
176 public Gtk.Notebook el;
177 private Xcls_GtkView _this;
183 public Xcls_notebook(Xcls_GtkView _owner )
186 _this.notebook = this;
187 this.el = new Gtk.Notebook();
191 // set gobject values
192 var child_0 = new Xcls_label_preview( _this );
194 var child_1 = new Xcls_label_code( _this );
196 var child_2 = new Xcls_ScrolledWindow5( _this );
198 this.el.append_page ( child_2.el , _this.label_preview.el );
199 var child_3 = new Xcls_ScrolledWindow8( _this );
201 this.el.append_page ( child_3.el , _this.label_code.el );
204 // user defined functions
206 public class Xcls_label_preview : Object
209 private Xcls_GtkView _this;
215 public Xcls_label_preview(Xcls_GtkView _owner )
218 _this.label_preview = this;
219 this.el = new Gtk.Label( "Preview" );
223 // set gobject values
226 // user defined functions
229 public class Xcls_label_code : Object
232 private Xcls_GtkView _this;
238 public Xcls_label_code(Xcls_GtkView _owner )
241 _this.label_code = this;
242 this.el = new Gtk.Label( "Preview Generated Code" );
246 // set gobject values
249 // user defined functions
252 public class Xcls_ScrolledWindow5 : Object
254 public Gtk.ScrolledWindow el;
255 private Xcls_GtkView _this;
261 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
264 this.el = new Gtk.ScrolledWindow( null, null );
268 // set gobject values
269 var child_0 = new Xcls_view_layout( _this );
271 this.el.add ( child_0.el );
274 // user defined functions
276 public class Xcls_view_layout : Object
278 public Gtk.Layout el;
279 private Xcls_GtkView _this;
285 public Xcls_view_layout(Xcls_GtkView _owner )
288 _this.view_layout = this;
289 this.el = new Gtk.Layout( null, null );
293 // set gobject values
294 var child_0 = new Xcls_container( _this );
296 this.el.put ( child_0.el , 10,10 );
299 // user defined functions
301 public class Xcls_container : Object
304 private Xcls_GtkView _this;
310 public Xcls_container(Xcls_GtkView _owner )
313 _this.container = this;
314 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
318 // set gobject values
321 // user defined functions
326 public class Xcls_ScrolledWindow8 : Object
328 public Gtk.ScrolledWindow el;
329 private Xcls_GtkView _this;
335 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
338 this.el = new Gtk.ScrolledWindow( null, null );
342 // set gobject values
343 var child_0 = new Xcls_sourceview( _this );
345 this.el.add ( child_0.el );
348 // user defined functions
350 public class Xcls_sourceview : Object
352 public Gtk.SourceView el;
353 private Xcls_GtkView _this;
360 public Xcls_sourceview(Xcls_GtkView _owner )
363 _this.sourceview = this;
364 this.el = new Gtk.SourceView();
369 // set gobject values
370 this.el.editable = false;
371 this.el.show_line_marks = true;
372 this.el.show_line_numbers = true;
378 var description = Pango.FontDescription.from_string("monospace");
379 description.set_size(8000);
380 this.el.override_font(description);
383 var buf = this.el.get_buffer();
384 buf.notify.connect((ps) => {
388 if (ps.name != "cursor-position") {
391 print("cursor changed : %d\n", buf.cursor_position);
393 buf.get_iter_at_offset(out cpos, buf.cursor_position);
395 var ln = cpos.get_line();
397 var node = _this.file.lineToNode(ln);
399 print("can not find node\n");
402 var ltree = _this.main_window.windowstate.left_tree;
403 var tp = ltree.model.treePathFromNode(node);
404 print("got tree path %s\n", tp);
406 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
409 // highlight the node..
415 var attrs = new Gtk.SourceMarkAttributes();
416 var pink = Gdk.RGBA();
417 pink.parse ( "pink");
418 attrs.set_background ( pink);
419 attrs.set_icon_name ( "process-stop");
420 attrs.query_tooltip_text.connect(( mark) => {
421 //print("tooltip query? %s\n", mark.name);
425 this.el.set_mark_attributes ("ERR", attrs, 1);
427 var wattrs = new Gtk.SourceMarkAttributes();
428 var blue = Gdk.RGBA();
429 blue.parse ( "#ABF4EB");
430 wattrs.set_background ( blue);
431 wattrs.set_icon_name ( "process-stop");
432 wattrs.query_tooltip_text.connect(( mark) => {
433 //print("tooltip query? %s\n", mark.name);
437 this.el.set_mark_attributes ("WARN", wattrs, 1);
441 var dattrs = new Gtk.SourceMarkAttributes();
442 var purple = Gdk.RGBA();
443 purple.parse ( "#EEA9FF");
444 dattrs.set_background ( purple);
445 dattrs.set_icon_name ( "process-stop");
446 dattrs.query_tooltip_text.connect(( mark) => {
447 //print("tooltip query? %s\n", mark.name);
451 this.el.set_mark_attributes ("DEPR", dattrs, 1);
454 var gattrs = new Gtk.SourceMarkAttributes();
455 var grey = Gdk.RGBA();
456 grey.parse ( "#ccc");
457 gattrs.set_background ( grey);
460 this.el.set_mark_attributes ("grey", gattrs, 1);
470 // user defined functions
471 public void nodeSelected (JsRender.Node? sel) {
475 // this is connected in widnowstate
476 print("node selected");
477 var buf = this.el.get_buffer();
479 var sbuf = (Gtk.SourceBuffer) buf;
482 while(Gtk.events_pending()) {
483 Gtk.main_iteration();
487 // clear all the marks..
491 sbuf.get_bounds (out start, out end);
492 sbuf.remove_source_marks (start, end, "grey");
500 sbuf.get_iter_at_line(out iter, sel.line_start);
501 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
503 for (var i = 0; i < buf.get_line_count();i++) {
504 if (i < sel.line_start || i > sel.line_end) {
506 sbuf.get_iter_at_line(out iter, i);
507 sbuf.create_source_mark(null, "grey", iter);
515 public void loadFile ( ) {
517 var buf = this.el.get_buffer();
519 var sbuf = (Gtk.SourceBuffer) buf;
523 if (_this.file == null || _this.file.xtype != "Gtk") {
524 print("xtype != Gtk");
525 this.loading = false;
531 var regex = new Regex("\\.bjs$");
534 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
535 } catch (GLib.RegexError e) {
536 this.loading = false;
541 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
542 print("File path has no errors\n");
543 this.loading = false;
550 GLib.FileUtils.get_contents (valafn, out str);
552 this.loading = false;
556 // print("setting str %d\n", str.length);
557 buf.set_text(str, str.length);
558 var lm = Gtk.SourceLanguageManager.get_default();
560 //?? is javascript going to work as js?
562 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
568 sbuf.get_bounds (out start, out end);
569 sbuf.remove_source_marks (start, end, null); // remove all marks..
572 if (_this.main_window.windowstate.last_compile_result != null) {
573 var obj = _this.main_window.windowstate.last_compile_result;
574 this.highlightErrorsJson("ERR", obj);
575 this.highlightErrorsJson("WARN", obj);
576 this.highlightErrorsJson("DEPR", obj);
578 //while (Gtk.events_pending()) {
579 // Gtk.main_iteration();
582 this.loading = false;
584 public void highlightErrorsJson (string type, Json.Object obj) {
588 var buf = this.el.get_buffer();
589 var sbuf = (Gtk.SourceBuffer)buf;
590 buf.get_bounds (out start, out end);
592 sbuf.remove_source_marks (start, end, type);
595 // we should highlight other types of errors..
597 if (!obj.has_member(type)) {
598 print("Return has no errors\n");
601 var err = obj.get_object_member(type);
603 if (_this.file == null) {
604 return; // just in case the file has not loaded yet?
610 var regex = new Regex("\\.bjs$");
613 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
614 } catch (GLib.RegexError e) {
618 if (!err.has_member(valafn)) {
619 print("File path has no errors\n");
622 var lines = err.get_object_member(valafn);
626 var tlines = buf.get_line_count () +1;
628 lines.foreach_member((obj, line, node) => {
631 // print("get inter\n");
632 var eline = int.parse(line) -1 ;
633 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
636 if (eline > tlines || eline < 0) {
639 sbuf.get_iter_at_line( out iter, eline);
640 //print("mark line\n");
641 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
642 var ar = lines.get_array_member(line);
643 for (var i = 0 ; i < ar.get_length(); i++) {
644 msg += (msg.length > 0) ? "\n" : "";
645 msg += ar.get_string_element(i);
649 sbuf.create_source_mark(msg, type, iter);