Browse Source

cdb popup line ok

Nicolas Cannasse 6 years ago
parent
commit
a8fe30f7f2
3 changed files with 43 additions and 1 deletions
  1. 4 0
      hide/Ide.hx
  2. 4 1
      hide/comp/ContextMenu.hx
  3. 35 0
      hide/comp/cdb/Editor.hx

+ 4 - 0
hide/Ide.hx

@@ -88,6 +88,10 @@ class Ide {
 		fileWatcher = new hide.tools.FileWatcher();
 
 		setProject(ideConfig.currentProject);
+		window.window.document.addEventListener("mousedown", function(e) {
+			mouseX = e.x;
+			mouseY = e.y;
+		});
 		window.window.document.addEventListener("mousemove", function(e) {
 			mouseX = e.x;
 			mouseY = e.y;

+ 4 - 1
hide/comp/ContextMenu.hx

@@ -14,7 +14,10 @@ class ContextMenu {
 	public function new( config : Array<ContextMenuItem> ) {
 		var menu = makeMenu(config);
 		var ide = hide.Ide.inst;
-		menu.popup(ide.mouseX, ide.mouseY);
+		// wait until mousedown to get correct mouse pos
+		haxe.Timer.delay(function() {
+			menu.popup(ide.mouseX, ide.mouseY)
+		},0);
 	}
 
 	function makeMenu( config : Array<ContextMenuItem> ) {

+ 35 - 0
hide/comp/cdb/Editor.hx

@@ -508,6 +508,41 @@ class Editor extends Component {
 	}
 
 	public function popupLine( line : Line ) {
+		var sheet = line.table.sheet;
+		var sepIndex = sheet.separators.indexOf(line.index);
+		new hide.comp.ContextMenu([
+			{ label : "Move Up", click : moveLine.bind(line,-1) },
+			{ label : "Move Down", click : moveLine.bind(line,1) },
+			{ label : "Insert", click : function() {
+				insertLine(line.table,line.index);
+				cursor.move(0,1,false,false);
+			} },
+			{ label : "Delete", click : function() {
+				beginChanges();
+				sheet.deleteLine(line.index);
+				endChanges();
+				refreshAll();
+			} },
+			{ label : "Separator", enabled : !sheet.props.hide, checked : sepIndex >= 0, click : function() {
+				beginChanges();
+				if( sepIndex >= 0 ) {
+					sheet.separators.splice(sepIndex, 1);
+					if( sheet.props.separatorTitles != null ) sheet.props.separatorTitles.splice(sepIndex, 1);
+				} else {
+					sepIndex = sheet.separators.length;
+					for( i in 0...sheet.separators.length )
+						if( sheet.separators[i] > line.index ) {
+							sepIndex = i;
+							break;
+						}
+					sheet.separators.insert(sepIndex, line.index);
+					if( sheet.props.separatorTitles != null && sheet.props.separatorTitles.length > sepIndex )
+						sheet.props.separatorTitles.insert(sepIndex, null);
+				}
+				endChanges();
+				refresh();
+			} }
+		]);
 	}
 
 	public function close() {