فهرست منبع

Copy/Paste for Range

Also normaized Copy/Paste behavior of file select and range (can right
click both header or selector)
Clement Espeute 2 سال پیش
والد
کامیت
dd492bce91
2فایلهای تغییر یافته به همراه37 افزوده شده و 4 حذف شده
  1. 6 2
      hide/comp/FileSelect.hx
  2. 31 2
      hide/comp/Range.hx

+ 6 - 2
hide/comp/FileSelect.hx

@@ -21,7 +21,8 @@ class FileSelect extends Component {
 				}, false, path);
 			}
 		});
-		root.contextmenu(function(e) {
+
+		function contextMenu(e) {
 			e.preventDefault();
 			var fpath = getFullPath();
 			new ContextMenu([
@@ -35,7 +36,10 @@ class FileSelect extends Component {
 				{ label : "Open in explorer", enabled : fpath != null, click : function() Sys.command("explorer.exe",["/select,"+fpath.split("/").join("\\")]) },
 			]);
 			return false;
-		});
+		}
+
+		root.parent().prev("dt").contextmenu(contextMenu);
+		root.contextmenu(contextMenu);
 
 		// allow drag files
 		root.on("dragover", function(e) {

+ 31 - 2
hide/comp/Range.hx

@@ -43,14 +43,22 @@ class Range extends Component {
 		else
 			current = 0;
 
-		root.parent().prev("dt").contextmenu(function(e) {
+		function contextMenu(e) {
 			e.preventDefault();
 			new ContextMenu([
 				{ label : "Reset", click : reset },
+				{ label : "sep", isSeparator: true},
+				{ label : "Copy", click : copy},
+				{ label : "Paste", click: paste, enabled : canPaste()},
+				{ label : "sep", isSeparator: true},
 				{ label : "Cancel", click : function() {} },
 			]);
 			return false;
-		});
+		}
+
+		root.parent().prev("dt").contextmenu(contextMenu);
+
+		element.contextmenu(contextMenu);
 
 		f.on("input", function(_) {
 			var v = Math.round(Std.parseFloat(f.val()) * 100 * scale) / 100;
@@ -91,6 +99,27 @@ class Range extends Component {
 		});
 	}
 
+	public function copy() {
+		ide.setClipboard(Std.string(value));
+	}
+
+	public function paste() {
+		var val = getClipboardValue();
+		if (val != null) {
+			set_value(val);
+			onChange(false);
+		}
+	}
+
+	public function canPaste() : Bool {
+		return getClipboardValue() != null;
+	}
+
+	public function getClipboardValue() : Null<Float> {
+		var str = ide.getClipboard();
+		return Std.parseFloat(str);
+	}
+
 	public function reset() {
 		value = original;
 		onChange(false);