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 var filename = this.file.getIconFileName(false);
63 var win = this.el.get_parent_window();
64 var width = win.get_width();
65 var height = win.get_height();
67 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
68 screenshot.save(filename,"png");
80 // should we hold until it's printed...
91 public void loadFile (JsRender.JsRender file)
95 if (file.tree == null) {
99 this.sourceview.loadFile();
103 if (this.lastObj != null) {
104 this.container.el.remove(this.lastObj);
107 // hide the compile view at present..
113 print("ALLOC SET SIZES %d, %d\n", w,h);
115 // set the container size min to 500/500 or 20 px less than max..
116 w = int.max (w-20, 500);
117 h = int.max (h-20, 500);
119 print("SET SIZES %d, %d\n", w,h);
120 _this.container.el.set_size_request(w,h);
122 _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
123 var rgba = Gdk.RGBA ();
125 _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
128 var x = new JsRender.NodeToGtk(file.tree);
129 var obj = x.munge() as Gtk.Widget;
136 this.container.el.add(obj);
142 public class Xcls_notebook : Object
144 public Gtk.Notebook el;
145 private Xcls_GtkView _this;
151 public Xcls_notebook(Xcls_GtkView _owner )
154 _this.notebook = this;
155 this.el = new Gtk.Notebook();
159 // set gobject values
160 var child_0 = new Xcls_label_preview( _this );
162 var child_1 = new Xcls_label_code( _this );
164 var child_2 = new Xcls_ScrolledWindow5( _this );
166 this.el.append_page ( child_2.el , _this.label_preview.el );
167 var child_3 = new Xcls_ScrolledWindow8( _this );
169 this.el.append_page ( child_3.el , _this.label_code.el );
172 // user defined functions
174 public class Xcls_label_preview : Object
177 private Xcls_GtkView _this;
183 public Xcls_label_preview(Xcls_GtkView _owner )
186 _this.label_preview = this;
187 this.el = new Gtk.Label( "Preview" );
191 // set gobject values
194 // user defined functions
197 public class Xcls_label_code : Object
200 private Xcls_GtkView _this;
206 public Xcls_label_code(Xcls_GtkView _owner )
209 _this.label_code = this;
210 this.el = new Gtk.Label( "Preview Generated Code" );
214 // set gobject values
217 // user defined functions
220 public class Xcls_ScrolledWindow5 : Object
222 public Gtk.ScrolledWindow el;
223 private Xcls_GtkView _this;
229 public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
232 this.el = new Gtk.ScrolledWindow( null, null );
236 // set gobject values
237 var child_0 = new Xcls_view_layout( _this );
239 this.el.add ( child_0.el );
242 // user defined functions
244 public class Xcls_view_layout : Object
246 public Gtk.Layout el;
247 private Xcls_GtkView _this;
253 public Xcls_view_layout(Xcls_GtkView _owner )
256 _this.view_layout = this;
257 this.el = new Gtk.Layout( null, null );
261 // set gobject values
262 var child_0 = new Xcls_container( _this );
264 this.el.put ( child_0.el , 10,10 );
267 // user defined functions
269 public class Xcls_container : Object
272 private Xcls_GtkView _this;
278 public Xcls_container(Xcls_GtkView _owner )
281 _this.container = this;
282 this.el = new Gtk.HBox( true, 0 );
286 // set gobject values
289 // user defined functions
294 public class Xcls_ScrolledWindow8 : Object
296 public Gtk.ScrolledWindow el;
297 private Xcls_GtkView _this;
303 public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
306 this.el = new Gtk.ScrolledWindow( null, null );
310 // set gobject values
311 var child_0 = new Xcls_sourceview( _this );
313 this.el.add ( child_0.el );
316 // user defined functions
318 public class Xcls_sourceview : Object
320 public Gtk.SourceView el;
321 private Xcls_GtkView _this;
328 public Xcls_sourceview(Xcls_GtkView _owner )
331 _this.sourceview = this;
332 this.el = new Gtk.SourceView();
337 // set gobject values
338 this.el.editable = false;
339 this.el.show_line_marks = true;
340 this.el.show_line_numbers = true;
346 var description = Pango.FontDescription.from_string("monospace");
347 description.set_size(8000);
348 this.el.override_font(description);
351 var buf = this.el.get_buffer();
352 buf.notify.connect((ps) => {
356 if (ps.name != "cursor-position") {
359 print("cursor changed : %d\n", buf.cursor_position);
361 buf.get_iter_at_offset(out cpos, buf.cursor_position);
363 var ln = cpos.get_line();
365 var node = _this.file.lineToNode(ln);
367 print("can not find node\n");
370 var ltree = _this.main_window.windowstate.left_tree;
371 var tp = ltree.model.treePathFromNode(node);
372 print("got tree path %s\n", tp);
374 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
377 // highlight the node..
383 var attrs = new Gtk.SourceMarkAttributes();
384 var pink = Gdk.RGBA();
385 pink.parse ( "pink");
386 attrs.set_background ( pink);
387 attrs.set_icon_name ( "process-stop");
388 attrs.query_tooltip_text.connect(( mark) => {
389 //print("tooltip query? %s\n", mark.name);
393 this.el.set_mark_attributes ("ERR", attrs, 1);
395 var wattrs = new Gtk.SourceMarkAttributes();
396 var blue = Gdk.RGBA();
397 blue.parse ( "#ABF4EB");
398 wattrs.set_background ( blue);
399 wattrs.set_icon_name ( "process-stop");
400 wattrs.query_tooltip_text.connect(( mark) => {
401 //print("tooltip query? %s\n", mark.name);
405 this.el.set_mark_attributes ("WARN", wattrs, 1);
409 var dattrs = new Gtk.SourceMarkAttributes();
410 var purple = Gdk.RGBA();
411 purple.parse ( "#EEA9FF");
412 dattrs.set_background ( purple);
413 dattrs.set_icon_name ( "process-stop");
414 dattrs.query_tooltip_text.connect(( mark) => {
415 //print("tooltip query? %s\n", mark.name);
419 this.el.set_mark_attributes ("DEPR", dattrs, 1);
422 var gattrs = new Gtk.SourceMarkAttributes();
423 var grey = Gdk.RGBA();
424 grey.parse ( "#ccc");
425 gattrs.set_background ( grey);
428 this.el.set_mark_attributes ("grey", gattrs, 1);
438 // user defined functions
439 public void nodeSelected (JsRender.Node? sel) {
443 // this is connected in widnowstate
444 print("node selected");
445 var buf = this.el.get_buffer();
447 var sbuf = (Gtk.SourceBuffer) buf;
450 while(Gtk.events_pending()) {
451 Gtk.main_iteration();
455 // clear all the marks..
459 sbuf.get_bounds (out start, out end);
460 sbuf.remove_source_marks (start, end, "grey");
468 sbuf.get_iter_at_line(out iter, sel.line_start);
469 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.0f);
471 for (var i = 0; i < buf.get_line_count();i++) {
472 if (i < sel.line_start || i > sel.line_end) {
474 sbuf.get_iter_at_line(out iter, i);
475 sbuf.create_source_mark(null, "grey", iter);
483 public void loadFile ( ) {
485 var buf = this.el.get_buffer();
487 var sbuf = (Gtk.SourceBuffer) buf;
491 if (_this.file == null || _this.file.xtype != "Gtk") {
492 print("xtype != Gtk");
493 this.loading = false;
499 var regex = new Regex("\\.bjs$");
502 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
503 } catch (GLib.RegexError e) {
504 this.loading = false;
508 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
509 print("File path has no errors\n");
510 this.loading = false;
515 GLib.FileUtils.get_contents (valafn, out str);
517 // print("setting str %d\n", str.length);
518 buf.set_text(str, str.length);
519 var lm = Gtk.SourceLanguageManager.get_default();
521 //?? is javascript going to work as js?
523 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
529 sbuf.get_bounds (out start, out end);
530 sbuf.remove_source_marks (start, end, null); // remove all marks..
533 if (_this.main_window.windowstate.last_compile_result != null) {
534 var obj = _this.main_window.windowstate.last_compile_result;
535 this.highlightErrorsJson("ERR", obj);
536 this.highlightErrorsJson("WARN", obj);
537 this.highlightErrorsJson("DEPR", obj);
539 //while (Gtk.events_pending()) {
540 // Gtk.main_iteration();
543 this.loading = false;
545 public void highlightErrorsJson (string type, Json.Object obj) {
549 var buf = this.el.get_buffer();
550 var sbuf = (Gtk.SourceBuffer)buf;
551 buf.get_bounds (out start, out end);
553 sbuf.remove_source_marks (start, end, type);
556 // we should highlight other types of errors..
558 if (!obj.has_member(type)) {
559 print("Return has no errors\n");
562 var err = obj.get_object_member(type);
568 var regex = new Regex("\\.bjs$");
571 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
572 } catch (GLib.RegexError e) {
576 if (!err.has_member(valafn)) {
577 print("File path has no errors\n");
580 var lines = err.get_object_member(valafn);
584 var tlines = buf.get_line_count () +1;
586 lines.foreach_member((obj, line, node) => {
589 // print("get inter\n");
590 var eline = int.parse(line) -1 ;
591 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
594 if (eline > tlines || eline < 0) {
597 sbuf.get_iter_at_line( out iter, eline);
598 //print("mark line\n");
599 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
600 var ar = lines.get_array_member(line);
601 for (var i = 0 ; i < ar.get_length(); i++) {
602 msg += (msg.length > 0) ? "\n" : "";
603 msg += ar.get_string_element(i);
607 sbuf.create_source_mark(msg, type, iter);