Explorar o código

Allow dragging from the file tree to CDB Path cells (#114)

Leonardo Jeanteur %!s(int64=4) %!d(string=hai) anos
pai
achega
71ee2e8e1a
Modificáronse 3 ficheiros con 41 adicións e 15 borrados
  1. 12 15
      hide/comp/cdb/Cell.hx
  2. 22 0
      hide/view/CdbTable.hx
  3. 7 0
      hide/view/FileTree.hx

+ 12 - 15
hide/comp/cdb/Cell.hx

@@ -32,6 +32,9 @@ class Cell extends Component {
 			if(!visible)
 			if(!visible)
 				return;
 				return;
 		}
 		}
+
+		// Used to get the Cell component back from its DOM/Jquery element
+		root.prop("cellComp", this);
 		if( column.kind == Script ) root.addClass("t_script");
 		if( column.kind == Script ) root.addClass("t_script");
 		refresh();
 		refresh();
 		switch( column.type ) {
 		switch( column.type ) {
@@ -41,21 +44,6 @@ class Cell extends Component {
 				e.stopPropagation();
 				e.stopPropagation();
 				@:privateAccess line.table.toggleList(this);
 				@:privateAccess line.table.toggleList(this);
 			});
 			});
-		case TFile:
-			if (canEdit()) {
-				element.on("drop", function(e : js.jquery.Event) {
-					var e : js.html.DragEvent = untyped e.originalEvent;
-					if (e.dataTransfer.files.length > 0) {
-						e.preventDefault();
-						e.stopPropagation();
-						setValue(ide.makeRelative(untyped e.dataTransfer.files.item(0).path));
-						refresh();
-					}
-				});
-				element.dblclick(function(_) edit());
-			} else {
-				root.addClass("t_readonly");
-			}
 		case TString if( column.kind == Script ):
 		case TString if( column.kind == Script ):
 			element.click(function(_) edit());
 			element.click(function(_) edit());
 		default:
 		default:
@@ -76,6 +64,15 @@ class Cell extends Component {
 		});
 		});
 	}
 	}
 
 
+	public function dragDropFile( relativePath : String, isDrop : Bool = false ) : Bool {
+		if ( !canEdit() || column.type != TFile) return false;
+		if ( isDrop ) {
+			setValue(relativePath);
+			refresh();
+		}
+		return true;
+	}
+
 	function evaluate() {
 	function evaluate() {
 		var f = editor.formulas.get(this);
 		var f = editor.formulas.get(this);
 		if( f == null ) return;
 		if( f == null ) return;

+ 22 - 0
hide/view/CdbTable.hx

@@ -137,6 +137,28 @@ class CdbTable extends hide.ui.View<{}> {
 		editor.refresh();
 		editor.refresh();
 	}
 	}
 
 
+	override public function onDragDrop( items : Array<String>, isDrop : Bool ) {
+		if( items.length == 0 )
+			return false;
+		var path = ide.makeRelative(items[0]);
+		var cell = getCellFromMousePos(ide.mouseX, ide.mouseY);
+		if( cell == null )
+			return false;
+		return cell.dragDropFile(path, isDrop);
+	}
+
+	public function getCellFromMousePos( x : Int, y : Int ) : Null<hide.comp.cdb.Cell> {
+		var pickedEl = js.Browser.document.elementFromPoint(x, y);
+		var el = pickedEl;
+		while (el != null) {
+			var cellRoot = new Element(el);
+			var cell : hide.comp.cdb.Cell = cellRoot.prop("cellComp");
+			if (cell != null) return cell;
+			el = el.parentElement;
+		}
+		return null;
+	}
+
 	override function getTitle() {
 	override function getTitle() {
 		return "CDB"+ @:privateAccess (ide.databaseDiff != null ? " - "+ide.databaseDiff : "");
 		return "CDB"+ @:privateAccess (ide.databaseDiff != null ? " - "+ide.databaseDiff : "");
 	}
 	}

+ 7 - 0
hide/view/FileTree.hx

@@ -132,6 +132,13 @@ class FileTree extends FileView {
 						js.Browser.window.alert(e);
 						js.Browser.window.alert(e);
 					}
 					}
 					} },
 					} },
+				{ label : "Copy Relative Path", enabled : current != null, click : function() {
+					try {
+						ide.setClipboard(current);
+					} catch (e : Dynamic) {
+						js.Browser.window.alert(e);
+					}
+					} },
 				{ label : "Move", enabled : current != null, click : function() {
 				{ label : "Move", enabled : current != null, click : function() {
 					ide.chooseDirectory(function(dir) {
 					ide.chooseDirectory(function(dir) {
 						onRename(current, "/"+dir+"/"+current.split("/").pop());
 						onRename(current, "/"+dir+"/"+current.split("/").pop());