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 createThumb () {
59 if (this.file == null) {
62 // only screenshot the gtk preview..
63 if (this.notebook.el.page > 0 ) {
68 var filename = this.file.getIconFileName(false);
70 var win = this.el.get_parent_window();
71 var width = win.get_width();
72 var height = win.get_height();
74 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
75 screenshot.save(filename,"png");
87 // should we hold until it's printed...
98 public void loadFile (JsRender.JsRender file)
102 if (file.tree == null) {
106 this.sourceview.loadFile();
110 if (this.lastObj != null) {
111 this.container.el.remove(this.lastObj);
114 // hide the compile view at present..
120 print("ALLOC SET SIZES %d, %d\n", w,h);
122 // set the container size min to 500/500 or 20 px less than max..
123 w = int.max (w-20, 500);
124 h = int.max (h-20, 500);
126 print("SET SIZES %d, %d\n", w,h);
127 _this.container.el.set_size_request(w,h);
129 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
130 var rgba = Gdk.RGBA ();
132 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
135 var x = new JsRender.NodeToGtk(file.tree);
136 var obj = x.munge() as Gtk.Widget;
143 this.container.el.add(obj);
149 public class Xcls_notebook : Object
151 public Gtk.Notebook el;
152 private Xcls_GtkView _this;
158 public Xcls_notebook(Xcls_GtkView _owner )
161 _this.notebook = this;
162 this.el = new Gtk.Notebook();
166 // set gobject values
167 var child_0 = new Xcls_label_preview( _this );
169 var child_1 = new Xcls_label_code( _this );
171 var child_2 = new Xcls_ScrolledWindow5( _this );
173 this.el.append_page ( child_2.el , _this.label_preview.el );
174 var child_3 = new Xcls_ScrolledWindow8( _this );
176 this.el.append_page ( child_3.el , _this.label_code.el );
179 // user defined functions
181 public class Xcls_label_preview : Object
184 private Xcls_GtkView _this;
190 public Xcls_label_preview(Xcls_GtkView _owner )
193 _this.label_preview = this;
194 this.el = new Gtk.Label( "Preview" );
198 // set gobject values
201 // user defined functions
204 public class Xcls_label_code : Object
207 private Xcls_GtkView _this;
213 public Xcls_label_code(Xcls_GtkView _owner )
216 _this.label_code = this;
217 this.el = new Gtk.Label( "Preview Generated Code" );
221 // set gobject values
224 // user defined functions
227 public class Xcls_ScrolledWindow5 : Object
229 public Gtk.ScrolledWindow el;
230 private Xcls_GtkView _this;
236 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
239 this.el = new Gtk.ScrolledWindow( null, null );
243 // set gobject values
244 var child_0 = new Xcls_view_layout( _this );
246 this.el.add ( child_0.el );
249 // user defined functions
251 public class Xcls_view_layout : Object
253 public Gtk.Layout el;
254 private Xcls_GtkView _this;
260 public Xcls_view_layout(Xcls_GtkView _owner )
263 _this.view_layout = this;
264 this.el = new Gtk.Layout( null, null );
268 // set gobject values
269 var child_0 = new Xcls_container( _this );
271 this.el.put ( child_0.el , 10,10 );
274 // user defined functions
276 public class Xcls_container : Object
279 private Xcls_GtkView _this;
285 public Xcls_container(Xcls_GtkView _owner )
288 _this.container = this;
289 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
293 // set gobject values
296 // user defined functions
301 public class Xcls_ScrolledWindow8 : Object
303 public Gtk.ScrolledWindow el;
304 private Xcls_GtkView _this;
310 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
313 this.el = new Gtk.ScrolledWindow( null, null );
317 // set gobject values
318 var child_0 = new Xcls_sourceview( _this );
320 this.el.add ( child_0.el );
323 // user defined functions
325 public class Xcls_sourceview : Object
327 public Gtk.SourceView el;
328 private Xcls_GtkView _this;
335 public Xcls_sourceview(Xcls_GtkView _owner )
338 _this.sourceview = this;
339 this.el = new Gtk.SourceView();
344 // set gobject values
345 this.el.editable = false;
346 this.el.show_line_marks = true;
347 this.el.show_line_numbers = true;
353 var description = Pango.FontDescription.from_string("monospace");
354 description.set_size(8000);
355 this.el.override_font(description);
358 var buf = this.el.get_buffer();
359 buf.notify.connect((ps) => {
363 if (ps.name != "cursor-position") {
366 print("cursor changed : %d\n", buf.cursor_position);
368 buf.get_iter_at_offset(out cpos, buf.cursor_position);
370 var ln = cpos.get_line();
372 var node = _this.file.lineToNode(ln);
374 print("can not find node\n");
377 var ltree = _this.main_window.windowstate.left_tree;
378 var tp = ltree.model.treePathFromNode(node);
379 print("got tree path %s\n", tp);
381 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
384 // highlight the node..
390 var attrs = new Gtk.SourceMarkAttributes();
391 var pink = Gdk.RGBA();
392 pink.parse ( "pink");
393 attrs.set_background ( pink);
394 attrs.set_icon_name ( "process-stop");
395 attrs.query_tooltip_text.connect(( mark) => {
396 //print("tooltip query? %s\n", mark.name);
400 this.el.set_mark_attributes ("ERR", attrs, 1);
402 var wattrs = new Gtk.SourceMarkAttributes();
403 var blue = Gdk.RGBA();
404 blue.parse ( "#ABF4EB");
405 wattrs.set_background ( blue);
406 wattrs.set_icon_name ( "process-stop");
407 wattrs.query_tooltip_text.connect(( mark) => {
408 //print("tooltip query? %s\n", mark.name);
412 this.el.set_mark_attributes ("WARN", wattrs, 1);
416 var dattrs = new Gtk.SourceMarkAttributes();
417 var purple = Gdk.RGBA();
418 purple.parse ( "#EEA9FF");
419 dattrs.set_background ( purple);
420 dattrs.set_icon_name ( "process-stop");
421 dattrs.query_tooltip_text.connect(( mark) => {
422 //print("tooltip query? %s\n", mark.name);
426 this.el.set_mark_attributes ("DEPR", dattrs, 1);
429 var gattrs = new Gtk.SourceMarkAttributes();
430 var grey = Gdk.RGBA();
431 grey.parse ( "#ccc");
432 gattrs.set_background ( grey);
435 this.el.set_mark_attributes ("grey", gattrs, 1);
445 // user defined functions
446 public void nodeSelected (JsRender.Node? sel) {
450 // this is connected in widnowstate
451 print("node selected");
452 var buf = this.el.get_buffer();
454 var sbuf = (Gtk.SourceBuffer) buf;
457 while(Gtk.events_pending()) {
458 Gtk.main_iteration();
462 // clear all the marks..
466 sbuf.get_bounds (out start, out end);
467 sbuf.remove_source_marks (start, end, "grey");
475 sbuf.get_iter_at_line(out iter, sel.line_start);
476 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
478 for (var i = 0; i < buf.get_line_count();i++) {
479 if (i < sel.line_start || i > sel.line_end) {
481 sbuf.get_iter_at_line(out iter, i);
482 sbuf.create_source_mark(null, "grey", iter);
490 public void loadFile ( ) {
492 var buf = this.el.get_buffer();
494 var sbuf = (Gtk.SourceBuffer) buf;
498 if (_this.file == null || _this.file.xtype != "Gtk") {
499 print("xtype != Gtk");
500 this.loading = false;
506 var regex = new Regex("\\.bjs$");
509 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
510 } catch (GLib.RegexError e) {
511 this.loading = false;
516 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
517 print("File path has no errors\n");
518 this.loading = false;
525 GLib.FileUtils.get_contents (valafn, out str);
527 this.loading = false;
531 // print("setting str %d\n", str.length);
532 buf.set_text(str, str.length);
533 var lm = Gtk.SourceLanguageManager.get_default();
535 //?? is javascript going to work as js?
537 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
543 sbuf.get_bounds (out start, out end);
544 sbuf.remove_source_marks (start, end, null); // remove all marks..
547 if (_this.main_window.windowstate.last_compile_result != null) {
548 var obj = _this.main_window.windowstate.last_compile_result;
549 this.highlightErrorsJson("ERR", obj);
550 this.highlightErrorsJson("WARN", obj);
551 this.highlightErrorsJson("DEPR", obj);
553 //while (Gtk.events_pending()) {
554 // Gtk.main_iteration();
557 this.loading = false;
559 public void highlightErrorsJson (string type, Json.Object obj) {
563 var buf = this.el.get_buffer();
564 var sbuf = (Gtk.SourceBuffer)buf;
565 buf.get_bounds (out start, out end);
567 sbuf.remove_source_marks (start, end, type);
570 // we should highlight other types of errors..
572 if (!obj.has_member(type)) {
573 print("Return has no errors\n");
576 var err = obj.get_object_member(type);
578 if (_this.file == null) {
579 return; // just in case the file has not loaded yet?
585 var regex = new Regex("\\.bjs$");
588 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
589 } catch (GLib.RegexError e) {
593 if (!err.has_member(valafn)) {
594 print("File path has no errors\n");
597 var lines = err.get_object_member(valafn);
601 var tlines = buf.get_line_count () +1;
603 lines.foreach_member((obj, line, node) => {
606 // print("get inter\n");
607 var eline = int.parse(line) -1 ;
608 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
611 if (eline > tlines || eline < 0) {
614 sbuf.get_iter_at_line( out iter, eline);
615 //print("mark line\n");
616 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
617 var ar = lines.get_array_member(line);
618 for (var i = 0 ; i < ar.get_length(); i++) {
619 msg += (msg.length > 0) ? "\n" : "";
620 msg += ar.get_string_element(i);
624 sbuf.create_source_mark(msg, type, iter);