Browse Source

handle rename sheet wrt DataFiles

Nicolas Cannasse 4 years ago
parent
commit
ea617ab870
2 changed files with 16 additions and 10 deletions
  1. 8 3
      hide/comp/cdb/DataFiles.hx
  2. 8 7
      hide/comp/cdb/Editor.hx

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

@@ -137,7 +137,7 @@ class DataFiles {
 			gatherRec(dir.split("/"),[],0);
 	}
 
-	public static function save( ?onSaveBase, ?force ) {
+	public static function save( ?onSaveBase, ?force, ?prevSheetNames : Map<String,String> ) {
 		var ide = Ide.inst;
 		var temp = [];
 		var titles = [];
@@ -160,6 +160,9 @@ class DataFiles {
 			if( s.props.dataFiles != null ) {
 				var sheet = @:privateAccess s.sheet;
 				var sheetName = getTypeName(s);
+				var prevName = sheetName;
+				if( prevSheetNames != null && prevSheetNames.exists(sheetName) )
+					prevName = prevSheetNames.get(sheetName);
 				var ldata = sheet.linesData;
 				for( i in 0...s.lines.length ) {
 					var o = s.lines[i];
@@ -174,10 +177,12 @@ class DataFiles {
 						}
 						var all = pf.getPrefabsByPath(p.path);
 						var inst : hrt.prefab.Prefab = all[p.index];
-						if( inst == null || inst.getCdbType() != sheetName )
+						if( inst == null || inst.getCdbType() != prevName )
 							ide.error("Can't save prefab data "+p.path);
-						else
+						else {
+							if( prevName != sheetName ) Reflect.setField(o,"$cdbtype", sheetName);
 							inst.props = o;
+						}
 					}
 				}
 				var old = Reflect.copy(sheet);

+ 8 - 7
hide/comp/cdb/Editor.hx

@@ -857,28 +857,28 @@ class Editor extends Component {
 			{ label : "Edit", click : function () editColumn(sheet, col) },
 			{ label : "Add Column", click : function () newColumn(sheet, indexColumn) },
 			{ label : "", isSeparator: true },
-			{ label : "Move Left", enabled:  (indexColumn > 0 && 
+			{ label : "Move Left", enabled:  (indexColumn > 0 &&
 				nextVisibleColumnIndex(table, indexColumn, Left) > -1), click : function () {
 				beginChanges();
 				var nextIndex = nextVisibleColumnIndex(table, indexColumn, Left);
 				sheet.columns.remove(col);
 				sheet.columns.insert(nextIndex, col);
-				if (cursor.x == indexColumn) 
+				if (cursor.x == indexColumn)
 					cursor.set(cursor.table, nextIndex, cursor.y);
-				else if (cursor.x == nextIndex) 
+				else if (cursor.x == nextIndex)
 					cursor.set(cursor.table, nextIndex + 1, cursor.y);
 				endChanges();
 				refresh();
 			}},
-			{ label : "Move Right", enabled: (indexColumn < sheet.columns.length - 1 && 
+			{ label : "Move Right", enabled: (indexColumn < sheet.columns.length - 1 &&
 				nextVisibleColumnIndex(table, indexColumn, Right) < sheet.columns.length), click : function () {
 				beginChanges();
 				var nextIndex = nextVisibleColumnIndex(table, indexColumn, Right);
 				sheet.columns.remove(col);
 				sheet.columns.insert(nextIndex, col);
-				if (cursor.x == indexColumn) 
+				if (cursor.x == indexColumn)
 					cursor.set(cursor.table, nextIndex, cursor.y);
-				else if (cursor.x == nextIndex) 
+				else if (cursor.x == nextIndex)
 					cursor.set(cursor.table, nextIndex - 1, cursor.y);
 				endChanges();
 				refresh();
@@ -927,7 +927,7 @@ class Editor extends Component {
 			})});
 
 			switch(col.type) {
-			case TId | TString: 
+			case TId | TString:
 				menu.push({ label : "Sort", click: () -> table.sortBy(col) });
 			default:
 			}
@@ -1089,6 +1089,7 @@ class Editor extends Component {
 			if( StringTools.startsWith(s.name, old + "@") )
 				s.rename(name + "@" + s.name.substr(old.length + 1));
 		endChanges();
+		DataFiles.save(true,[ sheet.name => old ]);
 		return true;
 	}