Fixed many issues with new History module, including saved status.

+ Fixed (old) bug that label content wasn't being saved.
This commit is contained in:
Adsooi 2024-10-11 02:03:27 +02:00
parent 2dc9234b22
commit 448d94fee3
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
19 changed files with 479 additions and 459 deletions

View file

@ -23,9 +23,16 @@ import { Action, Actions } from "../history/index.mjs"
class UpdatedEvent extends BaseEvent {
class ClearedEvent extends BaseEvent {
constructor() {
super("updated")
super("cleared")
}
}
class AddedEvent extends BaseEvent {
constructor(action) {
super("added")
this.action = action
}
}
@ -44,7 +51,7 @@ class RedoneEvent extends BaseEvent {
}
class HistoryAPI extends Module {
static emits = ["updated", "undone", "redone"]
static emits = ["cleared", "added", "undone", "redone"]
#helper
@ -113,7 +120,7 @@ class HistoryAPI extends Module {
if(!this.initialized) throw new Error("Attempting clear before initialize!")
this.undoStack = []
this.redoStack = []
this.emit(new UpdatedEvent())
this.emit(new ClearedEvent())
}
/**
@ -127,7 +134,7 @@ class HistoryAPI extends Module {
this.undoStack.push(action)
if(this.#helper.getSettingBool("reset_redo_stack"))
this.redoStack = []
this.emit(new UpdatedEvent())
this.emit(new AddedEvent(action))
}
}

View file

@ -79,7 +79,6 @@ export class CanvasInterface extends Interface {
export class RootInterface extends Interface {
width = NUMBER
height = NUMBER
updateObjectsLists = FUNCTION
}
export class DialogInterface extends Interface {

View file

@ -22,26 +22,59 @@ import History from "./history.mjs"
import Canvas from "./canvas.mjs"
import Settings from "./settings.mjs"
import { DialogInterface, RootInterface } from "./interface.mjs"
import { BaseEvent } from "../events.mjs"
class LoadedEvent extends BaseEvent {
constructor() {
super("loaded")
}
}
class SavedEvent extends BaseEvent {
constructor() {
super("saved")
}
}
class ModifiedEvent extends BaseEvent {
constructor() {
super("modified")
}
}
class IOAPI extends Module {
static emits = ["loaded", "saved", "modified"]
/** @type {RootInterface} */
#rootElement
/** @type {{show: function(string)}} */
#alert
#saved = true
constructor() {
super("IO", {
alert: DialogInterface,
root: RootInterface
})
/**
* Path of the currently opened file. Empty if no file is opened.
* @type {string}
*/
this.saveFileName = ""
// Settings.on("changed", this.__emitModified.bind(this))
console.log("Init IO", this)
History.on("added undone redone", this.__emitModified.bind(this))
}
__emitModified() {
this.#saved = false
this.emit(new ModifiedEvent())
}
/**
* True if no changes have been made since last save, false otherwise.
* @return {boolean}
*/
get saved() { return this.#saved }
/**
* Initializes module with QML elements.
* @param {RootInterface} root
@ -92,7 +125,7 @@ class IOAPI extends Module {
}
Helper.write(filename, JSON.stringify(settings))
this.#alert.show(qsTranslate("io", "Saved plot to '%1'.").arg(filename.split("/").pop()))
History.history.saved = true
this.emit(new SavedEvent())
}
/**
@ -159,8 +192,6 @@ class IOAPI extends Module {
if("history" in data)
History.unserialize(...data["history"])
// Refreshing sidebar
this.#rootElement.updateObjectsLists()
} else {
error = qsTranslate("io", "Invalid file provided.")
}
@ -172,7 +203,7 @@ class IOAPI extends Module {
}
Canvas.redraw()
this.#alert.show(qsTranslate("io", "Loaded file '%1'.").arg(basename))
History.history.saved = true
this.emit(new LoadedEvent())
}
}

View file

@ -63,7 +63,7 @@ export default class BodePhase extends ExecutableObject {
// Create new point
om_0 = Objects.createNewRegisteredObject("Point", [Objects.getNewName("ω"), this.color, "name"])
om_0.labelPosition = this.phase.execute() >= 0 ? "above" : "below"
History.history.addToHistory(new CreateNewObject(om_0.name, "Point", om_0.export()))
History.addToHistory(new CreateNewObject(om_0.name, "Point", om_0.export()))
labelPosition = "below"
}
om_0.requiredBy.push(this)