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 this.buffer.el.get_iter_at_offset(out beg, this.last_search_end);
200 this.searchcontext.forward(beg, out st, out en);
201 this.last_search_end = en.get_offset();
203 this.view.el.grab_focus();
204 this.buffer.el.place_cursor(st);
205 this.view.el.scroll_to_iter(st, 0.1f, true, 0.0f, 0.5f);
209 public class Xcls_notebook : Object
211 public Gtk.Notebook el;
212 private Xcls_GtkView _this;
218 public Xcls_notebook(Xcls_GtkView _owner )
221 _this.notebook = this;
222 this.el = new Gtk.Notebook();
226 // set gobject values
227 var child_0 = new Xcls_label_preview( _this );
229 var child_1 = new Xcls_label_code( _this );
231 var child_2 = new Xcls_ScrolledWindow5( _this );
233 this.el.append_page ( child_2.el , _this.label_preview.el );
234 var child_3 = new Xcls_ScrolledWindow8( _this );
236 this.el.append_page ( child_3.el , _this.label_code.el );
239 // user defined functions
241 public class Xcls_label_preview : Object
244 private Xcls_GtkView _this;
250 public Xcls_label_preview(Xcls_GtkView _owner )
253 _this.label_preview = this;
254 this.el = new Gtk.Label( "Preview" );
258 // set gobject values
261 // user defined functions
264 public class Xcls_label_code : Object
267 private Xcls_GtkView _this;
273 public Xcls_label_code(Xcls_GtkView _owner )
276 _this.label_code = this;
277 this.el = new Gtk.Label( "Preview Generated Code" );
281 // set gobject values
284 // user defined functions
287 public class Xcls_ScrolledWindow5 : Object
289 public Gtk.ScrolledWindow el;
290 private Xcls_GtkView _this;
296 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
299 this.el = new Gtk.ScrolledWindow( null, null );
303 // set gobject values
304 var child_0 = new Xcls_view_layout( _this );
306 this.el.add ( child_0.el );
309 // user defined functions
311 public class Xcls_view_layout : Object
313 public Gtk.Layout el;
314 private Xcls_GtkView _this;
320 public Xcls_view_layout(Xcls_GtkView _owner )
323 _this.view_layout = this;
324 this.el = new Gtk.Layout( null, null );
328 // set gobject values
329 var child_0 = new Xcls_container( _this );
331 this.el.put ( child_0.el , 10,10 );
334 // user defined functions
336 public class Xcls_container : Object
339 private Xcls_GtkView _this;
345 public Xcls_container(Xcls_GtkView _owner )
348 _this.container = this;
349 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
353 // set gobject values
356 // user defined functions
361 public class Xcls_ScrolledWindow8 : Object
363 public Gtk.ScrolledWindow el;
364 private Xcls_GtkView _this;
370 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
373 this.el = new Gtk.ScrolledWindow( null, null );
377 // set gobject values
378 var child_0 = new Xcls_sourceview( _this );
380 this.el.add ( child_0.el );
383 // user defined functions
385 public class Xcls_sourceview : Object
387 public Gtk.SourceView el;
388 private Xcls_GtkView _this;
395 public Xcls_sourceview(Xcls_GtkView _owner )
398 _this.sourceview = this;
399 this.el = new Gtk.SourceView();
404 // set gobject values
405 this.el.editable = false;
406 this.el.show_line_marks = true;
407 this.el.show_line_numbers = true;
413 var description = Pango.FontDescription.from_string("monospace");
414 description.set_size(8000);
415 this.el.override_font(description);
418 var buf = this.el.get_buffer();
419 buf.notify.connect((ps) => {
423 if (ps.name != "cursor-position") {
426 print("cursor changed : %d\n", buf.cursor_position);
428 buf.get_iter_at_offset(out cpos, buf.cursor_position);
430 var ln = cpos.get_line();
432 var node = _this.file.lineToNode(ln);
434 print("can not find node\n");
437 var ltree = _this.main_window.windowstate.left_tree;
438 var tp = ltree.model.treePathFromNode(node);
439 print("got tree path %s\n", tp);
441 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
444 // highlight the node..
450 var attrs = new Gtk.SourceMarkAttributes();
451 var pink = Gdk.RGBA();
452 pink.parse ( "pink");
453 attrs.set_background ( pink);
454 attrs.set_icon_name ( "process-stop");
455 attrs.query_tooltip_text.connect(( mark) => {
456 //print("tooltip query? %s\n", mark.name);
460 this.el.set_mark_attributes ("ERR", attrs, 1);
462 var wattrs = new Gtk.SourceMarkAttributes();
463 var blue = Gdk.RGBA();
464 blue.parse ( "#ABF4EB");
465 wattrs.set_background ( blue);
466 wattrs.set_icon_name ( "process-stop");
467 wattrs.query_tooltip_text.connect(( mark) => {
468 //print("tooltip query? %s\n", mark.name);
472 this.el.set_mark_attributes ("WARN", wattrs, 1);
476 var dattrs = new Gtk.SourceMarkAttributes();
477 var purple = Gdk.RGBA();
478 purple.parse ( "#EEA9FF");
479 dattrs.set_background ( purple);
480 dattrs.set_icon_name ( "process-stop");
481 dattrs.query_tooltip_text.connect(( mark) => {
482 //print("tooltip query? %s\n", mark.name);
486 this.el.set_mark_attributes ("DEPR", dattrs, 1);
489 var gattrs = new Gtk.SourceMarkAttributes();
490 var grey = Gdk.RGBA();
491 grey.parse ( "#ccc");
492 gattrs.set_background ( grey);
495 this.el.set_mark_attributes ("grey", gattrs, 1);
505 // user defined functions
506 public void nodeSelected (JsRender.Node? sel) {
510 // this is connected in widnowstate
511 print("node selected");
512 var buf = this.el.get_buffer();
514 var sbuf = (Gtk.SourceBuffer) buf;
517 while(Gtk.events_pending()) {
518 Gtk.main_iteration();
522 // clear all the marks..
526 sbuf.get_bounds (out start, out end);
527 sbuf.remove_source_marks (start, end, "grey");
535 sbuf.get_iter_at_line(out iter, sel.line_start);
536 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
538 for (var i = 0; i < buf.get_line_count();i++) {
539 if (i < sel.line_start || i > sel.line_end) {
541 sbuf.get_iter_at_line(out iter, i);
542 sbuf.create_source_mark(null, "grey", iter);
550 public string toString () {
553 this.el.get_buffer().get_start_iter(out s);
554 this.el.get_buffer().get_end_iter(out e);
555 var ret = this.el.get_buffer().get_text(s,e,true);
556 //print("TO STRING? " + ret);
559 public void loadFile ( ) {
561 var buf = this.el.get_buffer();
563 var sbuf = (Gtk.SourceBuffer) buf;
567 if (_this.file == null || _this.file.xtype != "Gtk") {
568 print("xtype != Gtk");
569 this.loading = false;
575 var regex = new Regex("\\.bjs$");
578 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
579 } catch (GLib.RegexError e) {
580 this.loading = false;
585 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
586 print("File path has no errors\n");
587 this.loading = false;
594 GLib.FileUtils.get_contents (valafn, out str);
596 this.loading = false;
600 // print("setting str %d\n", str.length);
601 buf.set_text(str, str.length);
602 var lm = Gtk.SourceLanguageManager.get_default();
604 //?? is javascript going to work as js?
606 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
612 sbuf.get_bounds (out start, out end);
613 sbuf.remove_source_marks (start, end, null); // remove all marks..
616 if (_this.main_window.windowstate.last_compile_result != null) {
617 var obj = _this.main_window.windowstate.last_compile_result;
618 this.highlightErrorsJson("ERR", obj);
619 this.highlightErrorsJson("WARN", obj);
620 this.highlightErrorsJson("DEPR", obj);
622 //while (Gtk.events_pending()) {
623 // Gtk.main_iteration();
626 this.loading = false;
628 public void highlightErrorsJson (string type, Json.Object obj) {
632 var buf = this.el.get_buffer();
633 var sbuf = (Gtk.SourceBuffer)buf;
634 buf.get_bounds (out start, out end);
636 sbuf.remove_source_marks (start, end, type);
639 // we should highlight other types of errors..
641 if (!obj.has_member(type)) {
642 print("Return has no errors\n");
645 var err = obj.get_object_member(type);
647 if (_this.file == null) {
648 return; // just in case the file has not loaded yet?
654 var regex = new Regex("\\.bjs$");
657 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
658 } catch (GLib.RegexError e) {
662 if (!err.has_member(valafn)) {
663 print("File path has no errors\n");
666 var lines = err.get_object_member(valafn);
670 var tlines = buf.get_line_count () +1;
672 lines.foreach_member((obj, line, node) => {
675 // print("get inter\n");
676 var eline = int.parse(line) -1 ;
677 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
680 if (eline > tlines || eline < 0) {
683 sbuf.get_iter_at_line( out iter, eline);
684 //print("mark line\n");
685 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
686 var ar = lines.get_array_member(line);
687 for (var i = 0 ; i < ar.get_length(); i++) {
688 msg += (msg.length > 0) ? "\n" : "";
689 msg += ar.get_string_element(i);
693 sbuf.create_source_mark(msg, type, iter);