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) {
59 public void createThumb () {
62 if (this.file == null) {
65 // only screenshot the gtk preview..
66 if (this.notebook.el.page > 0 ) {
71 var filename = this.file.getIconFileName(false);
73 var win = this.el.get_parent_window();
74 var width = win.get_width();
75 var height = win.get_height();
77 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
78 screenshot.save(filename,"png");
90 // should we hold until it's printed...
101 public void loadFile (JsRender.JsRender file)
105 if (file.tree == null) {
109 this.sourceview.loadFile();
113 if (this.lastObj != null) {
114 this.container.el.remove(this.lastObj);
117 // hide the compile view at present..
123 print("ALLOC SET SIZES %d, %d\n", w,h);
125 // set the container size min to 500/500 or 20 px less than max..
126 w = int.max (w-20, 500);
127 h = int.max (h-20, 500);
129 print("SET SIZES %d, %d\n", w,h);
130 _this.container.el.set_size_request(w,h);
132 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
133 var rgba = Gdk.RGBA ();
135 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
138 var x = new JsRender.NodeToGtk(file.tree);
139 var obj = x.munge() as Gtk.Widget;
146 this.container.el.add(obj);
152 public class Xcls_notebook : Object
154 public Gtk.Notebook el;
155 private Xcls_GtkView _this;
161 public Xcls_notebook(Xcls_GtkView _owner )
164 _this.notebook = this;
165 this.el = new Gtk.Notebook();
169 // set gobject values
170 var child_0 = new Xcls_label_preview( _this );
172 var child_1 = new Xcls_label_code( _this );
174 var child_2 = new Xcls_ScrolledWindow5( _this );
176 this.el.append_page ( child_2.el , _this.label_preview.el );
177 var child_3 = new Xcls_ScrolledWindow8( _this );
179 this.el.append_page ( child_3.el , _this.label_code.el );
182 // user defined functions
184 public class Xcls_label_preview : Object
187 private Xcls_GtkView _this;
193 public Xcls_label_preview(Xcls_GtkView _owner )
196 _this.label_preview = this;
197 this.el = new Gtk.Label( "Preview" );
201 // set gobject values
204 // user defined functions
207 public class Xcls_label_code : Object
210 private Xcls_GtkView _this;
216 public Xcls_label_code(Xcls_GtkView _owner )
219 _this.label_code = this;
220 this.el = new Gtk.Label( "Preview Generated Code" );
224 // set gobject values
227 // user defined functions
230 public class Xcls_ScrolledWindow5 : Object
232 public Gtk.ScrolledWindow el;
233 private Xcls_GtkView _this;
239 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
242 this.el = new Gtk.ScrolledWindow( null, null );
246 // set gobject values
247 var child_0 = new Xcls_view_layout( _this );
249 this.el.add ( child_0.el );
252 // user defined functions
254 public class Xcls_view_layout : Object
256 public Gtk.Layout el;
257 private Xcls_GtkView _this;
263 public Xcls_view_layout(Xcls_GtkView _owner )
266 _this.view_layout = this;
267 this.el = new Gtk.Layout( null, null );
271 // set gobject values
272 var child_0 = new Xcls_container( _this );
274 this.el.put ( child_0.el , 10,10 );
277 // user defined functions
279 public class Xcls_container : Object
282 private Xcls_GtkView _this;
288 public Xcls_container(Xcls_GtkView _owner )
291 _this.container = this;
292 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
296 // set gobject values
299 // user defined functions
304 public class Xcls_ScrolledWindow8 : Object
306 public Gtk.ScrolledWindow el;
307 private Xcls_GtkView _this;
313 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
316 this.el = new Gtk.ScrolledWindow( null, null );
320 // set gobject values
321 var child_0 = new Xcls_sourceview( _this );
323 this.el.add ( child_0.el );
326 // user defined functions
328 public class Xcls_sourceview : Object
330 public Gtk.SourceView el;
331 private Xcls_GtkView _this;
338 public Xcls_sourceview(Xcls_GtkView _owner )
341 _this.sourceview = this;
342 this.el = new Gtk.SourceView();
347 // set gobject values
348 this.el.editable = false;
349 this.el.show_line_marks = true;
350 this.el.show_line_numbers = true;
356 var description = Pango.FontDescription.from_string("monospace");
357 description.set_size(8000);
358 this.el.override_font(description);
361 var buf = this.el.get_buffer();
362 buf.notify.connect((ps) => {
366 if (ps.name != "cursor-position") {
369 print("cursor changed : %d\n", buf.cursor_position);
371 buf.get_iter_at_offset(out cpos, buf.cursor_position);
373 var ln = cpos.get_line();
375 var node = _this.file.lineToNode(ln);
377 print("can not find node\n");
380 var ltree = _this.main_window.windowstate.left_tree;
381 var tp = ltree.model.treePathFromNode(node);
382 print("got tree path %s\n", tp);
384 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
387 // highlight the node..
393 var attrs = new Gtk.SourceMarkAttributes();
394 var pink = Gdk.RGBA();
395 pink.parse ( "pink");
396 attrs.set_background ( pink);
397 attrs.set_icon_name ( "process-stop");
398 attrs.query_tooltip_text.connect(( mark) => {
399 //print("tooltip query? %s\n", mark.name);
403 this.el.set_mark_attributes ("ERR", attrs, 1);
405 var wattrs = new Gtk.SourceMarkAttributes();
406 var blue = Gdk.RGBA();
407 blue.parse ( "#ABF4EB");
408 wattrs.set_background ( blue);
409 wattrs.set_icon_name ( "process-stop");
410 wattrs.query_tooltip_text.connect(( mark) => {
411 //print("tooltip query? %s\n", mark.name);
415 this.el.set_mark_attributes ("WARN", wattrs, 1);
419 var dattrs = new Gtk.SourceMarkAttributes();
420 var purple = Gdk.RGBA();
421 purple.parse ( "#EEA9FF");
422 dattrs.set_background ( purple);
423 dattrs.set_icon_name ( "process-stop");
424 dattrs.query_tooltip_text.connect(( mark) => {
425 //print("tooltip query? %s\n", mark.name);
429 this.el.set_mark_attributes ("DEPR", dattrs, 1);
432 var gattrs = new Gtk.SourceMarkAttributes();
433 var grey = Gdk.RGBA();
434 grey.parse ( "#ccc");
435 gattrs.set_background ( grey);
438 this.el.set_mark_attributes ("grey", gattrs, 1);
448 // user defined functions
449 public void nodeSelected (JsRender.Node? sel) {
453 // this is connected in widnowstate
454 print("node selected");
455 var buf = this.el.get_buffer();
457 var sbuf = (Gtk.SourceBuffer) buf;
460 while(Gtk.events_pending()) {
461 Gtk.main_iteration();
465 // clear all the marks..
469 sbuf.get_bounds (out start, out end);
470 sbuf.remove_source_marks (start, end, "grey");
478 sbuf.get_iter_at_line(out iter, sel.line_start);
479 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
481 for (var i = 0; i < buf.get_line_count();i++) {
482 if (i < sel.line_start || i > sel.line_end) {
484 sbuf.get_iter_at_line(out iter, i);
485 sbuf.create_source_mark(null, "grey", iter);
493 public void loadFile ( ) {
495 var buf = this.el.get_buffer();
497 var sbuf = (Gtk.SourceBuffer) buf;
501 if (_this.file == null || _this.file.xtype != "Gtk") {
502 print("xtype != Gtk");
503 this.loading = false;
509 var regex = new Regex("\\.bjs$");
512 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
513 } catch (GLib.RegexError e) {
514 this.loading = false;
519 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
520 print("File path has no errors\n");
521 this.loading = false;
528 GLib.FileUtils.get_contents (valafn, out str);
530 this.loading = false;
534 // print("setting str %d\n", str.length);
535 buf.set_text(str, str.length);
536 var lm = Gtk.SourceLanguageManager.get_default();
538 //?? is javascript going to work as js?
540 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
546 sbuf.get_bounds (out start, out end);
547 sbuf.remove_source_marks (start, end, null); // remove all marks..
550 if (_this.main_window.windowstate.last_compile_result != null) {
551 var obj = _this.main_window.windowstate.last_compile_result;
552 this.highlightErrorsJson("ERR", obj);
553 this.highlightErrorsJson("WARN", obj);
554 this.highlightErrorsJson("DEPR", obj);
556 //while (Gtk.events_pending()) {
557 // Gtk.main_iteration();
560 this.loading = false;
562 public void highlightErrorsJson (string type, Json.Object obj) {
566 var buf = this.el.get_buffer();
567 var sbuf = (Gtk.SourceBuffer)buf;
568 buf.get_bounds (out start, out end);
570 sbuf.remove_source_marks (start, end, type);
573 // we should highlight other types of errors..
575 if (!obj.has_member(type)) {
576 print("Return has no errors\n");
579 var err = obj.get_object_member(type);
581 if (_this.file == null) {
582 return; // just in case the file has not loaded yet?
588 var regex = new Regex("\\.bjs$");
591 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
592 } catch (GLib.RegexError e) {
596 if (!err.has_member(valafn)) {
597 print("File path has no errors\n");
600 var lines = err.get_object_member(valafn);
604 var tlines = buf.get_line_count () +1;
606 lines.foreach_member((obj, line, node) => {
609 // print("get inter\n");
610 var eline = int.parse(line) -1 ;
611 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
614 if (eline > tlines || eline < 0) {
617 sbuf.get_iter_at_line( out iter, eline);
618 //print("mark line\n");
619 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
620 var ar = lines.get_array_member(line);
621 for (var i = 0 ; i < ar.get_length(); i++) {
622 msg += (msg.length > 0) ? "\n" : "";
623 msg += ar.get_string_element(i);
627 sbuf.create_source_mark(msg, type, iter);