-static Xcls_GtkView _GtkView;
+static Xcls_WindowRooView _WindowRooView;
-public class Xcls_GtkView : Object
+public class Xcls_WindowRooView : Object
{
public Gtk.Box el;
- private Xcls_GtkView _this;
+ private Xcls_WindowRooView _this;
- public static Xcls_GtkView singleton()
+ public static Xcls_WindowRooView singleton()
{
- if (_GtkView == null) {
- _GtkView= new Xcls_GtkView();
+ if (_WindowRooView == null) {
+ _WindowRooView= new Xcls_WindowRooView();
}
- return _GtkView;
+ return _WindowRooView;
}
public Xcls_notebook notebook;
public Xcls_label_preview label_preview;
public Xcls_label_code label_code;
- public Xcls_view_layout view_layout;
- public Xcls_container container;
+ public Xcls_paned paned;
+ public Xcls_viewbox viewbox;
+ public Xcls_AutoRedraw AutoRedraw;
+ public Xcls_viewcontainer viewcontainer;
+ public Xcls_view view;
+ public Xcls_inspectorcontainer inspectorcontainer;
public Xcls_sourceview sourceview;
// my vars (def)
public Xcls_MainWindow main_window;
// ctor
- public Xcls_GtkView()
+ public Xcls_WindowRooView()
{
_this = this;
this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
var child_0 = new Xcls_notebook( _this );
child_0.ref();
this.el.pack_start ( child_0.el , true,true,0 );
-
- //listeners
- this.el.size_allocate.connect( (aloc) => {
-
- this.width = aloc.width;
- this.height =aloc.height;
- });
}
// user defined functions
if (this.file == null) {
return;
}
- // only screenshot the gtk preview..
- if (this.notebook.el.page > 0 ) {
+ if (this.notebook.el.page > 0 ) {
return;
}
-
var filename = this.file.getIconFileName(false);
var win = this.el.get_parent_window();
var width = win.get_width();
- var height = win.get_height();
- try {
- Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, height); // this.el.position?
- screenshot.save(filename,"png");
- } catch (Error e) {
-
+ // var height = win.get_height();
+ try {
+ Gdk.Pixbuf screenshot = Gdk.pixbuf_get_from_window(win, 0, 0, width, this.paned.el.position);
+ screenshot.save(filename,"png");
+ } catch(Error e) {
+ //noop
}
-
- return;
-
-
-
- // should we hold until it's printed...
-
-
-
-
-
-
-
}
- public void loadFile (JsRender.JsRender file)
+ public void loadFile (JsRender.JsRender file)
{
- this.file = null;
-
- if (file.tree == null) {
- return;
- }
- this.notebook.el.page = 0;// gtk preview
-
-
-
- this.file = file;
- this.sourceview.loadFile();
- this.searchcontext = null;
-
-
- if (this.lastObj != null) {
- this.container.el.remove(this.lastObj);
- }
-
- // hide the compile view at present..
-
-
- var w = this.width;
- var h = this.height;
-
- print("ALLOC SET SIZES %d, %d\n", w,h);
-
- // set the container size min to 500/500 or 20 px less than max..
- w = int.max (w-20, 500);
- h = int.max (h-20, 500);
-
- print("SET SIZES %d, %d\n", w,h);
- _this.container.el.set_size_request(w,h);
-
- _this.view_layout.el.set_size(w,h); // should be baded on calc.. -- see update_scrolled.
- var rgba = Gdk.RGBA ();
- rgba.parse ("#ccc");
- _this.view_layout.el.override_background_color(Gtk.StateFlags.NORMAL, rgba);
-
-
- var x = new JsRender.NodeToGtk(file.tree);
- var obj = x.munge() as Gtk.Widget;
- this.lastObj = null;
- if (obj == null) {
- return;
- }
- this.lastObj = obj;
-
- this.container.el.add(obj);
- obj.show_all();
-
-
-
+ this.file = file;
+ this.view.renderJS(true);
+ this.notebook.el.page = 0;// gtk preview
+ this.sourceview.loadFile();
+
}
public int search (string txt) {
this.notebook.el.page = 1;
}
- public void forwardSearch () {
+ public void requestRedraw () {
+ this.view.renderJS(false);
+ this.sourceview.loadFile();
+ }
+ public void forwardSearch (bool change_focus) {
if (this.searchcontext == null) {
return;
this.last_search_end = 0;
} else {
this.last_search_end = en.get_offset();
-
- this.sourceview.el.grab_focus();
-
+ if (change_focus) {
+ this.sourceview.el.grab_focus();
+ }
buf.place_cursor(st);
var ln = st.get_line();
buf.get_iter_at_line(out stl,ln);
public class Xcls_notebook : Object
{
public Gtk.Notebook el;
- private Xcls_GtkView _this;
+ private Xcls_WindowRooView _this;
// my vars (def)
// ctor
- public Xcls_notebook(Xcls_GtkView _owner )
+ public Xcls_notebook(Xcls_WindowRooView _owner )
{
_this = _owner;
_this.notebook = this;
child_0.ref();
var child_1 = new Xcls_label_code( _this );
child_1.ref();
- var child_2 = new Xcls_ScrolledWindow5( _this );
+ var child_2 = new Xcls_paned( _this );
child_2.ref();
- this.el.append_page ( child_2.el , _this.label_preview.el );
- var child_3 = new Xcls_ScrolledWindow8( _this );
+ this.el.add ( child_2.el );
+ var child_3 = new Xcls_ScrolledWindow14( _this );
child_3.ref();
this.el.append_page ( child_3.el , _this.label_code.el );
}
public class Xcls_label_preview : Object
{
public Gtk.Label el;
- private Xcls_GtkView _this;
+ private Xcls_WindowRooView _this;
// my vars (def)
// ctor
- public Xcls_label_preview(Xcls_GtkView _owner )
+ public Xcls_label_preview(Xcls_WindowRooView _owner )
{
_this = _owner;
_this.label_preview = this;
public class Xcls_label_code : Object
{
public Gtk.Label el;
- private Xcls_GtkView _this;
+ private Xcls_WindowRooView _this;
// my vars (def)
// ctor
- public Xcls_label_code(Xcls_GtkView _owner )
+ public Xcls_label_code(Xcls_WindowRooView _owner )
{
_this = _owner;
_this.label_code = this;
// user defined functions
}
- public class Xcls_ScrolledWindow5 : Object
+ public class Xcls_paned : Object
{
- public Gtk.ScrolledWindow el;
- private Xcls_GtkView _this;
+ public Gtk.Paned el;
+ private Xcls_WindowRooView _this;
// my vars (def)
// ctor
- public Xcls_ScrolledWindow5(Xcls_GtkView _owner )
+ public Xcls_paned(Xcls_WindowRooView _owner )
{
_this = _owner;
- this.el = new Gtk.ScrolledWindow( null, null );
+ _this.paned = this;
+ this.el = new Gtk.Paned( Gtk.Orientation.VERTICAL );
// my vars (dec)
// set gobject values
- var child_0 = new Xcls_view_layout( _this );
+ var child_0 = new Xcls_viewbox( _this );
child_0.ref();
- this.el.add ( child_0.el );
+ this.el.pack1 ( child_0.el , true,true );
+ var child_1 = new Xcls_inspectorcontainer( _this );
+ child_1.ref();
+ this.el.pack2 ( child_1.el , true,true );
}
// user defined functions
}
- public class Xcls_view_layout : Object
+ public class Xcls_viewbox : Object
{
- public Gtk.Layout el;
- private Xcls_GtkView _this;
+ public Gtk.Box el;
+ private Xcls_WindowRooView _this;
// my vars (def)
// ctor
- public Xcls_view_layout(Xcls_GtkView _owner )
+ public Xcls_viewbox(Xcls_WindowRooView _owner )
{
_this = _owner;
- _this.view_layout = this;
- this.el = new Gtk.Layout( null, null );
+ _this.viewbox = this;
+ this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
// my vars (dec)
// set gobject values
- var child_0 = new Xcls_container( _this );
+ this.el.homogeneous = false;
+ var child_0 = new Xcls_Box7( _this );
child_0.ref();
- this.el.put ( child_0.el , 10,10 );
+ this.el.pack_start ( child_0.el , false,true,0 );
+ var child_1 = new Xcls_viewcontainer( _this );
+ child_1.ref();
+ this.el.pack_end ( child_1.el , true,true,0 );
}
// user defined functions
}
- public class Xcls_container : Object
+ public class Xcls_Box7 : Object
{
public Gtk.Box el;
- private Xcls_GtkView _this;
+ private Xcls_WindowRooView _this;
// my vars (def)
// ctor
- public Xcls_container(Xcls_GtkView _owner )
+ public Xcls_Box7(Xcls_WindowRooView _owner )
{
_this = _owner;
- _this.container = this;
this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
// my vars (dec)
// set gobject values
+ this.el.homogeneous = true;
+ this.el.height_request = 20;
+ this.el.vexpand = false;
+ var child_0 = new Xcls_Button8( _this );
+ child_0.ref();
+ this.el.pack_start ( child_0.el , false,false,0 );
+ var child_1 = new Xcls_AutoRedraw( _this );
+ child_1.ref();
+ this.el.pack_start ( child_1.el , false,false,0 );
+ var child_2 = new Xcls_Button10( _this );
+ child_2.ref();
+ this.el.pack_start ( child_2.el , false,false,0 );
+ }
+
+ // user defined functions
+ }
+ public class Xcls_Button8 : Object
+ {
+ public Gtk.Button el;
+ private Xcls_WindowRooView _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_Button8(Xcls_WindowRooView _owner )
+ {
+ _this = _owner;
+ this.el = new Gtk.Button();
+
+ // my vars (dec)
+
+ // set gobject values
+ this.el.label = "Redraw";
+
+ //listeners
+ this.el.clicked.connect( ( ) => {
+ _this.view.renderJS( true);
+ });
}
// user defined functions
}
+ public class Xcls_AutoRedraw : Object
+ {
+ public Gtk.CheckButton el;
+ private Xcls_WindowRooView _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_AutoRedraw(Xcls_WindowRooView _owner )
+ {
+ _this = _owner;
+ _this.AutoRedraw = this;
+ this.el = new Gtk.CheckButton();
+
+ // my vars (dec)
+
+ // set gobject values
+ this.el.active = true;
+ this.el.label = "Auto Redraw On";
+
+ //listeners
+ this.el.toggled.connect( (state) => {
+ this.el.set_label(this.el.active ? "Auto Redraw On" : "Auto Redraw Off");
+ });
+ }
+
+ // user defined functions
+ }
+
+ public class Xcls_Button10 : Object
+ {
+ public Gtk.Button el;
+ private Xcls_WindowRooView _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_Button10(Xcls_WindowRooView _owner )
+ {
+ _this = _owner;
+ this.el = new Gtk.Button();
+
+ // my vars (dec)
+
+ // set gobject values
+ this.el.label = "Full Redraw";
+
+ //listeners
+ this.el.clicked.connect( () => {
+ _this.view.redraws = 99;
+ _this.view.el.web_context.clear_cache();
+ //_this.view.renderJS(true);
+ FakeServerCache.clear();
+ _this.view.reInit();
+
+ });
+ }
+
+ // user defined functions
+ }
+
+
+ public class Xcls_viewcontainer : Object
+ {
+ public Gtk.ScrolledWindow el;
+ private Xcls_WindowRooView _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_viewcontainer(Xcls_WindowRooView _owner )
+ {
+ _this = _owner;
+ _this.viewcontainer = this;
+ this.el = new Gtk.ScrolledWindow( null, null );
+
+ // my vars (dec)
+
+ // set gobject values
+ this.el.shadow_type = Gtk.ShadowType.IN;
+ var child_0 = new Xcls_view( _this );
+ child_0.ref();
+ this.el.add ( child_0.el );
+
+ // init method
+
+ this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
+ }
+
+ // user defined functions
+ }
+ public class Xcls_view : Object
+ {
+ public WebKit.WebView el;
+ private Xcls_WindowRooView _this;
+
+
+ // my vars (def)
+ public string renderedData;
+ public bool refreshRequired;
+ public WebKit.WebInspector inspector;
+ public string runjs;
+ public int redraws;
+ public GLib.DateTime lastRedraw;
+ public string runhtml;
+ public bool pendingRedraw;
+
+ // ctor
+ public Xcls_view(Xcls_WindowRooView _owner )
+ {
+ _this = _owner;
+ _this.view = this;
+ this.el = new WebKit.WebView();
+
+ // my vars (dec)
+ this.renderedData = "";
+ this.refreshRequired = false;
+ this.runjs = "";
+ this.redraws = 0;
+ this.lastRedraw = null;
+ this.runhtml = "";
+ this.pendingRedraw = false;
+
+ // set gobject values
+
+ // init method
+
+ {
+ // this may not work!?
+ var settings = this.el.get_settings();
+ settings.enable_developer_extras = true;
+
+
+ var fs= new FakeServer(this.el);
+ fs.ref();
+ // this was an attempt to change the url perms.. did not work..
+ // settings.enable_file_access_from_file_uris = true;
+ // settings.enable_offline_web_application_cache - true;
+ // settings.enable_universal_access_from_file_uris = true;
+
+
+
+
+
+
+ // FIXME - base url of script..
+ // we need it so some of the database features work.
+ this.el.load_html( "Render not ready" ,
+ //fixme - should be a config option!
+ // or should we catch stuff and fix it up..
+ "http://localhost/app.Builder/"
+ );
+
+
+ //this.el.open('file:///' + __script_path__ + '/../builder.html');
+ /*
+ Gtk.drag_dest_set
+ (
+ this.el, //
+ Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT,
+ null, // list of targets
+ Gdk.DragAction.COPY // what to do with data after dropped
+ );
+
+ // print("RB: TARGETS : " + LeftTree.atoms["STRING"]);
+ Gtk.drag_dest_set_target_list(this.el, this.get('/Window').targetList);
+ */
+ GLib.Timeout.add_seconds(1, () =>{
+ //print("run refresh?");
+ if (this.el == null) {
+ return false;
+ }
+ this.runRefresh();
+ return true;
+ });
+
+
+ }
+
+ //listeners
+ this.el.script_dialog.connect( (dialog) => {
+ if (this.el == null) {
+ return true;
+ }
+
+ var msg = dialog.get_message();
+ if (msg.length < 4) {
+ return false;
+ }
+ if (msg.substring(0,4) != "IPC:") {
+ return false;
+ }
+ var ar = msg.split(":", 3);
+ if (ar.length < 3) {
+ return false;
+ }
+ switch(ar[1]) {
+ case "SAVEHTML":
+ _this.file.saveHTML(ar[2]);
+ return true;
+ default:
+ return false;
+ }
+
+ });
+ this.el.show.connect( ( ) => {
+ this.initInspector();;
+ });
+ this.el.drag_drop.connect( ( ctx, x, y,time, ud) => {
+ return false;
+ /*
+ print("TARGET: drag-drop");
+ var is_valid_drop_site = true;
+
+
+ Gtk.drag_get_data
+ (
+ w, // will receive 'drag-data-received' signal
+ ctx, /* represents the current state of the DnD
+ this.get('/Window').atoms["STRING"], /* the target type we want
+ time /* time stamp
+ );
+
+
+ /* No target offered by source => error
+
+
+ return is_valid_drop_site;
+ */
+ });
+ this.el.load_changed.connect( (le) => {
+ if (le != WebKit.LoadEvent.FINISHED) {
+ return;
+ }
+ if (this.runjs.length < 1) {
+ return;
+ }
+ // this.el.run_javascript(this.runjs, null);
+ FakeServerCache.remove( this.runjs);
+ this.runjs = "";
+ });
+ }
+
+ // user defined functions
+ public void reInit () {
+ print("reInit?");
+ // if this happens destroy the webkit..
+ // recreate it..
+ this.el.stop_loading();
+
+ if (_this.viewbox.el.get_parent() == null) {
+ return;
+ }
+
+
+ _this.viewbox.el.remove(_this.viewcontainer.el);
+ _this.paned.el.remove(_this.inspectorcontainer.el);
+
+ // destory seems to cause problems.
+ //this.el.destroy();
+ //_this.viewcontainer.el.destroy();
+ //_this.inspectorcontainer.el.destroy();
+ var inv =new Xcls_inspectorcontainer(_this);
+ inv.ref();
+ _this.paned.el.pack2(inv.el,true,true);
+
+
+ this.el = null;
+ var nv =new Xcls_viewcontainer(_this);
+ nv.ref();
+ _this.viewbox.el.pack_end(nv.el,true,true,0);
+
+
+ inv.el.show_all();
+ nv.el.show_all();
+ //while(Gtk.events_pending ()) Gtk.main_iteration ();
+ //_this.view.renderJS(true);
+ _this.view.refreshRequired = true;
+ }
+ public void runRefresh ()
+ {
+ // this is run every 2 seconds from the init..
+
+
+
+ if (!this.refreshRequired) {
+ // print("no refresh required");
+ return;
+ }
+
+ if (this.lastRedraw != null) {
+ // do not redraw if last redraw was less that 5 seconds ago.
+ if ((int64)(new DateTime.now_local()).difference(this.lastRedraw) < 5000 ) {
+ return;
+ }
+ }
+
+ if (_this.file == null) {
+ return;
+ }
+
+
+ this.refreshRequired = false;
+ // print("HTML RENDERING");
+
+
+ //this.get('/BottomPane').el.show();
+ //this.get('/BottomPane').el.set_current_page(2);// webkit inspector
+ _this.file.webkit_page_id = this.el.get_page_id();
+
+ var js = _this.file.toSourcePreview();
+
+ if (js.length < 1) {
+ print("no data");
+ return;
+ }
+ // var data = js[0];
+ this.redraws++;
+
+ var project = _this.file.project;
+
+ //print (project.fn);
+ // set it to non-empty.
+
+ // runhtml = runhtml.length ? runhtml : '<script type="text/javascript"></script>';
+
+
+ // this.runhtml = this.runhtml || '';
+
+
+ // then we need to reload the browser using
+ // load_html_string..
+
+ // then trigger a redraw once it's loaded..
+ this.pendingRedraw = true;
+
+ var runhtml = "<script type=\"text/javascript\">\n" ;
+ string builderhtml;
+
+ try {
+ GLib.FileUtils.get_contents(BuilderApplication.configDirectory() + "/resources/roo.builder.js", out builderhtml);
+ } catch (Error e) {
+ builderhtml = "";
+ }
+
+ runhtml += builderhtml + "\n";
+ runhtml += "</script>\n" ;
+
+ // fix to make sure they are the same..
+ this.runhtml = project.runhtml;
+ // need to modify paths
+
+ string inhtml;
+ var base_template = _this.file.project.base_template;
+
+ if (base_template.length > 0 && !FileUtils.test(
+ BuilderApplication.configDirectory() + "/resources/" + base_template, FileTest.EXISTS)
+ ) {
+ print("invalid base_template name - using default: %s\n", base_template);
+ base_template = "";
+
+ }
+ try {
+ GLib.FileUtils.get_contents(
+ BuilderApplication.configDirectory() + "/resources/" +
+ (base_template.length > 0 ? base_template : "roo.builder.html")
+ , out inhtml);
+
+ } catch (Error e) {
+ inhtml = "";
+ }
+ this.renderedData = js;
+
+
+ string js_src = js + "\n" +
+ "Roo.onReady(function() {\n" +
+ "if (" + _this.file.name +".show) " + _this.file.name +".show({});\n" +
+ "Roo.XComponent.build();\n" +
+ "});\n";
+
+ // print("render js: " + js);
+ //if (!this.ready) {
+ // console.log('not loaded yet');
+ //}
+ this.lastRedraw = new DateTime.now_local();
+
+
+ //this.runjs = js_src;
+ var fc = FakeServerCache.factory_with_data(js_src);
+ this.runjs = fc.fname;
+
+ var html = inhtml.replace("</head>", runhtml + this.runhtml +
+ "<script type=\"text/javascript\" src=\"xhttp://localhost" + fc.fname + "\"></script>" +
+ // "<script type=\"text/javascript\">\n" +
+ // js_src + "\n" +
+ // "</script>" +
+
+ "</head>");
+ //print("LOAD HTML " + html);
+
+ var rootURL = _this.file.project.rootURL;
+
+
+
+ this.el.load_html( html ,
+ //fixme - should be a config option!
+ (rootURL.length > 0 ? rootURL : "xhttp://localhost/app.Builder.js/")
+ );
+
+ // force the inspector...
+ // this.initInspector();
+
+ // - no need for this, the builder javascript will call it when build is complete
+ //GLib.Timeout.add_seconds(1, () => {
+ // this.el.run_javascript("Builder.saveHTML()",null);
+ // return false;
+ //});
+ // print( "before render" + this.lastRedraw);
+ // print( "after render" + (new Date()));
+
+ }
+ public void initInspector () {
+
+ /* if (this.inspector == this.el.get_inspector()) {
+ this.inspector.show();
+ this.inspector.open_window();
+ print("init inspecter called, and inspector is the same as existing\n");
+ return;
+ }
+ print("new inspector?\n");
+ */
+ this.inspector = this.el.get_inspector();
+ this.inspector.ref();
+
+ // got a new inspector...
+
+ this.inspector.open_window.connect(() => {
+ this.inspector = this.el.get_inspector();
+ print("inspector attach\n");
+ var wv = this.inspector.get_web_view();
+ if (wv != null) {
+ print("got inspector web view\n");
+
+ var cn = _this.inspectorcontainer.el.get_child();
+ if (cn != null) {
+ _this.inspectorcontainer.el.remove(cn);
+ }
+
+ _this.inspectorcontainer.el.add(wv);
+ wv.show();
+ } else {
+ //this.inspector.close();
+
+ //this.inspector = null;
+
+
+ }
+ return true;
+
+ });
+ /*
+ this.inspector.closed.connect(() => {
+ print("inspector closed?!?");
+ // if this happens destroy the webkit..
+ // recreate it..
+ this.el.stop_loading();
+
+ if (_this.viewbox.el.get_parent() == null) {
+ return;
+ }
+
+
+ _this.viewbox.el.remove(_this.viewcontainer.el);
+ _this.el.remove(_this.inspectorcontainer.el);
+
+ // destory seems to cause problems.
+ //this.el.destroy();
+ //_this.viewcontainer.el.destroy();
+ //_this.inspectorcontainer.el.destroy();
+
+ this.el = null;
+ var nv =new Xcls_viewcontainer(_this);
+ nv.ref();
+ _this.viewbox.el.pack_end(nv.el,true,true,0);
+
+ var inv =new Xcls_inspectorcontainer(_this);
+ inv.ref();
+ _this.el.pack2(inv.el,true,true);
+
+ inv.el.show_all();
+ nv.el.show_all();
+ //while(Gtk.events_pending ()) Gtk.main_iteration ();
+ //_this.view.renderJS(true);
+ _this.view.refreshRequired = true;
+
+ });
+ */
+
+ this.inspector.show();
+ }
+ public void renderJS (bool force) {
+
+ // this is the public redraw call..
+ // we refresh in a loop privately..
+ var autodraw = _this.AutoRedraw.el.active;
+ if (!autodraw && !force) {
+ print("Skipping redraw - no force, and autodraw off");
+ return;
+ }
+
+ this.refreshRequired = true;
+ }
+ }
+
- public class Xcls_ScrolledWindow8 : Object
+ public class Xcls_inspectorcontainer : Object
{
public Gtk.ScrolledWindow el;
- private Xcls_GtkView _this;
+ private Xcls_WindowRooView _this;
// my vars (def)
// ctor
- public Xcls_ScrolledWindow8(Xcls_GtkView _owner )
+ public Xcls_inspectorcontainer(Xcls_WindowRooView _owner )
+ {
+ _this = _owner;
+ _this.inspectorcontainer = this;
+ this.el = new Gtk.ScrolledWindow( null, null );
+
+ // my vars (dec)
+
+ // set gobject values
+ this.el.shadow_type = Gtk.ShadowType.IN;
+
+ // init method
+
+ this.el.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
+ }
+
+ // user defined functions
+ }
+
+
+ public class Xcls_ScrolledWindow14 : Object
+ {
+ public Gtk.ScrolledWindow el;
+ private Xcls_WindowRooView _this;
+
+
+ // my vars (def)
+
+ // ctor
+ public Xcls_ScrolledWindow14(Xcls_WindowRooView _owner )
{
_this = _owner;
this.el = new Gtk.ScrolledWindow( null, null );
public class Xcls_sourceview : Object
{
public Gtk.SourceView el;
- private Xcls_GtkView _this;
+ private Xcls_WindowRooView _this;
// my vars (def)
public bool loading;
public bool allow_node_scroll;
+ public string propSelected;
// ctor
- public Xcls_sourceview(Xcls_GtkView _owner )
+ public Xcls_sourceview(Xcls_WindowRooView _owner )
{
_this = _owner;
_this.sourceview = this;
// my vars (dec)
this.loading = true;
this.allow_node_scroll = true;
+ this.propSelected = "";
// set gobject values
this.el.editable = false;
this.el.override_font(description);
this.loading = true;
- var buf = this.el.get_buffer();
- buf.notify.connect((ps) => {
- if (this.loading) {
- return;
- }
- if (ps.name != "cursor-position") {
- return;
- }
- print("cursor changed : %d\n", buf.cursor_position);
- Gtk.TextIter cpos;
- buf.get_iter_at_offset(out cpos, buf.cursor_position);
-
- var ln = cpos.get_line();
-
- var node = _this.file.lineToNode(ln);
-
- if (node == null) {
- print("can not find node\n");
- return;
- }
- var ltree = _this.main_window.windowstate.left_tree;
- var tp = ltree.model.treePathFromNode(node);
- print("got tree path %s\n", tp);
- if (tp != "") {
- this.allow_node_scroll = false;
- print("changing cursor on tree..\n");
- ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
- // scrolling is disabled... as node selection calls scroll 10ms after it changes.
- GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
- this.allow_node_scroll = true;
- return false;
- });
- }
-
- // highlight the node..
-
- });
+ //var buf = this.el.get_buffer();
+ //buf.notify.connect(this.onCursorChanged);
}
+
+ //listeners
+ this.el.button_release_event.connect( () => {
+ this.onCursorChanged();
+
+ return false;
+ });
}
// user defined functions
- public void nodeSelected (JsRender.Node? sel) {
+ public void onCursorChanged (/*ParamSpec ps*/) {
+ if (this.loading) {
+ return;
+ }
+ // if (ps.name != "cursor-position") {
+ // return;
+ // }
+
+ var buf = this.el.get_buffer();
+ print("cursor changed : %d\n", buf.cursor_position);
+ Gtk.TextIter cpos;
+ buf.get_iter_at_offset(out cpos, buf.cursor_position);
+
+ var ln = cpos.get_line();
+ print("cursor changed line : %d\n", ln);
+ var node = _this.file.lineToNode(ln+1);
+
+ if (node == null) {
+ print("can not find node\n");
+ return;
+ }
+ var prop = node.lineToProp(ln+1);
+ print("prop : %s", prop == null ? "???" : prop);
+
+
+
+
+
+
+ var ltree = _this.main_window.windowstate.left_tree;
+ var tp = ltree.model.treePathFromNode(node);
+ print("got tree path %s\n", tp);
+ if (tp != "") {
+ this.allow_node_scroll = false; /// block node scrolling..
+
+
+ //print("changing cursor on tree..\n");
+
+
+
+ // let's try allowing editing on the methods.
+ // a little klunky at present..
+ this.propSelected = "";
+ if (prop != null) {
+ //see if we can find it..
+ var kv = prop.split(":");
+ if (kv[0] == "p") {
+
+ //var k = prop.get_key(kv[1]);
+ // fixme -- need to determine if it's an editable property...
+ this.propSelected = prop;
+
+ } else if (kv[0] == "l") {
+ this.propSelected = prop;
+
+ }
+ }
+ ltree.view.setCursor(tp, "editor");
+ // ltree.view.el.set_cursor(new Gtk.TreePath.from_string(tp), null, false);
+ this.nodeSelected(node,false);
+
+ // scrolling is disabled... as node selection calls scroll 10ms after it changes.
+ GLib.Timeout.add_full(GLib.Priority.DEFAULT,100 , () => {
+ this.allow_node_scroll = true;
+ return false;
+ });
+ }
+
+ // highlight the node..
+ }
+ public void nodeSelected (JsRender.Node? sel, bool scroll ) {
// clear all the marks..
- Gtk.TextIter start;
+ Gtk.TextIter start;
Gtk.TextIter end;
sbuf.get_bounds (out start, out end);
if (sel == null) {
+ print("no selected node\n");
// no highlighting..
return;
}
+
+ print("highlight region %d to %d\n", sel.line_start,sel.line_end);
Gtk.TextIter iter;
sbuf.get_iter_at_line(out iter, sel.line_start);
//if (cur_line > sel.line_start && cur_line < sel.line_end) {
//} else {
- if (this.allow_node_scroll) {
+ if (scroll) {
this.el.scroll_to_iter(iter, 0.1f, true, 0.0f, 0.5f);
}
-
+ var start_line = sel.line_start;
+ var end_line = sel.line_end;
+
+
+ this.el.editable = false;
+ // now if we have selected a property...
+ if (this.propSelected.length> 0 ) {
+
+ int nstart, nend;
+ if (sel.getPropertyRange(this.propSelected, out nstart, out nend) && nend > nstart) {
+ start_line = nstart;
+ end_line = nend;
+ this.el.editable = true;
+ }
+ print("propSelected = %s range %d -> %d\n", this.propSelected, nstart, nend);
+
+
+ }
+
+ // check selection - if it's out of 'bounds'
+ if (this.el.editable && sbuf.get_has_selection()) {
+ Gtk.TextIter sel_start_iter, sel_end_iter;
+ sbuf.get_selection_bounds(out sel_start_iter, out sel_end_iter);
+
+ if (sel_start_iter.get_line() < start_line || sel_end_iter.get_line() > end_line ||
+ sel_start_iter.get_line() > end_line || sel_end_iter.get_line() < start_line ) {
+ // save?
+ this.el.editable = false;
+ }
+
+ }
+
+
+
for (var i = 0; i < buf.get_line_count();i++) {
- if (i < sel.line_start || i > sel.line_end) {
+ if (i < (start_line -1) || i > (end_line -1)) {
sbuf.get_iter_at_line(out iter, i);
sbuf.create_source_mark(null, "grey", iter);
}
public void loadFile ( ) {
this.loading = true;
+
+
+ // get the cursor and scroll position....
var buf = this.el.get_buffer();
+ var cpos = buf.cursor_position;
+
+
+
+ var vadj = this.el.get_vadjustment();
+
+
+
buf.set_text("",0);
var sbuf = (Gtk.SourceBuffer) buf;
- if (_this.file == null || _this.file.xtype != "Gtk") {
- print("xtype != Gtk");
+ if (_this.file == null || _this.file.xtype != "Roo") {
+ print("xtype != Roo");
this.loading = false;
return;
}
- var valafn = "";
- try {
- var regex = new Regex("\\.bjs$");
-
-
- valafn = regex.replace(_this.file.path,_this.file.path.length , 0 , ".vala");
- } catch (GLib.RegexError e) {
- this.loading = false;
- return;
- }
-
-
- if (!FileUtils.test(valafn,FileTest.IS_REGULAR) ) {
- print("File path has no errors\n");
- this.loading = false;
- return ;
- }
-
- string str;
- try {
-
- GLib.FileUtils.get_contents (valafn, out str);
- } catch (Error e) {
- this.loading = false;
- return ;
- }
-
+ // get the string from the rendered tree...
+
+ var str = _this.file.toSource();
+
// print("setting str %d\n", str.length);
buf.set_text(str, str.length);
var lm = Gtk.SourceLanguageManager.get_default();
sbuf.remove_source_marks (start, end, null); // remove all marks..
- if (_this.main_window.windowstate.last_compile_result != null) {
- var obj = _this.main_window.windowstate.last_compile_result;
- this.highlightErrorsJson("ERR", obj);
- this.highlightErrorsJson("WARN", obj);
- this.highlightErrorsJson("DEPR", obj);
+ while(Gtk.events_pending()) {
+ Gtk.main_iteration();
}
- //while (Gtk.events_pending()) {
- // Gtk.main_iteration();
- // }
+
+ Gtk.TextIter cpos_iter;
+ buf.get_iter_at_offset(out cpos_iter, cpos);
+ buf.place_cursor(cpos_iter);
+
+ this.el.set_vadjustment(vadj);
+
+
this.loading = false;
}