1 if(!dojo._hasResource["dijit._tree.dndSelector"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dijit._tree.dndSelector"] = true;
3 dojo.provide("dijit._tree.dndSelector");
4 dojo.require("dojo.dnd.common");
5 dojo.require("dijit._tree.dndContainer");
7 dojo.declare("dijit._tree.dndSelector",
8 dijit._tree.dndContainer,
10 constructor: function(tree, params){
13 this.simpleSelection=false;
16 dojo.connect(this.tree.domNode, "onmousedown", this,"onMouseDown"),
17 dojo.connect(this.tree.domNode, "onmouseup", this,"onMouseUp")
21 // object attributes (for markup)
22 singular: false, // is singular property
25 getSelectedItems: function(){
26 var selectedItems = []
27 for (var i in this.selection){
28 selectedItems.push(dijit.getEnclosingWidget(this.selection[i]).item);
33 getSelectedNodes: function(){
34 return this.selection;
37 selectNone: function(){
38 // summary: unselects all items
39 return this._removeSelection()._removeAnchor(); // self
42 insertItems: function(item, parent){
43 // summary: inserts new data items (see Container's insertNodes method for details)
45 //we actually need to add things to the store here instead of adding noes to the tree directly
49 // summary: prepares the object to be garbage-collected
50 dojo.dnd.Selector.superclass.destroy.call(this);
51 this.selection = this.anchor = null;
55 onMouseDown: function(e){
56 // summary: event processor for onmousedown
57 // e: Event: mouse event
58 if(!this.current){ return; }
60 var item = dijit.getEnclosingWidget(this.current).item
61 var id = this.tree.model.getIdentity(item);
63 if (!this.current.id) {
67 if (!this.current.type) {
68 this.current.type="data";
71 if(!this.singular && !dojo.dnd.getCopyKeyState(e) && !e.shiftKey && (this.current.id in this.selection)){
72 this.simpleSelection = true;
78 if(this.anchor == this.current){
79 if(dojo.dnd.getCopyKeyState(e)){
84 this.anchor = this.current;
85 this._addItemClass(this.anchor, "Anchor");
87 this.selection[this.current.id] = this.current;
90 if(!this.singular && e.shiftKey){
91 if (dojo.dnd.getCopyKeyState(e)){
92 //TODO add range to selection
94 //TODO select new range from anchor
97 if(dojo.dnd.getCopyKeyState(e)){
98 if(this.anchor == this.current){
99 delete this.selection[this.anchor.id];
100 this._removeAnchor();
102 if(this.current.id in this.selection){
103 this._removeItemClass(this.current, "Selected");
104 delete this.selection[this.current.id];
107 this._removeItemClass(this.anchor, "Anchor");
108 this._addItemClass(this.anchor, "Selected");
110 this.anchor = this.current;
111 this._addItemClass(this.current, "Anchor");
112 this.selection[this.current.id] = this.current;
116 var item = dijit.getEnclosingWidget(this.current).item
117 var id = this.tree.model.getIdentity(item);
118 if(!(id in this.selection)){
120 this.anchor = this.current;
121 this._addItemClass(this.current, "Anchor");
122 this.selection[id] = this.current;
131 onMouseMove: function() {
135 onOverEvent: function() {
136 this.onmousemoveEvent = dojo.connect(this.node, "onmousemove", this, "onMouseMove");
139 onMouseUp: function(e){
140 // summary: event processor for onmouseup
141 // e: Event: mouse event
142 if(!this.simpleSelection){ return; }
143 this.simpleSelection = false;
146 this.anchor = this.current;
147 this._addItemClass(this.anchor, "Anchor");
148 this.selection[this.current.id] = this.current;
151 _removeSelection: function(){
152 // summary: unselects all items
153 var e = dojo.dnd._empty;
154 for(var i in this.selection){
155 if(i in e){ continue; }
156 var node = dojo.byId(i);
157 if(node){ this._removeItemClass(node, "Selected"); }
162 _removeAnchor: function(){
164 this._removeItemClass(this.anchor, "Anchor");