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 JsRender.JsRender file;
27 public Xcls_MainWindow main_window;
33 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
42 var child_0 = new Xcls_notebook( _this );
44 this.el.pack_start ( child_0.el , true,true,0 );
47 this.el.size_allocate.connect( (aloc) => {
49 this.width = aloc.width;
50 this.height =aloc.height;
54 // user defined functions
55 public void createThumb () {
58 if (this.file == null) {
61 // only screenshot the gtk preview..
62 if (this.notebook.el.page > 0 ) {
67 var filename = this.file.getIconFileName(false);
69 var win = this.el.get_parent_window();
70 var width = win.get_width();
71 var height = win.get_height();
73 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
74 screenshot.save(filename,"png");
86 // should we hold until it's printed...
97 public void loadFile (JsRender.JsRender file)
101 if (file.tree == null) {
105 this.sourceview.loadFile();
109 if (this.lastObj != null) {
110 this.container.el.remove(this.lastObj);
113 // hide the compile view at present..
119 print("ALLOC SET SIZES %d, %d\n", w,h);
121 // set the container size min to 500/500 or 20 px less than max..
122 w = int.max (w-20, 500);
123 h = int.max (h-20, 500);
125 print("SET SIZES %d, %d\n", w,h);
126 _this.container.el.set_size_request(w,h);
128 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
129 var rgba = Gdk.RGBA ();
131 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
134 var x = new JsRender.NodeToGtk(file.tree);
135 var obj = x.munge() as Gtk.Widget;
142 this.container.el.add(obj);
148 public class Xcls_notebook : Object
150 public Gtk.Notebook el;
151 private Xcls_GtkView _this;
157 public Xcls_notebook(Xcls_GtkView _owner )
160 _this.notebook = this;
161 this.el = new Gtk.Notebook();
165 // set gobject values
166 var child_0 = new Xcls_label_preview( _this );
168 var child_1 = new Xcls_label_code( _this );
170 var child_2 = new Xcls_ScrolledWindow5( _this );
172 this.el.append_page ( child_2.el , _this.label_preview.el );
173 var child_3 = new Xcls_ScrolledWindow8( _this );
175 this.el.append_page ( child_3.el , _this.label_code.el );
178 // user defined functions
180 public class Xcls_label_preview : Object
183 private Xcls_GtkView _this;
189 public Xcls_label_preview(Xcls_GtkView _owner )
192 _this.label_preview = this;
193 this.el = new Gtk.Label( "Preview" );
197 // set gobject values
200 // user defined functions
203 public class Xcls_label_code : Object
206 private Xcls_GtkView _this;
212 public Xcls_label_code(Xcls_GtkView _owner )
215 _this.label_code = this;
216 this.el = new Gtk.Label( "Preview Generated Code" );
220 // set gobject values
223 // user defined functions
226 public class Xcls_ScrolledWindow5 : Object
228 public Gtk.ScrolledWindow el;
229 private Xcls_GtkView _this;
235 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
238 this.el = new Gtk.ScrolledWindow( null, null );
242 // set gobject values
243 var child_0 = new Xcls_view_layout( _this );
245 this.el.add ( child_0.el );
248 // user defined functions
250 public class Xcls_view_layout : Object
252 public Gtk.Layout el;
253 private Xcls_GtkView _this;
259 public Xcls_view_layout(Xcls_GtkView _owner )
262 _this.view_layout = this;
263 this.el = new Gtk.Layout( null, null );
267 // set gobject values
268 var child_0 = new Xcls_container( _this );
270 this.el.put ( child_0.el , 10,10 );
273 // user defined functions
275 public class Xcls_container : Object
278 private Xcls_GtkView _this;
284 public Xcls_container(Xcls_GtkView _owner )
287 _this.container = this;
288 this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
292 // set gobject values
295 // user defined functions
300 public class Xcls_ScrolledWindow8 : Object
302 public Gtk.ScrolledWindow el;
303 private Xcls_GtkView _this;
309 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
312 this.el = new Gtk.ScrolledWindow( null, null );
316 // set gobject values
317 var child_0 = new Xcls_sourceview( _this );
319 this.el.add ( child_0.el );
322 // user defined functions
324 public class Xcls_sourceview : Object
326 public Gtk.SourceView el;
327 private Xcls_GtkView _this;
334 public Xcls_sourceview(Xcls_GtkView _owner )
337 _this.sourceview = this;
338 this.el = new Gtk.SourceView();
343 // set gobject values
344 this.el.editable = false;
345 this.el.show_line_marks = true;
346 this.el.show_line_numbers = true;
352 var description = Pango.FontDescription.from_string("monospace");
353 description.set_size(8000);
354 this.el.override_font(description);
357 var buf = this.el.get_buffer();
358 buf.notify.connect((ps) => {
362 if (ps.name != "cursor-position") {
365 print("cursor changed : %d\n", buf.cursor_position);
367 buf.get_iter_at_offset(out cpos, buf.cursor_position);
369 var ln = cpos.get_line();
371 var node = _this.file.lineToNode(ln);
373 print("can not find node\n");
376 var ltree = _this.main_window.windowstate.left_tree;
377 var tp = ltree.model.treePathFromNode(node);
378 print("got tree path %s\n", tp);
380 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
383 // highlight the node..
389 var attrs = new Gtk.SourceMarkAttributes();
390 var pink = Gdk.RGBA();
391 pink.parse ( "pink");
392 attrs.set_background ( pink);
393 attrs.set_icon_name ( "process-stop");
394 attrs.query_tooltip_text.connect(( mark) => {
395 //print("tooltip query? %s\n", mark.name);
399 this.el.set_mark_attributes ("ERR", attrs, 1);
401 var wattrs = new Gtk.SourceMarkAttributes();
402 var blue = Gdk.RGBA();
403 blue.parse ( "#ABF4EB");
404 wattrs.set_background ( blue);
405 wattrs.set_icon_name ( "process-stop");
406 wattrs.query_tooltip_text.connect(( mark) => {
407 //print("tooltip query? %s\n", mark.name);
411 this.el.set_mark_attributes ("WARN", wattrs, 1);
415 var dattrs = new Gtk.SourceMarkAttributes();
416 var purple = Gdk.RGBA();
417 purple.parse ( "#EEA9FF");
418 dattrs.set_background ( purple);
419 dattrs.set_icon_name ( "process-stop");
420 dattrs.query_tooltip_text.connect(( mark) => {
421 //print("tooltip query? %s\n", mark.name);
425 this.el.set_mark_attributes ("DEPR", dattrs, 1);
428 var gattrs = new Gtk.SourceMarkAttributes();
429 var grey = Gdk.RGBA();
430 grey.parse ( "#ccc");
431 gattrs.set_background ( grey);
434 this.el.set_mark_attributes ("grey", gattrs, 1);
444 // user defined functions
445 public void nodeSelected (JsRender.Node? sel) {
449 // this is connected in widnowstate
450 print("node selected");
451 var buf = this.el.get_buffer();
453 var sbuf = (Gtk.SourceBuffer) buf;
456 while(Gtk.events_pending()) {
457 Gtk.main_iteration();
461 // clear all the marks..
465 sbuf.get_bounds (out start, out end);
466 sbuf.remove_source_marks (start, end, "grey");
474 sbuf.get_iter_at_line(out iter, sel.line_start);
475 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
477 for (var i = 0; i < buf.get_line_count();i++) {
478 if (i < sel.line_start || i > sel.line_end) {
480 sbuf.get_iter_at_line(out iter, i);
481 sbuf.create_source_mark(null, "grey", iter);
489 public void loadFile ( ) {
491 var buf = this.el.get_buffer();
493 var sbuf = (Gtk.SourceBuffer) buf;
497 if (_this.file == null || _this.file.xtype != "Gtk") {
498 print("xtype != Gtk");
499 this.loading = false;
505 var regex = new Regex("\\.bjs$");
508 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
509 } catch (GLib.RegexError e) {
510 this.loading = false;
514 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
515 print("File path has no errors\n");
516 this.loading = false;
521 GLib.FileUtils.get_contents (valafn, out str);
523 // print("setting str %d\n", str.length);
524 buf.set_text(str, str.length);
525 var lm = Gtk.SourceLanguageManager.get_default();
527 //?? is javascript going to work as js?
529 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
535 sbuf.get_bounds (out start, out end);
536 sbuf.remove_source_marks (start, end, null); // remove all marks..
539 if (_this.main_window.windowstate.last_compile_result != null) {
540 var obj = _this.main_window.windowstate.last_compile_result;
541 this.highlightErrorsJson("ERR", obj);
542 this.highlightErrorsJson("WARN", obj);
543 this.highlightErrorsJson("DEPR", obj);
545 //while (Gtk.events_pending()) {
546 // Gtk.main_iteration();
549 this.loading = false;
551 public void highlightErrorsJson (string type, Json.Object obj) {
555 var buf = this.el.get_buffer();
556 var sbuf = (Gtk.SourceBuffer)buf;
557 buf.get_bounds (out start, out end);
559 sbuf.remove_source_marks (start, end, type);
562 // we should highlight other types of errors..
564 if (!obj.has_member(type)) {
565 print("Return has no errors\n");
568 var err = obj.get_object_member(type);
574 var regex = new Regex("\\.bjs$");
577 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
578 } catch (GLib.RegexError e) {
582 if (!err.has_member(valafn)) {
583 print("File path has no errors\n");
586 var lines = err.get_object_member(valafn);
590 var tlines = buf.get_line_count () +1;
592 lines.foreach_member((obj, line, node) => {
595 // print("get inter\n");
596 var eline = int.parse(line) -1 ;
597 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
600 if (eline > tlines || eline < 0) {
603 sbuf.get_iter_at_line( out iter, eline);
604 //print("mark line\n");
605 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
606 var ar = lines.get_array_member(line);
607 for (var i = 0 ; i < ar.get_length(); i++) {
608 msg += (msg.length > 0) ? "\n" : "";
609 msg += ar.get_string_element(i);
613 sbuf.create_source_mark(msg, type, iter);