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 Gtk.SourceSearchContext searchcontext;
26 public JsRender.JsRender file;
28 public Xcls_MainWindow main_window;
34 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
43 this.el.hexpand = true;
44 var child_0 = new Xcls_notebook( _this );
46 this.el.pack_start ( child_0.el , true,true,0 );
49 this.el.size_allocate.connect( (aloc) => {
51 this.width = aloc.width;
52 this.height =aloc.height;
56 // user defined functions
57 public void scroll_to_line (int line) {
58 this.notebook.el.page = 1;// code preview...
60 GLib.Timeout.add(500, () => {
65 var buf = this.sourceview.el.get_buffer();
67 var sbuf = (Gtk.SourceBuffer) buf;
71 sbuf.get_iter_at_line(out iter, line);
72 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
78 public void createThumb () {
81 if (this.file == null) {
84 // only screenshot the gtk preview..
85 if (this.notebook.el.page > 0 ) {
90 var filename = this.file.getIconFileName(false);
92 var win = this.el.get_parent_window();
93 var width = win.get_width();
94 var height = win.get_height();
96 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
97 screenshot.save(filename,"png");
109 // should we hold until it's printed...
120 public void loadFile (JsRender.JsRender file)
124 if (file.tree == null) {
127 this.notebook.el.page = 0;// gtk preview
132 this.sourceview.loadFile();
136 if (this.lastObj != null) {
137 this.container.el.remove(this.lastObj);
140 // hide the compile view at present..
146 print("ALLOC SET SIZES %d, %d\n", w,h);
148 // set the container size min to 500/500 or 20 px less than max..
149 w = int.max (w-20, 500);
150 h = int.max (h-20, 500);
152 print("SET SIZES %d, %d\n", w,h);
153 _this.container.el.set_size_request(w,h);
155 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
156 var rgba = Gdk.RGBA ();
158 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
161 var x = new JsRender.NodeToGtk(file.tree);
162 var obj = x.munge() as Gtk.Widget;
169 this.container.el.add(obj);
175 public int search (string txt) {
176 var s = new Gtk.SourceSearchSettings();
177 var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
178 this.searchcontext = new Gtk.SourceSearchContext(buf,s);
179 this.searchcontext.set_highlight(true);
180 s.set_search_text(txt);
181 return this.searchcontext.get_occurrences_count();
185 public class Xcls_notebook : Object
187 public Gtk.Notebook el;
188 private Xcls_GtkView _this;
194 public Xcls_notebook(Xcls_GtkView _owner )
197 _this.notebook = this;
198 this.el = new Gtk.Notebook();
202 // set gobject values
203 var child_0 = new Xcls_label_preview( _this );
205 var child_1 = new Xcls_label_code( _this );
207 var child_2 = new Xcls_ScrolledWindow5( _this );
209 this.el.append_page ( child_2.el , _this.label_preview.el );
210 var child_3 = new Xcls_ScrolledWindow8( _this );
212 this.el.append_page ( child_3.el , _this.label_code.el );
215 // user defined functions
217 public class Xcls_label_preview : Object
220 private Xcls_GtkView _this;
226 public Xcls_label_preview(Xcls_GtkView _owner )
229 _this.label_preview = this;
230 this.el = new Gtk.Label( "Preview" );
234 // set gobject values
237 // user defined functions
240 public class Xcls_label_code : Object
243 private Xcls_GtkView _this;
249 public Xcls_label_code(Xcls_GtkView _owner )
252 _this.label_code = this;
253 this.el = new Gtk.Label( "Preview Generated Code" );
257 // set gobject values
260 // user defined functions
263 public class Xcls_ScrolledWindow5 : Object
265 public Gtk.ScrolledWindow el;
266 private Xcls_GtkView _this;
272 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
275 this.el = new Gtk.ScrolledWindow( null, null );
279 // set gobject values
280 var child_0 = new Xcls_view_layout( _this );
282 this.el.add ( child_0.el );
285 // user defined functions
287 public class Xcls_view_layout : Object
289 public Gtk.Layout el;
290 private Xcls_GtkView _this;
296 public Xcls_view_layout(Xcls_GtkView _owner )
299 _this.view_layout = this;
300 this.el = new Gtk.Layout( null, null );
304 // set gobject values
305 var child_0 = new Xcls_container( _this );
307 this.el.put ( child_0.el , 10,10 );
310 // user defined functions
312 public class Xcls_container : Object
315 private Xcls_GtkView _this;
321 public Xcls_container(Xcls_GtkView _owner )
324 _this.container = this;
325 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
329 // set gobject values
332 // user defined functions
337 public class Xcls_ScrolledWindow8 : Object
339 public Gtk.ScrolledWindow el;
340 private Xcls_GtkView _this;
346 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
349 this.el = new Gtk.ScrolledWindow( null, null );
353 // set gobject values
354 var child_0 = new Xcls_sourceview( _this );
356 this.el.add ( child_0.el );
359 // user defined functions
361 public class Xcls_sourceview : Object
363 public Gtk.SourceView el;
364 private Xcls_GtkView _this;
371 public Xcls_sourceview(Xcls_GtkView _owner )
374 _this.sourceview = this;
375 this.el = new Gtk.SourceView();
380 // set gobject values
381 this.el.editable = false;
382 this.el.show_line_marks = true;
383 this.el.show_line_numbers = true;
389 var description = Pango.FontDescription.from_string("monospace");
390 description.set_size(8000);
391 this.el.override_font(description);
394 var buf = this.el.get_buffer();
395 buf.notify.connect((ps) => {
399 if (ps.name != "cursor-position") {
402 print("cursor changed : %d\n", buf.cursor_position);
404 buf.get_iter_at_offset(out cpos, buf.cursor_position);
406 var ln = cpos.get_line();
408 var node = _this.file.lineToNode(ln);
410 print("can not find node\n");
413 var ltree = _this.main_window.windowstate.left_tree;
414 var tp = ltree.model.treePathFromNode(node);
415 print("got tree path %s\n", tp);
417 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
420 // highlight the node..
426 var attrs = new Gtk.SourceMarkAttributes();
427 var pink = Gdk.RGBA();
428 pink.parse ( "pink");
429 attrs.set_background ( pink);
430 attrs.set_icon_name ( "process-stop");
431 attrs.query_tooltip_text.connect(( mark) => {
432 //print("tooltip query? %s\n", mark.name);
436 this.el.set_mark_attributes ("ERR", attrs, 1);
438 var wattrs = new Gtk.SourceMarkAttributes();
439 var blue = Gdk.RGBA();
440 blue.parse ( "#ABF4EB");
441 wattrs.set_background ( blue);
442 wattrs.set_icon_name ( "process-stop");
443 wattrs.query_tooltip_text.connect(( mark) => {
444 //print("tooltip query? %s\n", mark.name);
448 this.el.set_mark_attributes ("WARN", wattrs, 1);
452 var dattrs = new Gtk.SourceMarkAttributes();
453 var purple = Gdk.RGBA();
454 purple.parse ( "#EEA9FF");
455 dattrs.set_background ( purple);
456 dattrs.set_icon_name ( "process-stop");
457 dattrs.query_tooltip_text.connect(( mark) => {
458 //print("tooltip query? %s\n", mark.name);
462 this.el.set_mark_attributes ("DEPR", dattrs, 1);
465 var gattrs = new Gtk.SourceMarkAttributes();
466 var grey = Gdk.RGBA();
467 grey.parse ( "#ccc");
468 gattrs.set_background ( grey);
471 this.el.set_mark_attributes ("grey", gattrs, 1);
481 // user defined functions
482 public void nodeSelected (JsRender.Node? sel) {
486 // this is connected in widnowstate
487 print("node selected");
488 var buf = this.el.get_buffer();
490 var sbuf = (Gtk.SourceBuffer) buf;
493 while(Gtk.events_pending()) {
494 Gtk.main_iteration();
498 // clear all the marks..
502 sbuf.get_bounds (out start, out end);
503 sbuf.remove_source_marks (start, end, "grey");
511 sbuf.get_iter_at_line(out iter, sel.line_start);
512 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
514 for (var i = 0; i < buf.get_line_count();i++) {
515 if (i < sel.line_start || i > sel.line_end) {
517 sbuf.get_iter_at_line(out iter, i);
518 sbuf.create_source_mark(null, "grey", iter);
526 public string toString () {
529 this.el.get_buffer().get_start_iter(out s);
530 this.el.get_buffer().get_end_iter(out e);
531 var ret = this.el.get_buffer().get_text(s,e,true);
532 //print("TO STRING? " + ret);
535 public void loadFile ( ) {
537 var buf = this.el.get_buffer();
539 var sbuf = (Gtk.SourceBuffer) buf;
543 if (_this.file == null || _this.file.xtype != "Gtk") {
544 print("xtype != Gtk");
545 this.loading = false;
551 var regex = new Regex("\\.bjs$");
554 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
555 } catch (GLib.RegexError e) {
556 this.loading = false;
561 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
562 print("File path has no errors\n");
563 this.loading = false;
570 GLib.FileUtils.get_contents (valafn, out str);
572 this.loading = false;
576 // print("setting str %d\n", str.length);
577 buf.set_text(str, str.length);
578 var lm = Gtk.SourceLanguageManager.get_default();
580 //?? is javascript going to work as js?
582 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
588 sbuf.get_bounds (out start, out end);
589 sbuf.remove_source_marks (start, end, null); // remove all marks..
592 if (_this.main_window.windowstate.last_compile_result != null) {
593 var obj = _this.main_window.windowstate.last_compile_result;
594 this.highlightErrorsJson("ERR", obj);
595 this.highlightErrorsJson("WARN", obj);
596 this.highlightErrorsJson("DEPR", obj);
598 //while (Gtk.events_pending()) {
599 // Gtk.main_iteration();
602 this.loading = false;
604 public void highlightErrorsJson (string type, Json.Object obj) {
608 var buf = this.el.get_buffer();
609 var sbuf = (Gtk.SourceBuffer)buf;
610 buf.get_bounds (out start, out end);
612 sbuf.remove_source_marks (start, end, type);
615 // we should highlight other types of errors..
617 if (!obj.has_member(type)) {
618 print("Return has no errors\n");
621 var err = obj.get_object_member(type);
623 if (_this.file == null) {
624 return; // just in case the file has not loaded yet?
630 var regex = new Regex("\\.bjs$");
633 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
634 } catch (GLib.RegexError e) {
638 if (!err.has_member(valafn)) {
639 print("File path has no errors\n");
642 var lines = err.get_object_member(valafn);
646 var tlines = buf.get_line_count () +1;
648 lines.foreach_member((obj, line, node) => {
651 // print("get inter\n");
652 var eline = int.parse(line) -1 ;
653 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
656 if (eline > tlines || eline < 0) {
659 sbuf.get_iter_at_line( out iter, eline);
660 //print("mark line\n");
661 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
662 var ar = lines.get_array_member(line);
663 for (var i = 0 ; i < ar.get_length(); i++) {
664 msg += (msg.length > 0) ? "\n" : "";
665 msg += ar.get_string_element(i);
669 sbuf.create_source_mark(msg, type, iter);