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_label_preview label_preview;
16 public Xcls_label_code label_code;
17 public Xcls_view_layout view_layout;
18 public Xcls_container container;
19 public Xcls_sourceview sourceview;
22 public Gtk.Widget lastObj;
24 public JsRender.JsRender file;
26 public Xcls_MainWindow main_window;
32 this.el = new Gtk.VBox( true, 0 );
41 var child_0 = new Xcls_Notebook2( _this );
43 this.el.pack_start ( child_0.el , true,true,0 );
46 this.el.size_allocate.connect( (aloc) => {
48 this.width = aloc.width;
49 this.height =aloc.height;
53 // user defined functions
54 public void createThumb () {
57 if (this.file == null) {
60 var filename = this.file.getIconFileName(false);
62 var win = this.el.get_parent_window();
63 var width = win.get_width();
64 var height = win.get_height();
66 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
68 screenshot.save(filename,"png");
77 // should we hold until it's printed...
88 public void loadFile (JsRender.JsRender file)
92 if (file.tree == null) {
96 this.sourceview.loadFile();
100 if (this.lastObj != null) {
101 this.container.el.remove(this.lastObj);
104 // hide the compile view at present..
110 print("ALLOC SET SIZES %d, %d\n", w,h);
112 // set the container size min to 500/500 or 20 px less than max..
113 w = int.max (w-20, 500);
114 h = int.max (h-20, 500);
116 print("SET SIZES %d, %d\n", w,h);
117 _this.container.el.set_size_request(w,h);
119 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
120 var rgba = Gdk.RGBA ();
122 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
125 var x = new JsRender.NodeToGtk(file.tree);
126 var obj = x.munge() as Gtk.Widget;
133 this.container.el.add(obj);
139 public class Xcls_Notebook2 : Object
141 public Gtk.Notebook el;
142 private Xcls_GtkView _this;
148 public Xcls_Notebook2(Xcls_GtkView _owner )
151 this.el = new Gtk.Notebook();
155 // set gobject values
156 var child_0 = new Xcls_label_preview( _this );
158 var child_1 = new Xcls_label_code( _this );
160 var child_2 = new Xcls_ScrolledWindow5( _this );
162 this.el.append_page ( child_2.el , _this.label_preview.el );
163 var child_3 = new Xcls_ScrolledWindow8( _this );
165 this.el.append_page ( child_3.el , _this.label_code.el );
168 // user defined functions
170 public class Xcls_label_preview : Object
173 private Xcls_GtkView _this;
179 public Xcls_label_preview(Xcls_GtkView _owner )
182 _this.label_preview = this;
183 this.el = new Gtk.Label( "Preview" );
187 // set gobject values
190 // user defined functions
193 public class Xcls_label_code : Object
196 private Xcls_GtkView _this;
202 public Xcls_label_code(Xcls_GtkView _owner )
205 _this.label_code = this;
206 this.el = new Gtk.Label( "Code" );
210 // set gobject values
213 // user defined functions
216 public class Xcls_ScrolledWindow5 : Object
218 public Gtk.ScrolledWindow el;
219 private Xcls_GtkView _this;
225 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
228 this.el = new Gtk.ScrolledWindow( null, null );
232 // set gobject values
233 var child_0 = new Xcls_view_layout( _this );
235 this.el.add ( child_0.el );
238 // user defined functions
240 public class Xcls_view_layout : Object
242 public Gtk.Layout el;
243 private Xcls_GtkView _this;
249 public Xcls_view_layout(Xcls_GtkView _owner )
252 _this.view_layout = this;
253 this.el = new Gtk.Layout( null, null );
257 // set gobject values
258 var child_0 = new Xcls_container( _this );
260 this.el.put ( child_0.el , 10,10 );
263 // user defined functions
265 public class Xcls_container : Object
268 private Xcls_GtkView _this;
274 public Xcls_container(Xcls_GtkView _owner )
277 _this.container = this;
278 this.el = new Gtk.HBox( true, 0 );
282 // set gobject values
285 // user defined functions
290 public class Xcls_ScrolledWindow8 : Object
292 public Gtk.ScrolledWindow el;
293 private Xcls_GtkView _this;
299 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
302 this.el = new Gtk.ScrolledWindow( null, null );
306 // set gobject values
307 var child_0 = new Xcls_sourceview( _this );
309 this.el.add ( child_0.el );
312 // user defined functions
314 public class Xcls_sourceview : Object
316 public Gtk.SourceView el;
317 private Xcls_GtkView _this;
323 public Xcls_sourceview(Xcls_GtkView _owner )
326 _this.sourceview = this;
327 this.el = new Gtk.SourceView();
331 // set gobject values
332 this.el.editable = false;
333 this.el.show_line_marks = true;
334 this.el.show_line_numbers = true;
340 var description = Pango.FontDescription.from_string("monospace");
341 description.set_size(8000);
342 this.el.override_font(description);
344 var buf = this.el.get_buffer();
345 buf.notify.connect((ps) => {
346 if (ps.name != "cursor-position") {
349 print("cursor changed : %d\n", buf.cursor_position);
351 buf.get_iter_at_offset(out cpos, buf.cursor_position);
353 var ln = cpos.get_line();
355 var node = _this.file.lineToNode(ln);
357 print("can not find node\n");
360 var ltree = _this.main_window.windowstate.left_tree;
361 var tp = ltree.model.treePathFromNode(node);
362 print("got tree path %s\n", tp);
364 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
367 // highlight the node..
373 var attrs = new Gtk.SourceMarkAttributes();
374 var pink = Gdk.RGBA();
375 pink.parse ( "pink");
376 attrs.set_background ( pink);
377 attrs.set_icon_name ( "process-stop");
378 attrs.query_tooltip_text.connect(( mark) => {
379 //print("tooltip query? %s\n", mark.name);
383 this.el.set_mark_attributes ("ERR", attrs, 1);
385 var wattrs = new Gtk.SourceMarkAttributes();
386 var blue = Gdk.RGBA();
387 blue.parse ( "#ABF4EB");
388 wattrs.set_background ( blue);
389 wattrs.set_icon_name ( "process-stop");
390 wattrs.query_tooltip_text.connect(( mark) => {
391 //print("tooltip query? %s\n", mark.name);
395 this.el.set_mark_attributes ("WARN", wattrs, 1);
399 var dattrs = new Gtk.SourceMarkAttributes();
400 var purple = Gdk.RGBA();
401 purple.parse ( "#EEA9FF");
402 dattrs.set_background ( purple);
403 dattrs.set_icon_name ( "process-stop");
404 dattrs.query_tooltip_text.connect(( mark) => {
405 //print("tooltip query? %s\n", mark.name);
409 this.el.set_mark_attributes ("DEPR", dattrs, 1);
412 var gattrs = new Gtk.SourceMarkAttributes();
413 var grey = Gdk.RGBA();
414 grey.parse ( "#ccc");
415 gattrs.set_background ( grey);
418 this.el.set_mark_attributes ("grey", gattrs, 1);
428 // user defined functions
429 public void nodeSelected (JsRender.Node? sel) {
433 // this is connected in widnowstate
434 print("node selected");
435 var buf = this.el.get_buffer();
437 var sbuf = (Gtk.SourceBuffer) buf;
440 while(Gtk.events_pending()) {
441 Gtk.main_iteration();
445 // clear all the marks..
449 sbuf.get_bounds (out start, out end);
450 sbuf.remove_source_marks (start, end, "grey");
458 sbuf.get_iter_at_line(out iter, sel.line_start);
459 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
461 for (var i = 0; i < buf.get_line_count();i++) {
462 if (i < sel.line_start || i > sel.line_end) {
464 sbuf.get_iter_at_line(out iter, i);
465 sbuf.create_source_mark(null, "grey", iter);
473 public void loadFile ( ) {
474 var buf = this.el.get_buffer();
476 var sbuf = (Gtk.SourceBuffer) buf;
480 if (_this.file == null || _this.file.xtype != "Gtk") {
481 print("xtype != Gtk");
487 var regex = new Regex("\\.bjs$");
490 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
491 } catch (GLib.RegexError e) {
495 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
496 print("File path has no errors\n");
501 GLib.FileUtils.get_contents (valafn, out str);
503 // print("setting str %d\n", str.length);
504 buf.set_text(str, str.length);
505 var lm = Gtk.SourceLanguageManager.get_default();
507 //?? is javascript going to work as js?
509 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
515 sbuf.get_bounds (out start, out end);
516 sbuf.remove_source_marks (start, end, null); // remove all marks..
519 if (_this.main_window.windowstate.last_compile_result != null) {
520 var obj = _this.main_window.windowstate.last_compile_result;
521 this.highlightErrorsJson("ERR", obj);
522 this.highlightErrorsJson("WARN", obj);
523 this.highlightErrorsJson("DEPR", obj);
527 public void highlightErrorsJson (string type, Json.Object obj) {
531 var buf = this.el.get_buffer();
532 var sbuf = (Gtk.SourceBuffer)buf;
533 buf.get_bounds (out start, out end);
535 sbuf.remove_source_marks (start, end, type);
538 // we should highlight other types of errors..
540 if (!obj.has_member(type)) {
541 print("Return has no errors\n");
544 var err = obj.get_object_member(type);
550 var regex = new Regex("\\.bjs$");
553 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
554 } catch (GLib.RegexError e) {
558 if (!err.has_member(valafn)) {
559 print("File path has no errors\n");
562 var lines = err.get_object_member(valafn);
566 var tlines = buf.get_line_count () +1;
568 lines.foreach_member((obj, line, node) => {
571 // print("get inter\n");
572 var eline = int.parse(line) -1 ;
573 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
576 if (eline > tlines || eline < 0) {
579 sbuf.get_iter_at_line( out iter, eline);
580 //print("mark line\n");
581 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
582 var ar = lines.get_array_member(line);
583 for (var i = 0 ; i < ar.get_length(); i++) {
584 msg += (msg.length > 0) ? "\n" : "";
585 msg += ar.get_string_element(i);
589 sbuf.create_source_mark(msg, type, iter);