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 int last_search_end;
26 public Gtk.SourceSearchContext searchcontext;
27 public JsRender.JsRender file;
29 public Xcls_MainWindow main_window;
35 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
40 this.last_search_end = 0;
45 this.el.hexpand = true;
46 var child_0 = new Xcls_notebook( _this );
48 this.el.pack_start ( child_0.el , true,true,0 );
51 this.el.size_allocate.connect( (aloc) => {
53 this.width = aloc.width;
54 this.height =aloc.height;
58 // user defined functions
59 public void scroll_to_line (int line) {
60 this.notebook.el.page = 1;// code preview...
62 GLib.Timeout.add(500, () => {
67 var buf = this.sourceview.el.get_buffer();
69 var sbuf = (Gtk.SourceBuffer) buf;
73 sbuf.get_iter_at_line(out iter, line);
74 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
80 public void createThumb () {
83 if (this.file == null) {
86 // only screenshot the gtk preview..
87 if (this.notebook.el.page > 0 ) {
92 var filename = this.file.getIconFileName(false);
94 var win = this.el.get_parent_window();
95 var width = win.get_width();
96 var height = win.get_height();
98 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
99 screenshot.save(filename,"png");
111 // should we hold until it's printed...
122 public void loadFile (JsRender.JsRender file)
126 if (file.tree == null) {
129 this.notebook.el.page = 0;// gtk preview
134 this.sourceview.loadFile();
135 this.searchcontext = null;
138 if (this.lastObj != null) {
139 this.container.el.remove(this.lastObj);
142 // hide the compile view at present..
148 print("ALLOC SET SIZES %d, %d\n", w,h);
150 // set the container size min to 500/500 or 20 px less than max..
151 w = int.max (w-20, 500);
152 h = int.max (h-20, 500);
154 print("SET SIZES %d, %d\n", w,h);
155 _this.container.el.set_size_request(w,h);
157 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
158 var rgba = Gdk.RGBA ();
160 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
163 var x = new JsRender.NodeToGtk(file.tree);
164 var obj = x.munge() as Gtk.Widget;
171 this.container.el.add(obj);
177 public int search (string txt) {
178 var s = new Gtk.SourceSearchSettings();
179 var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
180 this.searchcontext = new Gtk.SourceSearchContext(buf,s);
181 this.searchcontext.set_highlight(true);
182 s.set_search_text(txt);
184 Gtk.TextIter beg, st,en;
186 buf.get_start_iter(out beg);
187 this.searchcontext.forward(beg, out st, out en);
188 this.last_search_end = 0;
189 return this.searchcontext.get_occurrences_count();
193 public void forwardSearch () {
195 if (this.searchcontext == null) {
199 Gtk.TextIter beg, st,en;
201 var buf = this.sourceview.el.get_buffer();
202 buf.get_iter_at_offset(out beg, this.last_search_end);
203 if (!this.searchcontext.forward(beg, out st, out en)) {
204 this.last_search_end = 0;
206 this.last_search_end = en.get_offset();
208 this.sourceview.el.grab_focus();
209 buf.place_cursor(st);
210 this.sourceview.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
214 public class Xcls_notebook : Object
216 public Gtk.Notebook el;
217 private Xcls_GtkView _this;
223 public Xcls_notebook(Xcls_GtkView _owner )
226 _this.notebook = this;
227 this.el = new Gtk.Notebook();
231 // set gobject values
232 var child_0 = new Xcls_label_preview( _this );
234 var child_1 = new Xcls_label_code( _this );
236 var child_2 = new Xcls_ScrolledWindow5( _this );
238 this.el.append_page ( child_2.el , _this.label_preview.el );
239 var child_3 = new Xcls_ScrolledWindow8( _this );
241 this.el.append_page ( child_3.el , _this.label_code.el );
244 // user defined functions
246 public class Xcls_label_preview : Object
249 private Xcls_GtkView _this;
255 public Xcls_label_preview(Xcls_GtkView _owner )
258 _this.label_preview = this;
259 this.el = new Gtk.Label( "Preview" );
263 // set gobject values
266 // user defined functions
269 public class Xcls_label_code : Object
272 private Xcls_GtkView _this;
278 public Xcls_label_code(Xcls_GtkView _owner )
281 _this.label_code = this;
282 this.el = new Gtk.Label( "Preview Generated Code" );
286 // set gobject values
289 // user defined functions
292 public class Xcls_ScrolledWindow5 : Object
294 public Gtk.ScrolledWindow el;
295 private Xcls_GtkView _this;
301 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
304 this.el = new Gtk.ScrolledWindow( null, null );
308 // set gobject values
309 var child_0 = new Xcls_view_layout( _this );
311 this.el.add ( child_0.el );
314 // user defined functions
316 public class Xcls_view_layout : Object
318 public Gtk.Layout el;
319 private Xcls_GtkView _this;
325 public Xcls_view_layout(Xcls_GtkView _owner )
328 _this.view_layout = this;
329 this.el = new Gtk.Layout( null, null );
333 // set gobject values
334 var child_0 = new Xcls_container( _this );
336 this.el.put ( child_0.el , 10,10 );
339 // user defined functions
341 public class Xcls_container : Object
344 private Xcls_GtkView _this;
350 public Xcls_container(Xcls_GtkView _owner )
353 _this.container = this;
354 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
358 // set gobject values
361 // user defined functions
366 public class Xcls_ScrolledWindow8 : Object
368 public Gtk.ScrolledWindow el;
369 private Xcls_GtkView _this;
375 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
378 this.el = new Gtk.ScrolledWindow( null, null );
382 // set gobject values
383 var child_0 = new Xcls_sourceview( _this );
385 this.el.add ( child_0.el );
388 // user defined functions
390 public class Xcls_sourceview : Object
392 public Gtk.SourceView el;
393 private Xcls_GtkView _this;
398 public bool allow_node_scroll;
401 public Xcls_sourceview(Xcls_GtkView _owner )
404 _this.sourceview = this;
405 this.el = new Gtk.SourceView();
409 this.allow_node_scroll = true;
411 // set gobject values
412 this.el.editable = false;
413 this.el.show_line_marks = true;
414 this.el.show_line_numbers = true;
420 var description = Pango.FontDescription.from_string("monospace");
421 description.set_size(8000);
422 this.el.override_font(description);
425 var buf = this.el.get_buffer();
426 buf.notify.connect((ps) => {
430 if (ps.name != "cursor-position") {
433 print("cursor changed : %d\n", buf.cursor_position);
435 buf.get_iter_at_offset(out cpos, buf.cursor_position);
437 var ln = cpos.get_line();
439 var node = _this.file.lineToNode(ln);
441 print("can not find node\n");
444 var ltree = _this.main_window.windowstate.left_tree;
445 var tp = ltree.model.treePathFromNode(node);
446 print("got tree path %s\n", tp);
448 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
451 // highlight the node..
457 var attrs = new Gtk.SourceMarkAttributes();
458 var pink = Gdk.RGBA();
459 pink.parse ( "pink");
460 attrs.set_background ( pink);
461 attrs.set_icon_name ( "process-stop");
462 attrs.query_tooltip_text.connect(( mark) => {
463 //print("tooltip query? %s\n", mark.name);
467 this.el.set_mark_attributes ("ERR", attrs, 1);
469 var wattrs = new Gtk.SourceMarkAttributes();
470 var blue = Gdk.RGBA();
471 blue.parse ( "#ABF4EB");
472 wattrs.set_background ( blue);
473 wattrs.set_icon_name ( "process-stop");
474 wattrs.query_tooltip_text.connect(( mark) => {
475 //print("tooltip query? %s\n", mark.name);
479 this.el.set_mark_attributes ("WARN", wattrs, 1);
483 var dattrs = new Gtk.SourceMarkAttributes();
484 var purple = Gdk.RGBA();
485 purple.parse ( "#EEA9FF");
486 dattrs.set_background ( purple);
487 dattrs.set_icon_name ( "process-stop");
488 dattrs.query_tooltip_text.connect(( mark) => {
489 //print("tooltip query? %s\n", mark.name);
493 this.el.set_mark_attributes ("DEPR", dattrs, 1);
496 var gattrs = new Gtk.SourceMarkAttributes();
497 var grey = Gdk.RGBA();
498 grey.parse ( "#ccc");
499 gattrs.set_background ( grey);
502 this.el.set_mark_attributes ("grey", gattrs, 1);
512 // user defined functions
513 public void nodeSelected (JsRender.Node? sel) {
517 // this is connected in widnowstate
518 print("node selected");
519 var buf = this.el.get_buffer();
521 var sbuf = (Gtk.SourceBuffer) buf;
524 while(Gtk.events_pending()) {
525 Gtk.main_iteration();
529 // clear all the marks..
533 sbuf.get_bounds (out start, out end);
534 sbuf.remove_source_marks (start, end, "grey");
542 sbuf.get_iter_at_line(out iter, sel.line_start);
543 if (this.allow_node_scroll) {
545 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
548 for (var i = 0; i < buf.get_line_count();i++) {
549 if (i < sel.line_start || i > sel.line_end) {
551 sbuf.get_iter_at_line(out iter, i);
552 sbuf.create_source_mark(null, "grey", iter);
560 public string toString () {
563 this.el.get_buffer().get_start_iter(out s);
564 this.el.get_buffer().get_end_iter(out e);
565 var ret = this.el.get_buffer().get_text(s,e,true);
566 //print("TO STRING? " + ret);
569 public void loadFile ( ) {
571 var buf = this.el.get_buffer();
573 var sbuf = (Gtk.SourceBuffer) buf;
577 if (_this.file == null || _this.file.xtype != "Gtk") {
578 print("xtype != Gtk");
579 this.loading = false;
585 var regex = new Regex("\\.bjs$");
588 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
589 } catch (GLib.RegexError e) {
590 this.loading = false;
595 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
596 print("File path has no errors\n");
597 this.loading = false;
604 GLib.FileUtils.get_contents (valafn, out str);
606 this.loading = false;
610 // print("setting str %d\n", str.length);
611 buf.set_text(str, str.length);
612 var lm = Gtk.SourceLanguageManager.get_default();
614 //?? is javascript going to work as js?
616 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
622 sbuf.get_bounds (out start, out end);
623 sbuf.remove_source_marks (start, end, null); // remove all marks..
626 if (_this.main_window.windowstate.last_compile_result != null) {
627 var obj = _this.main_window.windowstate.last_compile_result;
628 this.highlightErrorsJson("ERR", obj);
629 this.highlightErrorsJson("WARN", obj);
630 this.highlightErrorsJson("DEPR", obj);
632 //while (Gtk.events_pending()) {
633 // Gtk.main_iteration();
636 this.loading = false;
638 public void highlightErrorsJson (string type, Json.Object obj) {
642 var buf = this.el.get_buffer();
643 var sbuf = (Gtk.SourceBuffer)buf;
644 buf.get_bounds (out start, out end);
646 sbuf.remove_source_marks (start, end, type);
649 // we should highlight other types of errors..
651 if (!obj.has_member(type)) {
652 print("Return has no errors\n");
655 var err = obj.get_object_member(type);
657 if (_this.file == null) {
658 return; // just in case the file has not loaded yet?
664 var regex = new Regex("\\.bjs$");
667 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
668 } catch (GLib.RegexError e) {
672 if (!err.has_member(valafn)) {
673 print("File path has no errors\n");
676 var lines = err.get_object_member(valafn);
680 var tlines = buf.get_line_count () +1;
682 lines.foreach_member((obj, line, node) => {
685 // print("get inter\n");
686 var eline = int.parse(line) -1 ;
687 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
690 if (eline > tlines || eline < 0) {
693 sbuf.get_iter_at_line( out iter, eline);
694 //print("mark line\n");
695 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
696 var ar = lines.get_array_member(line);
697 for (var i = 0 ; i < ar.get_length(); i++) {
698 msg += (msg.length > 0) ? "\n" : "";
699 msg += ar.get_string_element(i);
703 sbuf.create_source_mark(msg, type, iter);