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 var buf = this.sourceview.el.get_buffer();
60 var sbuf = (Gtk.SourceBuffer) buf;
64 sbuf.get_iter_at_line(out iter, line);
65 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
67 this.notebook.el.page = 1;// code preview...
70 public void createThumb () {
73 if (this.file == null) {
76 // only screenshot the gtk preview..
77 if (this.notebook.el.page > 0 ) {
82 var filename = this.file.getIconFileName(false);
84 var win = this.el.get_parent_window();
85 var width = win.get_width();
86 var height = win.get_height();
88 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
89 screenshot.save(filename,"png");
101 // should we hold until it's printed...
112 public void loadFile (JsRender.JsRender file)
116 if (file.tree == null) {
120 this.sourceview.loadFile();
124 if (this.lastObj != null) {
125 this.container.el.remove(this.lastObj);
128 // hide the compile view at present..
134 print("ALLOC SET SIZES %d, %d\n", w,h);
136 // set the container size min to 500/500 or 20 px less than max..
137 w = int.max (w-20, 500);
138 h = int.max (h-20, 500);
140 print("SET SIZES %d, %d\n", w,h);
141 _this.container.el.set_size_request(w,h);
143 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
144 var rgba = Gdk.RGBA ();
146 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
149 var x = new JsRender.NodeToGtk(file.tree);
150 var obj = x.munge() as Gtk.Widget;
157 this.container.el.add(obj);
163 public class Xcls_notebook : Object
165 public Gtk.Notebook el;
166 private Xcls_GtkView _this;
172 public Xcls_notebook(Xcls_GtkView _owner )
175 _this.notebook = this;
176 this.el = new Gtk.Notebook();
180 // set gobject values
181 var child_0 = new Xcls_label_preview( _this );
183 var child_1 = new Xcls_label_code( _this );
185 var child_2 = new Xcls_ScrolledWindow5( _this );
187 this.el.append_page ( child_2.el , _this.label_preview.el );
188 var child_3 = new Xcls_ScrolledWindow8( _this );
190 this.el.append_page ( child_3.el , _this.label_code.el );
193 // user defined functions
195 public class Xcls_label_preview : Object
198 private Xcls_GtkView _this;
204 public Xcls_label_preview(Xcls_GtkView _owner )
207 _this.label_preview = this;
208 this.el = new Gtk.Label( "Preview" );
212 // set gobject values
215 // user defined functions
218 public class Xcls_label_code : Object
221 private Xcls_GtkView _this;
227 public Xcls_label_code(Xcls_GtkView _owner )
230 _this.label_code = this;
231 this.el = new Gtk.Label( "Preview Generated Code" );
235 // set gobject values
238 // user defined functions
241 public class Xcls_ScrolledWindow5 : Object
243 public Gtk.ScrolledWindow el;
244 private Xcls_GtkView _this;
250 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
253 this.el = new Gtk.ScrolledWindow( null, null );
257 // set gobject values
258 var child_0 = new Xcls_view_layout( _this );
260 this.el.add ( child_0.el );
263 // user defined functions
265 public class Xcls_view_layout : Object
267 public Gtk.Layout el;
268 private Xcls_GtkView _this;
274 public Xcls_view_layout(Xcls_GtkView _owner )
277 _this.view_layout = this;
278 this.el = new Gtk.Layout( null, null );
282 // set gobject values
283 var child_0 = new Xcls_container( _this );
285 this.el.put ( child_0.el , 10,10 );
288 // user defined functions
290 public class Xcls_container : Object
293 private Xcls_GtkView _this;
299 public Xcls_container(Xcls_GtkView _owner )
302 _this.container = this;
303 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
307 // set gobject values
310 // user defined functions
315 public class Xcls_ScrolledWindow8 : Object
317 public Gtk.ScrolledWindow el;
318 private Xcls_GtkView _this;
324 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
327 this.el = new Gtk.ScrolledWindow( null, null );
331 // set gobject values
332 var child_0 = new Xcls_sourceview( _this );
334 this.el.add ( child_0.el );
337 // user defined functions
339 public class Xcls_sourceview : Object
341 public Gtk.SourceView el;
342 private Xcls_GtkView _this;
349 public Xcls_sourceview(Xcls_GtkView _owner )
352 _this.sourceview = this;
353 this.el = new Gtk.SourceView();
358 // set gobject values
359 this.el.editable = false;
360 this.el.show_line_marks = true;
361 this.el.show_line_numbers = true;
367 var description = Pango.FontDescription.from_string("monospace");
368 description.set_size(8000);
369 this.el.override_font(description);
372 var buf = this.el.get_buffer();
373 buf.notify.connect((ps) => {
377 if (ps.name != "cursor-position") {
380 print("cursor changed : %d\n", buf.cursor_position);
382 buf.get_iter_at_offset(out cpos, buf.cursor_position);
384 var ln = cpos.get_line();
386 var node = _this.file.lineToNode(ln);
388 print("can not find node\n");
391 var ltree = _this.main_window.windowstate.left_tree;
392 var tp = ltree.model.treePathFromNode(node);
393 print("got tree path %s\n", tp);
395 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
398 // highlight the node..
404 var attrs = new Gtk.SourceMarkAttributes();
405 var pink = Gdk.RGBA();
406 pink.parse ( "pink");
407 attrs.set_background ( pink);
408 attrs.set_icon_name ( "process-stop");
409 attrs.query_tooltip_text.connect(( mark) => {
410 //print("tooltip query? %s\n", mark.name);
414 this.el.set_mark_attributes ("ERR", attrs, 1);
416 var wattrs = new Gtk.SourceMarkAttributes();
417 var blue = Gdk.RGBA();
418 blue.parse ( "#ABF4EB");
419 wattrs.set_background ( blue);
420 wattrs.set_icon_name ( "process-stop");
421 wattrs.query_tooltip_text.connect(( mark) => {
422 //print("tooltip query? %s\n", mark.name);
426 this.el.set_mark_attributes ("WARN", wattrs, 1);
430 var dattrs = new Gtk.SourceMarkAttributes();
431 var purple = Gdk.RGBA();
432 purple.parse ( "#EEA9FF");
433 dattrs.set_background ( purple);
434 dattrs.set_icon_name ( "process-stop");
435 dattrs.query_tooltip_text.connect(( mark) => {
436 //print("tooltip query? %s\n", mark.name);
440 this.el.set_mark_attributes ("DEPR", dattrs, 1);
443 var gattrs = new Gtk.SourceMarkAttributes();
444 var grey = Gdk.RGBA();
445 grey.parse ( "#ccc");
446 gattrs.set_background ( grey);
449 this.el.set_mark_attributes ("grey", gattrs, 1);
459 // user defined functions
460 public void nodeSelected (JsRender.Node? sel) {
464 // this is connected in widnowstate
465 print("node selected");
466 var buf = this.el.get_buffer();
468 var sbuf = (Gtk.SourceBuffer) buf;
471 while(Gtk.events_pending()) {
472 Gtk.main_iteration();
476 // clear all the marks..
480 sbuf.get_bounds (out start, out end);
481 sbuf.remove_source_marks (start, end, "grey");
489 sbuf.get_iter_at_line(out iter, sel.line_start);
490 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
492 for (var i = 0; i < buf.get_line_count();i++) {
493 if (i < sel.line_start || i > sel.line_end) {
495 sbuf.get_iter_at_line(out iter, i);
496 sbuf.create_source_mark(null, "grey", iter);
504 public void loadFile ( ) {
506 var buf = this.el.get_buffer();
508 var sbuf = (Gtk.SourceBuffer) buf;
512 if (_this.file == null || _this.file.xtype != "Gtk") {
513 print("xtype != Gtk");
514 this.loading = false;
520 var regex = new Regex("\\.bjs$");
523 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
524 } catch (GLib.RegexError e) {
525 this.loading = false;
530 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
531 print("File path has no errors\n");
532 this.loading = false;
539 GLib.FileUtils.get_contents (valafn, out str);
541 this.loading = false;
545 // print("setting str %d\n", str.length);
546 buf.set_text(str, str.length);
547 var lm = Gtk.SourceLanguageManager.get_default();
549 //?? is javascript going to work as js?
551 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
557 sbuf.get_bounds (out start, out end);
558 sbuf.remove_source_marks (start, end, null); // remove all marks..
561 if (_this.main_window.windowstate.last_compile_result != null) {
562 var obj = _this.main_window.windowstate.last_compile_result;
563 this.highlightErrorsJson("ERR", obj);
564 this.highlightErrorsJson("WARN", obj);
565 this.highlightErrorsJson("DEPR", obj);
567 //while (Gtk.events_pending()) {
568 // Gtk.main_iteration();
571 this.loading = false;
573 public void highlightErrorsJson (string type, Json.Object obj) {
577 var buf = this.el.get_buffer();
578 var sbuf = (Gtk.SourceBuffer)buf;
579 buf.get_bounds (out start, out end);
581 sbuf.remove_source_marks (start, end, type);
584 // we should highlight other types of errors..
586 if (!obj.has_member(type)) {
587 print("Return has no errors\n");
590 var err = obj.get_object_member(type);
592 if (_this.file == null) {
593 return; // just in case the file has not loaded yet?
599 var regex = new Regex("\\.bjs$");
602 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
603 } catch (GLib.RegexError e) {
607 if (!err.has_member(valafn)) {
608 print("File path has no errors\n");
611 var lines = err.get_object_member(valafn);
615 var tlines = buf.get_line_count () +1;
617 lines.foreach_member((obj, line, node) => {
620 // print("get inter\n");
621 var eline = int.parse(line) -1 ;
622 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
625 if (eline > tlines || eline < 0) {
628 sbuf.get_iter_at_line( out iter, eline);
629 //print("mark line\n");
630 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
631 var ar = lines.get_array_member(line);
632 for (var i = 0 ; i < ar.get_length(); i++) {
633 msg += (msg.length > 0) ? "\n" : "";
634 msg += ar.get_string_element(i);
638 sbuf.create_source_mark(msg, type, iter);