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) {
58 sbuf.get_iter_at_line(out iter, sel.line_start);
59 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
62 public void createThumb () {
65 if (this.file == null) {
68 // only screenshot the gtk preview..
69 if (this.notebook.el.page > 0 ) {
74 var filename = this.file.getIconFileName(false);
76 var win = this.el.get_parent_window();
77 var width = win.get_width();
78 var height = win.get_height();
80 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
81 screenshot.save(filename,"png");
93 // should we hold until it's printed...
104 public void loadFile (JsRender.JsRender file)
108 if (file.tree == null) {
112 this.sourceview.loadFile();
116 if (this.lastObj != null) {
117 this.container.el.remove(this.lastObj);
120 // hide the compile view at present..
126 print("ALLOC SET SIZES %d, %d\n", w,h);
128 // set the container size min to 500/500 or 20 px less than max..
129 w = int.max (w-20, 500);
130 h = int.max (h-20, 500);
132 print("SET SIZES %d, %d\n", w,h);
133 _this.container.el.set_size_request(w,h);
135 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
136 var rgba = Gdk.RGBA ();
138 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
141 var x = new JsRender.NodeToGtk(file.tree);
142 var obj = x.munge() as Gtk.Widget;
149 this.container.el.add(obj);
155 public class Xcls_notebook : Object
157 public Gtk.Notebook el;
158 private Xcls_GtkView _this;
164 public Xcls_notebook(Xcls_GtkView _owner )
167 _this.notebook = this;
168 this.el = new Gtk.Notebook();
172 // set gobject values
173 var child_0 = new Xcls_label_preview( _this );
175 var child_1 = new Xcls_label_code( _this );
177 var child_2 = new Xcls_ScrolledWindow5( _this );
179 this.el.append_page ( child_2.el , _this.label_preview.el );
180 var child_3 = new Xcls_ScrolledWindow8( _this );
182 this.el.append_page ( child_3.el , _this.label_code.el );
185 // user defined functions
187 public class Xcls_label_preview : Object
190 private Xcls_GtkView _this;
196 public Xcls_label_preview(Xcls_GtkView _owner )
199 _this.label_preview = this;
200 this.el = new Gtk.Label( "Preview" );
204 // set gobject values
207 // user defined functions
210 public class Xcls_label_code : Object
213 private Xcls_GtkView _this;
219 public Xcls_label_code(Xcls_GtkView _owner )
222 _this.label_code = this;
223 this.el = new Gtk.Label( "Preview Generated Code" );
227 // set gobject values
230 // user defined functions
233 public class Xcls_ScrolledWindow5 : Object
235 public Gtk.ScrolledWindow el;
236 private Xcls_GtkView _this;
242 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
245 this.el = new Gtk.ScrolledWindow( null, null );
249 // set gobject values
250 var child_0 = new Xcls_view_layout( _this );
252 this.el.add ( child_0.el );
255 // user defined functions
257 public class Xcls_view_layout : Object
259 public Gtk.Layout el;
260 private Xcls_GtkView _this;
266 public Xcls_view_layout(Xcls_GtkView _owner )
269 _this.view_layout = this;
270 this.el = new Gtk.Layout( null, null );
274 // set gobject values
275 var child_0 = new Xcls_container( _this );
277 this.el.put ( child_0.el , 10,10 );
280 // user defined functions
282 public class Xcls_container : Object
285 private Xcls_GtkView _this;
291 public Xcls_container(Xcls_GtkView _owner )
294 _this.container = this;
295 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
299 // set gobject values
302 // user defined functions
307 public class Xcls_ScrolledWindow8 : Object
309 public Gtk.ScrolledWindow el;
310 private Xcls_GtkView _this;
316 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
319 this.el = new Gtk.ScrolledWindow( null, null );
323 // set gobject values
324 var child_0 = new Xcls_sourceview( _this );
326 this.el.add ( child_0.el );
329 // user defined functions
331 public class Xcls_sourceview : Object
333 public Gtk.SourceView el;
334 private Xcls_GtkView _this;
341 public Xcls_sourceview(Xcls_GtkView _owner )
344 _this.sourceview = this;
345 this.el = new Gtk.SourceView();
350 // set gobject values
351 this.el.editable = false;
352 this.el.show_line_marks = true;
353 this.el.show_line_numbers = true;
359 var description = Pango.FontDescription.from_string("monospace");
360 description.set_size(8000);
361 this.el.override_font(description);
364 var buf = this.el.get_buffer();
365 buf.notify.connect((ps) => {
369 if (ps.name != "cursor-position") {
372 print("cursor changed : %d\n", buf.cursor_position);
374 buf.get_iter_at_offset(out cpos, buf.cursor_position);
376 var ln = cpos.get_line();
378 var node = _this.file.lineToNode(ln);
380 print("can not find node\n");
383 var ltree = _this.main_window.windowstate.left_tree;
384 var tp = ltree.model.treePathFromNode(node);
385 print("got tree path %s\n", tp);
387 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
390 // highlight the node..
396 var attrs = new Gtk.SourceMarkAttributes();
397 var pink = Gdk.RGBA();
398 pink.parse ( "pink");
399 attrs.set_background ( pink);
400 attrs.set_icon_name ( "process-stop");
401 attrs.query_tooltip_text.connect(( mark) => {
402 //print("tooltip query? %s\n", mark.name);
406 this.el.set_mark_attributes ("ERR", attrs, 1);
408 var wattrs = new Gtk.SourceMarkAttributes();
409 var blue = Gdk.RGBA();
410 blue.parse ( "#ABF4EB");
411 wattrs.set_background ( blue);
412 wattrs.set_icon_name ( "process-stop");
413 wattrs.query_tooltip_text.connect(( mark) => {
414 //print("tooltip query? %s\n", mark.name);
418 this.el.set_mark_attributes ("WARN", wattrs, 1);
422 var dattrs = new Gtk.SourceMarkAttributes();
423 var purple = Gdk.RGBA();
424 purple.parse ( "#EEA9FF");
425 dattrs.set_background ( purple);
426 dattrs.set_icon_name ( "process-stop");
427 dattrs.query_tooltip_text.connect(( mark) => {
428 //print("tooltip query? %s\n", mark.name);
432 this.el.set_mark_attributes ("DEPR", dattrs, 1);
435 var gattrs = new Gtk.SourceMarkAttributes();
436 var grey = Gdk.RGBA();
437 grey.parse ( "#ccc");
438 gattrs.set_background ( grey);
441 this.el.set_mark_attributes ("grey", gattrs, 1);
451 // user defined functions
452 public void nodeSelected (JsRender.Node? sel) {
456 // this is connected in widnowstate
457 print("node selected");
458 var buf = this.el.get_buffer();
460 var sbuf = (Gtk.SourceBuffer) buf;
463 while(Gtk.events_pending()) {
464 Gtk.main_iteration();
468 // clear all the marks..
472 sbuf.get_bounds (out start, out end);
473 sbuf.remove_source_marks (start, end, "grey");
481 sbuf.get_iter_at_line(out iter, sel.line_start);
482 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
484 for (var i = 0; i < buf.get_line_count();i++) {
485 if (i < sel.line_start || i > sel.line_end) {
487 sbuf.get_iter_at_line(out iter, i);
488 sbuf.create_source_mark(null, "grey", iter);
496 public void loadFile ( ) {
498 var buf = this.el.get_buffer();
500 var sbuf = (Gtk.SourceBuffer) buf;
504 if (_this.file == null || _this.file.xtype != "Gtk") {
505 print("xtype != Gtk");
506 this.loading = false;
512 var regex = new Regex("\\.bjs$");
515 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
516 } catch (GLib.RegexError e) {
517 this.loading = false;
522 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
523 print("File path has no errors\n");
524 this.loading = false;
531 GLib.FileUtils.get_contents (valafn, out str);
533 this.loading = false;
537 // print("setting str %d\n", str.length);
538 buf.set_text(str, str.length);
539 var lm = Gtk.SourceLanguageManager.get_default();
541 //?? is javascript going to work as js?
543 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
549 sbuf.get_bounds (out start, out end);
550 sbuf.remove_source_marks (start, end, null); // remove all marks..
553 if (_this.main_window.windowstate.last_compile_result != null) {
554 var obj = _this.main_window.windowstate.last_compile_result;
555 this.highlightErrorsJson("ERR", obj);
556 this.highlightErrorsJson("WARN", obj);
557 this.highlightErrorsJson("DEPR", obj);
559 //while (Gtk.events_pending()) {
560 // Gtk.main_iteration();
563 this.loading = false;
565 public void highlightErrorsJson (string type, Json.Object obj) {
569 var buf = this.el.get_buffer();
570 var sbuf = (Gtk.SourceBuffer)buf;
571 buf.get_bounds (out start, out end);
573 sbuf.remove_source_marks (start, end, type);
576 // we should highlight other types of errors..
578 if (!obj.has_member(type)) {
579 print("Return has no errors\n");
582 var err = obj.get_object_member(type);
584 if (_this.file == null) {
585 return; // just in case the file has not loaded yet?
591 var regex = new Regex("\\.bjs$");
594 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
595 } catch (GLib.RegexError e) {
599 if (!err.has_member(valafn)) {
600 print("File path has no errors\n");
603 var lines = err.get_object_member(valafn);
607 var tlines = buf.get_line_count () +1;
609 lines.foreach_member((obj, line, node) => {
612 // print("get inter\n");
613 var eline = int.parse(line) -1 ;
614 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
617 if (eline > tlines || eline < 0) {
620 sbuf.get_iter_at_line( out iter, eline);
621 //print("mark line\n");
622 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
623 var ar = lines.get_array_member(line);
624 for (var i = 0 ; i < ar.get_length(); i++) {
625 msg += (msg.length > 0) ? "\n" : "";
626 msg += ar.get_string_element(i);
630 sbuf.create_source_mark(msg, type, iter);