Handle dragging files setting drag cursor

On drag over CM instance, call setDragCursor with event and 'editor'
string
Set ondragover function call upon this function too with folder/file
string, same as when init'ing via get branch
setDragCursor function added, handles cursor for dropping files editior,
folder and file including if we have the CTRL key down or not
This commit is contained in:
Matt Pass
2016-03-19 11:10:30 +00:00
parent 875d8a75ca
commit 344bd2dd50
2 changed files with 60 additions and 30 deletions

View File

@@ -478,6 +478,11 @@ var ICEcoder = {
top.ICEcoder.mouseDownInCM = "editor";
},
// On drag over
cMonDragOver: function(thisCM,evt,cMinstance) {
top.ICEcoder.setDragCursor(evt,'editor');
},
// On render line
cMonRenderLine: function(thisCM,cMinstance,line,element) {
var paneMatch;
@@ -1787,6 +1792,7 @@ var ICEcoder = {
newLI.draggable = false;
newLI.ondragstart = function(event) {top.ICEcoder.addDefaultDragData(this,event)};
newLI.ondrag = function(event) {top.ICEcoder.draggingWithKeyTest(event);if(top.ICEcoder.getcMInstance()){top.ICEcoder.editorFocusInstance.indexOf('diff') == -1 ? top.ICEcoder.getcMInstance().focus() : top.ICEcoder.getcMdiffInstance().focus()}};
newLI.ondragover = function(event) {top.ICEcoder.setDragCursor(event,actionElemType=="folder" ? 'folder' : 'file')};
newLI.ondragend = function() {top.ICEcoder.dropFile(this)};
newLI.innerHTML = innerLI
locNest.nextSibling.appendChild(newLI);
@@ -1809,6 +1815,7 @@ var ICEcoder = {
newLI.draggable = false;
newLI.ondragstart = function(event) {top.ICEcoder.addDefaultDragData(this,event)};
newLI.ondrag = function(event) {top.ICEcoder.draggingWithKeyTest(event);if(top.ICEcoder.getcMInstance()){top.ICEcoder.editorFocusInstance.indexOf('diff') == -1 ? top.ICEcoder.getcMInstance().focus() : top.ICEcoder.getcMdiffInstance().focus()}};
newLI.ondragover = function(event) {top.ICEcoder.setDragCursor(event,actionElemType=="folder" ? 'folder' : 'file')};
newLI.ondragend = function() {top.ICEcoder.dropFile(this)};
newLI.innerHTML = innerLI;
// Append or insert depending on which of the above if statements is true
@@ -1933,6 +1940,28 @@ var ICEcoder = {
evt.dataTransfer.setData('Text', elem.id);
},
// Set a copy, move or none drag cursor type
setDragCursor: function(evt,dropType) {
var cursorIcon;
// Prevent the default and establish if CTRL key is down
evt.preventDefault();
top.ICEcoder.draggingWithKeyTest(evt);
// Establish the cursor to show
cursorIcon =
dropType == "editor"
? top.ICEcoder.draggingWithKey == "CTRL"
? "copy"
: "link"
: dropType == "folder"
? top.ICEcoder.draggingWithKey == "CTRL"
? "copy"
: "move"
: "none";
evt.dataTransfer.dropEffect = cursorIcon;
},
// On dropping a file, do something
dropFile: function(elem) {
var filePath, tgtPath;