Prechádzať zdrojové kódy

added cell context menu & goto

Nicolas Cannasse 4 rokov pred
rodič
commit
688b9989a3

+ 24 - 0
hide/comp/cdb/Cell.hx

@@ -53,6 +53,30 @@ class Cell extends Component {
 			else
 				root.addClass("t_readonly");
 		}
+
+		root.click(function(e) {
+			editor.cursor.clickCell(this, e.shiftKey);
+			e.stopPropagation();
+		});
+		root.contextmenu(function(e) {
+			showMenu();
+			e.stopPropagation();
+			e.preventDefault();
+		});
+	}
+
+	function showMenu() {
+		var menu : Array<hide.comp.ContextMenu.ContextMenuItem> = null;
+		switch( column.type ) {
+		case TRef(_):
+			if( value != null && value != "" )
+				menu = [
+					{ label : "Goto", click : () -> @:privateAccess editor.gotoReference(this) },
+				];
+		default:
+		}
+		if( menu != null )
+			new ContextMenu(menu);
 	}
 
 	public function canEdit() {

+ 14 - 3
hide/comp/cdb/Editor.hx

@@ -104,7 +104,7 @@ class Editor extends Component {
 				cursor.update();
 			}
 		});
-		keys.register("cdb.gotoReference", gotoReference);
+		keys.register("cdb.gotoReference", () -> gotoReference(cursor.getCell()));
 		base = sheet.base;
 		cursor = new Cursor(this);
 		if( displayMode == null ) displayMode = Table;
@@ -151,6 +151,18 @@ class Editor extends Component {
 		searchFilter(currentFilter);
 	}
 
+	public function setFilter( f : String ) {
+		if( searchBox != null ) {
+			if( f == null )
+				searchBox.hide();
+			else {
+				searchBox.show();
+				searchBox.find("input").val(f);
+			}
+		}
+		searchFilter(f);
+	}
+
 	function searchFilter( filter : String ) {
 		if( filter == "" ) filter = null;
 		if( filter != null ) filter = filter.toLowerCase();
@@ -484,8 +496,7 @@ class Editor extends Component {
 		// todo : port from old cdb
 	}
 
-	function gotoReference() {
-		var c = cursor.getCell();
+	function gotoReference( c : Cell ) {
 		if( c == null || c.value == null ) return;
 		switch( c.column.type ) {
 		case TRef(s):

+ 0 - 4
hide/comp/cdb/Line.hx

@@ -28,10 +28,6 @@ class Line extends Component {
 			var cell = new Cell(v, this, c);
 			if( c.type == TId && view != null && view.forbid != null && view.forbid.indexOf(cell.value) >= 0 )
 				element.addClass("hidden");
-			v.click(function(e) {
-				table.editor.cursor.clickCell(cell, e.shiftKey);
-				e.stopPropagation();
-			});
 		}
 	}
 

+ 0 - 5
hide/comp/cdb/Table.hx

@@ -318,11 +318,6 @@ class Table extends Component {
 			var cell = new Cell(td, line, c);
 			lines.push(line);
 
-			td.click(function(e) {
-				editor.cursor.clickCell(cell, e.shiftKey);
-				e.stopPropagation();
-			});
-
 			th.mousedown(function(e) {
 				if( e.which == 3 ) {
 					editor.popupColumn(this, c, cell);

+ 1 - 0
hide/view/CdbTable.hx

@@ -29,6 +29,7 @@ class CdbTable extends hide.ui.View<{}> {
 		var index = sheets.indexOf(s.name);
 		if( index < 0 ) return;
 		tabs.currentTab = tabContents[index].parent();
+		editor.setFilter(null);
 		editor.cursor.setDefault(line, column);
 		editor.focus();
 		haxe.Timer.delay(() -> editor.cursor.update(), 1); // scroll