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_label_preview label_preview;
16 public Xcls_label_code label_code;
17 public Xcls_view_layout view_layout;
18 public Xcls_container container;
19 public Xcls_sourceview sourceview;
22 public Gtk.Widget lastObj;
24 public JsRender.JsRender file;
26 public Xcls_MainWindow main_window;
32 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
41 var child_0 = new Xcls_Notebook2( _this );
43 this.el.pack_start ( child_0.el , true,true,0 );
46 this.el.size_allocate.connect( (aloc) => {
48 this.width = aloc.width;
49 this.height =aloc.height;
53 // user defined functions
54 public void createThumb () {
57 if (this.file == null) {
60 var filename = this.file.getIconFileName(false);
62 var win = this.el.get_parent_window();
63 var width = win.get_width();
64 var height = win.get_height();
66 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
67 screenshot.save(filename,"png");
79 // should we hold until it's printed...
90 public void loadFile (JsRender.JsRender file)
94 if (file.tree == null) {
98 this.sourceview.loadFile();
102 if (this.lastObj != null) {
103 this.container.el.remove(this.lastObj);
106 // hide the compile view at present..
112 print("ALLOC SET SIZES %d, %d\n", w,h);
114 // set the container size min to 500/500 or 20 px less than max..
115 w = int.max (w-20, 500);
116 h = int.max (h-20, 500);
118 print("SET SIZES %d, %d\n", w,h);
119 _this.container.el.set_size_request(w,h);
121 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
122 var rgba = Gdk.RGBA ();
124 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
127 var x = new JsRender.NodeToGtk(file.tree);
128 var obj = x.munge() as Gtk.Widget;
135 this.container.el.add(obj);
141 public class Xcls_Notebook2 : Object
143 public Gtk.Notebook el;
144 private Xcls_GtkView _this;
150 public Xcls_Notebook2(Xcls_GtkView _owner )
153 this.el = new Gtk.Notebook();
157 // set gobject values
158 var child_0 = new Xcls_label_preview( _this );
160 var child_1 = new Xcls_label_code( _this );
162 var child_2 = new Xcls_ScrolledWindow5( _this );
164 this.el.append_page ( child_2.el , _this.label_preview.el );
165 var child_3 = new Xcls_ScrolledWindow8( _this );
167 this.el.append_page ( child_3.el , _this.label_code.el );
170 // user defined functions
172 public class Xcls_label_preview : Object
175 private Xcls_GtkView _this;
181 public Xcls_label_preview(Xcls_GtkView _owner )
184 _this.label_preview = this;
185 this.el = new Gtk.Label( "Preview" );
189 // set gobject values
192 // user defined functions
195 public class Xcls_label_code : Object
198 private Xcls_GtkView _this;
204 public Xcls_label_code(Xcls_GtkView _owner )
207 _this.label_code = this;
208 this.el = new Gtk.Label( "Preview Generated Code" );
212 // set gobject values
215 // user defined functions
218 public class Xcls_ScrolledWindow5 : Object
220 public Gtk.ScrolledWindow el;
221 private Xcls_GtkView _this;
227 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
230 this.el = new Gtk.ScrolledWindow( null, null );
234 // set gobject values
235 var child_0 = new Xcls_view_layout( _this );
237 this.el.add ( child_0.el );
240 // user defined functions
242 public class Xcls_view_layout : Object
244 public Gtk.Layout el;
245 private Xcls_GtkView _this;
251 public Xcls_view_layout(Xcls_GtkView _owner )
254 _this.view_layout = this;
255 this.el = new Gtk.Layout( null, null );
259 // set gobject values
260 var child_0 = new Xcls_container( _this );
262 this.el.put ( child_0.el , 10,10 );
265 // user defined functions
267 public class Xcls_container : Object
270 private Xcls_GtkView _this;
276 public Xcls_container(Xcls_GtkView _owner )
279 _this.container = this;
280 this.el = new Gtk.HBox( true, 0 );
284 // set gobject values
287 // user defined functions
292 public class Xcls_ScrolledWindow8 : Object
294 public Gtk.ScrolledWindow el;
295 private Xcls_GtkView _this;
301 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
304 this.el = new Gtk.ScrolledWindow( null, null );
308 // set gobject values
309 var child_0 = new Xcls_sourceview( _this );
311 this.el.add ( child_0.el );
314 // user defined functions
316 public class Xcls_sourceview : Object
318 public Gtk.SourceView el;
319 private Xcls_GtkView _this;
326 public Xcls_sourceview(Xcls_GtkView _owner )
329 _this.sourceview = this;
330 this.el = new Gtk.SourceView();
335 // set gobject values
336 this.el.editable = false;
337 this.el.show_line_marks = true;
338 this.el.show_line_numbers = true;
344 var description = Pango.FontDescription.from_string("monospace");
345 description.set_size(8000);
346 this.el.override_font(description);
349 var buf = this.el.get_buffer();
350 buf.notify.connect((ps) => {
354 if (ps.name != "cursor-position") {
357 print("cursor changed : %d\n", buf.cursor_position);
359 buf.get_iter_at_offset(out cpos, buf.cursor_position);
361 var ln = cpos.get_line();
363 var node = _this.file.lineToNode(ln);
365 print("can not find node\n");
368 var ltree = _this.main_window.windowstate.left_tree;
369 var tp = ltree.model.treePathFromNode(node);
370 print("got tree path %s\n", tp);
372 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
375 // highlight the node..
381 var attrs = new Gtk.SourceMarkAttributes();
382 var pink = Gdk.RGBA();
383 pink.parse ( "pink");
384 attrs.set_background ( pink);
385 attrs.set_icon_name ( "process-stop");
386 attrs.query_tooltip_text.connect(( mark) => {
387 //print("tooltip query? %s\n", mark.name);
391 this.el.set_mark_attributes ("ERR", attrs, 1);
393 var wattrs = new Gtk.SourceMarkAttributes();
394 var blue = Gdk.RGBA();
395 blue.parse ( "#ABF4EB");
396 wattrs.set_background ( blue);
397 wattrs.set_icon_name ( "process-stop");
398 wattrs.query_tooltip_text.connect(( mark) => {
399 //print("tooltip query? %s\n", mark.name);
403 this.el.set_mark_attributes ("WARN", wattrs, 1);
407 var dattrs = new Gtk.SourceMarkAttributes();
408 var purple = Gdk.RGBA();
409 purple.parse ( "#EEA9FF");
410 dattrs.set_background ( purple);
411 dattrs.set_icon_name ( "process-stop");
412 dattrs.query_tooltip_text.connect(( mark) => {
413 //print("tooltip query? %s\n", mark.name);
417 this.el.set_mark_attributes ("DEPR", dattrs, 1);
420 var gattrs = new Gtk.SourceMarkAttributes();
421 var grey = Gdk.RGBA();
422 grey.parse ( "#ccc");
423 gattrs.set_background ( grey);
426 this.el.set_mark_attributes ("grey", gattrs, 1);
436 // user defined functions
437 public void nodeSelected (JsRender.Node? sel) {
441 // this is connected in widnowstate
442 print("node selected");
443 var buf = this.el.get_buffer();
445 var sbuf = (Gtk.SourceBuffer) buf;
448 while(Gtk.events_pending()) {
449 Gtk.main_iteration();
453 // clear all the marks..
457 sbuf.get_bounds (out start, out end);
458 sbuf.remove_source_marks (start, end, "grey");
466 sbuf.get_iter_at_line(out iter, sel.line_start);
467 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
469 for (var i = 0; i < buf.get_line_count();i++) {
470 if (i < sel.line_start || i > sel.line_end) {
472 sbuf.get_iter_at_line(out iter, i);
473 sbuf.create_source_mark(null, "grey", iter);
481 public void loadFile ( ) {
483 var buf = this.el.get_buffer();
485 var sbuf = (Gtk.SourceBuffer) buf;
489 if (_this.file == null || _this.file.xtype != "Gtk") {
490 print("xtype != Gtk");
491 this.loading = false;
497 var regex = new Regex("\\.bjs$");
500 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
501 } catch (GLib.RegexError e) {
502 this.loading = false;
506 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
507 print("File path has no errors\n");
508 this.loading = false;
513 GLib.FileUtils.get_contents (valafn, out str);
515 // print("setting str %d\n", str.length);
516 buf.set_text(str, str.length);
517 var lm = Gtk.SourceLanguageManager.get_default();
519 //?? is javascript going to work as js?
521 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
527 sbuf.get_bounds (out start, out end);
528 sbuf.remove_source_marks (start, end, null); // remove all marks..
531 if (_this.main_window.windowstate.last_compile_result != null) {
532 var obj = _this.main_window.windowstate.last_compile_result;
533 this.highlightErrorsJson("ERR", obj);
534 this.highlightErrorsJson("WARN", obj);
535 this.highlightErrorsJson("DEPR", obj);
537 //while (Gtk.events_pending()) {
538 // Gtk.main_iteration();
541 this.loading = false;
543 public void highlightErrorsJson (string type, Json.Object obj) {
547 var buf = this.el.get_buffer();
548 var sbuf = (Gtk.SourceBuffer)buf;
549 buf.get_bounds (out start, out end);
551 sbuf.remove_source_marks (start, end, type);
554 // we should highlight other types of errors..
556 if (!obj.has_member(type)) {
557 print("Return has no errors\n");
560 var err = obj.get_object_member(type);
566 var regex = new Regex("\\.bjs$");
569 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
570 } catch (GLib.RegexError e) {
574 if (!err.has_member(valafn)) {
575 print("File path has no errors\n");
578 var lines = err.get_object_member(valafn);
582 var tlines = buf.get_line_count () +1;
584 lines.foreach_member((obj, line, node) => {
587 // print("get inter\n");
588 var eline = int.parse(line) -1 ;
589 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
592 if (eline > tlines || eline < 0) {
595 sbuf.get_iter_at_line( out iter, eline);
596 //print("mark line\n");
597 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
598 var ar = lines.get_array_member(line);
599 for (var i = 0 ; i < ar.get_length(); i++) {
600 msg += (msg.length > 0) ? "\n" : "";
601 msg += ar.get_string_element(i);
605 sbuf.create_source_mark(msg, type, iter);