|
@@ -14,7 +14,7 @@ typedef UndoSheet = {
|
|
typedef UndoState = {
|
|
typedef UndoState = {
|
|
var data : Any;
|
|
var data : Any;
|
|
var sheet : String;
|
|
var sheet : String;
|
|
- var cursor : { sheet : String, x : Int, y : Int, select : Null<{ x : Int, y : Int }> };
|
|
|
|
|
|
+ var cursor : Cursor.CursorState;
|
|
var tables : Array<UndoSheet>;
|
|
var tables : Array<UndoSheet>;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -53,17 +53,21 @@ class Editor extends Component {
|
|
var api : EditorApi;
|
|
var api : EditorApi;
|
|
var undoState : Array<UndoState> = [];
|
|
var undoState : Array<UndoState> = [];
|
|
var currentValue : Any;
|
|
var currentValue : Any;
|
|
|
|
+ var cdbTable : hide.view.CdbTable;
|
|
public var view : cdb.DiffFile.ConfigView;
|
|
public var view : cdb.DiffFile.ConfigView;
|
|
public var config : hide.Config;
|
|
public var config : hide.Config;
|
|
public var cursor : Cursor;
|
|
public var cursor : Cursor;
|
|
public var keys : hide.ui.Keys;
|
|
public var keys : hide.ui.Keys;
|
|
public var undo : hide.ui.UndoHistory;
|
|
public var undo : hide.ui.UndoHistory;
|
|
|
|
+ public var cursorStates : Array<UndoState> = [];
|
|
|
|
+ public var cursorIndex : Int = 0;
|
|
public var formulas : Formulas;
|
|
public var formulas : Formulas;
|
|
|
|
|
|
- public function new(config,api) {
|
|
|
|
|
|
+ public function new(config, api, ?cdbTable) {
|
|
super(null,null);
|
|
super(null,null);
|
|
this.api = api;
|
|
this.api = api;
|
|
this.config = config;
|
|
this.config = config;
|
|
|
|
+ this.cdbTable = cdbTable;
|
|
view = cast this.config.get("cdb.view");
|
|
view = cast this.config.get("cdb.view");
|
|
undo = new hide.ui.UndoHistory();
|
|
undo = new hide.ui.UndoHistory();
|
|
}
|
|
}
|
|
@@ -90,6 +94,9 @@ class Editor extends Component {
|
|
cell.edit();
|
|
cell.edit();
|
|
});
|
|
});
|
|
element.contextmenu(function(e) e.preventDefault());
|
|
element.contextmenu(function(e) e.preventDefault());
|
|
|
|
+
|
|
|
|
+ cdbTable.element.mousedown(onMouseDown);
|
|
|
|
+
|
|
keys = new hide.ui.Keys(element);
|
|
keys = new hide.ui.Keys(element);
|
|
keys.addListener(onKey);
|
|
keys.addListener(onKey);
|
|
keys.register("search", function() {
|
|
keys.register("search", function() {
|
|
@@ -102,6 +109,8 @@ class Editor extends Component {
|
|
keys.register("cdb.showReferences", showReferences);
|
|
keys.register("cdb.showReferences", showReferences);
|
|
keys.register("undo", function() undo.undo());
|
|
keys.register("undo", function() undo.undo());
|
|
keys.register("redo", function() undo.redo());
|
|
keys.register("redo", function() undo.redo());
|
|
|
|
+ keys.register("cdb.moveBack", () -> cursorJump(true));
|
|
|
|
+ keys.register("cdb.moveAhead", () -> cursorJump(false));
|
|
keys.register("cdb.insertLine", function() { insertLine(cursor.table,cursor.y); cursor.move(0,1,false,false); });
|
|
keys.register("cdb.insertLine", function() { insertLine(cursor.table,cursor.y); cursor.move(0,1,false,false); });
|
|
for( k in ["cdb.editCell","rename"] )
|
|
for( k in ["cdb.editCell","rename"] )
|
|
keys.register(k, function() {
|
|
keys.register(k, function() {
|
|
@@ -122,14 +131,31 @@ class Editor extends Component {
|
|
});
|
|
});
|
|
keys.register("cdb.gotoReference", () -> gotoReference(cursor.getCell()));
|
|
keys.register("cdb.gotoReference", () -> gotoReference(cursor.getCell()));
|
|
base = sheet.base;
|
|
base = sheet.base;
|
|
- cursor = new Cursor(this);
|
|
|
|
|
|
+ if( cursor == null )
|
|
|
|
+ cursor = new Cursor(this);
|
|
|
|
+ else if ( !tables.contains(cursor.table) )
|
|
|
|
+ cursor.set();
|
|
if( displayMode == null ) displayMode = Table;
|
|
if( displayMode == null ) displayMode = Table;
|
|
DataFiles.load();
|
|
DataFiles.load();
|
|
if( currentValue == null ) currentValue = api.copy();
|
|
if( currentValue == null ) currentValue = api.copy();
|
|
refresh();
|
|
refresh();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ function onMouseDown( e : js.jquery.Event ) {
|
|
|
|
+ switch ( e.which ) {
|
|
|
|
+ case 4:
|
|
|
|
+ cursorJump(true);
|
|
|
|
+ return false;
|
|
|
|
+ case 5:
|
|
|
|
+ cursorJump(false);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
function onKey( e : js.jquery.Event ) {
|
|
function onKey( e : js.jquery.Event ) {
|
|
|
|
+ if( e.altKey )
|
|
|
|
+ return false;
|
|
switch( e.keyCode ) {
|
|
switch( e.keyCode ) {
|
|
case K.LEFT:
|
|
case K.LEFT:
|
|
cursor.move( -1, 0, e.shiftKey, e.ctrlKey);
|
|
cursor.move( -1, 0, e.shiftKey, e.ctrlKey);
|
|
@@ -419,14 +445,8 @@ class Editor extends Component {
|
|
return {
|
|
return {
|
|
data : currentValue,
|
|
data : currentValue,
|
|
sheet : getCurrentSheet(),
|
|
sheet : getCurrentSheet(),
|
|
- cursor : cursor.table == null ? null : {
|
|
|
|
- sheet : cursor.table.sheet.name,
|
|
|
|
- x : cursor.x,
|
|
|
|
- y : cursor.y,
|
|
|
|
- select : cursor.select == null ? null : { x : cursor.select.x, y : cursor.select.y }
|
|
|
|
- },
|
|
|
|
|
|
+ cursor : cursor.getState(),
|
|
tables : [for( i in 1...tables.length ) {
|
|
tables : [for( i in 1...tables.length ) {
|
|
- var t = tables[i];
|
|
|
|
function makeParent(t:Table) : UndoSheet {
|
|
function makeParent(t:Table) : UndoSheet {
|
|
var tp = t.parent;
|
|
var tp = t.parent;
|
|
return { sheet : t.sheet.name, parent : tp == null ? null : {
|
|
return { sheet : t.sheet.name, parent : tp == null ? null : {
|
|
@@ -448,7 +468,7 @@ class Editor extends Component {
|
|
var t = openRec(s.parent.sheet);
|
|
var t = openRec(s.parent.sheet);
|
|
if( t != null ) {
|
|
if( t != null ) {
|
|
var cell = t.lines[s.parent.line].cells[t.displayMode == Properties || t.displayMode == AllProperties ? 0 : s.parent.column];
|
|
var cell = t.lines[s.parent.line].cells[t.displayMode == Properties || t.displayMode == AllProperties ? 0 : s.parent.column];
|
|
- if( cell.line.subTable == null )
|
|
|
|
|
|
+ if( cell.line.subTable == null && (cell.column.type == TList || cell.column.type == TProperties) )
|
|
cell.open(true);
|
|
cell.open(true);
|
|
return cell.line.subTable;
|
|
return cell.line.subTable;
|
|
}
|
|
}
|
|
@@ -464,14 +484,15 @@ class Editor extends Component {
|
|
|
|
|
|
if( cur != null ) {
|
|
if( cur != null ) {
|
|
var table = null;
|
|
var table = null;
|
|
- for( t in tables )
|
|
|
|
- if( t.sheet.name == cur.sheet ) {
|
|
|
|
|
|
+ for( t in tables ) {
|
|
|
|
+ if( t.sheet.getPath() == cur.sheet ) {
|
|
table = t;
|
|
table = t;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
if( table != null && doFocus )
|
|
if( table != null && doFocus )
|
|
focus();
|
|
focus();
|
|
- cursor.set(table, cur.x, cur.y, cur.select == null ? null : { x : cur.select.x, y : cur.select.y } );
|
|
|
|
|
|
+ cursor.setState(cur, table);
|
|
} else
|
|
} else
|
|
cursor.set();
|
|
cursor.set();
|
|
}
|
|
}
|
|
@@ -501,6 +522,7 @@ class Editor extends Component {
|
|
currentValue = newValue;
|
|
currentValue = newValue;
|
|
currentSheet = newSheet;
|
|
currentSheet = newSheet;
|
|
}
|
|
}
|
|
|
|
+ pushCursorState();
|
|
api.load(currentValue);
|
|
api.load(currentValue);
|
|
DataFiles.save(true); // save reloaded data
|
|
DataFiles.save(true); // save reloaded data
|
|
element.removeClass("is-cdb-editor");
|
|
element.removeClass("is-cdb-editor");
|
|
@@ -516,6 +538,97 @@ class Editor extends Component {
|
|
api.save();
|
|
api.save();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ function undoStatesEqual( s1 : UndoState, s2 : UndoState, cmpCursors = true ) {
|
|
|
|
+ function cursorEqual(c1 : Cursor.CursorState, c2 : Cursor.CursorState) {
|
|
|
|
+ if( c1 == c2 )
|
|
|
|
+ return true;
|
|
|
|
+ if( c1 == null || c2 == null )
|
|
|
|
+ return false;
|
|
|
|
+ return c1.sheet == c2.sheet && c1.x == c2.x && c1.y == c2.y;
|
|
|
|
+ }
|
|
|
|
+ function undoSheetEqual(s1 : UndoSheet, s2 : UndoSheet) {
|
|
|
|
+ if( s1.parent == null && s2.parent == null )
|
|
|
|
+ return s1.sheet == s2.sheet;
|
|
|
|
+ if( s1.parent == null || s2.parent == null )
|
|
|
|
+ return false;
|
|
|
|
+ if ( s1.sheet != s2.sheet || s1.parent.column != s2.parent.column || s1.parent.line != s2.parent.line )
|
|
|
|
+ return false;
|
|
|
|
+ return undoSheetEqual(s1.parent.sheet, s2.parent.sheet);
|
|
|
|
+ }
|
|
|
|
+ if ( s1.sheet != s2.sheet )
|
|
|
|
+ return false;
|
|
|
|
+ if( s1.tables.length != s2.tables.length )
|
|
|
|
+ return false;
|
|
|
|
+ for( i in 0...s1.tables.length ) {
|
|
|
|
+ if( !undoSheetEqual(s1.tables[i], s2.tables[i]) )
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ if( !cmpCursors )
|
|
|
|
+ return true;
|
|
|
|
+ if( cursorEqual(s1.cursor, s2.cursor) )
|
|
|
|
+ return true;
|
|
|
|
+ if( s1.cursor == null || s2.cursor == null )
|
|
|
|
+ return false;
|
|
|
|
+ return s1.cursor.y == -1 && s2.cursor.y == -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function pushCursorState() {
|
|
|
|
+ if ( cursor == null )
|
|
|
|
+ return;
|
|
|
|
+ var state = getState();
|
|
|
|
+ state.data = null;
|
|
|
|
+
|
|
|
|
+ var stateBehind = (cursorStates.length <= 0) ? null : cursorStates[cursorIndex];
|
|
|
|
+ if( stateBehind != null && undoStatesEqual(state, stateBehind) )
|
|
|
|
+ return;
|
|
|
|
+ var stateAhead = (cursorStates.length <= 0 || cursorIndex >= cursorStates.length - 1) ? null : cursorStates[cursorIndex + 1];
|
|
|
|
+ if ( stateAhead != null && undoStatesEqual(state, stateAhead) ) {
|
|
|
|
+ cursorIndex++;
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if( cursorIndex < cursorStates.length - 1 && cursorIndex >= 0 ) {
|
|
|
|
+ if( stateBehind != null && !undoStatesEqual(state, stateBehind, false) ) {
|
|
|
|
+ cursorStates.splice(cursorIndex + 1, cursorStates.length);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ cursorStates.insert(cursorIndex + 1, state);
|
|
|
|
+ if( cursorIndex < cursorStates.length - 1 )
|
|
|
|
+ cursorIndex++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function cursorJump(back = true) {
|
|
|
|
+ focus();
|
|
|
|
+
|
|
|
|
+ if( (back && cursorIndex <= 0) || (!back && cursorIndex >= cursorStates.length - 1) )
|
|
|
|
+ return;
|
|
|
|
+ pushCursorState();
|
|
|
|
+ if(back)
|
|
|
|
+ cursorIndex--;
|
|
|
|
+ else
|
|
|
|
+ cursorIndex++;
|
|
|
|
+
|
|
|
|
+ var state = cursorStates[cursorIndex];
|
|
|
|
+ syncSheet(null, state.sheet);
|
|
|
|
+
|
|
|
|
+ if( undoStatesEqual(state, getState(), false) ) {
|
|
|
|
+ setState(state, true);
|
|
|
|
+ if( cursor.table != null ) {
|
|
|
|
+ for( t in tables ) {
|
|
|
|
+ if( t.sheet.getPath() == cursor.table.sheet.getPath() )
|
|
|
|
+ cursor.table = t;
|
|
|
|
+ }
|
|
|
|
+ cursor.update();
|
|
|
|
+ }
|
|
|
|
+ } else
|
|
|
|
+ refresh(state);
|
|
|
|
+
|
|
|
|
+ if( cdbTable != null )
|
|
|
|
+ @:privateAccess cdbTable.syncTabs();
|
|
|
|
+ }
|
|
|
|
+
|
|
public static var inRefreshAll(default,null) : Bool;
|
|
public static var inRefreshAll(default,null) : Bool;
|
|
public static function refreshAll( eraseUndo = false ) {
|
|
public static function refreshAll( eraseUndo = false ) {
|
|
var editors : Array<Editor> = [for( e in new Element(".is-cdb-editor").elements() ) e.data("cdb")];
|
|
var editors : Array<Editor> = [for( e in new Element(".is-cdb-editor").elements() ) e.data("cdb")];
|
|
@@ -576,7 +689,6 @@ class Editor extends Component {
|
|
}
|
|
}
|
|
|
|
|
|
public function refresh( ?state : UndoState ) {
|
|
public function refresh( ?state : UndoState ) {
|
|
-
|
|
|
|
if( state == null )
|
|
if( state == null )
|
|
state = getState();
|
|
state = getState();
|
|
|
|
|
|
@@ -612,12 +724,11 @@ class Editor extends Component {
|
|
new Table(this, currentSheet, content, displayMode);
|
|
new Table(this, currentSheet, content, displayMode);
|
|
content.appendTo(element);
|
|
content.appendTo(element);
|
|
|
|
|
|
- if( state != null )
|
|
|
|
- setState(state, hasFocus);
|
|
|
|
|
|
+ setState(state, hasFocus);
|
|
|
|
|
|
if( cursor.table != null ) {
|
|
if( cursor.table != null ) {
|
|
for( t in tables )
|
|
for( t in tables )
|
|
- if( t.sheet.name == cursor.table.sheet.name )
|
|
|
|
|
|
+ if( t.sheet.getPath() == cursor.table.sheet.getPath() )
|
|
cursor.table = t;
|
|
cursor.table = t;
|
|
cursor.update();
|
|
cursor.update();
|
|
}
|
|
}
|