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 Gee.ArrayList<int> search (string txt) {
57 var ret = new Gee.ArrayList<int>();
58 var str = this.sourceview.toString();
63 public void scroll_to_line (int line) {
64 this.notebook.el.page = 1;// code preview...
66 GLib.Timeout.add(500, () => {
71 var buf = this.sourceview.el.get_buffer();
73 var sbuf = (Gtk.SourceBuffer) buf;
77 sbuf.get_iter_at_line(out iter, line);
78 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
84 public void createThumb () {
87 if (this.file == null) {
90 // only screenshot the gtk preview..
91 if (this.notebook.el.page > 0 ) {
96 var filename = this.file.getIconFileName(false);
98 var win = this.el.get_parent_window();
99 var width = win.get_width();
100 var height = win.get_height();
102 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
103 screenshot.save(filename,"png");
115 // should we hold until it's printed...
126 public void loadFile (JsRender.JsRender file)
130 if (file.tree == null) {
133 this.notebook.el.page = 0;// gtk preview
138 this.sourceview.loadFile();
142 if (this.lastObj != null) {
143 this.container.el.remove(this.lastObj);
146 // hide the compile view at present..
152 print("ALLOC SET SIZES %d, %d\n", w,h);
154 // set the container size min to 500/500 or 20 px less than max..
155 w = int.max (w-20, 500);
156 h = int.max (h-20, 500);
158 print("SET SIZES %d, %d\n", w,h);
159 _this.container.el.set_size_request(w,h);
161 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
162 var rgba = Gdk.RGBA ();
164 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
167 var x = new JsRender.NodeToGtk(file.tree);
168 var obj = x.munge() as Gtk.Widget;
175 this.container.el.add(obj);
181 public class Xcls_notebook : Object
183 public Gtk.Notebook el;
184 private Xcls_GtkView _this;
190 public Xcls_notebook(Xcls_GtkView _owner )
193 _this.notebook = this;
194 this.el = new Gtk.Notebook();
198 // set gobject values
199 var child_0 = new Xcls_label_preview( _this );
201 var child_1 = new Xcls_label_code( _this );
203 var child_2 = new Xcls_ScrolledWindow5( _this );
205 this.el.append_page ( child_2.el , _this.label_preview.el );
206 var child_3 = new Xcls_ScrolledWindow8( _this );
208 this.el.append_page ( child_3.el , _this.label_code.el );
211 // user defined functions
213 public class Xcls_label_preview : Object
216 private Xcls_GtkView _this;
222 public Xcls_label_preview(Xcls_GtkView _owner )
225 _this.label_preview = this;
226 this.el = new Gtk.Label( "Preview" );
230 // set gobject values
233 // user defined functions
236 public class Xcls_label_code : Object
239 private Xcls_GtkView _this;
245 public Xcls_label_code(Xcls_GtkView _owner )
248 _this.label_code = this;
249 this.el = new Gtk.Label( "Preview Generated Code" );
253 // set gobject values
256 // user defined functions
259 public class Xcls_ScrolledWindow5 : Object
261 public Gtk.ScrolledWindow el;
262 private Xcls_GtkView _this;
268 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
271 this.el = new Gtk.ScrolledWindow( null, null );
275 // set gobject values
276 var child_0 = new Xcls_view_layout( _this );
278 this.el.add ( child_0.el );
281 // user defined functions
283 public class Xcls_view_layout : Object
285 public Gtk.Layout el;
286 private Xcls_GtkView _this;
292 public Xcls_view_layout(Xcls_GtkView _owner )
295 _this.view_layout = this;
296 this.el = new Gtk.Layout( null, null );
300 // set gobject values
301 var child_0 = new Xcls_container( _this );
303 this.el.put ( child_0.el , 10,10 );
306 // user defined functions
308 public class Xcls_container : Object
311 private Xcls_GtkView _this;
317 public Xcls_container(Xcls_GtkView _owner )
320 _this.container = this;
321 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
325 // set gobject values
328 // user defined functions
333 public class Xcls_ScrolledWindow8 : Object
335 public Gtk.ScrolledWindow el;
336 private Xcls_GtkView _this;
342 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
345 this.el = new Gtk.ScrolledWindow( null, null );
349 // set gobject values
350 var child_0 = new Xcls_sourceview( _this );
352 this.el.add ( child_0.el );
355 // user defined functions
357 public class Xcls_sourceview : Object
359 public Gtk.SourceView el;
360 private Xcls_GtkView _this;
367 public Xcls_sourceview(Xcls_GtkView _owner )
370 _this.sourceview = this;
371 this.el = new Gtk.SourceView();
376 // set gobject values
377 this.el.editable = false;
378 this.el.show_line_marks = true;
379 this.el.show_line_numbers = true;
385 var description = Pango.FontDescription.from_string("monospace");
386 description.set_size(8000);
387 this.el.override_font(description);
390 var buf = this.el.get_buffer();
391 buf.notify.connect((ps) => {
395 if (ps.name != "cursor-position") {
398 print("cursor changed : %d\n", buf.cursor_position);
400 buf.get_iter_at_offset(out cpos, buf.cursor_position);
402 var ln = cpos.get_line();
404 var node = _this.file.lineToNode(ln);
406 print("can not find node\n");
409 var ltree = _this.main_window.windowstate.left_tree;
410 var tp = ltree.model.treePathFromNode(node);
411 print("got tree path %s\n", tp);
413 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
416 // highlight the node..
422 var attrs = new Gtk.SourceMarkAttributes();
423 var pink = Gdk.RGBA();
424 pink.parse ( "pink");
425 attrs.set_background ( pink);
426 attrs.set_icon_name ( "process-stop");
427 attrs.query_tooltip_text.connect(( mark) => {
428 //print("tooltip query? %s\n", mark.name);
432 this.el.set_mark_attributes ("ERR", attrs, 1);
434 var wattrs = new Gtk.SourceMarkAttributes();
435 var blue = Gdk.RGBA();
436 blue.parse ( "#ABF4EB");
437 wattrs.set_background ( blue);
438 wattrs.set_icon_name ( "process-stop");
439 wattrs.query_tooltip_text.connect(( mark) => {
440 //print("tooltip query? %s\n", mark.name);
444 this.el.set_mark_attributes ("WARN", wattrs, 1);
448 var dattrs = new Gtk.SourceMarkAttributes();
449 var purple = Gdk.RGBA();
450 purple.parse ( "#EEA9FF");
451 dattrs.set_background ( purple);
452 dattrs.set_icon_name ( "process-stop");
453 dattrs.query_tooltip_text.connect(( mark) => {
454 //print("tooltip query? %s\n", mark.name);
458 this.el.set_mark_attributes ("DEPR", dattrs, 1);
461 var gattrs = new Gtk.SourceMarkAttributes();
462 var grey = Gdk.RGBA();
463 grey.parse ( "#ccc");
464 gattrs.set_background ( grey);
467 this.el.set_mark_attributes ("grey", gattrs, 1);
477 // user defined functions
478 public void nodeSelected (JsRender.Node? sel) {
482 // this is connected in widnowstate
483 print("node selected");
484 var buf = this.el.get_buffer();
486 var sbuf = (Gtk.SourceBuffer) buf;
489 while(Gtk.events_pending()) {
490 Gtk.main_iteration();
494 // clear all the marks..
498 sbuf.get_bounds (out start, out end);
499 sbuf.remove_source_marks (start, end, "grey");
507 sbuf.get_iter_at_line(out iter, sel.line_start);
508 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
510 for (var i = 0; i < buf.get_line_count();i++) {
511 if (i < sel.line_start || i > sel.line_end) {
513 sbuf.get_iter_at_line(out iter, i);
514 sbuf.create_source_mark(null, "grey", iter);
522 public string toString () {
525 public void loadFile ( ) {
527 var buf = this.el.get_buffer();
529 var sbuf = (Gtk.SourceBuffer) buf;
533 if (_this.file == null || _this.file.xtype != "Gtk") {
534 print("xtype != Gtk");
535 this.loading = false;
541 var regex = new Regex("\\.bjs$");
544 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
545 } catch (GLib.RegexError e) {
546 this.loading = false;
551 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
552 print("File path has no errors\n");
553 this.loading = false;
560 GLib.FileUtils.get_contents (valafn, out str);
562 this.loading = false;
566 // print("setting str %d\n", str.length);
567 buf.set_text(str, str.length);
568 var lm = Gtk.SourceLanguageManager.get_default();
570 //?? is javascript going to work as js?
572 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
578 sbuf.get_bounds (out start, out end);
579 sbuf.remove_source_marks (start, end, null); // remove all marks..
582 if (_this.main_window.windowstate.last_compile_result != null) {
583 var obj = _this.main_window.windowstate.last_compile_result;
584 this.highlightErrorsJson("ERR", obj);
585 this.highlightErrorsJson("WARN", obj);
586 this.highlightErrorsJson("DEPR", obj);
588 //while (Gtk.events_pending()) {
589 // Gtk.main_iteration();
592 this.loading = false;
594 public void highlightErrorsJson (string type, Json.Object obj) {
598 var buf = this.el.get_buffer();
599 var sbuf = (Gtk.SourceBuffer)buf;
600 buf.get_bounds (out start, out end);
602 sbuf.remove_source_marks (start, end, type);
605 // we should highlight other types of errors..
607 if (!obj.has_member(type)) {
608 print("Return has no errors\n");
611 var err = obj.get_object_member(type);
613 if (_this.file == null) {
614 return; // just in case the file has not loaded yet?
620 var regex = new Regex("\\.bjs$");
623 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
624 } catch (GLib.RegexError e) {
628 if (!err.has_member(valafn)) {
629 print("File path has no errors\n");
632 var lines = err.get_object_member(valafn);
636 var tlines = buf.get_line_count () +1;
638 lines.foreach_member((obj, line, node) => {
641 // print("get inter\n");
642 var eline = int.parse(line) -1 ;
643 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
646 if (eline > tlines || eline < 0) {
649 sbuf.get_iter_at_line( out iter, eline);
650 //print("mark line\n");
651 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
652 var ar = lines.get_array_member(line);
653 for (var i = 0 ; i < ar.get_length(); i++) {
654 msg += (msg.length > 0) ? "\n" : "";
655 msg += ar.get_string_element(i);
659 sbuf.create_source_mark(msg, type, iter);