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);
350 var node = _this.file.lineToNode(buf.cursor_position);
351 // highlight the node..
357 var attrs = new Gtk.SourceMarkAttributes();
358 var pink = new Gdk.RGBA();
359 pink.parse ( "pink");
360 attrs.set_background ( pink);
361 attrs.set_icon_name ( "process-stop");
362 attrs.query_tooltip_text.connect(( mark) => {
363 //print("tooltip query? %s\n", mark.name);
367 this.el.set_mark_attributes ("ERR", attrs, 1);
369 var wattrs = new Gtk.SourceMarkAttributes();
370 var blue = new Gdk.RGBA();
371 blue.parse ( "#ABF4EB");
372 wattrs.set_background ( blue);
373 wattrs.set_icon_name ( "process-stop");
374 wattrs.query_tooltip_text.connect(( mark) => {
375 //print("tooltip query? %s\n", mark.name);
379 this.el.set_mark_attributes ("WARN", wattrs, 1);
383 var dattrs = new Gtk.SourceMarkAttributes();
384 var purple = new Gdk.RGBA();
385 purple.parse ( "#EEA9FF");
386 dattrs.set_background ( purple);
387 dattrs.set_icon_name ( "process-stop");
388 dattrs.query_tooltip_text.connect(( mark) => {
389 //print("tooltip query? %s\n", mark.name);
393 this.el.set_mark_attributes ("DEPR", dattrs, 1);
396 var gattrs = new Gtk.SourceMarkAttributes();
397 var grey = new Gdk.RGBA();
398 grey.parse ( "#ccc");
399 gattrs.set_background ( grey);
402 this.el.set_mark_attributes ("grey", gattrs, 1);
412 // user defined functions
413 public void nodeSelected (JsRender.Node? sel) {
417 // this is connected in widnowstate
418 print("node selected");
419 var buf = this.el.get_buffer();
421 var sbuf = (Gtk.SourceBuffer) buf;
424 while(Gtk.events_pending()) {
425 Gtk.main_iteration();
429 // clear all the marks..
433 sbuf.get_bounds (out start, out end);
434 sbuf.remove_source_marks (start, end, "grey");
442 sbuf.get_iter_at_line(out iter, sel.line_start);
443 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
445 for (var i = 0; i < buf.get_line_count();i++) {
446 if (i < sel.line_start || i > sel.line_end) {
448 sbuf.get_iter_at_line(out iter, i);
449 sbuf.create_source_mark(null, "grey", iter);
457 public void loadFile ( ) {
458 var buf = this.el.get_buffer();
460 var sbuf = (Gtk.SourceBuffer) buf;
464 if (_this.file == null || _this.file.xtype != "Gtk") {
465 print("xtype != Gtk");
471 var regex = new Regex("\\.bjs$");
474 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
475 } catch (GLib.RegexError e) {
479 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
480 print("File path has no errors\n");
485 GLib.FileUtils.get_contents (valafn, out str);
487 // print("setting str %d\n", str.length);
488 buf.set_text(str, str.length);
489 var lm = Gtk.SourceLanguageManager.get_default();
491 //?? is javascript going to work as js?
493 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
499 sbuf.get_bounds (out start, out end);
500 sbuf.remove_source_marks (start, end, null); // remove all marks..
503 if (_this.main_window.windowstate.last_compile_result != null) {
504 var obj = _this.main_window.windowstate.last_compile_result;
505 this.highlightErrorsJson("ERR", obj);
506 this.highlightErrorsJson("WARN", obj);
507 this.highlightErrorsJson("DEPR", obj);
511 public void highlightErrorsJson (string type, Json.Object obj) {
515 var buf = this.el.get_buffer();
516 var sbuf = (Gtk.SourceBuffer)buf;
517 buf.get_bounds (out start, out end);
519 sbuf.remove_source_marks (start, end, type);
522 // we should highlight other types of errors..
524 if (!obj.has_member(type)) {
525 print("Return has no errors\n");
528 var err = obj.get_object_member(type);
534 var regex = new Regex("\\.bjs$");
537 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
538 } catch (GLib.RegexError e) {
542 if (!err.has_member(valafn)) {
543 print("File path has no errors\n");
546 var lines = err.get_object_member(valafn);
550 var tlines = buf.get_line_count () +1;
552 lines.foreach_member((obj, line, node) => {
555 // print("get inter\n");
556 var eline = int.parse(line) -1 ;
557 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
560 if (eline > tlines || eline < 0) {
563 sbuf.get_iter_at_line( out iter, eline);
564 //print("mark line\n");
565 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
566 var ar = lines.get_array_member(line);
567 for (var i = 0 ; i < ar.get_length(); i++) {
568 msg += (msg.length > 0) ? "\n" : "";
569 msg += ar.get_string_element(i);
573 sbuf.create_source_mark(msg, type, iter);