1 static Xcls_GladeuiView _GladeuiView;
3 public class Xcls_GladeuiView : Object
6 private Xcls_GladeuiView _this;
8 public static Xcls_GladeuiView singleton()
10 if (_GladeuiView == null) {
11 _GladeuiView= new Xcls_GladeuiView();
15 public Xcls_notebook notebook;
16 public Xcls_label_preview label_preview;
17 public Xcls_label_code label_code;
18 public Xcls_designview designview;
19 public Xcls_sourceview sourceview;
22 public Gtk.Widget lastObj;
23 public Xcls_MainWindow main_window;
24 public int last_search_end;
25 public Gtk.SourceSearchContext searchcontext;
27 public JsRender.JsRender file;
31 public Xcls_GladeuiView()
34 this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
38 this.last_search_end = 0;
44 this.el.hexpand = true;
45 this.el.vexpand = true;
46 var child_0 = new Xcls_Button2( _this );
48 this.el.append( child_0.el );
49 var child_1 = new Xcls_GestureClick5( _this );
51 this.el.add_controller ( child_1.el );
52 var child_2 = new Xcls_ColumnView6( _this );
54 this.el.append( child_2.el );
55 var child_3 = new Xcls_notebook( _this );
57 this.el.pack_start ( child_3.el , true,true,0 );
60 this.el.size_allocate.connect( (aloc) => {
62 this.width = aloc.width;
63 this.height =aloc.height;
67 // user defined functions
68 public void loadFile (JsRender.JsRender file)
75 // clear existing elements from project?
77 var p = this.designview.el.get_project();
78 var li = p.get_objects().copy();
79 // should remove all..
80 for (var i =0; i < li.length(); i++) {
81 p.remove_object(li.nth_data(i));
84 if (file.tree == null) {
88 // print("%s\n",tf.tree.toJsonString());
89 var x = new JsRender.NodeToGlade((Project.Gtk) file.project, file.tree, null);
90 Glade.App.set_window(_this.main_window.el); // see if setting it again forces it to go to the irght locations.
92 FileIOStream iostream;
93 var f = File.new_tmp ("tpl-XXXXXX.glade", out iostream);
94 var ostream = iostream.output_stream;
95 var dostream = new DataOutputStream (ostream);
96 dostream.put_string (x.munge());
98 print("LOADING %s\n",f.get_path ());
99 //p.load_from_file(f.get_path ());
101 p.load_from_file("/tmp/glade.xml");
104 public void initGlade () {
105 _this.designview = new Xcls_designview( _this );
107 var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
109 _this.notebook.el.append_page(box, _this.label_preview.el);
110 Glade.App.set_window(this.main_window.el);
111 // var pal = new Glade.Palette();
112 //var ins = new Glade.Inspector();
114 box.pack_start(_this.designview.el);
115 // box.pack_start(pal);
116 //box.pack_start(ins);
119 _this.designview.el.show();
123 public void forwardSearch (bool change_focus) {
125 if (this.searchcontext == null) {
128 this.notebook.el.page = 1;
129 Gtk.TextIter beg, st,en, stl;
131 var buf = this.sourceview.el.get_buffer();
132 buf.get_iter_at_offset(out beg, this.last_search_end);
133 if (!this.searchcontext.forward(beg, out st, out en)) {
134 this.last_search_end = 0;
136 this.last_search_end = en.get_offset();
138 this.sourceview.el.grab_focus();
140 buf.place_cursor(st);
141 var ln = st.get_line();
142 buf.get_iter_at_line(out stl,ln);
144 this.sourceview.el.scroll_to_iter(stl, 0.0f, true, 0.0f, 0.5f);
148 public int search (string txt) {
149 this.notebook.el.page = 1;
150 var s = new Gtk.SourceSearchSettings();
151 var buf = (Gtk.SourceBuffer) this.sourceview.el.get_buffer();
152 this.searchcontext = new Gtk.SourceSearchContext(buf,s);
153 this.searchcontext.set_highlight(true);
154 s.set_search_text(txt);
156 Gtk.TextIter beg, st,en;
158 buf.get_start_iter(out beg);
159 this.searchcontext.forward(beg, out st, out en);
160 this.last_search_end = 0;
161 return this.searchcontext.get_occurrences_count();
165 public void createThumb () {
168 if (this.file == null) {
171 // only screenshot the gtk preview..
172 if (this.notebook.el.page > 0 ) {
177 var filename = this.file.getIconFileName(false);
179 var win = this.designview.el.get_parent_window();
180 var width = win.get_width();
181 var height = win.get_height();
183 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
184 screenshot.save(filename,"png");
197 public void scroll_to_line (int line) {
198 this.notebook.el.page = 1;// code preview...
200 GLib.Timeout.add(500, () => {
205 var buf = this.sourceview.el.get_buffer();
207 var sbuf = (Gtk.SourceBuffer) buf;
211 sbuf.get_iter_at_line(out iter, line);
212 this.sourceview.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
218 public class Xcls_Button2 : Object
220 public Gtk.Button el;
221 private Xcls_GladeuiView _this;
227 public Xcls_Button2(Xcls_GladeuiView _owner )
230 this.el = new Gtk.Button();
234 // set gobject values
235 var child_0 = new Xcls_Box3( _this );
237 this.el.child = child_0.el;
238 var child_1 = new Xcls_GestureClick4( _this );
240 this.el.add_controller( child_1.el );
243 // user defined functions
245 public class Xcls_Box3 : Object
248 private Xcls_GladeuiView _this;
254 public Xcls_Box3(Xcls_GladeuiView _owner )
257 this.el = new Gtk.Box( null, 0 );
261 // set gobject values
264 // user defined functions
267 public class Xcls_GestureClick4 : Object
269 public Gtk.GestureClick el;
270 private Xcls_GladeuiView _this;
276 public Xcls_GestureClick4(Xcls_GladeuiView _owner )
279 this.el = new Gtk.GestureClick();
283 // set gobject values
286 this.el.pressed.connect( (n_press, x, y) => {
292 // user defined functions
296 public class Xcls_GestureClick5 : Object
298 public Gtk.GestureClick el;
299 private Xcls_GladeuiView _this;
305 public Xcls_GestureClick5(Xcls_GladeuiView _owner )
308 this.el = new Gtk.GestureClick();
312 // set gobject values
315 // user defined functions
318 public class Xcls_ColumnView6 : Object
320 public Gtk.ColumnView el;
321 private Xcls_GladeuiView _this;
327 public Xcls_ColumnView6(Xcls_GladeuiView _owner )
330 this.el = new Gtk.ColumnView( null );
334 // set gobject values
335 var child_0 = new Xcls_SingleSelection7( _this );
337 this.el.model = child_0.el;
338 var child_1 = new Xcls_ColumnViewColumn9( _this );
340 this.el.append( child_1.el );
343 // user defined functions
345 public class Xcls_SingleSelection7 : Object
347 public Gtk.SingleSelection el;
348 private Xcls_GladeuiView _this;
354 public Xcls_SingleSelection7(Xcls_GladeuiView _owner )
357 this.el = new Gtk.SingleSelection( null );
361 // set gobject values
362 var child_0 = new Xcls_TreeListModel8( _this );
364 this.el.model = child_0.el;
367 // user defined functions
369 public class Xcls_TreeListModel8 : Object
371 public Gtk.TreeListModel el;
372 private Xcls_GladeuiView _this;
378 public Xcls_TreeListModel8(Xcls_GladeuiView _owner )
381 this.el = new Gtk.TreeListModel( null, true, true, () => { } );
385 // set gobject values
388 // user defined functions
392 public class Xcls_ColumnViewColumn9 : Object
394 public Gtk.ColumnViewColumn el;
395 private Xcls_GladeuiView _this;
401 public Xcls_ColumnViewColumn9(Xcls_GladeuiView _owner )
404 this.el = new Gtk.ColumnViewColumn( "", null );
408 // set gobject values
411 // user defined functions
415 public class Xcls_notebook : Object
417 public Gtk.Notebook el;
418 private Xcls_GladeuiView _this;
424 public Xcls_notebook(Xcls_GladeuiView _owner )
427 _this.notebook = this;
428 this.el = new Gtk.Notebook();
432 // set gobject values
433 var child_0 = new Xcls_label_preview( _this );
435 var child_1 = new Xcls_label_code( _this );
437 var child_2 = new Xcls_designview( _this );
439 var child_3 = new Xcls_sourceview( _this );
441 this.el.append_page ( child_3.el , _this.label_code.el );
444 // user defined functions
446 public class Xcls_label_preview : Object
449 private Xcls_GladeuiView _this;
455 public Xcls_label_preview(Xcls_GladeuiView _owner )
458 _this.label_preview = this;
459 this.el = new Gtk.Label( "Preview" );
463 // set gobject values
466 // user defined functions
469 public class Xcls_label_code : Object
472 private Xcls_GladeuiView _this;
478 public Xcls_label_code(Xcls_GladeuiView _owner )
481 _this.label_code = this;
482 this.el = new Gtk.Label( "Preview Generated Code" );
486 // set gobject values
489 // user defined functions
492 public class Xcls_designview : Object
494 public Glade.DesignView el;
495 private Xcls_GladeuiView _this;
499 public JsRender.JsRender file;
502 public Xcls_designview(Xcls_GladeuiView _owner )
505 _this.designview = this;
506 this.el = _this.main_window == null ? null : new Glade.DesignView(_this.main_window.gladeproject);
516 // user defined functions
517 public void test () {
520 public void createThumb () {
523 if (this.file == null) {
526 var filename = this.file.getIconFileName(false);
528 var win = this.el.get_parent_window();
529 var width = win.get_width();
530 var height = win.get_height();
532 Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
534 screenshot.save(filename,"png");
542 public class Xcls_sourceview : Object
544 public Gtk.SourceView el;
545 private Xcls_GladeuiView _this;
550 public gboolean show_line_numbers;
551 public bool allow_node_scroll;
552 public gboolean show_line_marks;
553 public gboolean editable;
556 public Xcls_sourceview(Xcls_GladeuiView _owner )
559 _this.sourceview = this;
560 this.el = new Gtk.SourceView();
564 this.show_line_numbers = true;
565 this.allow_node_scroll = true;
566 this.show_line_marks = true;
567 this.editable = false;
573 var description = Pango.FontDescription.from_string("monospace");
574 description.set_size(8000);
575 this.el.override_font(description);
578 var buf = this.el.get_buffer();
579 buf.notify.connect((ps) => {
583 if (ps.name != "cursor-position") {
586 print("cursor changed : %d\n", buf.cursor_position);
588 buf.get_iter_at_offset(out cpos, buf.cursor_position);
590 var ln = cpos.get_line();
592 var node = _this.file.lineToNode(ln);
595 print("can not find node\n");
598 var ltree = _this.main_window.windowstate.left_tree;
599 var tp = ltree.model.treePathFromNode(node);
600 print("got tree path %s\n", tp);
602 this.allow_node_scroll = false;
603 print("changing cursor on tree..\n");
604 ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
605 // scrolling is disabled... as node selection calls scroll 10ms after it changes.
606 GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
607 this.allow_node_scroll = true;
612 // highlight the node..
618 var attrs = new Gtk.SourceMarkAttributes();
619 var pink = Gdk.RGBA();
620 pink.parse ( "pink");
621 attrs.set_background ( pink);
622 attrs.set_icon_name ( "process-stop");
623 attrs.query_tooltip_text.connect(( mark) => {
624 //print("tooltip query? %s\n", mark.name);
628 this.el.set_mark_attributes ("ERR", attrs, 1);
630 var wattrs = new Gtk.SourceMarkAttributes();
631 var blue = Gdk.RGBA();
632 blue.parse ( "#ABF4EB");
633 wattrs.set_background ( blue);
634 wattrs.set_icon_name ( "process-stop");
635 wattrs.query_tooltip_text.connect(( mark) => {
636 //print("tooltip query? %s\n", mark.name);
640 this.el.set_mark_attributes ("WARN", wattrs, 1);
644 var dattrs = new Gtk.SourceMarkAttributes();
645 var purple = Gdk.RGBA();
646 purple.parse ( "#EEA9FF");
647 dattrs.set_background ( purple);
648 dattrs.set_icon_name ( "process-stop");
649 dattrs.query_tooltip_text.connect(( mark) => {
650 //print("tooltip query? %s\n", mark.name);
654 this.el.set_mark_attributes ("DEPR", dattrs, 1);
657 var gattrs = new Gtk.SourceMarkAttributes();
658 var grey = Gdk.RGBA();
659 grey.parse ( "#ccc");
660 gattrs.set_background ( grey);
663 this.el.set_mark_attributes ("grey", gattrs, 1);
673 // user defined functions
674 public void loadFile ( ) {
678 var buf = this.el.get_buffer();
680 var sbuf = (Gtk.SourceBuffer) buf;
684 if (_this.file == null || _this.file.xtype != "Gtk") {
685 print("xtype != Gtk");
686 this.loading = false;
692 var regex = new Regex("\\.bjs$");
695 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
696 } catch (GLib.RegexError e) {
697 this.loading = false;
702 if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
703 print("File path has no errors\n");
704 this.loading = false;
711 GLib.FileUtils.get_contents (valafn, out str);
713 this.loading = false;
717 // print("setting str %d\n", str.length);
718 buf.set_text(str, str.length);
719 var lm = Gtk.SourceLanguageManager.get_default();
721 //?? is javascript going to work as js?
723 ((Gtk.SourceBuffer)(buf)) .set_language(lm.get_language(_this.file.language));
729 sbuf.get_bounds (out start, out end);
730 sbuf.remove_source_marks (start, end, null); // remove all marks..
733 if (_this.main_window.windowstate.last_compile_result != null) {
734 var obj = _this.main_window.windowstate.last_compile_result;
735 this.highlightErrorsJson("ERR", obj);
736 this.highlightErrorsJson("WARN", obj);
737 this.highlightErrorsJson("DEPR", obj);
739 //while (Gtk.events_pending()) {
740 // Gtk.main_iteration();
743 this.loading = false;
745 public void nodeSelected (JsRender.Node? sel) {
749 // this is connected in widnowstate
750 print("Roo-view - node selected\n");
751 var buf = this.el.get_buffer();
753 var sbuf = (Gtk.SourceBuffer) buf;
756 while(Gtk.events_pending()) {
757 Gtk.main_iteration();
761 // clear all the marks..
765 sbuf.get_bounds (out start, out end);
766 sbuf.remove_source_marks (start, end, "grey");
774 sbuf.get_iter_at_line(out iter, sel.line_start);
777 Gtk.TextIter cur_iter;
778 sbuf.get_iter_at_offset(out cur_iter, sbuf.cursor_position);
780 //var cur_line = cur_iter.get_line();
781 //if (cur_line > sel.line_start && cur_line < sel.line_end) {
784 if (this.allow_node_scroll) {
786 this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
791 for (var i = 0; i < buf.get_line_count();i++) {
792 if (i < sel.line_start || i > sel.line_end) {
794 sbuf.get_iter_at_line(out iter, i);
795 sbuf.create_source_mark(null, "grey", iter);
803 public void highlightErrorsJson (string type, Json.Object obj) {
807 var buf = this.el.get_buffer();
808 var sbuf = (Gtk.SourceBuffer)buf;
809 buf.get_bounds (out start, out end);
811 sbuf.remove_source_marks (start, end, type);
814 // we should highlight other types of errors..
816 if (!obj.has_member(type)) {
817 print("Return has no errors\n");
820 var err = obj.get_object_member(type);
822 if (_this.file == null) {
823 return; // just in case the file has not loaded yet?
829 var regex = new Regex("\\.bjs$");
832 valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
833 } catch (GLib.RegexError e) {
837 if (!err.has_member(valafn)) {
838 print("File path has no errors\n");
841 var lines = err.get_object_member(valafn);
845 var tlines = buf.get_line_count () +1;
847 lines.foreach_member((obj, line, node) => {
850 // print("get inter\n");
851 var eline = int.parse(line) -1 ;
852 print("GOT ERROR on line %s -- converted to %d\n", line,eline);
855 if (eline > tlines || eline < 0) {
858 sbuf.get_iter_at_line( out iter, eline);
859 //print("mark line\n");
860 var msg = type + " on line: %d - %s".printf(eline+1, valafn);
861 var ar = lines.get_array_member(line);
862 for (var i = 0 ; i < ar.get_length(); i++) {
863 msg += (msg.length > 0) ? "\n" : "";
864 msg += ar.get_string_element(i);
868 sbuf.create_source_mark(msg, type, iter);
876 public string toString () {
879 this.el.get_buffer().get_start_iter(out s);
880 this.el.get_buffer().get_end_iter(out e);
881 var ret = this.el.get_buffer().get_text(s,e,true);
882 //print("TO STRING? " + ret);