瀏覽代碼

RemoteConsole: support openCDB with selectExpr

Yuxiao Mao 6 月之前
父節點
當前提交
4cd556d27b
共有 2 個文件被更改,包括 25 次插入3 次删除
  1. 18 1
      hrt/impl/RemoteConsole.hx
  2. 7 2
      hrt/impl/RemoteTools.hx

+ 18 - 1
hrt/impl/RemoteConsole.hx

@@ -326,7 +326,21 @@ class RemoteConsoleConnection {
 			var sheet = hide.Ide.inst.database.getSheet(args.cdbsheet);
 			hide.Ide.inst.open("hide.view.CdbTable", {}, null, function(view) {
 				hide.Ide.inst.focus();
-				Std.downcast(view, hide.view.CdbTable).goto(sheet, args.line, args.column);
+				var line = args.line;
+				if( sheet != null && args.selectExpr != null ) {
+					try {
+						var expr = parser.parseString(args.selectExpr);
+						for( i in 0...sheet.lines.length ) {
+							if( evalExpr(sheet.lines[i], expr) == true ) {
+								line = i;
+								break;
+							}
+						}
+					} catch( e ) {
+						hide.Ide.inst.quickError(e);
+					}
+				}
+				Std.downcast(view, hide.view.CdbTable).goto(sheet, line, args.column ?? -1);
 			});
 		} else {
 			hide.Ide.inst.showFileInResources(args.file);
@@ -377,6 +391,8 @@ class RemoteConsoleConnection {
 			}
 		case EIdent("$"):
 			return o;
+		case EIdent("null"):
+			return null;
 		case EIdent(v):
 			return v; // Unknown ident, consider as a String literal
 		case EField(e, f):
@@ -387,6 +403,7 @@ class RemoteConsoleConnection {
 			var v2 = evalExpr(o, e2);
 			switch( op ) {
 			case "==": return Reflect.compare(v1, v2) == 0;
+			case "&&": return v1 == true && v2 == true;
 			default:
 				throw "Can't eval " + Std.string(v1) + " " + op + " " + Std.string(v2);
 			}

+ 7 - 2
hrt/impl/RemoteTools.hx

@@ -77,8 +77,13 @@ class RemoteTools {
 		rc?.sendCommand("logError", msg);
 	}
 
-	public static function openCdb( sheet : String, ?line : Int, ?column : Int ) {
-		rc?.sendCommand("open", { cdbsheet : sheet, line : line, column : column });
+	/**
+		@param selectExpr hscript expression that are used for select a line in the given sheet.
+		Example: `$.id == Some_Unique_Id`, `$.name == SomeName`
+		(`"` can be omitted in String literal when no ambiguity).
+	 */
+	public static function openCdb( sheet : String, ?line : Int, ?column : Int, ?selectExpr : String ) {
+		rc?.sendCommand("open", { cdbsheet : sheet, line : line, column : column, selectExpr : selectExpr });
 	}
 
 	public static function openRes( file : String ) {