Browse Source

Ref viewer prototype

Clement Espeute 2 years ago
parent
commit
3831fcbf68
3 changed files with 116 additions and 6 deletions
  1. 58 5
      hide/comp/cdb/Editor.hx
  2. 36 1
      hide/view/CdbTable.hx
  3. 22 0
      hide/view/RefViewer.hx

+ 58 - 5
hide/comp/cdb/Editor.hx

@@ -899,6 +899,7 @@ class Editor extends Component {
 		if( results != null ) {
 		if( results != null ) {
 			for( rs in results ) {
 			for( rs in results ) {
 				var path = [];
 				var path = [];
+				var coords = [];
 				for( i in 0...rs.s.length ) {
 				for( i in 0...rs.s.length ) {
 					var s = rs.s[i];
 					var s = rs.s[i];
 					var oid = Reflect.field(rs.o.path[i], s.id);
 					var oid = Reflect.field(rs.o.path[i], s.id);
@@ -908,8 +909,54 @@ class Editor extends Component {
 					else
 					else
 						path.push(oid);
 						path.push(oid);
 				}
 				}
-				path.push(rs.s[rs.s.length-1].c);
-				message.push(rs.s[0].s.name+"  "+path.join("."));
+
+				// Build a path of coordinates in the tables and subtable of the editor for the goto-reference functionality
+				var isSheet = true;
+				var curIdx = 0;
+				while(curIdx < rs.o.indexes.length) {
+					var colNo = 0;
+					var lineNo = 0;
+
+					function findColumnId(sheet: cdb.Sheet, name: String) {
+						var retid = null;
+						for (id => c in sheet.columns) {
+							if (c.name == name) {
+								retid = id;
+								break;
+							}
+						}
+						if (retid == null)
+							throw "wtf";
+
+						return retid;
+					}
+
+					if (isSheet) {
+						// sheets will reference an id, and optionally a column
+
+						lineNo = rs.o.indexes[curIdx];
+						var sheet = rs.s[curIdx].s;
+						var columns = sheet.columns;
+						if (curIdx < rs.o.indexes.length) {
+							colNo = findColumnId(sheet, rs.s[curIdx].c);
+							isSheet = rs.s[curIdx].s.columns[colNo].type != TProperties;
+						}
+					}
+					else {
+						// properties will only reference a column, which is then treated as a line in the editor
+						lineNo = findColumnId(rs.s[curIdx].s, rs.s[curIdx].c);
+						isSheet = rs.s[curIdx].s.columns[lineNo].type != TProperties;
+					}
+
+					curIdx += 1;
+
+					coords.push({line: lineNo, column: colNo});
+				}
+
+				openReference2(rs.s[0].s, coords);
+				return [];
+				//path.push(rs.s[rs.s.length-1].c);
+				//message.push(rs.s[0].s.name+"  "+path.join("."));
 			}
 			}
 		}
 		}
 		if (withCodePaths) {
 		if (withCodePaths) {
@@ -983,7 +1030,7 @@ class Editor extends Component {
 
 
 				var results = [];
 				var results = [];
 				for( s in sheet.base.sheets ) {
 				for( s in sheet.base.sheets ) {
-					for( c in s.columns )
+					for( cid => c in s.columns )
 						switch( c.type ) {
 						switch( c.type ) {
 						case TString:
 						case TString:
 							if (c.kind == cdb.Data.ColumnKind.Script) {
 							if (c.kind == cdb.Data.ColumnKind.Script) {
@@ -1072,6 +1119,8 @@ class Editor extends Component {
 			ide.message("No reference found");
 			ide.message("No reference found");
 			return;
 			return;
 		}
 		}
+		//ide.open("hide.view.RefViewer", {refs: [], editor: this});
+
 		ide.message(message.join("\n"));
 		ide.message(message.join("\n"));
 	}
 	}
 
 
@@ -1089,8 +1138,12 @@ class Editor extends Component {
 		}
 		}
 	}
 	}
 
 
-	function openReference( s : cdb.Sheet, line : Int, column : Int ) {
-		ide.open("hide.view.CdbTable", {}, function(view) Std.downcast(view,hide.view.CdbTable).goto(s,line,column));
+	function openReference2(rootSheet : cdb.Sheet, coords: Array<{line: Int, column: Int}>, ?scriptLine: Int) {
+		ide.open("hide.view.CdbTable", {}, function(view) Std.downcast(view,hide.view.CdbTable).goto2(rootSheet,coords,scriptLine));
+	}
+
+	function openReference( s : cdb.Sheet, line : Int, column : Int, ?scriptLine: Int ) {
+		ide.open("hide.view.CdbTable", {}, function(view) Std.downcast(view,hide.view.CdbTable).goto(s,line,column,scriptLine));
 	}
 	}
 
 
 	public function syncSheet( ?base, ?name ) {
 	public function syncSheet( ?base, ?name ) {

+ 36 - 1
hide/view/CdbTable.hx

@@ -24,7 +24,32 @@ class CdbTable extends hide.ui.View<{}> {
 		view = cast this.config.get("cdb.view");
 		view = cast this.config.get("cdb.view");
 	}
 	}
 
 
-	public function goto( s : cdb.Sheet, ?line : Int, ?column : Int ) {
+	public function goto2(rootSheet : cdb.Sheet, coords: Array<{line: Int, column: Int}>, ?scriptLine: Int) {
+
+
+		var sheets = [for( s in getSheets() ) s.name];
+		var index = sheets.indexOf(rootSheet.name);
+		if( index < 0 ) return;
+		tabs.currentTab = tabContents[index].parent();
+		editor.setFilter(null);
+		var curTable = @:privateAccess editor.tables[0];
+		for (i in 0...coords.length) {
+			var c = coords[i];
+			editor.cursor.set(curTable, c.column, c.line);
+			if( editor.cursor.table != null && c.line != null ) {
+				editor.cursor.table.expandLine(c.line);
+				if (i < coords.length - 1) {
+					editor.cursor.getCell().open(false);
+					curTable = editor.cursor.table;
+				}
+			}
+			else
+				break;
+		}
+
+	}
+
+	public function goto( s : cdb.Sheet, ?line : Int, ?column : Int, ?scriptLine : Int ) {
 		var sheets = [for( s in getSheets() ) s.name];
 		var sheets = [for( s in getSheets() ) s.name];
 		var index = sheets.indexOf(s.name);
 		var index = sheets.indexOf(s.name);
 		if( index < 0 ) return;
 		if( index < 0 ) return;
@@ -35,6 +60,16 @@ class CdbTable extends hide.ui.View<{}> {
 				editor.cursor.setDefault(line, column);
 				editor.cursor.setDefault(line, column);
 			if( editor.cursor.table != null )
 			if( editor.cursor.table != null )
 				editor.cursor.table.expandLine(line);
 				editor.cursor.table.expandLine(line);
+			if (scriptLine != null) {
+				var cell = editor.cursor.getCell();
+				if (cell != null) {
+					cell.open(false);
+					var scr = Std.downcast(cell.line.subTable, hide.comp.cdb.ScriptTable);
+					if (scr != null) {
+						@:privateAccess scr.script.editor.setPosition({column:0, lineNumber: scriptLine});
+					}
+				}
+			}
 		}
 		}
 		editor.focus();
 		editor.focus();
 		haxe.Timer.delay(() -> editor.cursor.update(), 1); // scroll
 		haxe.Timer.delay(() -> editor.cursor.update(), 1); // scroll

+ 22 - 0
hide/view/RefViewer.hx

@@ -0,0 +1,22 @@
+package hide.view;
+
+enum Info {
+	Script(line: Int);
+	Cell(sheet: cdb.Sheet, line: Int, column : Int, ?scriptLine: Int);
+}
+
+class Data {
+	var refs : Array<Info>;
+}
+
+class RefViewer extends hide.ui.View<Data> {
+	public function new(state: Data) {
+		super(state);
+	}
+
+	override function onDisplay() {
+		element.append(new Element("<p> hello worlds ?</p>"));
+	}
+
+	static var _ = hide.ui.View.register(RefViewer, {position: Bottom, width: 100});
+}