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) {
127 this.sourceview.loadFile();
131 if (this.lastObj != null) {
132 this.container.el.remove(this.lastObj);
135 // hide the compile view at present..
141 print("ALLOC SET SIZES %d, %d\n", w,h);
143 // set the container size min to 500/500 or 20 px less than max..
144 w = int.max (w-20, 500);
145 h = int.max (h-20, 500);
147 print("SET SIZES %d, %d\n", w,h);
148 _this.container.el.set_size_request(w,h);
150 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
151 var rgba = Gdk.RGBA ();
153 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
156 var x = new JsRender.NodeToGtk(file.tree);
157 var obj = x.munge() as Gtk.Widget;
164 this.container.el.add(obj);
170 public class Xcls_notebook : Object
172 public Gtk.Notebook el;
173 private Xcls_GtkView _this;
179 public Xcls_notebook(Xcls_GtkView _owner )
182 _this.notebook = this;
183 this.el = new Gtk.Notebook();
187 // set gobject values
188 var child_0 = new Xcls_label_preview( _this );
190 var child_1 = new Xcls_label_code( _this );
192 var child_2 = new Xcls_ScrolledWindow5( _this );
194 this.el.append_page ( child_2.el , _this.label_preview.el );
195 var child_3 = new Xcls_ScrolledWindow8( _this );
197 this.el.append_page ( child_3.el , _this.label_code.el );
200 // user defined functions
202 public class Xcls_label_preview : Object
205 private Xcls_GtkView _this;
211 public Xcls_label_preview(Xcls_GtkView _owner )
214 _this.label_preview = this;
215 this.el = new Gtk.Label( "Preview" );
219 // set gobject values
222 // user defined functions
225 public class Xcls_label_code : Object
228 private Xcls_GtkView _this;
234 public Xcls_label_code(Xcls_GtkView _owner )
237 _this.label_code = this;
238 this.el = new Gtk.Label( "Preview Generated Code" );
242 // set gobject values
245 // user defined functions
248 public class Xcls_ScrolledWindow5 : Object
250 public Gtk.ScrolledWindow el;
251 private Xcls_GtkView _this;
257 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
260 this.el = new Gtk.ScrolledWindow( null, null );
264 // set gobject values
265 var child_0 = new Xcls_view_layout( _this );
267 this.el.add ( child_0.el );
270 // user defined functions
272 public class Xcls_view_layout : Object
274 public Gtk.Layout el;
275 private Xcls_GtkView _this;
281 public Xcls_view_layout(Xcls_GtkView _owner )
284 _this.view_layout = this;
285 this.el = new Gtk.Layout( null, null );
289 // set gobject values
290 var child_0 = new Xcls_container( _this );
292 this.el.put ( child_0.el , 10,10 );
295 // user defined functions
297 public class Xcls_container : Object
300 private Xcls_GtkView _this;
306 public Xcls_container(Xcls_GtkView _owner )
309 _this.container = this;
310 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
314 // set gobject values
317 // user defined functions
322 public class Xcls_ScrolledWindow8 : Object
324 public Gtk.ScrolledWindow el;
325 private Xcls_GtkView _this;
331 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
334 this.el = new Gtk.ScrolledWindow( null, null );
338 // set gobject values
339 var child_0 = new Xcls_sourceview( _this );
341 this.el.add ( child_0.el );
344 // user defined functions
346 public class Xcls_sourceview : Object
348 public Gtk.SourceView el;
349 private Xcls_GtkView _this;
356 public Xcls_sourceview(Xcls_GtkView _owner )
359 _this.sourceview = this;
360 this.el = new Gtk.SourceView();
365 // set gobject values
366 this.el.editable = false;
367 this.el.show_line_marks = true;
368 this.el.show_line_numbers = true;
374 var description = Pango.FontDescription.from_string("monospace");
375 description.set_size(8000);
376 this.el.override_font(description);
379 var buf = this.el.get_buffer();
380 buf.notify.connect((ps) => {
384 if (ps.name != "cursor-position") {
387 print("cursor changed : %d\n", buf.cursor_position);
389 buf.get_iter_at_offset(out cpos, buf.cursor_position);
391 var ln = cpos.get_line();
393 var node = _this.file.lineToNode(ln);
395 print("can not find node\n");
398 var ltree = _this.main_window.windowstate.left_tree;
399 var tp = ltree.model.treePathFromNode(node);
400 print("got tree path %s\n", tp);
402 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
405 // highlight the node..
411 var attrs = new Gtk.SourceMarkAttributes();
412 var pink = Gdk.RGBA();
413 pink.parse ( "pink");
414 attrs.set_background ( pink);
415 attrs.set_icon_name ( "process-stop");
416 attrs.query_tooltip_text.connect(( mark) => {
417 //print("tooltip query? %s\n", mark.name);
421 this.el.set_mark_attributes ("ERR", attrs, 1);
423 var wattrs = new Gtk.SourceMarkAttributes();
424 var blue = Gdk.RGBA();
425 blue.parse ( "#ABF4EB");
426 wattrs.set_background ( blue);
427 wattrs.set_icon_name ( "process-stop");
428 wattrs.query_tooltip_text.connect(( mark) => {
429 //print("tooltip query? %s\n", mark.name);
433 this.el.set_mark_attributes ("WARN", wattrs, 1);
437 var dattrs = new Gtk.SourceMarkAttributes();
438 var purple = Gdk.RGBA();
439 purple.parse ( "#EEA9FF");
440 dattrs.set_background ( purple);
441 dattrs.set_icon_name ( "process-stop");
442 dattrs.query_tooltip_text.connect(( mark) => {
443 //print("tooltip query? %s\n", mark.name);
447 this.el.set_mark_attributes ("DEPR", dattrs, 1);
450 var gattrs = new Gtk.SourceMarkAttributes();
451 var grey = Gdk.RGBA();
452 grey.parse ( "#ccc");
453 gattrs.set_background ( grey);
456 this.el.set_mark_attributes ("grey", gattrs, 1);
466 // user defined functions
467 public void nodeSelected (JsRender.Node? sel) {
471 // this is connected in widnowstate
472 print("node selected");
473 var buf = this.el.get_buffer();
475 var sbuf = (Gtk.SourceBuffer) buf;
478 while(Gtk.events_pending()) {
479 Gtk.main_iteration();
483 // clear all the marks..
487 sbuf.get_bounds (out start, out end);
488 sbuf.remove_source_marks (start, end, "grey");
496 sbuf.get_iter_at_line(out iter, sel.line_start);
497 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
499 for (var i = 0; i < buf.get_line_count();i++) {
500 if (i < sel.line_start || i > sel.line_end) {
502 sbuf.get_iter_at_line(out iter, i);
503 sbuf.create_source_mark(null, "grey", iter);
511 public void loadFile ( ) {
513 var buf = this.el.get_buffer();
515 var sbuf = (Gtk.SourceBuffer) buf;
519 if (_this.file == null || _this.file.xtype != "Gtk") {
520 print("xtype != Gtk");
521 this.loading = false;
527 var regex = new Regex("\\.bjs$");
530 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
531 } catch (GLib.RegexError e) {
532 this.loading = false;
537 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
538 print("File path has no errors\n");
539 this.loading = false;
546 GLib.FileUtils.get_contents (valafn, out str);
548 this.loading = false;
552 // print("setting str %d\n", str.length);
553 buf.set_text(str, str.length);
554 var lm = Gtk.SourceLanguageManager.get_default();
556 //?? is javascript going to work as js?
558 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
564 sbuf.get_bounds (out start, out end);
565 sbuf.remove_source_marks (start, end, null); // remove all marks..
568 if (_this.main_window.windowstate.last_compile_result != null) {
569 var obj = _this.main_window.windowstate.last_compile_result;
570 this.highlightErrorsJson("ERR", obj);
571 this.highlightErrorsJson("WARN", obj);
572 this.highlightErrorsJson("DEPR", obj);
574 //while (Gtk.events_pending()) {
575 // Gtk.main_iteration();
578 this.loading = false;
580 public void highlightErrorsJson (string type, Json.Object obj) {
584 var buf = this.el.get_buffer();
585 var sbuf = (Gtk.SourceBuffer)buf;
586 buf.get_bounds (out start, out end);
588 sbuf.remove_source_marks (start, end, type);
591 // we should highlight other types of errors..
593 if (!obj.has_member(type)) {
594 print("Return has no errors\n");
597 var err = obj.get_object_member(type);
599 if (_this.file == null) {
600 return; // just in case the file has not loaded yet?
606 var regex = new Regex("\\.bjs$");
609 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
610 } catch (GLib.RegexError e) {
614 if (!err.has_member(valafn)) {
615 print("File path has no errors\n");
618 var lines = err.get_object_member(valafn);
622 var tlines = buf.get_line_count () +1;
624 lines.foreach_member((obj, line, node) => {
627 // print("get inter\n");
628 var eline = int.parse(line) -1 ;
629 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
632 if (eline > tlines || eline < 0) {
635 sbuf.get_iter_at_line( out iter, eline);
636 //print("mark line\n");
637 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
638 var ar = lines.get_array_member(line);
639 for (var i = 0 ; i < ar.get_length(); i++) {
640 msg += (msg.length > 0) ? "\n" : "";
641 msg += ar.get_string_element(i);
645 sbuf.create_source_mark(msg, type, iter);