Commit 09ca76e0 authored by Eugene Lazutkin's avatar Eugene Lazutkin

Added the customization for copyOnly sources. Refs #3229.

git-svn-id: http://svn.dojotoolkit.org/src/dojo/trunk@9348 560b804f-0ae3-0310-86f3-f6aa0a117693
parent 8df1ec56
......@@ -49,10 +49,10 @@ dojo.extend(dojo.dnd.Manager, {
// copy: Boolean: copy items, if true, move items otherwise
this.source = source;
this.nodes = nodes;
this.copy = copy;
this.copy = copy && true || false; // normalizing to true boolean
this.avatar = this.makeAvatar();
dojo.body().appendChild(this.avatar.node);
dojo.publish("dndStart", [source, nodes, copy]);
dojo.publish("dndStart", [source, nodes, this.copy]);
this.events = [
dojo.connect(dojo.doc, "onmousemove", this, "onMouseMove"),
dojo.connect(dojo.doc, "onmouseup", this, "onMouseUp"),
......@@ -96,8 +96,9 @@ dojo.extend(dojo.dnd.Manager, {
var a = this.avatar;
if(a){
dojo.marginBox(a.node, {l: e.pageX + this.OFFSET_X, t: e.pageY + this.OFFSET_Y});
if(this.copy != dojo.dnd.multiSelectKey(e)){
this._setCopyStatus(dojo.dnd.multiSelectKey(e));
var copy = this.source.copyState(dojo.dnd.multiSelectKey(e)) && true || false;
if(this.copy != copy){
this._setCopyStatus(copy);
}
}
},
......@@ -106,7 +107,7 @@ dojo.extend(dojo.dnd.Manager, {
// e: Event: mouse event
if(this.avatar){
if(this.target && this.canDropFlag){
dojo.publish("dndDrop", [this.source, this.nodes, dojo.dnd.multiSelectKey(e)]);
dojo.publish("dndDrop", [this.source, this.nodes, this.source.copyState(dojo.dnd.multiSelectKey(e)) && true || false]);
}else{
dojo.publish("dndCancel");
}
......@@ -121,7 +122,10 @@ dojo.extend(dojo.dnd.Manager, {
if(this.avatar){
switch(e.keyCode){
case dojo.keys.CTRL:
if(!this.copy){ this._setCopyStatus(true); }
var copy = this.source.copyState(true) && true || false;
if(this.copy != copy){
this._setCopyStatus(copy);
}
break;
case dojo.keys.ESCAPE:
dojo.publish("dndCancel");
......@@ -133,7 +137,12 @@ dojo.extend(dojo.dnd.Manager, {
onKeyUp: function(e){
// summary: event processor for onkeyup, watching for CTRL for copy/move status
// e: Event: keyboard event
if(this.avatar && e.keyCode == dojo.keys.CTRL && this.copy){ this._setCopyStatus(false); }
if(this.avatar && e.keyCode == dojo.keys.CTRL){
var copy = this.source.copyState(true) && true || false;
if(this.copy != copy){
this._setCopyStatus(copy);
}
}
},
// utilities
_setCopyStatus: function(copy){
......
......@@ -28,6 +28,7 @@ function(node, params){
// isSource: Boolean: can be used as a DnD source, if true; assumed to be "true" if omitted
// accept: Array: list of accepted types (text strings) for a target; assumed to be ["text"] if omitted
// horizontal: Boolean: a horizontal container, if true, vertical otherwise or when omitted
// copyOnly: Boolean: always copy items, if true, use a state of Ctrl key otherwise
// the rest of parameters are passed to the selector
if(!params){ params = {}; }
this.isSource = typeof params.isSource == "undefined" ? true : params.isSource;
......@@ -40,6 +41,7 @@ function(node, params){
}
}
this.horizontal = params.horizontal;
this.copyOnly = params.copyOnly;
// class-specific variables
this.isDragging = false;
this.mouseDown = false;
......@@ -99,7 +101,7 @@ function(node, params){
if(this.mouseDown && this.isSource){
var nodes = this.getSelectedNodes();
if(nodes.length){
m.startDrag(this, nodes, dojo.dnd.multiSelectKey(e));
m.startDrag(this, nodes, this.copyState(dojo.dnd.multiSelectKey(e)));
}
}
}
......@@ -229,6 +231,12 @@ function(node, params){
}
return accepted; // Boolean
},
copyState: function(keyPressed){
// summary: Returns true, if we need to copy items, false to move.
// It is separate to be overwritten dynamically, if needed.
// keyPressed: Boolean: the "multiSelectKey" was pressed
return this.copyOnly || keyPressed; // Boolean
},
_markTargetAnchor: function(before){
// summary: assigns a class to the current target anchor based on "before" status
// before: Boolean: insert before, if true, after otherwise
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment