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 this.notebook.el.page = 1;
179 var s = new Gtk.SourceSearchSettings();
180 var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
181 this.searchcontext = new Gtk.SourceSearchContext(buf,s);
182 this.searchcontext.set_highlight(true);
183 s.set_search_text(txt);
185 Gtk.TextIter beg, st,en;
187 buf.get_start_iter(out beg);
188 this.searchcontext.forward(beg, out st, out en);
189 this.last_search_end = 0;
190 return this.searchcontext.get_occurrences_count();
194 public void forwardSearch (bool change_focus) {
196 if (this.searchcontext == null) {
199 this.notebook.el.page = 1;
200 Gtk.TextIter beg, st,en, stl;
202 var buf = this.sourceview.el.get_buffer();
203 buf.get_iter_at_offset(out beg, this.last_search_end);
204 if (!this.searchcontext.forward(beg, out st, out en)) {
205 this.last_search_end = 0;
207 this.last_search_end = en.get_offset();
209 this.sourceview.el.grab_focus();
211 buf.place_cursor(st);
212 var ln = st.get_line();
213 buf.get_iter_at_line(out stl,ln);
215 this.sourceview.el.scroll_to_iter(stl, 0.0f, true, 0.0f, 0.5f);
219 public class Xcls_notebook : Object
221 public Gtk.Notebook el;
222 private Xcls_GtkView _this;
228 public Xcls_notebook(Xcls_GtkView _owner )
231 _this.notebook = this;
232 this.el = new Gtk.Notebook();
236 // set gobject values
237 var child_0 = new Xcls_label_preview( _this );
239 var child_1 = new Xcls_label_code( _this );
241 var child_2 = new Xcls_ScrolledWindow5( _this );
243 this.el.append_page ( child_2.el , _this.label_preview.el );
244 var child_3 = new Xcls_ScrolledWindow8( _this );
246 this.el.append_page ( child_3.el , _this.label_code.el );
249 // user defined functions
251 public class Xcls_label_preview : Object
254 private Xcls_GtkView _this;
260 public Xcls_label_preview(Xcls_GtkView _owner )
263 _this.label_preview = this;
264 this.el = new Gtk.Label( "Preview" );
268 // set gobject values
271 // user defined functions
274 public class Xcls_label_code : Object
277 private Xcls_GtkView _this;
283 public Xcls_label_code(Xcls_GtkView _owner )
286 _this.label_code = this;
287 this.el = new Gtk.Label( "Preview Generated Code" );
291 // set gobject values
294 // user defined functions
297 public class Xcls_ScrolledWindow5 : Object
299 public Gtk.ScrolledWindow el;
300 private Xcls_GtkView _this;
306 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
309 this.el = new Gtk.ScrolledWindow( null, null );
313 // set gobject values
314 var child_0 = new Xcls_view_layout( _this );
316 this.el.add ( child_0.el );
319 // user defined functions
321 public class Xcls_view_layout : Object
323 public Gtk.Layout el;
324 private Xcls_GtkView _this;
330 public Xcls_view_layout(Xcls_GtkView _owner )
333 _this.view_layout = this;
334 this.el = new Gtk.Layout( null, null );
338 // set gobject values
339 var child_0 = new Xcls_container( _this );
341 this.el.put ( child_0.el , 10,10 );
344 // user defined functions
346 public class Xcls_container : Object
349 private Xcls_GtkView _this;
355 public Xcls_container(Xcls_GtkView _owner )
358 _this.container = this;
359 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
363 // set gobject values
366 // user defined functions
371 public class Xcls_ScrolledWindow8 : Object
373 public Gtk.ScrolledWindow el;
374 private Xcls_GtkView _this;
380 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
383 this.el = new Gtk.ScrolledWindow( null, null );
387 // set gobject values
388 var child_0 = new Xcls_sourceview( _this );
390 this.el.add ( child_0.el );
393 // user defined functions
395 public class Xcls_sourceview : Object
397 public Gtk.SourceView el;
398 private Xcls_GtkView _this;
403 public bool allow_node_scroll;
406 public Xcls_sourceview(Xcls_GtkView _owner )
409 _this.sourceview = this;
410 this.el = new Gtk.SourceView();
414 this.allow_node_scroll = true;
416 // set gobject values
417 this.el.editable = false;
418 this.el.show_line_marks = true;
419 this.el.show_line_numbers = true;
425 var description = Pango.FontDescription.from_string("monospace");
426 description.set_size(8000);
427 this.el.override_font(description);
430 var buf = this.el.get_buffer();
431 buf.notify.connect((ps) => {
435 if (ps.name != "cursor-position") {
438 print("cursor changed : %d\n", buf.cursor_position);
440 buf.get_iter_at_offset(out cpos, buf.cursor_position);
442 var ln = cpos.get_line();
444 var node = _this.file.lineToNode(ln);
447 print("can not find node\n");
450 var ltree = _this.main_window.windowstate.left_tree;
451 var tp = ltree.model.treePathFromNode(node);
452 print("got tree path %s\n", tp);
454 this.allow_node_scroll = false;
455 print("changing cursor on tree..\n");
456 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
457 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
458 GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
459 this.allow_node_scroll = true;
464 // highlight the node..
470 var attrs = new Gtk.SourceMarkAttributes();
471 var pink = Gdk.RGBA();
472 pink.parse ( "pink");
473 attrs.set_background ( pink);
474 attrs.set_icon_name ( "process-stop");
475 attrs.query_tooltip_text.connect(( mark) => {
476 //print("tooltip query? %s\n", mark.name);
480 this.el.set_mark_attributes ("ERR", attrs, 1);
482 var wattrs = new Gtk.SourceMarkAttributes();
483 var blue = Gdk.RGBA();
484 blue.parse ( "#ABF4EB");
485 wattrs.set_background ( blue);
486 wattrs.set_icon_name ( "process-stop");
487 wattrs.query_tooltip_text.connect(( mark) => {
488 //print("tooltip query? %s\n", mark.name);
492 this.el.set_mark_attributes ("WARN", wattrs, 1);
496 var dattrs = new Gtk.SourceMarkAttributes();
497 var purple = Gdk.RGBA();
498 purple.parse ( "#EEA9FF");
499 dattrs.set_background ( purple);
500 dattrs.set_icon_name ( "process-stop");
501 dattrs.query_tooltip_text.connect(( mark) => {
502 //print("tooltip query? %s\n", mark.name);
506 this.el.set_mark_attributes ("DEPR", dattrs, 1);
509 var gattrs = new Gtk.SourceMarkAttributes();
510 var grey = Gdk.RGBA();
511 grey.parse ( "#ccc");
512 gattrs.set_background ( grey);
515 this.el.set_mark_attributes ("grey", gattrs, 1);
525 // user defined functions
526 public void nodeSelected (JsRender.Node? sel) {
530 // this is connected in widnowstate
531 print("node selected\n");
532 var buf = this.el.get_buffer();
534 var sbuf = (Gtk.SourceBuffer) buf;
537 while(Gtk.events_pending()) {
538 Gtk.main_iteration();
542 // clear all the marks..
546 sbuf.get_bounds (out start, out end);
547 sbuf.remove_source_marks (start, end, "grey");
555 sbuf.get_iter_at_line(out iter, sel.line_start);
558 Gtk.TextIter cur_iter;
559 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
561 //var cur_line = cur_iter.get_line();
562 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
565 if (this.allow_node_scroll) {
567 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
572 for (var i = 0; i < buf.get_line_count();i++) {
573 if (i < sel.line_start || i > sel.line_end) {
575 sbuf.get_iter_at_line(out iter, i);
576 sbuf.create_source_mark(null, "grey", iter);
584 public string toString () {
587 this.el.get_buffer().get_start_iter(out s);
588 this.el.get_buffer().get_end_iter(out e);
589 var ret = this.el.get_buffer().get_text(s,e,true);
590 //print("TO STRING? " + ret);
593 public void loadFile ( ) {
595 var buf = this.el.get_buffer();
597 var sbuf = (Gtk.SourceBuffer) buf;
601 if (_this.file == null || _this.file.xtype != "Gtk") {
602 print("xtype != Gtk");
603 this.loading = false;
609 var regex = new Regex("\\.bjs$");
612 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
613 } catch (GLib.RegexError e) {
614 this.loading = false;
619 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
620 print("File path has no errors\n");
621 this.loading = false;
628 GLib.FileUtils.get_contents (valafn, out str);
630 this.loading = false;
634 // print("setting str %d\n", str.length);
635 buf.set_text(str, str.length);
636 var lm = Gtk.SourceLanguageManager.get_default();
638 //?? is javascript going to work as js?
640 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
646 sbuf.get_bounds (out start, out end);
647 sbuf.remove_source_marks (start, end, null); // remove all marks..
650 if (_this.main_window.windowstate.last_compile_result != null) {
651 var obj = _this.main_window.windowstate.last_compile_result;
652 this.highlightErrorsJson("ERR", obj);
653 this.highlightErrorsJson("WARN", obj);
654 this.highlightErrorsJson("DEPR", obj);
656 //while (Gtk.events_pending()) {
657 // Gtk.main_iteration();
660 this.loading = false;
662 public void highlightErrorsJson (string type, Json.Object obj) {
666 var buf = this.el.get_buffer();
667 var sbuf = (Gtk.SourceBuffer)buf;
668 buf.get_bounds (out start, out end);
670 sbuf.remove_source_marks (start, end, type);
673 // we should highlight other types of errors..
675 if (!obj.has_member(type)) {
676 print("Return has no errors\n");
679 var err = obj.get_object_member(type);
681 if (_this.file == null) {
682 return; // just in case the file has not loaded yet?
688 var regex = new Regex("\\.bjs$");
691 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
692 } catch (GLib.RegexError e) {
696 if (!err.has_member(valafn)) {
697 print("File path has no errors\n");
700 var lines = err.get_object_member(valafn);
704 var tlines = buf.get_line_count () +1;
706 lines.foreach_member((obj, line, node) => {
709 // print("get inter\n");
710 var eline = int.parse(line) -1 ;
711 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
714 if (eline > tlines || eline < 0) {
717 sbuf.get_iter_at_line( out iter, eline);
718 //print("mark line\n");
719 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
720 var ar = lines.get_array_member(line);
721 for (var i = 0 ; i < ar.get_length(); i++) {
722 msg += (msg.length > 0) ? "\n" : "";
723 msg += ar.get_string_element(i);
727 sbuf.create_source_mark(msg, type, iter);