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;
184 buf.get_start_iter(out beg);
185 this.searchcontext.forward(beg, out st, out en);
187 return this.searchcontext.get_occurrences_count();
191 public void forwardSearch () {
193 if (this.searchcontext == null) {
197 Gtk.TextIter beg, st,en;
199 var buf = this.sourceview.el.get_buffer();
200 buf.get_iter_at_offset(out beg, this.last_search_end);
201 this.searchcontext.forward(beg, out st, out en);
202 this.last_search_end = en.get_offset();
204 this.sourceview.el.grab_focus();
205 buf.place_cursor(st);
206 this.sourceview.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
210 public class Xcls_notebook : Object
212 public Gtk.Notebook el;
213 private Xcls_GtkView _this;
219 public Xcls_notebook(Xcls_GtkView _owner )
222 _this.notebook = this;
223 this.el = new Gtk.Notebook();
227 // set gobject values
228 var child_0 = new Xcls_label_preview( _this );
230 var child_1 = new Xcls_label_code( _this );
232 var child_2 = new Xcls_ScrolledWindow5( _this );
234 this.el.append_page ( child_2.el , _this.label_preview.el );
235 var child_3 = new Xcls_ScrolledWindow8( _this );
237 this.el.append_page ( child_3.el , _this.label_code.el );
240 // user defined functions
242 public class Xcls_label_preview : Object
245 private Xcls_GtkView _this;
251 public Xcls_label_preview(Xcls_GtkView _owner )
254 _this.label_preview = this;
255 this.el = new Gtk.Label( "Preview" );
259 // set gobject values
262 // user defined functions
265 public class Xcls_label_code : Object
268 private Xcls_GtkView _this;
274 public Xcls_label_code(Xcls_GtkView _owner )
277 _this.label_code = this;
278 this.el = new Gtk.Label( "Preview Generated Code" );
282 // set gobject values
285 // user defined functions
288 public class Xcls_ScrolledWindow5 : Object
290 public Gtk.ScrolledWindow el;
291 private Xcls_GtkView _this;
297 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
300 this.el = new Gtk.ScrolledWindow( null, null );
304 // set gobject values
305 var child_0 = new Xcls_view_layout( _this );
307 this.el.add ( child_0.el );
310 // user defined functions
312 public class Xcls_view_layout : Object
314 public Gtk.Layout el;
315 private Xcls_GtkView _this;
321 public Xcls_view_layout(Xcls_GtkView _owner )
324 _this.view_layout = this;
325 this.el = new Gtk.Layout( null, null );
329 // set gobject values
330 var child_0 = new Xcls_container( _this );
332 this.el.put ( child_0.el , 10,10 );
335 // user defined functions
337 public class Xcls_container : Object
340 private Xcls_GtkView _this;
346 public Xcls_container(Xcls_GtkView _owner )
349 _this.container = this;
350 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
354 // set gobject values
357 // user defined functions
362 public class Xcls_ScrolledWindow8 : Object
364 public Gtk.ScrolledWindow el;
365 private Xcls_GtkView _this;
371 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
374 this.el = new Gtk.ScrolledWindow( null, null );
378 // set gobject values
379 var child_0 = new Xcls_sourceview( _this );
381 this.el.add ( child_0.el );
384 // user defined functions
386 public class Xcls_sourceview : Object
388 public Gtk.SourceView el;
389 private Xcls_GtkView _this;
396 public Xcls_sourceview(Xcls_GtkView _owner )
399 _this.sourceview = this;
400 this.el = new Gtk.SourceView();
405 // set gobject values
406 this.el.editable = false;
407 this.el.show_line_marks = true;
408 this.el.show_line_numbers = true;
414 var description = Pango.FontDescription.from_string("monospace");
415 description.set_size(8000);
416 this.el.override_font(description);
419 var buf = this.el.get_buffer();
420 buf.notify.connect((ps) => {
424 if (ps.name != "cursor-position") {
427 print("cursor changed : %d\n", buf.cursor_position);
429 buf.get_iter_at_offset(out cpos, buf.cursor_position);
431 var ln = cpos.get_line();
433 var node = _this.file.lineToNode(ln);
435 print("can not find node\n");
438 var ltree = _this.main_window.windowstate.left_tree;
439 var tp = ltree.model.treePathFromNode(node);
440 print("got tree path %s\n", tp);
442 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
445 // highlight the node..
451 var attrs = new Gtk.SourceMarkAttributes();
452 var pink = Gdk.RGBA();
453 pink.parse ( "pink");
454 attrs.set_background ( pink);
455 attrs.set_icon_name ( "process-stop");
456 attrs.query_tooltip_text.connect(( mark) => {
457 //print("tooltip query? %s\n", mark.name);
461 this.el.set_mark_attributes ("ERR", attrs, 1);
463 var wattrs = new Gtk.SourceMarkAttributes();
464 var blue = Gdk.RGBA();
465 blue.parse ( "#ABF4EB");
466 wattrs.set_background ( blue);
467 wattrs.set_icon_name ( "process-stop");
468 wattrs.query_tooltip_text.connect(( mark) => {
469 //print("tooltip query? %s\n", mark.name);
473 this.el.set_mark_attributes ("WARN", wattrs, 1);
477 var dattrs = new Gtk.SourceMarkAttributes();
478 var purple = Gdk.RGBA();
479 purple.parse ( "#EEA9FF");
480 dattrs.set_background ( purple);
481 dattrs.set_icon_name ( "process-stop");
482 dattrs.query_tooltip_text.connect(( mark) => {
483 //print("tooltip query? %s\n", mark.name);
487 this.el.set_mark_attributes ("DEPR", dattrs, 1);
490 var gattrs = new Gtk.SourceMarkAttributes();
491 var grey = Gdk.RGBA();
492 grey.parse ( "#ccc");
493 gattrs.set_background ( grey);
496 this.el.set_mark_attributes ("grey", gattrs, 1);
506 // user defined functions
507 public void nodeSelected (JsRender.Node? sel) {
511 // this is connected in widnowstate
512 print("node selected");
513 var buf = this.el.get_buffer();
515 var sbuf = (Gtk.SourceBuffer) buf;
518 while(Gtk.events_pending()) {
519 Gtk.main_iteration();
523 // clear all the marks..
527 sbuf.get_bounds (out start, out end);
528 sbuf.remove_source_marks (start, end, "grey");
536 sbuf.get_iter_at_line(out iter, sel.line_start);
537 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
539 for (var i = 0; i < buf.get_line_count();i++) {
540 if (i < sel.line_start || i > sel.line_end) {
542 sbuf.get_iter_at_line(out iter, i);
543 sbuf.create_source_mark(null, "grey", iter);
551 public string toString () {
554 this.el.get_buffer().get_start_iter(out s);
555 this.el.get_buffer().get_end_iter(out e);
556 var ret = this.el.get_buffer().get_text(s,e,true);
557 //print("TO STRING? " + ret);
560 public void loadFile ( ) {
562 var buf = this.el.get_buffer();
564 var sbuf = (Gtk.SourceBuffer) buf;
568 if (_this.file == null || _this.file.xtype != "Gtk") {
569 print("xtype != Gtk");
570 this.loading = false;
576 var regex = new Regex("\\.bjs$");
579 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
580 } catch (GLib.RegexError e) {
581 this.loading = false;
586 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
587 print("File path has no errors\n");
588 this.loading = false;
595 GLib.FileUtils.get_contents (valafn, out str);
597 this.loading = false;
601 // print("setting str %d\n", str.length);
602 buf.set_text(str, str.length);
603 var lm = Gtk.SourceLanguageManager.get_default();
605 //?? is javascript going to work as js?
607 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
613 sbuf.get_bounds (out start, out end);
614 sbuf.remove_source_marks (start, end, null); // remove all marks..
617 if (_this.main_window.windowstate.last_compile_result != null) {
618 var obj = _this.main_window.windowstate.last_compile_result;
619 this.highlightErrorsJson("ERR", obj);
620 this.highlightErrorsJson("WARN", obj);
621 this.highlightErrorsJson("DEPR", obj);
623 //while (Gtk.events_pending()) {
624 // Gtk.main_iteration();
627 this.loading = false;
629 public void highlightErrorsJson (string type, Json.Object obj) {
633 var buf = this.el.get_buffer();
634 var sbuf = (Gtk.SourceBuffer)buf;
635 buf.get_bounds (out start, out end);
637 sbuf.remove_source_marks (start, end, type);
640 // we should highlight other types of errors..
642 if (!obj.has_member(type)) {
643 print("Return has no errors\n");
646 var err = obj.get_object_member(type);
648 if (_this.file == null) {
649 return; // just in case the file has not loaded yet?
655 var regex = new Regex("\\.bjs$");
658 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
659 } catch (GLib.RegexError e) {
663 if (!err.has_member(valafn)) {
664 print("File path has no errors\n");
667 var lines = err.get_object_member(valafn);
671 var tlines = buf.get_line_count () +1;
673 lines.foreach_member((obj, line, node) => {
676 // print("get inter\n");
677 var eline = int.parse(line) -1 ;
678 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
681 if (eline > tlines || eline < 0) {
684 sbuf.get_iter_at_line( out iter, eline);
685 //print("mark line\n");
686 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
687 var ar = lines.get_array_member(line);
688 for (var i = 0 ; i < ar.get_length(); i++) {
689 msg += (msg.length > 0) ? "\n" : "";
690 msg += ar.get_string_element(i);
694 sbuf.create_source_mark(msg, type, iter);