Browse Source

cdb undo redo save

Nicolas Cannasse 7 years ago
parent
commit
77e35884de
5 changed files with 42 additions and 4 deletions
  1. 9 0
      bin/defaultProps.json
  2. 19 0
      hide/comp/cdb/Editor.hx
  3. 6 3
      hide/comp/cdb/Table.hx
  4. 5 1
      hide/ui/Ide.hx
  5. 3 0
      hide/view/CdbTable.hx

+ 9 - 0
bin/defaultProps.json

@@ -18,9 +18,18 @@
 
 	"key.search" : "Ctrl-F",
 
+	// cdb keys
+
+	"key.cdb.showReferences" : "F3",
+
+	// cdb config
+
+	"cdb.databaseFile" : "data.cdb",
+
 	// paths to look files/shaders into - relative to project root
 	"haxe.classPath" : ["src"],
 
+
 	// reserved for internal ide usage
 	"hide" : {}
 

+ 19 - 0
hide/comp/cdb/Editor.hx

@@ -16,9 +16,11 @@ class Editor extends Component {
 		schema : Array<cdb.Data.Column>,
 	};
 	public var cursor : Cursor;
+	public var undo : hide.ui.UndoHistory;
 
 	public function new(root, sheet, keys) {
 		super(root);
+		this.undo = new hide.ui.UndoHistory();
 		this.sheet = sheet;
 		this.keys = keys;
 		keys.addListener(onKey);
@@ -27,6 +29,9 @@ class Editor extends Component {
 			searchBox.find("input").focus().select();
 		});
 		keys.register("copy", onCopy);
+		keys.register("cdb.showReferences", showReferences);
+		keys.register("undo", function() if( undo.undo() ) { refresh(); save(); });
+		keys.register("redo", function() if( undo.redo() ) { refresh(); save(); });
 		base = sheet.base;
 		cursor = new Cursor(this);
 		refresh();
@@ -46,6 +51,9 @@ class Editor extends Component {
 		case K.DOWN:
 			cursor.move( 0, 1, e.shiftKey, e.ctrlKey);
 			return true;
+		case K.TAB:
+			cursor.move( e.shiftKey ? -1 : 1, 0, false, false);
+			return true;
 		case K.SPACE:
 			e.preventDefault(); // prevent scroll
 		}
@@ -95,6 +103,11 @@ class Editor extends Component {
 		ide.setClipboard(clipboard.text);
 	}
 
+	function showReferences() {
+		if( cursor.table == null ) return;
+		// todo : port from old cdb
+	}
+
 	function refresh() {
 
 		root.html('');
@@ -126,6 +139,12 @@ class Editor extends Component {
 		new Table(this, sheet, content);
 		content.appendTo(root);
 
+		if( cursor.table != null ) {
+			for( t in tables )
+				if( t.sheet == cursor.table.sheet )
+					cursor.table = t;
+			cursor.update();
+		}
 	}
 
 	function quickExists(path) {

+ 6 - 3
hide/comp/cdb/Table.hx

@@ -110,9 +110,10 @@ class Table extends Component {
 						title = JTHIS.val();
 						JTHIS.remove();
 						content.text(title);
-						/*
+
+						var old = sheet.props.separatorTitles;
 						var titles = sheet.props.separatorTitles;
-						if( titles == null ) titles = [];
+						if( titles == null ) titles = [] else titles = titles.copy();
 						while( titles.length < pos )
 							titles.push(null);
 						titles[pos] = title == "" ? null : title;
@@ -120,7 +121,9 @@ class Table extends Component {
 							titles.pop();
 						if( titles.length == 0 ) titles = null;
 						sheet.props.separatorTitles = titles;
-						save();*/
+						editor.undo.change(Field(sheet.props,"separatorTitles",old));
+						editor.save(); // no undo on separator rename
+
 					}).keypress(function(e) {
 						e.stopPropagation();
 					}).keydown(function(e) {

+ 5 - 1
hide/ui/Ide.hx

@@ -281,7 +281,7 @@ class Ide {
 			r.onError = function(msg) error(msg);
 		}
 
-		var db = getPath("data.cdb");
+		var db = getPath(props.project.get("cdb.databaseFile"));
 		databaseFile = db;
 		database = new cdb.Database();
 		if( sys.FileSystem.exists(db) ) {
@@ -304,6 +304,10 @@ class Ide {
 		initLayout();
 	}
 
+	public function saveDatabase() {
+		sys.io.File.saveContent(databaseFile, database.save());
+	}
+
 	public function makeRelative( path : String ) {
 		path = path.split("\\").join("/");
 		if( StringTools.startsWith(path.toLowerCase(), resourceDir.toLowerCase()+"/") )

+ 3 - 0
hide/view/CdbTable.hx

@@ -23,6 +23,9 @@ class CdbTable extends hide.ui.View<{ path : String }> {
 		var keys = new hide.ui.Keys(props);
 		this.keys.subKeys = [keys];
 		editor = new hide.comp.cdb.Editor(root, sheet, keys);
+		editor.save = function() {
+			ide.saveDatabase();
+		};
 		new Element("<div style='width:100%; height:300px'></div>").appendTo(root);
 	}