2
0
Эх сурвалжийг харах

several cdb fixes, allow tilepos file rebase

Nicolas Cannasse 6 жил өмнө
parent
commit
798f8cefef

+ 7 - 4
hide/Ide.hx

@@ -415,7 +415,7 @@ class Ide {
 
 
 		databaseFile = config.project.get("cdb.databaseFile");
 		databaseFile = config.project.get("cdb.databaseFile");
 		loadDatabase();
 		loadDatabase();
-		fileWatcher.register(databaseFile,loadDatabase);
+		fileWatcher.register(databaseFile,function() loadDatabase(true));
 		databaseApi = {
 		databaseApi = {
 			copy : () -> (database.save() : Any),
 			copy : () -> (database.save() : Any),
 			load : (v:Any) -> database.load((v:String)),
 			load : (v:Any) -> database.load((v:String)),
@@ -521,10 +521,13 @@ class Ide {
 		js.Browser.location.reload();
 		js.Browser.location.reload();
 	}
 	}
 
 
-	function loadDatabase() {
-		database = new cdb.Database();
+	function loadDatabase( ?checkExists ) {
 		var db = getPath(databaseFile);
 		var db = getPath(databaseFile);
-		if( sys.FileSystem.exists(db) ) {
+		var exists = sys.FileSystem.exists(db);
+		if( checkExists && !exists )
+			return; // cancel load
+		database = new cdb.Database();
+		if( exists ) {
 			try {
 			try {
 				database.load(sys.io.File.getContent(db));
 				database.load(sys.io.File.getContent(db));
 			} catch( e : Dynamic ) {
 			} catch( e : Dynamic ) {

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

@@ -450,7 +450,7 @@ class Cell extends Component {
 				var v : Dynamic = { file : file, size : size, x : pos.x, y : pos.y };
 				var v : Dynamic = { file : file, size : size, x : pos.x, y : pos.y };
 				if( pos.width != 1 ) v.width = pos.width;
 				if( pos.width != 1 ) v.width = pos.width;
 				if( pos.height != 1 ) v.height = pos.height;
 				if( pos.height != 1 ) v.height = pos.height;
-				setValue(v);
+				setRawValue(v);
 			}
 			}
 
 
 			if( file == null ) {
 			if( file == null ) {
@@ -501,8 +501,13 @@ class Cell extends Component {
 		new Element("<div>").addClass("error").html(msg).appendTo(element);
 		new Element("<div>").addClass("error").html(msg).appendTo(element);
 	}
 	}
 
 
-	function setRawValue( str : String ) {
-		var newValue : Dynamic = try editor.base.parseValue(column.type, str, false) catch( e : Dynamic ) return;
+	function setRawValue( str : Dynamic ) {
+		var newValue : Dynamic;
+		if( Std.is(str,String) ) {
+			newValue = try editor.base.parseValue(column.type, str, false) catch( e : Dynamic ) return;
+		} else
+			newValue = str;
+
 		if( newValue == null || newValue == currentValue )
 		if( newValue == null || newValue == currentValue )
 			return;
 			return;
 
 
@@ -532,6 +537,27 @@ class Cell extends Component {
 			*/
 			*/
 		case TString if( column.kind == Script ):
 		case TString if( column.kind == Script ):
 			setValue(StringTools.trim(newValue));
 			setValue(StringTools.trim(newValue));
+		case TTilePos:
+			// if we change a file that has moved, change it for all instances having the same file
+			editor.beginChanges();
+			var obj = line.obj;
+			var change = false;
+			var oldV : cdb.Types.TilePos = currentValue;
+			var newV : cdb.Types.TilePos = newValue;
+			if( newV != null && oldV != null && oldV.file != newV.file && !sys.FileSystem.exists(ide.getPath(oldV.file)) && sys.FileSystem.exists(ide.getPath(newV.file)) ) {
+				for( l in table.lines) {
+					if( l == line ) continue;
+					var t : Dynamic = Reflect.field(l.obj, column.name);
+					if( t != null && t.file == oldV.file ) {
+						t.file = newV.file;
+						change = true;
+					}
+				}
+			}
+			setValue(newValue);
+			editor.endChanges();
+			if( change )
+				editor.refresh();
 		default:
 		default:
 			setValue(newValue);
 			setValue(newValue);
 		}
 		}

+ 6 - 1
hide/comp/cdb/Cursor.hx

@@ -90,11 +90,16 @@ class Cursor {
 		update();
 		update();
 	}
 	}
 
 
-	public function update() {
+	public function hide() {
 		var elt = editor.element;
 		var elt = editor.element;
 		elt.find(".selected").removeClass("selected");
 		elt.find(".selected").removeClass("selected");
 		elt.find(".cursorView").removeClass("cursorView");
 		elt.find(".cursorView").removeClass("cursorView");
 		elt.find(".cursorLine").removeClass("cursorLine");
 		elt.find(".cursorLine").removeClass("cursorLine");
+	}
+
+	public function update() {
+		var elt = editor.element;
+		hide();
 		if( table == null )
 		if( table == null )
 			return;
 			return;
 		if( y < 0 ) {
 		if( y < 0 ) {

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

@@ -54,6 +54,7 @@ class Editor extends Component {
 	function init() {
 	function init() {
 		element.attr("tabindex", 0);
 		element.attr("tabindex", 0);
 		element.on("focus", function(_) onFocus());
 		element.on("focus", function(_) onFocus());
+		element.on("blur", function(_) cursor.hide());
 		element.on("keypress", function(e) {
 		element.on("keypress", function(e) {
 			if( e.target.nodeName == "INPUT" )
 			if( e.target.nodeName == "INPUT" )
 				return;
 				return;
@@ -216,7 +217,7 @@ class Editor extends Component {
 			var y = sel.y2;
 			var y = sel.y2;
 			while( y >= sel.y1 ) {
 			while( y >= sel.y1 ) {
 				var line = cursor.table.lines[y];
 				var line = cursor.table.lines[y];
-				line.table.sheet.lines.splice(line.index, 1);
+				line.table.sheet.deleteLine(line.index);
 				hasChanges = true;
 				hasChanges = true;
 				y--;
 				y--;
 			}
 			}

+ 9 - 5
hide/tools/FileWatcher.hx

@@ -5,7 +5,7 @@ private typedef FileEvent = {path:String,fun:Void->Void,checkDel:Bool,element:js
 class FileWatcher {
 class FileWatcher {
 
 
 	var ide : hide.Ide;
 	var ide : hide.Ide;
-	var watches : Map<String,{ events : Array<FileEvent>, w : js.node.fs.FSWatcher, ignoreNext : Bool, changed : Bool, isDir : Bool }> = new Map();
+	var watches : Map<String,{ events : Array<FileEvent>, w : js.node.fs.FSWatcher, ignoreNext : Bool, wasChanged : Bool, changed : Bool, isDir : Bool }> = new Map();
 	var timer : haxe.Timer;
 	var timer : haxe.Timer;
 
 
 	public function new() {
 	public function new() {
@@ -77,20 +77,24 @@ class FileWatcher {
 				changed : false,
 				changed : false,
 				isDir : try sys.FileSystem.isDirectory(fullPath) catch( e : Dynamic ) false,
 				isDir : try sys.FileSystem.isDirectory(fullPath) catch( e : Dynamic ) false,
 				ignoreNext : false,
 				ignoreNext : false,
+				wasChanged : false,
 			};
 			};
 			w.w = try js.node.Fs.watch(fullPath, function(k:String, file:String) {
 			w.w = try js.node.Fs.watch(fullPath, function(k:String, file:String) {
-				if( w.changed || (w.isDir && k == "change") ) return;
+				if( w.isDir && k == "change" ) return;
+				if( k == "change" ) w.wasChanged = true;
+				if( w.changed ) return;
 				w.changed = true;
 				w.changed = true;
 				haxe.Timer.delay(function() {
 				haxe.Timer.delay(function() {
+					if( !w.changed ) return;
+					w.changed = false;
 					if( w.ignoreNext ) {
 					if( w.ignoreNext ) {
 						w.ignoreNext = false;
 						w.ignoreNext = false;
 						return;
 						return;
 					}
 					}
-					if( !w.changed ) return;
-					w.changed = false;
 					for( e in w.events.copy() )
 					for( e in w.events.copy() )
-						if( isLive(w.events,e) && (k == "change" || e.checkDel) )
+						if( isLive(w.events,e) && (w.wasChanged || e.checkDel) )
 							e.fun();
 							e.fun();
+					w.wasChanged = false;
 				}, 100);
 				}, 100);
 			}) catch( e : Dynamic ) {
 			}) catch( e : Dynamic ) {
 				// file does not exists, trigger a delayed event
 				// file does not exists, trigger a delayed event

+ 5 - 1
hide/ui/View.hx

@@ -176,7 +176,11 @@ class View<T> extends hide.comp.Component {
 		Gives focus if part of a tab group
 		Gives focus if part of a tab group
 	**/
 	**/
 	public function activate() {
 	public function activate() {
-		if( container != null ) container.parent.parent.setActiveContentItem(container.parent);
+		if( container != null ) {
+			var cur = container.parent.parent.getActiveContentItem();
+			if( cur != container.parent )
+				container.parent.parent.setActiveContentItem(container.parent);
+		}
 	}
 	}
 
 
 	public function saveState() {
 	public function saveState() {

+ 1 - 0
libs/golden/ContentItem.hx

@@ -15,6 +15,7 @@ extern class ContentItem {
 	public function off( type : String ) : Void;
 	public function off( type : String ) : Void;
 	public function replaceChild( c : ContentItem, config : Config.ItemConfig ) : Void;
 	public function replaceChild( c : ContentItem, config : Config.ItemConfig ) : Void;
 	public function getItemsByFilter( f : ContentItem -> Bool ) : Array<ContentItem>;
 	public function getItemsByFilter( f : ContentItem -> Bool ) : Array<ContentItem>;
+	public function getActiveContentItem() : ContentItem;
 	public function setActiveContentItem( item : ContentItem ) : Void;
 	public function setActiveContentItem( item : ContentItem ) : Void;
 
 
 }
 }