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);
68 public void createThumb () {
71 if (this.file == null) {
74 // only screenshot the gtk preview..
75 if (this.notebook.el.page > 0 ) {
80 var filename = this.file.getIconFileName(false);
82 var win = this.el.get_parent_window();
83 var width = win.get_width();
84 var height = win.get_height();
86 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
87 screenshot.save(filename,"png");
99 // should we hold until it's printed...
110 public void loadFile (JsRender.JsRender file)
114 if (file.tree == null) {
118 this.sourceview.loadFile();
122 if (this.lastObj != null) {
123 this.container.el.remove(this.lastObj);
126 // hide the compile view at present..
132 print("ALLOC SET SIZES %d, %d\n", w,h);
134 // set the container size min to 500/500 or 20 px less than max..
135 w = int.max (w-20, 500);
136 h = int.max (h-20, 500);
138 print("SET SIZES %d, %d\n", w,h);
139 _this.container.el.set_size_request(w,h);
141 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
142 var rgba = Gdk.RGBA ();
144 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
147 var x = new JsRender.NodeToGtk(file.tree);
148 var obj = x.munge() as Gtk.Widget;
155 this.container.el.add(obj);
161 public class Xcls_notebook : Object
163 public Gtk.Notebook el;
164 private Xcls_GtkView _this;
170 public Xcls_notebook(Xcls_GtkView _owner )
173 _this.notebook = this;
174 this.el = new Gtk.Notebook();
178 // set gobject values
179 var child_0 = new Xcls_label_preview( _this );
181 var child_1 = new Xcls_label_code( _this );
183 var child_2 = new Xcls_ScrolledWindow5( _this );
185 this.el.append_page ( child_2.el , _this.label_preview.el );
186 var child_3 = new Xcls_ScrolledWindow8( _this );
188 this.el.append_page ( child_3.el , _this.label_code.el );
191 // user defined functions
193 public class Xcls_label_preview : Object
196 private Xcls_GtkView _this;
202 public Xcls_label_preview(Xcls_GtkView _owner )
205 _this.label_preview = this;
206 this.el = new Gtk.Label( "Preview" );
210 // set gobject values
213 // user defined functions
216 public class Xcls_label_code : Object
219 private Xcls_GtkView _this;
225 public Xcls_label_code(Xcls_GtkView _owner )
228 _this.label_code = this;
229 this.el = new Gtk.Label( "Preview Generated Code" );
233 // set gobject values
236 // user defined functions
239 public class Xcls_ScrolledWindow5 : Object
241 public Gtk.ScrolledWindow el;
242 private Xcls_GtkView _this;
248 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
251 this.el = new Gtk.ScrolledWindow( null, null );
255 // set gobject values
256 var child_0 = new Xcls_view_layout( _this );
258 this.el.add ( child_0.el );
261 // user defined functions
263 public class Xcls_view_layout : Object
265 public Gtk.Layout el;
266 private Xcls_GtkView _this;
272 public Xcls_view_layout(Xcls_GtkView _owner )
275 _this.view_layout = this;
276 this.el = new Gtk.Layout( null, null );
280 // set gobject values
281 var child_0 = new Xcls_container( _this );
283 this.el.put ( child_0.el , 10,10 );
286 // user defined functions
288 public class Xcls_container : Object
291 private Xcls_GtkView _this;
297 public Xcls_container(Xcls_GtkView _owner )
300 _this.container = this;
301 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
305 // set gobject values
308 // user defined functions
313 public class Xcls_ScrolledWindow8 : Object
315 public Gtk.ScrolledWindow el;
316 private Xcls_GtkView _this;
322 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
325 this.el = new Gtk.ScrolledWindow( null, null );
329 // set gobject values
330 var child_0 = new Xcls_sourceview( _this );
332 this.el.add ( child_0.el );
335 // user defined functions
337 public class Xcls_sourceview : Object
339 public Gtk.SourceView el;
340 private Xcls_GtkView _this;
347 public Xcls_sourceview(Xcls_GtkView _owner )
350 _this.sourceview = this;
351 this.el = new Gtk.SourceView();
356 // set gobject values
357 this.el.editable = false;
358 this.el.show_line_marks = true;
359 this.el.show_line_numbers = true;
365 var description = Pango.FontDescription.from_string("monospace");
366 description.set_size(8000);
367 this.el.override_font(description);
370 var buf = this.el.get_buffer();
371 buf.notify.connect((ps) => {
375 if (ps.name != "cursor-position") {
378 print("cursor changed : %d\n", buf.cursor_position);
380 buf.get_iter_at_offset(out cpos, buf.cursor_position);
382 var ln = cpos.get_line();
384 var node = _this.file.lineToNode(ln);
386 print("can not find node\n");
389 var ltree = _this.main_window.windowstate.left_tree;
390 var tp = ltree.model.treePathFromNode(node);
391 print("got tree path %s\n", tp);
393 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
396 // highlight the node..
402 var attrs = new Gtk.SourceMarkAttributes();
403 var pink = Gdk.RGBA();
404 pink.parse ( "pink");
405 attrs.set_background ( pink);
406 attrs.set_icon_name ( "process-stop");
407 attrs.query_tooltip_text.connect(( mark) => {
408 //print("tooltip query? %s\n", mark.name);
412 this.el.set_mark_attributes ("ERR", attrs, 1);
414 var wattrs = new Gtk.SourceMarkAttributes();
415 var blue = Gdk.RGBA();
416 blue.parse ( "#ABF4EB");
417 wattrs.set_background ( blue);
418 wattrs.set_icon_name ( "process-stop");
419 wattrs.query_tooltip_text.connect(( mark) => {
420 //print("tooltip query? %s\n", mark.name);
424 this.el.set_mark_attributes ("WARN", wattrs, 1);
428 var dattrs = new Gtk.SourceMarkAttributes();
429 var purple = Gdk.RGBA();
430 purple.parse ( "#EEA9FF");
431 dattrs.set_background ( purple);
432 dattrs.set_icon_name ( "process-stop");
433 dattrs.query_tooltip_text.connect(( mark) => {
434 //print("tooltip query? %s\n", mark.name);
438 this.el.set_mark_attributes ("DEPR", dattrs, 1);
441 var gattrs = new Gtk.SourceMarkAttributes();
442 var grey = Gdk.RGBA();
443 grey.parse ( "#ccc");
444 gattrs.set_background ( grey);
447 this.el.set_mark_attributes ("grey", gattrs, 1);
457 // user defined functions
458 public void nodeSelected (JsRender.Node? sel) {
462 // this is connected in widnowstate
463 print("node selected");
464 var buf = this.el.get_buffer();
466 var sbuf = (Gtk.SourceBuffer) buf;
469 while(Gtk.events_pending()) {
470 Gtk.main_iteration();
474 // clear all the marks..
478 sbuf.get_bounds (out start, out end);
479 sbuf.remove_source_marks (start, end, "grey");
487 sbuf.get_iter_at_line(out iter, sel.line_start);
488 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
490 for (var i = 0; i < buf.get_line_count();i++) {
491 if (i < sel.line_start || i > sel.line_end) {
493 sbuf.get_iter_at_line(out iter, i);
494 sbuf.create_source_mark(null, "grey", iter);
502 public void loadFile ( ) {
504 var buf = this.el.get_buffer();
506 var sbuf = (Gtk.SourceBuffer) buf;
510 if (_this.file == null || _this.file.xtype != "Gtk") {
511 print("xtype != Gtk");
512 this.loading = false;
518 var regex = new Regex("\\.bjs$");
521 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
522 } catch (GLib.RegexError e) {
523 this.loading = false;
528 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
529 print("File path has no errors\n");
530 this.loading = false;
537 GLib.FileUtils.get_contents (valafn, out str);
539 this.loading = false;
543 // print("setting str %d\n", str.length);
544 buf.set_text(str, str.length);
545 var lm = Gtk.SourceLanguageManager.get_default();
547 //?? is javascript going to work as js?
549 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
555 sbuf.get_bounds (out start, out end);
556 sbuf.remove_source_marks (start, end, null); // remove all marks..
559 if (_this.main_window.windowstate.last_compile_result != null) {
560 var obj = _this.main_window.windowstate.last_compile_result;
561 this.highlightErrorsJson("ERR", obj);
562 this.highlightErrorsJson("WARN", obj);
563 this.highlightErrorsJson("DEPR", obj);
565 //while (Gtk.events_pending()) {
566 // Gtk.main_iteration();
569 this.loading = false;
571 public void highlightErrorsJson (string type, Json.Object obj) {
575 var buf = this.el.get_buffer();
576 var sbuf = (Gtk.SourceBuffer)buf;
577 buf.get_bounds (out start, out end);
579 sbuf.remove_source_marks (start, end, type);
582 // we should highlight other types of errors..
584 if (!obj.has_member(type)) {
585 print("Return has no errors\n");
588 var err = obj.get_object_member(type);
590 if (_this.file == null) {
591 return; // just in case the file has not loaded yet?
597 var regex = new Regex("\\.bjs$");
600 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
601 } catch (GLib.RegexError e) {
605 if (!err.has_member(valafn)) {
606 print("File path has no errors\n");
609 var lines = err.get_object_member(valafn);
613 var tlines = buf.get_line_count () +1;
615 lines.foreach_member((obj, line, node) => {
618 // print("get inter\n");
619 var eline = int.parse(line) -1 ;
620 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
623 if (eline > tlines || eline < 0) {
626 sbuf.get_iter_at_line( out iter, eline);
627 //print("mark line\n");
628 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
629 var ar = lines.get_array_member(line);
630 for (var i = 0 ; i < ar.get_length(); i++) {
631 msg += (msg.length > 0) ? "\n" : "";
632 msg += ar.get_string_element(i);
636 sbuf.create_source_mark(msg, type, iter);