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;
324 public Xcls_sourceview(Xcls_GtkView _owner )
327 _this.sourceview = this;
328 this.el = new Gtk.SourceView();
333 // set gobject values
334 this.el.editable = false;
335 this.el.show_line_marks = true;
336 this.el.show_line_numbers = true;
342 var description = Pango.FontDescription.from_string("monospace");
343 description.set_size(8000);
344 this.el.override_font(description);
347 var buf = this.el.get_buffer();
348 buf.notify.connect((ps) => {
352 if (ps.name != "cursor-position") {
355 print("cursor changed : %d\n", buf.cursor_position);
357 buf.get_iter_at_offset(out cpos, buf.cursor_position);
359 var ln = cpos.get_line();
361 var node = _this.file.lineToNode(ln);
363 print("can not find node\n");
366 var ltree = _this.main_window.windowstate.left_tree;
367 var tp = ltree.model.treePathFromNode(node);
368 print("got tree path %s\n", tp);
370 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
373 // highlight the node..
379 var attrs = new Gtk.SourceMarkAttributes();
380 var pink = Gdk.RGBA();
381 pink.parse ( "pink");
382 attrs.set_background ( pink);
383 attrs.set_icon_name ( "process-stop");
384 attrs.query_tooltip_text.connect(( mark) => {
385 //print("tooltip query? %s\n", mark.name);
389 this.el.set_mark_attributes ("ERR", attrs, 1);
391 var wattrs = new Gtk.SourceMarkAttributes();
392 var blue = Gdk.RGBA();
393 blue.parse ( "#ABF4EB");
394 wattrs.set_background ( blue);
395 wattrs.set_icon_name ( "process-stop");
396 wattrs.query_tooltip_text.connect(( mark) => {
397 //print("tooltip query? %s\n", mark.name);
401 this.el.set_mark_attributes ("WARN", wattrs, 1);
405 var dattrs = new Gtk.SourceMarkAttributes();
406 var purple = Gdk.RGBA();
407 purple.parse ( "#EEA9FF");
408 dattrs.set_background ( purple);
409 dattrs.set_icon_name ( "process-stop");
410 dattrs.query_tooltip_text.connect(( mark) => {
411 //print("tooltip query? %s\n", mark.name);
415 this.el.set_mark_attributes ("DEPR", dattrs, 1);
418 var gattrs = new Gtk.SourceMarkAttributes();
419 var grey = Gdk.RGBA();
420 grey.parse ( "#ccc");
421 gattrs.set_background ( grey);
424 this.el.set_mark_attributes ("grey", gattrs, 1);
434 // user defined functions
435 public void nodeSelected (JsRender.Node? sel) {
439 // this is connected in widnowstate
440 print("node selected");
441 var buf = this.el.get_buffer();
443 var sbuf = (Gtk.SourceBuffer) buf;
446 while(Gtk.events_pending()) {
447 Gtk.main_iteration();
451 // clear all the marks..
455 sbuf.get_bounds (out start, out end);
456 sbuf.remove_source_marks (start, end, "grey");
464 sbuf.get_iter_at_line(out iter, sel.line_start);
465 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
467 for (var i = 0; i < buf.get_line_count();i++) {
468 if (i < sel.line_start || i > sel.line_end) {
470 sbuf.get_iter_at_line(out iter, i);
471 sbuf.create_source_mark(null, "grey", iter);
479 public void loadFile ( ) {
481 var buf = this.el.get_buffer();
483 var sbuf = (Gtk.SourceBuffer) buf;
487 if (_this.file == null || _this.file.xtype != "Gtk") {
488 print("xtype != Gtk");
489 this.loading = false;
495 var regex = new Regex("\\.bjs$");
498 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
499 } catch (GLib.RegexError e) {
500 this.loading = false;
504 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
505 print("File path has no errors\n");
506 this.loading = false;
511 GLib.FileUtils.get_contents (valafn, out str);
513 // print("setting str %d\n", str.length);
514 buf.set_text(str, str.length);
515 var lm = Gtk.SourceLanguageManager.get_default();
517 //?? is javascript going to work as js?
519 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
525 sbuf.get_bounds (out start, out end);
526 sbuf.remove_source_marks (start, end, null); // remove all marks..
529 if (_this.main_window.windowstate.last_compile_result != null) {
530 var obj = _this.main_window.windowstate.last_compile_result;
531 this.highlightErrorsJson("ERR", obj);
532 this.highlightErrorsJson("WARN", obj);
533 this.highlightErrorsJson("DEPR", obj);
536 this.loading = false;
538 public void highlightErrorsJson (string type, Json.Object obj) {
542 var buf = this.el.get_buffer();
543 var sbuf = (Gtk.SourceBuffer)buf;
544 buf.get_bounds (out start, out end);
546 sbuf.remove_source_marks (start, end, type);
549 // we should highlight other types of errors..
551 if (!obj.has_member(type)) {
552 print("Return has no errors\n");
555 var err = obj.get_object_member(type);
561 var regex = new Regex("\\.bjs$");
564 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
565 } catch (GLib.RegexError e) {
569 if (!err.has_member(valafn)) {
570 print("File path has no errors\n");
573 var lines = err.get_object_member(valafn);
577 var tlines = buf.get_line_count () +1;
579 lines.foreach_member((obj, line, node) => {
582 // print("get inter\n");
583 var eline = int.parse(line) -1 ;
584 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
587 if (eline > tlines || eline < 0) {
590 sbuf.get_iter_at_line( out iter, eline);
591 //print("mark line\n");
592 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
593 var ar = lines.get_array_member(line);
594 for (var i = 0 ; i < ar.get_length(); i++) {
595 msg += (msg.length > 0) ? "\n" : "";
596 msg += ar.get_string_element(i);
600 sbuf.create_source_mark(msg, type, iter);