Просмотр исходного кода

fixes for new cdb separators format

Nicolas Cannasse 3 лет назад
Родитель
Сommit
70c1216994

+ 1 - 1
hide/comp/cdb/Cell.hx

@@ -452,7 +452,7 @@ class Cell extends Component {
 	public function getGroup() : String {
 		var gid : Null<Int> = Reflect.field(line.obj, "group");
 		if( gid == null ) return null;
-		return table.sheet.props.separatorTitles[gid-1];
+		return table.sheet.separators[gid-1].title;
 	}
 
 	public function getDocumentName() {

+ 1 - 7
hide/comp/cdb/DataFiles.hx

@@ -79,13 +79,11 @@ class DataFiles {
 		var lines : Array<Dynamic> = [];
 		var linesData : Array<DataProps> = [];
 		var separators = [];
-		var separatorTitles = [];
 		var sheetName = getTypeName(sheet);
 		@:privateAccess {
 			sheet.sheet.lines = lines;
 			sheet.sheet.linesData = linesData;
 			sheet.sheet.separators = separators;
-			sheet.props.separatorTitles = separatorTitles;
 		}
 		function loadFile( file : String ) {
 			var needSep = true;
@@ -106,8 +104,7 @@ class DataFiles {
 						}
 					}
 					if( needSep ) {
-						separators.push(lines.length);
-						separatorTitles.push(file.split("/").join(" > "));
+						separators.push({ index : lines.length, title : file.split("/").join(" > ") });
 						needSep = false;
 					}
 					if( sheet.idCol != null && Reflect.field(p.props,sheet.idCol.name) == "" )
@@ -217,17 +214,14 @@ class DataFiles {
 					}
 				}
 				var old = Reflect.copy(sheet);
-				var oldTitles = sheet.props.separatorTitles;
 				temp.push(function() {
 					sheet.lines = old.lines;
 					sheet.linesData = old.linesData;
 					sheet.separators = old.separators;
-					sheet.props.separatorTitles = oldTitles;
 				});
 				Reflect.deleteField(sheet,"lines");
 				Reflect.deleteField(sheet,"linesData");
 				sheet.separators = [];
-				Reflect.deleteField(sheet.props,"separatorTitles");
 			}
 		}
 		for( file => pf in prefabs ) {

+ 42 - 40
hide/comp/cdb/Editor.hx

@@ -1214,24 +1214,6 @@ class Editor extends Component {
 		endChanges();
 	}
 
-	function separatorCount( sheet : cdb.Sheet, fromLine : Int, toSep : Int ) {
-		var count = 0;
-		if( fromLine >= sheet.separators[toSep] ) {
-			for( i in (toSep + 1)...sheet.separators.length ) {
-				if( sheet.separators[i] > fromLine )
-					break;
-				count--;
-			}
-		} else {
-			for( i in 0...(toSep + 1) ) {
-				if( sheet.separators[i] <= fromLine )
-					continue;
-				count++;
-			}
-		}
-		return count;
-	}
-
 	public function popupLine( line : Line ) {
 		if( !line.table.canInsert() )
 			return;
@@ -1247,25 +1229,48 @@ class Editor extends Component {
 		var firstLine = isSelectedLine ? selection[0] : line;
 		var lastLine = isSelectedLine ? selection[selection.length - 1] : line;
 
-		var sepIndex = sheet.separators.indexOf(line.index);
+		var sepIndex = -1;
+		for( i in 0...sheet.separators.length )
+			if( sheet.separators[i].index == line.index ) {
+				sepIndex = i;
+				break;
+			}
+
 		var moveSubmenu : Array<hide.comp.ContextMenu.ContextMenuItem> = [];
-		if( sheet.props.separatorTitles != null ) {
-			for( i in 0...sheet.separators.length ) {
-				if( sheet.props.separatorTitles[i] == null )
-					continue;
-				var lastOfGroup = (i == sheet.separators.length - 1) ? line.table.lines.length : sheet.separators[i + 1];
-				var usedLine = firstLine;
-				if( lastOfGroup > line.index ) {
-					lastOfGroup--;
-					usedLine = lastLine;
+		for( sepIndex => sep in sheet.separators ) {
+			if( sep.title == null )
+				continue;
+
+			function separatorCount( fromLine : Int ) {
+				var count = 0;
+				if( fromLine >= sep.index ) {
+					for( i in (sepIndex + 1)...sheet.separators.length ) {
+						if( sheet.separators[i].index > fromLine )
+							break;
+						count--;
+					}
+				} else {
+					for( i in 0...(sepIndex + 1) ) {
+						if( sheet.separators[i].index <= fromLine )
+							continue;
+						count++;
+					}
 				}
-				var delta = lastOfGroup - usedLine.index + separatorCount(sheet, usedLine.index, i);
-				moveSubmenu.push({
-					label : sheet.props.separatorTitles[i],
-					enabled : true,
-					click : isSelectedLine ? moveLines.bind(selection, delta) : moveLine.bind(usedLine, delta),
-				});
+				return count;
+			}
+
+			var lastOfGroup = sepIndex == sheet.separators.length - 1 ? line.table.lines.length : sheet.separators[sepIndex + 1].index;
+			var usedLine = firstLine;
+			if( lastOfGroup > line.index ) {
+				lastOfGroup--;
+				usedLine = lastLine;
 			}
+			var delta = lastOfGroup - usedLine.index + separatorCount(usedLine.index);
+			moveSubmenu.push({
+				label : sep.title,
+				enabled : true,
+				click : isSelectedLine ? moveLines.bind(selection, delta) : moveLine.bind(usedLine, delta),
+			});
 		}
 
 		var hasLocText = false;
@@ -1295,7 +1300,7 @@ class Editor extends Component {
 				enabled:  (lastLine.index < sheet.lines.length - 1),
 				click : isSelectedLine ? moveLines.bind(selection, 1) : moveLine.bind(line, 1),
 			},
-			{ label : "Move to Group", enabled : sheet.props.separatorTitles != null, menu : moveSubmenu },
+			{ label : "Move to Group", enabled : moveSubmenu.length > 0, menu : moveSubmenu },
 			{ label : "", isSeparator : true },
 			{ label : "Insert", click : function() {
 				insertLine(line.table,line.index);
@@ -1312,17 +1317,14 @@ class Editor extends Component {
 				beginChanges();
 				if( sepIndex >= 0 ) {
 					sheet.separators.splice(sepIndex, 1);
-					if( sheet.props.separatorTitles != null ) sheet.props.separatorTitles.splice(sepIndex, 1);
 				} else {
 					sepIndex = sheet.separators.length;
 					for( i in 0...sheet.separators.length )
-						if( sheet.separators[i] > line.index ) {
+						if( sheet.separators[i].index > line.index ) {
 							sepIndex = i;
 							break;
 						}
-					sheet.separators.insert(sepIndex, line.index);
-					if( sheet.props.separatorTitles != null && sheet.props.separatorTitles.length > sepIndex )
-						sheet.props.separatorTitles.insert(sepIndex, null);
+					sheet.separators.insert(sepIndex, { index : line.index });
 				}
 				endChanges();
 				refresh();

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

@@ -44,14 +44,10 @@ class Line extends Component {
 			line = Std.downcast(t, SubTable).cell.line;
 			t = t.parent;
 		}
-		var seps = t.sheet.separators;
-		var i = seps.length - 1;
-		while( i >= 0 ) {
-			if( seps[i] < line.index ) {
-				var t = t.sheet.props.separatorTitles[i];
-				if( t != null ) return t;
-			}
-			i--;
+		for( i in 0...t.sheet.separators.length ) {
+			var sep = t.sheet.separators[t.sheet.separators.length - 1 - i];
+			if( sep.index < line.index && sep.title != null )
+				return sep.title.split(" > ").join("/");
 		}
 		return null;
 	}

+ 1 - 2
hide/comp/cdb/ObjEditor.hx

@@ -90,8 +90,7 @@ class ObjEditor extends Editor {
 		var sheetData = Reflect.copy(@:privateAccess sheet.sheet);
 		sheetData.linesData = null;
 		sheetData.lines = [for( i in 0...sheetData.columns.length ) obj];
-		sheetData.separators = [0];
-		sheetData.props = { separatorTitles: [fileReference] };
+		sheetData.separators = [{ index : 0, title : fileReference }];
 		var s = new cdb.Sheet(sheet.base, sheetData);
 		s.realSheet = sheet;
 		return s;

+ 25 - 26
hide/comp/cdb/Table.hx

@@ -186,15 +186,16 @@ class Table extends Component {
 
 		var tbody = J("<tbody>");
 
-		var lastSepTitle : String = null;
-		var snext = 0, hidden = false;
+		var groupClass : String = null;
+		var sepIndex = -1, sepNext = sheet.separators[++sepIndex], hidden = false;
 		for( i in 0...lines.length+1 ) {
-			while( sheet.separators[snext] == i ) {
-				var sep = makeSeparator(snext, colCount);
+			while( sepNext != null && sepNext.index == i ) {
+				var sep = makeSeparator(sepIndex, colCount);
 				sep.element.appendTo(tbody);
 				if( sep.hidden != null ) hidden = sep.hidden;
-				lastSepTitle = if( sheet.props.separatorTitles != null ) sheet.props.separatorTitles[snext] else null;
-				snext++;
+				if( sepNext.title != null )
+					groupClass = "group-"+StringTools.replace(sepNext.title.toLowerCase(), " ", "-");
+				sepNext = sheet.separators[++sepIndex];
 			}
 			if( i == lines.length ) break;
 			var line = lines[i];
@@ -202,8 +203,8 @@ class Table extends Component {
 				line.hide();
 			else
 				line.create();
-			if( lastSepTitle != null )
-				line.element.addClass("group-" + StringTools.replace(lastSepTitle.toLowerCase(), " ", "-"));
+			if( groupClass != null )
+				line.element.addClass(groupClass);
 			tbody.append(line.element);
 		}
 		element.append(tbody);
@@ -232,7 +233,8 @@ class Table extends Component {
 		var sep = J("<tr>").addClass("separator").append('<td colspan="${colCount+1}"><a href="#" class="toggle"></a><span></span></td>');
 		var content = sep.find("span");
 		var toggle = sep.find("a");
-		var title = if( sheet.props.separatorTitles != null ) sheet.props.separatorTitles[sindex] else null;
+		var sepInfo = sheet.separators[sindex];
+		var title = sepInfo.title;
 		if( title != null )
 			sep.addClass(StringTools.replace('separator-$title'.toLowerCase(), " ", "-"));
 
@@ -240,9 +242,10 @@ class Table extends Component {
 			var snext = 0, sref = -1;
 			var out = [];
 			for( i in 0...lines.length ) {
-				while( sheet.separators[snext] == i ) {
-					var title = if( sheet.props.separatorTitles != null ) sheet.props.separatorTitles[snext] else null;
-					if( title != null ) sref = snext;
+				while( true ) {
+					var sep = sheet.separators[snext];
+					if( sep == null || sep.index != i ) break;
+					if( sep.title != null ) sref = snext;
 					snext++;
 				}
 				if( sref == sindex )
@@ -291,18 +294,8 @@ class Table extends Component {
 				title = JTHIS.val();
 				JTHIS.remove();
 				if( title == "" ) title = null;
-
-				var old = sheet.props.separatorTitles;
-				var titles = sheet.props.separatorTitles;
-				if( titles == null ) titles = [] else titles = titles.copy();
-				while( titles.length < sindex )
-					titles.push(null);
-				titles[sindex] = title;
-				while( titles[titles.length - 1] == null && titles.length > 0 )
-					titles.pop();
-				if( titles.length == 0 ) titles = null;
 				editor.beginChanges();
-				sheet.props.separatorTitles = titles;
+				sheet.separators[sindex].title = title == null ? js.Lib.undefined : title;
 				editor.endChanges();
 				sync();
 			}).keypress(function(e) {
@@ -444,10 +437,16 @@ class Table extends Component {
 			for(i in 0...group.length)
 				sheet.lines[startIndex + i] = group[i];
 		}
-
+		var sepIndex = 0;
 		for(i in 0...lines.length) {
-			var sep = sheet.separators.indexOf(i) >= 0;
-			if(sep) {
+			var isSeparator = false;
+			while( sepIndex < sheet.separators.length ) {
+				var sep = sheet.separators[sepIndex];
+				if( sep.index > i ) break;
+				if( sep.index == i ) isSeparator = true;
+				sepIndex++;
+			}
+			if( isSeparator ) {
 				sort();
 				group = [];
 				startIndex = i;