Procházet zdrojové kódy

partial support for scoped script cdb enums

Nicolas Cannasse před 5 roky
rodič
revize
4bfb3c79c8
3 změnil soubory, kde provedl 42 přidání a 7 odebrání
  1. 15 3
      hide/comp/ScriptEditor.hx
  2. 8 3
      hide/comp/cdb/Cell.hx
  3. 19 1
      hide/comp/cdb/ScriptTable.hx

+ 15 - 3
hide/comp/ScriptEditor.hx

@@ -115,10 +115,17 @@ class ScriptChecker {
 
 			if( api.cdbEnums != null ) {
 				for( c in api.cdbEnums ) {
+					var path = c.split(".");
+					var sname = path.join("@");
+					var objPath = null;
+					if( path.length > 1 ) // might be a scoped id
+						objPath = this.constants.get("cdb.objID").split(":");
 					for( s in ide.database.sheets ) {
-						if( s.name != c ) continue;
-						var name = s.name.charAt(0).toUpperCase() + s.name.substr(1);
-						var kname = name+"Kind";
+						if( s.name != sname ) continue;
+						var name = path[path.length - 1];
+						name = name.charAt(0).toUpperCase() + name.substr(1);
+						var kname = path.join("_")+"Kind";
+						kname = kname.charAt(0).toUpperCase() + kname.substr(1);
 						if( cdbPack != "" ) kname = cdbPack + "." + kname;
 						var kind = checker.types.resolve(kname);
 						if( kind == null )
@@ -129,9 +136,14 @@ class ScriptChecker {
 							fields : new Map(),
 							statics : new Map()
 						};
+						var refPath = s.idCol.scope == null ? null : objPath.slice(0, s.idCol.scope).join(":")+":";
 						for( o in s.all ) {
 							var id = o.id;
 							if( id == null || id == "" ) continue;
+							if( refPath != null ) {
+								if( !StringTools.startsWith(id, refPath) ) continue;
+								id = id.substr(refPath.length);
+							}
 							cl.fields.set(id, { name : id, params : [], canWrite : false, t : kind, isPublic: true, complete : true });
 						}
 						checker.setGlobal(name, TInst(cl,[]));

+ 8 - 3
hide/comp/cdb/Cell.hx

@@ -184,7 +184,7 @@ class Cell extends Component {
 				editor.isUniqueID(sheet,obj,id) ? v : '<span class="error">#DUP($v)</span>';
 			}
 		case TString if( c.kind == Script ):
-			v == "" ? "&nbsp;" : colorizeScript(c,v);
+			v == "" ? "&nbsp;" : colorizeScript(c,v, sheet.idCol == null ? null : Reflect.field(obj, sheet.idCol.name));
 		case TString, TLayer(_):
 			v == "" ? "&nbsp;" : StringTools.htmlEscape(v).split("\n").join("<br/>");
 		case TRef(sname):
@@ -316,13 +316,18 @@ class Cell extends Component {
 
 	static var KWDS = ["for","if","var","this","while","else","do","break","continue","switch","function","return","new","throw","try","catch","case","default"];
 	static var KWD_REG = new EReg([for( k in KWDS ) "(\\b"+k+"\\b)"].join("|"),"g");
-	function colorizeScript( c : cdb.Data.Column, ecode : String ) {
+	function colorizeScript( c : cdb.Data.Column, ecode : String, objID : String ) {
 		var code = ecode;
 		code = StringTools.htmlEscape(code);
 		code = code.split("\n").join("<br/>");
 		code = code.split("\t").join("&nbsp;&nbsp;&nbsp;&nbsp;");
 		// typecheck
-		var error = new ScriptEditor.ScriptChecker(editor.config, "cdb."+getDocumentName()+(c == this.column ? "" : "."+ c.name), ["cdb."+table.sheet.name => line.obj]).check(ecode);
+		var error = new ScriptEditor.ScriptChecker(editor.config, "cdb."+getDocumentName()+(c == this.column ? "" : "."+ c.name),
+			[
+				"cdb."+table.sheet.name => line.obj,
+				"cdb.objID" => objID,
+			]
+		).check(ecode);
 		if( error != null )
 			return '<span class="error">'+code+'</span>';
 		// strings

+ 19 - 1
hide/comp/cdb/ScriptTable.hx

@@ -33,8 +33,26 @@ class ScriptTable extends SubTable {
 		var first = script == null;
 		element.html("<div class='cdb-script'></div>");
 		var div = element.children("div");
+		var ids = [];
+		var table = cell.table;
+		var obj = cell.line.obj;
+		while( table != null ) {
+			var idCol = table.getRealSheet().idCol;
+			if( idCol != null ) {
+				var id = Reflect.field(obj, idCol.name);
+				if( id == null ) id = "#";
+				ids.unshift(id);
+			}
+			var st = Std.downcast(table, SubTable);
+			table = table.parent;
+			if( st != null ) obj = st.cell.line.obj;
+		}
+
 		div.on("keypress keydown keyup", (e) -> e.stopPropagation());
-		var checker = new ScriptEditor.ScriptChecker(editor.config,"cdb."+cell.getDocumentName(),[ "cdb."+cell.table.sheet.name => cell.line.obj ]);
+		var checker = new ScriptEditor.ScriptChecker(editor.config,"cdb."+cell.getDocumentName(),[
+			"cdb."+cell.table.sheet.name => cell.line.obj,
+			"cdb.objID" => ids.join(":"),
+		]);
 		script = new ScriptEditor(cell.value, checker, div);
 		script.onSave = saveValue;
 		script.onClose = function() { close(); cell.focus(); }