Name change recorded properly in history browser.
This commit is contained in:
parent
c747edd002
commit
00ff4599d1
4 changed files with 88 additions and 6 deletions
|
@ -35,6 +35,33 @@ Item {
|
|||
redoStack = []
|
||||
}
|
||||
|
||||
function serialize() {
|
||||
let undoSt = [], redoSt = [];
|
||||
for(let i = 0; i < undoCount; i++)
|
||||
undoSt.push([
|
||||
undoStack[i].type(),
|
||||
undoStack[i].export()
|
||||
]);
|
||||
for(let i = 0; i < redoCount; i++)
|
||||
redoSt.push([
|
||||
redoStack[i].type(),
|
||||
redoStack[i].export()
|
||||
]);
|
||||
return [undoSt, redoSt]
|
||||
}
|
||||
|
||||
function unserialize(undoSt, redoSt) {
|
||||
clear();
|
||||
for(let i = 0; i < undoSt.length; i++)
|
||||
undoStack.push(new HistoryLib.Actions[undoSt[i][0]](...undoSt[i][1]))
|
||||
for(let i = 0; i < redoSt.length; i++)
|
||||
redoStack.push(new HistoryLib.Actions[redoSt[i][0]](...redoSt[i][1]))
|
||||
undoCount = undoSt.length;
|
||||
redoCount = redoSt.length;
|
||||
objectLists.update()
|
||||
}
|
||||
|
||||
|
||||
function addToHistory(action) {
|
||||
if(action instanceof HistoryLib.Action) {
|
||||
console.log("Added new entry to history: " + action.getReadableString())
|
||||
|
|
|
@ -141,6 +141,7 @@ ApplicationWindow {
|
|||
"showxgrad": settings.showxgrad,
|
||||
"showygrad": settings.showygrad,
|
||||
"textsize": settings.textsize,
|
||||
"history": history.serialize(),
|
||||
"width": root.width,
|
||||
"height": root.height,
|
||||
"objects": objs,
|
||||
|
@ -153,6 +154,7 @@ ApplicationWindow {
|
|||
var error = "";
|
||||
if(Object.keys(data).includes("type") && data["type"] == "logplotv1") {
|
||||
history.clear()
|
||||
// Importing settings
|
||||
settings.saveFilename = filename
|
||||
settings.xzoom = data["xzoom"]
|
||||
settings.yzoom = data["yzoom"]
|
||||
|
@ -171,9 +173,12 @@ ApplicationWindow {
|
|||
settings.linewidth = data["linewidth"]
|
||||
if("textsize" in data)
|
||||
settings.textsize = data["textsize"]
|
||||
if("history" in data)
|
||||
history.unserialize(...data["history"])
|
||||
root.height = data["height"]
|
||||
root.width = data["width"]
|
||||
|
||||
// Importing objectw
|
||||
Objects.currentObjects = {}
|
||||
for(var objType in data['objects']) {
|
||||
if(Object.keys(Objects.types).indexOf(objType) > -1) {
|
||||
|
|
|
@ -219,6 +219,9 @@ ListView {
|
|||
console.log(Objects.getObjectByName(newName).name, newName)
|
||||
newName = Objects.getNewName(newName)
|
||||
}
|
||||
history.addToHistory(new HistoryLib.NameChanged(
|
||||
objEditor.obj.name, objEditor.objType, newName
|
||||
))
|
||||
Objects.currentObjects[objEditor.objType][objEditor.objIndex].name = newName
|
||||
objEditor.obj = Objects.currentObjects[objEditor.objType][objEditor.objIndex]
|
||||
objectListList.update()
|
||||
|
|
|
@ -22,10 +22,11 @@
|
|||
|
||||
.import "objects.js" as Objects
|
||||
.import "utils.js" as Utils
|
||||
.import "mathlib.js" as MathLib
|
||||
|
||||
class Action {
|
||||
// Type of the action done.
|
||||
static type(){return 'Unknown'}
|
||||
type(){return 'Unknown'}
|
||||
|
||||
// TargetName is the name of the object that's targeted by the event.
|
||||
constructor(targetName = "", targetType = "Point") {
|
||||
|
@ -37,6 +38,10 @@ class Action {
|
|||
|
||||
redo() {}
|
||||
|
||||
export() {
|
||||
return [this.targetName, this.targetType]
|
||||
}
|
||||
|
||||
getReadableString() {
|
||||
return 'Unknown action'
|
||||
}
|
||||
|
@ -44,13 +49,14 @@ class Action {
|
|||
|
||||
class CreateNewObject extends Action {
|
||||
// Action used for the creation of an object
|
||||
static type(){return 'CreateNewObject'}
|
||||
type(){return 'CreateNewObject'}
|
||||
|
||||
constructor(targetName = "", targetType = "Point", properties = []) {
|
||||
super(targetName, targetType)
|
||||
this.targetProperties = properties
|
||||
}
|
||||
|
||||
|
||||
undo() {
|
||||
var targetIndex = Objects.getObjectsName(this.targetType).indexOf(this.targetName)
|
||||
Objects.currentObjects[this.targetType][targetIndex].delete()
|
||||
|
@ -61,6 +67,10 @@ class CreateNewObject extends Action {
|
|||
Objects.createNewRegisteredObject(this.targetType, this.targetProperties)
|
||||
}
|
||||
|
||||
export() {
|
||||
return [this.targetName, this.targetType, this.targetProperties]
|
||||
}
|
||||
|
||||
getReadableString() {
|
||||
return `New ${this.targetType} ${this.targetName} created.`
|
||||
}
|
||||
|
@ -68,7 +78,7 @@ class CreateNewObject extends Action {
|
|||
|
||||
class DeleteObject extends CreateNewObject {
|
||||
// Action used at the deletion of an object. Basicly the same thing as creating a new object, except Redo & Undo are reversed.
|
||||
static type(){return 'DeleteObject'}
|
||||
type(){return 'DeleteObject'}
|
||||
|
||||
undo() {
|
||||
super.redo()
|
||||
|
@ -85,14 +95,18 @@ class DeleteObject extends CreateNewObject {
|
|||
|
||||
class EditedProperty extends Action {
|
||||
// Action used everytime an object's property has been changed
|
||||
static type(){return 'EditedProperty'}
|
||||
type(){return 'EditedProperty'}
|
||||
|
||||
constructor(targetName = "", targetType = "Point", targetProperty = "visible", previousValue = false, newValue = true) {
|
||||
constructor(targetName = "", targetType = "Point", targetProperty = "visible", previousValue = false, newValue = true, valueIsExpressionNeedingImport = false) {
|
||||
super(targetName, targetType)
|
||||
this.targetProperty = targetProperty
|
||||
this.targetPropertyReadable = Utils.camelCase2readable(this.targetProperty)
|
||||
this.previousValue = previousValue
|
||||
this.newValue = newValue
|
||||
if(valueIsExpressionNeedingImport) {
|
||||
this.previousValue = new MathLib.Expression(this.previousValue);
|
||||
this.newValue = new MathLib.Expression(this.newValue);
|
||||
}
|
||||
}
|
||||
|
||||
undo() {
|
||||
|
@ -103,6 +117,14 @@ class EditedProperty extends Action {
|
|||
Objects.getObjectByName(this.targetName, this.targetType)[this.targetProperty] = this.newValue
|
||||
}
|
||||
|
||||
export() {
|
||||
if(this.previousValue instanceof MathLib.Expression) {
|
||||
return [this.targetName, this.targetType, this.targetProperty, this.previousValue.toEditableString(), this.newValue.toEditableString(), true]
|
||||
} else {
|
||||
return [this.targetName, this.targetType, this.targetProperty, this.previousValue, this.newValue, false]
|
||||
}
|
||||
}
|
||||
|
||||
getReadableString() {
|
||||
var prev = this.previousValue == null ? ""+this.previousValue : this.previousValue.toString()
|
||||
var next = this.newValue == null ? ""+this.newValue : this.newValue.toString()
|
||||
|
@ -112,7 +134,7 @@ class EditedProperty extends Action {
|
|||
|
||||
class EditedVisibility extends EditedProperty {
|
||||
// Action used everytime an object's property has been changed
|
||||
static type(){return 'EditedVisibility'}
|
||||
type(){return 'EditedVisibility'}
|
||||
|
||||
constructor(targetName = "", targetType = "Point", newValue = true) {
|
||||
super(targetName, targetType, "visible", !newValue, newValue)
|
||||
|
@ -126,3 +148,28 @@ class EditedVisibility extends EditedProperty {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NameChanged extends EditedProperty {
|
||||
// Action used everytime an object's property has been changed
|
||||
type(){return 'EditedVisibility'}
|
||||
|
||||
constructor(targetName = "", targetType = "Point", newName = "") {
|
||||
super(targetName, targetType, "name", targetName, newName)
|
||||
}
|
||||
|
||||
undo() {
|
||||
Objects.getObjectByName(this.newValue, this.targetType)['name'] = this.previousValue
|
||||
}
|
||||
|
||||
redo() {
|
||||
Objects.getObjectByName(this.previousValue, this.targetType)[this.targetProperty] = this.newValue
|
||||
}
|
||||
}
|
||||
|
||||
var Actions = {
|
||||
"Action": Action,
|
||||
"CreateNewObject": CreateNewObject,
|
||||
"DeleteObject": DeleteObject,
|
||||
"EditedProperty": EditedProperty,
|
||||
"EditedVisibility": EditedVisibility,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue