X-Git-Url: http://git.roojs.org/?p=app.Builder.js;a=blobdiff_plain;f=src%2FBuilder4%2FWindowLeftTree.vala;h=983284b4f3abafec2d9e865bb87de7090dfb5e14;hp=8018e8eebd7c9adf15aa274d5b8a3133eae75091;hb=HEAD;hpb=ee6057cbd37965049896c934151dca45ce68719f diff --git a/src/Builder4/WindowLeftTree.vala b/src/Builder4/WindowLeftTree.vala index 8018e8eeb..983284b4f 100644 --- a/src/Builder4/WindowLeftTree.vala +++ b/src/Builder4/WindowLeftTree.vala @@ -1,6 +1,6 @@ static Xcls_WindowLeftTree _WindowLeftTree; -public class Xcls_WindowLeftTree : Object +public class Xcls_WindowLeftTree : Object { public Gtk.ScrolledWindow el; private Xcls_WindowLeftTree _this; @@ -18,12 +18,12 @@ public class Xcls_WindowLeftTree : Object public Xcls_LeftTreeMenu LeftTreeMenu; // my vars (def) - public signal bool before_node_change (JsRender.Node? node); + public signal bool before_node_change (); public signal void changed (); - public signal void node_selected (JsRender.Node? node); + public signal void node_selected (JsRender.Node? node, string source); public Xcls_MainWindow main_window; - // ctor + // ctor public Xcls_WindowLeftTree() { _this = this; @@ -40,11 +40,12 @@ public class Xcls_WindowLeftTree : Object var child_1 = new Xcls_LeftTreeMenu( _this ); child_1.ref(); - // init method + // init method - this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); } + this.el.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC); + } - // user defined functions + // user defined functions public JsRender.Node? getActiveElement () { // return path to actie node. var path = this.getActivePath(); @@ -55,10 +56,10 @@ public class Xcls_WindowLeftTree : Object } public JsRender.JsRender getActiveFile () { - return this.model.file; + return this.main_window.windowstate.file; } public string getActivePath () { - var model = this.model; + var view = this.view.el; if (view.get_selection().count_selected_rows() < 1) { return ""; @@ -68,7 +69,7 @@ public class Xcls_WindowLeftTree : Object view.get_selection().get_selected(out mod, out iter); return mod.get_path(iter).to_string(); } - public class Xcls_view : Object + public class Xcls_view : Object { public Gtk.TreeView el; private Xcls_WindowLeftTree _this; @@ -79,10 +80,11 @@ public class Xcls_WindowLeftTree : Object public int drag_x; public string[] dropList; public int drag_y; + public string lastEventSource; public bool drag_in_motion; public bool blockChanges; - // ctor + // ctor public Xcls_view(Xcls_WindowLeftTree _owner ) { _this = _owner; @@ -90,9 +92,11 @@ public class Xcls_WindowLeftTree : Object this.el = new Gtk.TreeView(); // my vars (dec) + this.lastEventSource = ""; this.blockChanges = false; // set gobject values + this.el.expand = true; this.el.tooltip_column = 1; this.el.enable_tree_lines = true; this.el.headers_visible = false; @@ -103,12 +107,12 @@ public class Xcls_WindowLeftTree : Object child_1.ref(); this.el.append_column ( child_1.el ); - // init method + // init method { var description = new Pango.FontDescription(); description.set_size(8000); - this.el.modify_font(description); + this.el.override_font(description); var selection = this.el.get_selection(); selection.set_mode( Gtk.SelectionMode.SINGLE); @@ -125,7 +129,7 @@ public class Xcls_WindowLeftTree : Object Gtk.drag_source_set ( this.el, /* widget will be drag-able */ Gdk.ModifierType.BUTTON1_MASK, /* modifier that will start a drag */ - Builder4.Application.targetList, /* lists of target to support */ + BuilderApplication.targetList, /* lists of target to support */ Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */ ); @@ -136,19 +140,23 @@ public class Xcls_WindowLeftTree : Object ( this.el, /* widget that will accept a drop */ Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT, - Builder4.Application.targetList, /* lists of target to support */ + BuilderApplication.targetList, /* lists of target to support */ Gdk.DragAction.COPY | Gdk.DragAction.MOVE | Gdk.DragAction.LINK /* what to do with data after dropped */ ); //Gtk.drag_dest_set_target_list(this.el, Builder.Application.targetList); //Gtk.drag_dest_add_text_targets(this.el); } - // listeners + + //listeners this.el.button_press_event.connect( ( ev) => { //console.log("button press?"); - if (! _this.before_node_change(null) ) { + this.lastEventSource = "tree"; + if (! _this.before_node_change() ) { + return true; } + if (ev.type != Gdk.EventType.BUTTON_PRESS || ev.button != 3) { @@ -198,7 +206,7 @@ public class Xcls_WindowLeftTree : Object var xname = data.fqn(); print ("XNAME IS " + xname+ "\n"); this.dragData = tp; - this.dropList = _this.model.file.palete().getDropList(xname); + this.dropList = _this.main_window.windowstate.file.palete().getDropList(xname); print ("DROP LIST IS " + string.joinv(", ", this.dropList) + "\n"); @@ -222,13 +230,13 @@ public class Xcls_WindowLeftTree : Object if (this.blockChanges) { // probably not needed.. return ; } - if (!_this.before_node_change(null) ) { + if (!_this.before_node_change( ) ) { this.blockChanges = true; this.el.get_selection().unselect_all(); this.blockChanges = false; return; } - if (_this.model.file == null) { + if (_this.main_window.windowstate.file == null) { return; } @@ -237,7 +245,7 @@ public class Xcls_WindowLeftTree : Object // -- it appears that the selection is not updated. - + GLib.Timeout.add_full(GLib.Priority.DEFAULT,10 , () => { @@ -245,7 +253,7 @@ public class Xcls_WindowLeftTree : Object print("selected rows < 1\n"); //??this.model.load( false); - _this.node_selected(null); + _this.node_selected(null, this.lastEventSource); return false ; } @@ -263,7 +271,23 @@ public class Xcls_WindowLeftTree : Object _this.model.activePath = mod.get_path(iter).to_string(); var node = (JsRender.Node)value.dup_object(); - _this.node_selected(node); + _this.node_selected(node, this.lastEventSource); + while (Gtk.events_pending()) { + Gtk.main_iteration(); + } + var cp = mod.get_path(iter); + Gtk.TreePath sp, ep; + this.el.get_visible_range(out sp, out ep); + // if sp is before cp then retuns 1. + // if cp is before ep then retuns 1. + if (cp.compare(sp) >= 0 && ep.compare(cp) >=1) { + return false; + } + + + + this.el.scroll_to_cell(new Gtk.TreePath.from_string(_this.model.activePath), null, true, 0.1f,0.0f); + return false; }); //_this.after_node_change(node); @@ -458,7 +482,7 @@ public class Xcls_WindowLeftTree : Object GLib.Value value; _this.model.el.get_value(iter, 2, out value); var ndata = (JsRender.Node)(value.dup_object()); - var xname = ndata.fqn(); + var tp = mod.get_path(iter).to_string(); @@ -538,7 +562,13 @@ public class Xcls_WindowLeftTree : Object // for drop if (dropNodeType[0] == '{') { var pa = new Json.Parser(); - pa.load_from_data(dropNodeType); + try { + pa.load_from_data(dropNodeType); + } catch (Error e) { + Gtk.drag_finish (ctx, false, false, time); // drop failed.. + // no drop action... + return; + } dropNode.loadFromJson( pa.get_root().get_object(), 2); dropNodeType = dropNode.fqn(); @@ -553,18 +583,19 @@ public class Xcls_WindowLeftTree : Object // dropList --- need to gather this ... print("get dropList for : %s\n",dropNodeType); - var dropList = _this.model.file.palete().getDropList(dropNodeType); + var dropList = _this.main_window.windowstate.file.palete().getDropList(dropNodeType); print("dropList: %s\n", string.joinv(" , ", dropList)); // if drag action is link ... then we can drop it anywahere... if ((ctx.get_actions() & Gdk.DragAction.LINK) > 0) { - targetData = path.to_string() + "|%d".printf((int)pos); + // if path is null?? dragging into an empty tree? + targetData = (path == null ? "" : path.to_string()) + "|%d".printf((int)pos); } else { targetData = _this.model.findDropNodeByPath( isEmpty ? "" : path.to_string(), dropList, pos); - } + } @@ -747,9 +778,7 @@ public class Xcls_WindowLeftTree : Object Gtk.drag_finish (ctx, false, false, time); // drop failed.. return true; } - - var td_ar = targetData.split("|"); - + // continue on to allow drop.. @@ -790,7 +819,7 @@ public class Xcls_WindowLeftTree : Object }); } - // user defined functions + // user defined functions public void highlightDropPath ( string treepath, Gtk.TreeViewDropPosition pos) { // highlighting for drag/drop @@ -801,7 +830,16 @@ public class Xcls_WindowLeftTree : Object } } - public void selectNode (string treepath_str) { + public void setCursor (string treepath, string sourceEvent) { + this.lastEventSource = sourceEvent; + //this.blockChanges = true; << block changes prevents loading of 'node data' and firing of node_selected.. + this.el.set_cursor(new Gtk.TreePath.from_string(treepath), null, false); + // fire node_selected.. + //this.blockChanges = false; + this.lastEventSource = ""; + } + public void selectNode (string treepath_str, string source) { + this.lastEventSource = source; //this.selection.select_path(new Gtk.TreePath.from_string( treepath_str)); var tp = new Gtk.TreePath.from_string(treepath_str); @@ -809,7 +847,7 @@ public class Xcls_WindowLeftTree : Object this.el.scroll_to_cell(tp, null, false, 0,0); } } - public class Xcls_model : Object + public class Xcls_model : Object { public Gtk.TreeStore el; private Xcls_WindowLeftTree _this; @@ -817,11 +855,9 @@ public class Xcls_WindowLeftTree : Object // my vars (def) public DialogTemplateSelect template_select; - public JsRender.JsRender? file; public string activePath; - public Project.Project? project; - // ctor + // ctor public Xcls_model(Xcls_WindowLeftTree _owner ) { _this = _owner; @@ -830,17 +866,16 @@ public class Xcls_WindowLeftTree : Object // my vars (dec) this.template_select = null; - this.file = null; this.activePath = ""; - this.project = null; // set gobject values - // init method + // init method - print("model initialized"); } + print("model initialized"); + } - // user defined functions + // user defined functions public string findDropNode (string treepath_str, string[] targets) { // this is used by the dragdrop code in the roo version AFAIR.. @@ -866,34 +901,23 @@ public class Xcls_WindowLeftTree : Object public void loadFile (JsRender.JsRender f) { //console.dump(f); this.el.clear(); - this.file = f; + // needed??? + _this.main_window.windowstate.file = f; - // if (!f) { - // console.log('missing file'); - // return; - // } - - // load the file if not loaded.. + if (f.tree == null) { - f.loadItems( ); + try { + f.loadItems( ); + } catch (Error e) { + return; + } } // if it's still null? if (f.tree == null) { return; } - - /// this.get('/Window').setTitle(f.project.getName() + ' - ' + f.name); - - //if (f.items.length && typeof(f.items[0]) == 'string') { - - //this.get('/RightEditor').el.show(); - //this.get('/RightEditor.view').load( f.items[0]); - // return; - //} - //print("LOAD"); - //print(JSON.stringify(f.items, null,4)); - //console.dump(f.items); + var o = new Gee.ArrayList(); o.add(f.tree); this.load(o,null); @@ -914,37 +938,7 @@ public class Xcls_WindowLeftTree : Object } return; - /* - - //print("hide right editior"); - //this.get('/RightEditor').el.hide(); - //this.get('/Editor').el.hide(); - //print("set current tree"); - //this.currentTree = this.toJS(false, false)[0]; - //console.dump(this.currentTree); - //this.currentTree = this.currentTree || { items: [] }; - //_this.renderView(); - //console.dump(this.map); - //var RightPalete = imports.Builder.RightPalete.RightPalete; - - - var pm = this.get('/RightPalete.model'); - // set up provider.. - - this.get('/RightPalete').provider = this.get('/LeftTree').getPaleteProvider(); - - if (!this.get('/RightPalete').provider) { - print ("********* PALETE PROVIDER MISSING?!!"); - } - this.get('/LeftTree').renderView(); - - pm.load( this.get('/LeftTree').getPaleteProvider().gatherList(this.listAllTypes())); - - - - this.get('/Window.view-notebook').el.set_current_page( - this.get('/LeftTree.model').file.getType()== 'Roo' ? 0 : -1); - */ + } public void updateSelected () { @@ -1039,7 +1033,8 @@ public class Xcls_WindowLeftTree : Object } - return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER);// + "|" + prop; + // we need to add prop - as :store -> needs to bee added when dropping onto. + return path + "|%d".printf( (int) Gtk.TreeViewDropPosition.INTO_OR_AFTER) + "|" + prop; } /* last = "" + path; @@ -1116,7 +1111,7 @@ public class Xcls_WindowLeftTree : Object this.el.set(citer, 0, tr.get(i).nodeTitle(), 1, tr.get(i).nodeTip(), -1 ); - var o = new GLib.Value(typeof(Object)); + var o = GLib.Value(typeof(Object)); o.set_object((Object)tr.get(i)); this.el.set_value(citer, 2, o); @@ -1156,7 +1151,7 @@ public class Xcls_WindowLeftTree : Object var data = (JsRender.Node)(value.get_object()); print("removing node from Render\n"); if (data.parent == null) { - this.file.tree = null; + _this.main_window.windowstate.file.tree = null; } else { data.remove(); } @@ -1227,18 +1222,18 @@ public class Xcls_WindowLeftTree : Object // we only need to show the template if it's come from else where? if (show_templates) { - if (this.template_select == null) { - this.template_select = new DialogTemplateSelect(); - } + var ts = _this.main_window.windowstate.template_select; - var new_node = this.template_select.show( - (Gtk.Window) _this.el.get_toplevel (), - this.file.palete(), - node); + var new_node = ts.show( + _this.main_window, // (Gtk.Window) _this.el.get_toplevel (), + _this.main_window.windowstate.file.palete(), + node, + _this.main_window.windowstate.project); - if (new_node != null) { - node = new_node; + if (new_node == null) { + return; // do not add? } + node = new_node; } //print("pos is %d \n".printf(pos)); @@ -1248,7 +1243,7 @@ public class Xcls_WindowLeftTree : Object if ( parent_str.length < 1) { this.el.append(out n_iter, null); // drop at top level.. node.parent = null; - this.file.tree = node; + _this.main_window.windowstate.file.tree = node; } else if (pos < 2) { @@ -1310,7 +1305,7 @@ public class Xcls_WindowLeftTree : Object // work out what kind of packing to use.. -- should be in if (!node.has("pack") && parent_str.length > 1) { - this.file.palete().fillPack(node,parentNode); + _this.main_window.windowstate.file.palete().fillPack(node,parentNode); } @@ -1318,7 +1313,7 @@ public class Xcls_WindowLeftTree : Object // add the node... this.el.set(n_iter, 0, node.nodeTitle(), 1, node.nodeTip(), -1 ); - var o = new GLib.Value(typeof(Object)); + var o = GLib.Value(typeof(Object)); o.set_object((Object)node); this.el.set_value(n_iter, 2, o); @@ -1351,9 +1346,35 @@ public class Xcls_WindowLeftTree : Object + } + public string treePathFromNode (JsRender.Node node) { + // iterate through the tree and find the node + var ret = ""; + + this.el.foreach((mod, pth, iter) => { + // get the node.. + + + GLib.Value value; + _this.model.el.get_value(iter, 2, out value); + + + + var n = (JsRender.Node)value; + + print("compare %s to %s\n", n.fqn(), node.fqn()); + if (node == n) { + ret = pth.to_string(); + return true; + } + return false; + }); + return ret; + } } - public class Xcls_TreeViewColumn4 : Object + + public class Xcls_TreeViewColumn4 : Object { public Gtk.TreeViewColumn el; private Xcls_WindowLeftTree _this; @@ -1361,7 +1382,7 @@ public class Xcls_WindowLeftTree : Object // my vars (def) - // ctor + // ctor public Xcls_TreeViewColumn4(Xcls_WindowLeftTree _owner ) { _this = _owner; @@ -1375,13 +1396,14 @@ public class Xcls_WindowLeftTree : Object child_0.ref(); this.el.pack_start ( child_0.el , true ); - // init method + // init method - this.el.add_attribute(_this.renderer.el , "markup", 0 ); } + this.el.add_attribute(_this.renderer.el , "markup", 0 ); + } - // user defined functions + // user defined functions } - public class Xcls_renderer : Object + public class Xcls_renderer : Object { public Gtk.CellRendererText el; private Xcls_WindowLeftTree _this; @@ -1389,7 +1411,7 @@ public class Xcls_WindowLeftTree : Object // my vars (def) - // ctor + // ctor public Xcls_renderer(Xcls_WindowLeftTree _owner ) { _this = _owner; @@ -1401,9 +1423,12 @@ public class Xcls_WindowLeftTree : Object // set gobject values } - // user defined functions + // user defined functions } - public class Xcls_LeftTreeMenu : Object + + + + public class Xcls_LeftTreeMenu : Object { public Gtk.Menu el; private Xcls_WindowLeftTree _this; @@ -1411,7 +1436,7 @@ public class Xcls_WindowLeftTree : Object // my vars (def) - // ctor + // ctor public Xcls_LeftTreeMenu(Xcls_WindowLeftTree _owner ) { _this = _owner; @@ -1432,9 +1457,9 @@ public class Xcls_WindowLeftTree : Object this.el.add ( child_2.el ); } - // user defined functions + // user defined functions } - public class Xcls_MenuItem7 : Object + public class Xcls_MenuItem7 : Object { public Gtk.MenuItem el; private Xcls_WindowLeftTree _this; @@ -1442,7 +1467,7 @@ public class Xcls_WindowLeftTree : Object // my vars (def) - // ctor + // ctor public Xcls_MenuItem7(Xcls_WindowLeftTree _owner ) { _this = _owner; @@ -1453,7 +1478,7 @@ public class Xcls_WindowLeftTree : Object // set gobject values this.el.label = "Delete Element"; - // listeners + //listeners this.el.activate.connect( ( ) => { print("ACTIVATE?"); @@ -1463,9 +1488,10 @@ public class Xcls_WindowLeftTree : Object }); } - // user defined functions + // user defined functions } - public class Xcls_MenuItem8 : Object + + public class Xcls_MenuItem8 : Object { public Gtk.MenuItem el; private Xcls_WindowLeftTree _this; @@ -1473,7 +1499,7 @@ public class Xcls_WindowLeftTree : Object // my vars (def) - // ctor + // ctor public Xcls_MenuItem8(Xcls_WindowLeftTree _owner ) { _this = _owner; @@ -1484,12 +1510,12 @@ public class Xcls_WindowLeftTree : Object // set gobject values this.el.label = "Save as Template"; - // listeners + //listeners this.el.activate.connect( () => { DialogSaveTemplate.singleton().show( (Gtk.Window) _this.el.get_toplevel (), - _this.model.file.palete(), + _this.main_window.windowstate.file.palete(), _this.getActiveElement() ); @@ -1497,9 +1523,10 @@ public class Xcls_WindowLeftTree : Object }); } - // user defined functions + // user defined functions } - public class Xcls_MenuItem9 : Object + + public class Xcls_MenuItem9 : Object { public Gtk.MenuItem el; private Xcls_WindowLeftTree _this; @@ -1507,7 +1534,7 @@ public class Xcls_WindowLeftTree : Object // my vars (def) - // ctor + // ctor public Xcls_MenuItem9(Xcls_WindowLeftTree _owner ) { _this = _owner; @@ -1518,12 +1545,12 @@ public class Xcls_WindowLeftTree : Object // set gobject values this.el.label = "Save as Module"; - // listeners + //listeners this.el.activate.connect( () => { var node = _this.getActiveElement(); var name = DialogSaveModule.singleton().show( (Gtk.Window) _this.el.get_toplevel (), - _this.model.file.project, + _this.main_window.windowstate.project, node ); if (name.length < 1) { @@ -1555,12 +1582,14 @@ public class Xcls_WindowLeftTree : Object _this.model.el.remove(ref citer); } _this.changed(); - _this.node_selected(node); + _this.node_selected(node, "tree"); }); } - // user defined functions + // user defined functions } + + }