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) {
57 this.notebook.el.page = 1;// code preview...
59 GLib.Timeout.add(500, () => {
64 var buf = this.sourceview.el.get_buffer();
66 var sbuf = (Gtk.SourceBuffer) buf;
70 sbuf.get_iter_at_line(out iter, line);
71 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
77 public void createThumb () {
80 if (this.file == null) {
83 // only screenshot the gtk preview..
84 if (this.notebook.el.page > 0 ) {
89 var filename = this.file.getIconFileName(false);
91 var win = this.el.get_parent_window();
92 var width = win.get_width();
93 var height = win.get_height();
95 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
96 screenshot.save(filename,"png");
108 // should we hold until it's printed...
119 public void loadFile (JsRender.JsRender file)
123 if (file.tree == null) {
126 this.notebook.el.page = 0;// gtk preview
131 this.sourceview.loadFile();
135 if (this.lastObj != null) {
136 this.container.el.remove(this.lastObj);
139 // hide the compile view at present..
145 print("ALLOC SET SIZES %d, %d\n", w,h);
147 // set the container size min to 500/500 or 20 px less than max..
148 w = int.max (w-20, 500);
149 h = int.max (h-20, 500);
151 print("SET SIZES %d, %d\n", w,h);
152 _this.container.el.set_size_request(w,h);
154 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
155 var rgba = Gdk.RGBA ();
157 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
160 var x = new JsRender.NodeToGtk(file.tree);
161 var obj = x.munge() as Gtk.Widget;
168 this.container.el.add(obj);
174 public int search (string txt) {
175 var s = new Gtk.SourceSearchSettings();
176 var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
177 this.sourcecontext = new Gtk.SourceSearchContext(buf,s);
178 sctx.set_highlight(true);
179 s.set_search_text(txt);
180 return this.sourcecontext.get_occurences_count();
184 public class Xcls_notebook : Object
186 public Gtk.Notebook el;
187 private Xcls_GtkView _this;
193 public Xcls_notebook(Xcls_GtkView _owner )
196 _this.notebook = this;
197 this.el = new Gtk.Notebook();
201 // set gobject values
202 var child_0 = new Xcls_label_preview( _this );
204 var child_1 = new Xcls_label_code( _this );
206 var child_2 = new Xcls_ScrolledWindow5( _this );
208 this.el.append_page ( child_2.el , _this.label_preview.el );
209 var child_3 = new Xcls_ScrolledWindow8( _this );
211 this.el.append_page ( child_3.el , _this.label_code.el );
214 // user defined functions
216 public class Xcls_label_preview : Object
219 private Xcls_GtkView _this;
225 public Xcls_label_preview(Xcls_GtkView _owner )
228 _this.label_preview = this;
229 this.el = new Gtk.Label( "Preview" );
233 // set gobject values
236 // user defined functions
239 public class Xcls_label_code : Object
242 private Xcls_GtkView _this;
248 public Xcls_label_code(Xcls_GtkView _owner )
251 _this.label_code = this;
252 this.el = new Gtk.Label( "Preview Generated Code" );
256 // set gobject values
259 // user defined functions
262 public class Xcls_ScrolledWindow5 : Object
264 public Gtk.ScrolledWindow el;
265 private Xcls_GtkView _this;
271 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
274 this.el = new Gtk.ScrolledWindow( null, null );
278 // set gobject values
279 var child_0 = new Xcls_view_layout( _this );
281 this.el.add ( child_0.el );
284 // user defined functions
286 public class Xcls_view_layout : Object
288 public Gtk.Layout el;
289 private Xcls_GtkView _this;
295 public Xcls_view_layout(Xcls_GtkView _owner )
298 _this.view_layout = this;
299 this.el = new Gtk.Layout( null, null );
303 // set gobject values
304 var child_0 = new Xcls_container( _this );
306 this.el.put ( child_0.el , 10,10 );
309 // user defined functions
311 public class Xcls_container : Object
314 private Xcls_GtkView _this;
320 public Xcls_container(Xcls_GtkView _owner )
323 _this.container = this;
324 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
328 // set gobject values
331 // user defined functions
336 public class Xcls_ScrolledWindow8 : Object
338 public Gtk.ScrolledWindow el;
339 private Xcls_GtkView _this;
345 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
348 this.el = new Gtk.ScrolledWindow( null, null );
352 // set gobject values
353 var child_0 = new Xcls_sourceview( _this );
355 this.el.add ( child_0.el );
358 // user defined functions
360 public class Xcls_sourceview : Object
362 public Gtk.SourceView el;
363 private Xcls_GtkView _this;
370 public Xcls_sourceview(Xcls_GtkView _owner )
373 _this.sourceview = this;
374 this.el = new Gtk.SourceView();
379 // set gobject values
380 this.el.editable = false;
381 this.el.show_line_marks = true;
382 this.el.show_line_numbers = true;
388 var description = Pango.FontDescription.from_string("monospace");
389 description.set_size(8000);
390 this.el.override_font(description);
393 var buf = this.el.get_buffer();
394 buf.notify.connect((ps) => {
398 if (ps.name != "cursor-position") {
401 print("cursor changed : %d\n", buf.cursor_position);
403 buf.get_iter_at_offset(out cpos, buf.cursor_position);
405 var ln = cpos.get_line();
407 var node = _this.file.lineToNode(ln);
409 print("can not find node\n");
412 var ltree = _this.main_window.windowstate.left_tree;
413 var tp = ltree.model.treePathFromNode(node);
414 print("got tree path %s\n", tp);
416 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
419 // highlight the node..
425 var attrs = new Gtk.SourceMarkAttributes();
426 var pink = Gdk.RGBA();
427 pink.parse ( "pink");
428 attrs.set_background ( pink);
429 attrs.set_icon_name ( "process-stop");
430 attrs.query_tooltip_text.connect(( mark) => {
431 //print("tooltip query? %s\n", mark.name);
435 this.el.set_mark_attributes ("ERR", attrs, 1);
437 var wattrs = new Gtk.SourceMarkAttributes();
438 var blue = Gdk.RGBA();
439 blue.parse ( "#ABF4EB");
440 wattrs.set_background ( blue);
441 wattrs.set_icon_name ( "process-stop");
442 wattrs.query_tooltip_text.connect(( mark) => {
443 //print("tooltip query? %s\n", mark.name);
447 this.el.set_mark_attributes ("WARN", wattrs, 1);
451 var dattrs = new Gtk.SourceMarkAttributes();
452 var purple = Gdk.RGBA();
453 purple.parse ( "#EEA9FF");
454 dattrs.set_background ( purple);
455 dattrs.set_icon_name ( "process-stop");
456 dattrs.query_tooltip_text.connect(( mark) => {
457 //print("tooltip query? %s\n", mark.name);
461 this.el.set_mark_attributes ("DEPR", dattrs, 1);
464 var gattrs = new Gtk.SourceMarkAttributes();
465 var grey = Gdk.RGBA();
466 grey.parse ( "#ccc");
467 gattrs.set_background ( grey);
470 this.el.set_mark_attributes ("grey", gattrs, 1);
480 // user defined functions
481 public void nodeSelected (JsRender.Node? sel) {
485 // this is connected in widnowstate
486 print("node selected");
487 var buf = this.el.get_buffer();
489 var sbuf = (Gtk.SourceBuffer) buf;
492 while(Gtk.events_pending()) {
493 Gtk.main_iteration();
497 // clear all the marks..
501 sbuf.get_bounds (out start, out end);
502 sbuf.remove_source_marks (start, end, "grey");
510 sbuf.get_iter_at_line(out iter, sel.line_start);
511 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
513 for (var i = 0; i < buf.get_line_count();i++) {
514 if (i < sel.line_start || i > sel.line_end) {
516 sbuf.get_iter_at_line(out iter, i);
517 sbuf.create_source_mark(null, "grey", iter);
525 public string toString () {
528 this.el.get_buffer().get_start_iter(out s);
529 this.el.get_buffer().get_end_iter(out e);
530 var ret = this.el.get_buffer().get_text(s,e,true);
531 //print("TO STRING? " + ret);
534 public void loadFile ( ) {
536 var buf = this.el.get_buffer();
538 var sbuf = (Gtk.SourceBuffer) buf;
542 if (_this.file == null || _this.file.xtype != "Gtk") {
543 print("xtype != Gtk");
544 this.loading = false;
550 var regex = new Regex("\\.bjs$");
553 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
554 } catch (GLib.RegexError e) {
555 this.loading = false;
560 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
561 print("File path has no errors\n");
562 this.loading = false;
569 GLib.FileUtils.get_contents (valafn, out str);
571 this.loading = false;
575 // print("setting str %d\n", str.length);
576 buf.set_text(str, str.length);
577 var lm = Gtk.SourceLanguageManager.get_default();
579 //?? is javascript going to work as js?
581 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
587 sbuf.get_bounds (out start, out end);
588 sbuf.remove_source_marks (start, end, null); // remove all marks..
591 if (_this.main_window.windowstate.last_compile_result != null) {
592 var obj = _this.main_window.windowstate.last_compile_result;
593 this.highlightErrorsJson("ERR", obj);
594 this.highlightErrorsJson("WARN", obj);
595 this.highlightErrorsJson("DEPR", obj);
597 //while (Gtk.events_pending()) {
598 // Gtk.main_iteration();
601 this.loading = false;
603 public void highlightErrorsJson (string type, Json.Object obj) {
607 var buf = this.el.get_buffer();
608 var sbuf = (Gtk.SourceBuffer)buf;
609 buf.get_bounds (out start, out end);
611 sbuf.remove_source_marks (start, end, type);
614 // we should highlight other types of errors..
616 if (!obj.has_member(type)) {
617 print("Return has no errors\n");
620 var err = obj.get_object_member(type);
622 if (_this.file == null) {
623 return; // just in case the file has not loaded yet?
629 var regex = new Regex("\\.bjs$");
632 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
633 } catch (GLib.RegexError e) {
637 if (!err.has_member(valafn)) {
638 print("File path has no errors\n");
641 var lines = err.get_object_member(valafn);
645 var tlines = buf.get_line_count () +1;
647 lines.foreach_member((obj, line, node) => {
650 // print("get inter\n");
651 var eline = int.parse(line) -1 ;
652 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
655 if (eline > tlines || eline < 0) {
658 sbuf.get_iter_at_line( out iter, eline);
659 //print("mark line\n");
660 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
661 var ar = lines.get_array_member(line);
662 for (var i = 0 ; i < ar.get_length(); i++) {
663 msg += (msg.length > 0) ? "\n" : "";
664 msg += ar.get_string_element(i);
668 sbuf.create_source_mark(msg, type, iter);