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);
182 Gtk.TextIter beg, st,en;
185 buf.get_start_iter(out beg);
186 this.searchcontext.forward(beg, out st, out en);
188 return this.searchcontext.get_occurrences_count();
192 public class Xcls_notebook : Object
194 public Gtk.Notebook el;
195 private Xcls_GtkView _this;
201 public Xcls_notebook(Xcls_GtkView _owner )
204 _this.notebook = this;
205 this.el = new Gtk.Notebook();
209 // set gobject values
210 var child_0 = new Xcls_label_preview( _this );
212 var child_1 = new Xcls_label_code( _this );
214 var child_2 = new Xcls_ScrolledWindow5( _this );
216 this.el.append_page ( child_2.el , _this.label_preview.el );
217 var child_3 = new Xcls_ScrolledWindow8( _this );
219 this.el.append_page ( child_3.el , _this.label_code.el );
222 // user defined functions
224 public class Xcls_label_preview : Object
227 private Xcls_GtkView _this;
233 public Xcls_label_preview(Xcls_GtkView _owner )
236 _this.label_preview = this;
237 this.el = new Gtk.Label( "Preview" );
241 // set gobject values
244 // user defined functions
247 public class Xcls_label_code : Object
250 private Xcls_GtkView _this;
256 public Xcls_label_code(Xcls_GtkView _owner )
259 _this.label_code = this;
260 this.el = new Gtk.Label( "Preview Generated Code" );
264 // set gobject values
267 // user defined functions
270 public class Xcls_ScrolledWindow5 : Object
272 public Gtk.ScrolledWindow el;
273 private Xcls_GtkView _this;
279 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
282 this.el = new Gtk.ScrolledWindow( null, null );
286 // set gobject values
287 var child_0 = new Xcls_view_layout( _this );
289 this.el.add ( child_0.el );
292 // user defined functions
294 public class Xcls_view_layout : Object
296 public Gtk.Layout el;
297 private Xcls_GtkView _this;
303 public Xcls_view_layout(Xcls_GtkView _owner )
306 _this.view_layout = this;
307 this.el = new Gtk.Layout( null, null );
311 // set gobject values
312 var child_0 = new Xcls_container( _this );
314 this.el.put ( child_0.el , 10,10 );
317 // user defined functions
319 public class Xcls_container : Object
322 private Xcls_GtkView _this;
328 public Xcls_container(Xcls_GtkView _owner )
331 _this.container = this;
332 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
336 // set gobject values
339 // user defined functions
344 public class Xcls_ScrolledWindow8 : Object
346 public Gtk.ScrolledWindow el;
347 private Xcls_GtkView _this;
353 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
356 this.el = new Gtk.ScrolledWindow( null, null );
360 // set gobject values
361 var child_0 = new Xcls_sourceview( _this );
363 this.el.add ( child_0.el );
366 // user defined functions
368 public class Xcls_sourceview : Object
370 public Gtk.SourceView el;
371 private Xcls_GtkView _this;
378 public Xcls_sourceview(Xcls_GtkView _owner )
381 _this.sourceview = this;
382 this.el = new Gtk.SourceView();
387 // set gobject values
388 this.el.editable = false;
389 this.el.show_line_marks = true;
390 this.el.show_line_numbers = true;
396 var description = Pango.FontDescription.from_string("monospace");
397 description.set_size(8000);
398 this.el.override_font(description);
401 var buf = this.el.get_buffer();
402 buf.notify.connect((ps) => {
406 if (ps.name != "cursor-position") {
409 print("cursor changed : %d\n", buf.cursor_position);
411 buf.get_iter_at_offset(out cpos, buf.cursor_position);
413 var ln = cpos.get_line();
415 var node = _this.file.lineToNode(ln);
417 print("can not find node\n");
420 var ltree = _this.main_window.windowstate.left_tree;
421 var tp = ltree.model.treePathFromNode(node);
422 print("got tree path %s\n", tp);
424 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
427 // highlight the node..
433 var attrs = new Gtk.SourceMarkAttributes();
434 var pink = Gdk.RGBA();
435 pink.parse ( "pink");
436 attrs.set_background ( pink);
437 attrs.set_icon_name ( "process-stop");
438 attrs.query_tooltip_text.connect(( mark) => {
439 //print("tooltip query? %s\n", mark.name);
443 this.el.set_mark_attributes ("ERR", attrs, 1);
445 var wattrs = new Gtk.SourceMarkAttributes();
446 var blue = Gdk.RGBA();
447 blue.parse ( "#ABF4EB");
448 wattrs.set_background ( blue);
449 wattrs.set_icon_name ( "process-stop");
450 wattrs.query_tooltip_text.connect(( mark) => {
451 //print("tooltip query? %s\n", mark.name);
455 this.el.set_mark_attributes ("WARN", wattrs, 1);
459 var dattrs = new Gtk.SourceMarkAttributes();
460 var purple = Gdk.RGBA();
461 purple.parse ( "#EEA9FF");
462 dattrs.set_background ( purple);
463 dattrs.set_icon_name ( "process-stop");
464 dattrs.query_tooltip_text.connect(( mark) => {
465 //print("tooltip query? %s\n", mark.name);
469 this.el.set_mark_attributes ("DEPR", dattrs, 1);
472 var gattrs = new Gtk.SourceMarkAttributes();
473 var grey = Gdk.RGBA();
474 grey.parse ( "#ccc");
475 gattrs.set_background ( grey);
478 this.el.set_mark_attributes ("grey", gattrs, 1);
488 // user defined functions
489 public void nodeSelected (JsRender.Node? sel) {
493 // this is connected in widnowstate
494 print("node selected");
495 var buf = this.el.get_buffer();
497 var sbuf = (Gtk.SourceBuffer) buf;
500 while(Gtk.events_pending()) {
501 Gtk.main_iteration();
505 // clear all the marks..
509 sbuf.get_bounds (out start, out end);
510 sbuf.remove_source_marks (start, end, "grey");
518 sbuf.get_iter_at_line(out iter, sel.line_start);
519 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
521 for (var i = 0; i < buf.get_line_count();i++) {
522 if (i < sel.line_start || i > sel.line_end) {
524 sbuf.get_iter_at_line(out iter, i);
525 sbuf.create_source_mark(null, "grey", iter);
533 public string toString () {
536 this.el.get_buffer().get_start_iter(out s);
537 this.el.get_buffer().get_end_iter(out e);
538 var ret = this.el.get_buffer().get_text(s,e,true);
539 //print("TO STRING? " + ret);
542 public void loadFile ( ) {
544 var buf = this.el.get_buffer();
546 var sbuf = (Gtk.SourceBuffer) buf;
550 if (_this.file == null || _this.file.xtype != "Gtk") {
551 print("xtype != Gtk");
552 this.loading = false;
558 var regex = new Regex("\\.bjs$");
561 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
562 } catch (GLib.RegexError e) {
563 this.loading = false;
568 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
569 print("File path has no errors\n");
570 this.loading = false;
577 GLib.FileUtils.get_contents (valafn, out str);
579 this.loading = false;
583 // print("setting str %d\n", str.length);
584 buf.set_text(str, str.length);
585 var lm = Gtk.SourceLanguageManager.get_default();
587 //?? is javascript going to work as js?
589 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
595 sbuf.get_bounds (out start, out end);
596 sbuf.remove_source_marks (start, end, null); // remove all marks..
599 if (_this.main_window.windowstate.last_compile_result != null) {
600 var obj = _this.main_window.windowstate.last_compile_result;
601 this.highlightErrorsJson("ERR", obj);
602 this.highlightErrorsJson("WARN", obj);
603 this.highlightErrorsJson("DEPR", obj);
605 //while (Gtk.events_pending()) {
606 // Gtk.main_iteration();
609 this.loading = false;
611 public void highlightErrorsJson (string type, Json.Object obj) {
615 var buf = this.el.get_buffer();
616 var sbuf = (Gtk.SourceBuffer)buf;
617 buf.get_bounds (out start, out end);
619 sbuf.remove_source_marks (start, end, type);
622 // we should highlight other types of errors..
624 if (!obj.has_member(type)) {
625 print("Return has no errors\n");
628 var err = obj.get_object_member(type);
630 if (_this.file == null) {
631 return; // just in case the file has not loaded yet?
637 var regex = new Regex("\\.bjs$");
640 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
641 } catch (GLib.RegexError e) {
645 if (!err.has_member(valafn)) {
646 print("File path has no errors\n");
649 var lines = err.get_object_member(valafn);
653 var tlines = buf.get_line_count () +1;
655 lines.foreach_member((obj, line, node) => {
658 // print("get inter\n");
659 var eline = int.parse(line) -1 ;
660 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
663 if (eline > tlines || eline < 0) {
666 sbuf.get_iter_at_line( out iter, eline);
667 //print("mark line\n");
668 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
669 var ar = lines.get_array_member(line);
670 for (var i = 0 ; i < ar.get_length(); i++) {
671 msg += (msg.length > 0) ? "\n" : "";
672 msg += ar.get_string_element(i);
676 sbuf.create_source_mark(msg, type, iter);