diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/History.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/History.qml
index 47c4fbe..50cd168 100644
--- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/History.qml
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/History.qml
@@ -20,6 +20,7 @@ import QtQuick 2.12
import QtQml 2.12
import "../js/objects.js" as Objects
import "../js/historylib.js" as HistoryLib
+import "../js/history/common.js" as HistoryCommon
/*!
\qmltype History
@@ -209,5 +210,6 @@ Item {
Component.onCompleted: {
HistoryLib.history = historyObj
+ HistoryCommon.themeTextColor = sysPalette.windowText
}
}
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryBrowser.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryBrowser.qml
index f785cd0..40b7690 100644
--- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryBrowser.qml
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryBrowser.qml
@@ -43,11 +43,6 @@ ScrollView {
*/
property int actionWidth: width-20
- /*!
- \qmlproperty int HistoryBrowser::actionHeight
- Height of the actions.
- */
- property int actionHeight: 40
/*!
\qmlproperty int HistoryBrowser::darkTheme
true when the system is running with a dark theme, false otherwise.
@@ -72,7 +67,7 @@ ScrollView {
HistoryItem {
id: redoButton
width: actionWidth
- height: actionHeight
+ //height: actionHeight
isRedo: true
idx: index
darkTheme: historyBrowser.darkTheme
@@ -96,7 +91,7 @@ ScrollView {
anchors.right: parent.right
anchors.top: redoColumn.bottom
width: actionWidth
- height: actionHeight
+ height: 40
color: sysPalette.highlight
Text {
anchors.verticalCenter: parent.verticalCenter
@@ -120,7 +115,7 @@ ScrollView {
HistoryItem {
id: undoButton
width: actionWidth
- height: actionHeight
+ //height: actionHeight
isRedo: false
idx: index
darkTheme: historyBrowser.darkTheme
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryItem.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryItem.qml
index 1475853..909cbaa 100644
--- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryItem.qml
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/History/HistoryItem.qml
@@ -59,6 +59,14 @@ Button {
*/
readonly property var historyAction: isRedo ? history.redoStack[idx] : history.undoStack[history.undoCount-idx-1]
+ /*!
+ \qmlproperty int HistoryItem::actionHeight
+ Base height of the action.
+ */
+ readonly property int actionHeight: 40
+
+ height: Math.max(actionHeight, label.height + 15)
+
LinearGradient {
anchors.fill: parent
start: Qt.point(0, 0)
@@ -74,7 +82,7 @@ Button {
width: 18
height: 18
anchors.left: parent.left
- anchors.leftMargin: (parent.height-height)/2
+ anchors.leftMargin: 6
anchors.verticalCenter: parent.verticalCenter
color: sysPalette.windowText
@@ -85,19 +93,21 @@ Button {
id: label
anchors.left: icon.right
anchors.right: parent.right
- anchors.leftMargin: 4
- anchors.rightMargin: (parent.height-height)/2
+ anchors.leftMargin: 6
+ anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
font.pixelSize: 14
- text: historyAction.getReadableString()
+ text: historyAction.getHTMLString()
+ textFormat: Text.RichText
clip: true
+ wrapMode: Text.WordWrap
}
//text: historyAction.getReadableString()
ToolTip.visible: hovered
ToolTip.delay: 200
- ToolTip.text: label.text
+ ToolTip.text: historyAction.getReadableString()
onClicked: {
if(isRedo)
@@ -105,6 +115,14 @@ Button {
else
history.undoMultipleDefered(+idx+1)
}
+
+ Rectangle {
+ color: sysPalette. window
+ anchors.left: parent.left
+ anchors.right: parent.right
+ anchors.bottom: parent.bottom
+ height: 1
+ }
}
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml
index 7c008f8..d16b2f6 100644
--- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml
@@ -215,7 +215,7 @@ ListView {
color: obj.color
title: qsTr("Pick new color for %1 %2").arg(Objects.types[objType].displayType()).arg(obj.name)
onAccepted: {
- history.addToHistory(new HistoryLib.EditedProperty(
+ history.addToHistory(new HistoryLib.ColorChanged(
obj.name, objType, "color",
obj.color, color.toString()
))
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/color.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/color.js
new file mode 100644
index 0000000..ec50642
--- /dev/null
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/color.js
@@ -0,0 +1,53 @@
+/**
+ * LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
+ * Copyright (C) 2022 Ad5001
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+.pragma library
+
+.import "editproperty.js" as EP
+.import "../objects.js" as Objects
+
+
+class ColorChanged extends EP.EditedProperty {
+ // Action used everytime when an object's color is changed
+ type(){return 'ColorChanged'}
+
+ icon(){return 'appearance'}
+
+
+ color(darkVer=false){return darkVer ? 'purple' : 'plum'}
+
+ getReadableString() {
+ return qsTr("%1 %2's color changed from %3 to %4.")
+ .arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
+ .arg(this.previousValue).arg(this.newValue)
+ }
+
+ formatColor(color) {
+ return ` `
+ }
+
+ getHTMLString() {
+ return qsTr("%1 %2's color changed from %3 to %4.")
+ .arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
+ .arg(this.formatColor(this.previousValue)).arg(this.formatColor(this.newValue))
+ }
+}
+
+
+
+
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.js
index 5f51fe8..909da64 100644
--- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.js
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.js
@@ -18,6 +18,8 @@
.pragma library
+var themeTextColor;
+
class Action {
// Type of the action done.
@@ -39,7 +41,18 @@ class Action {
return [this.targetName, this.targetType]
}
+ // String used in the toolkit
getReadableString() {
return 'Unknown action'
}
+
+ // Returns an HTML tag containing the icon of a type
+ getIconRichText(type) {
+ return ``
+ }
+
+ // String used in the preview
+ getHTMLString() {
+ return this.getReadableString()
+ }
}
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.js
new file mode 100644
index 0000000..2a3f505
--- /dev/null
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/create.js
@@ -0,0 +1,56 @@
+/**
+ * LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
+ * Copyright (C) 2022 Ad5001
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+.pragma library
+
+.import "../objects.js" as Objects
+.import "common.js" as C
+
+class CreateNewObject extends C.Action {
+ // Action used for the creation of an object
+ type(){return 'CreateNewObject'}
+
+ icon(){return 'create'}
+
+ color(darkVer=false){return darkVer ? 'green' : 'lime'}
+
+ 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()
+ Objects.currentObjects[this.targetType].splice(targetIndex, 1)
+ }
+
+ redo() {
+ Objects.createNewRegisteredObject(this.targetType, this.targetProperties)
+ }
+
+ export() {
+ return [this.targetName, this.targetType, this.targetProperties]
+ }
+
+ getReadableString() {
+ return qsTr("New %1 %2 created.").arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
+ }
+}
+
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/delete.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/delete.js
new file mode 100644
index 0000000..19ebe3e
--- /dev/null
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/delete.js
@@ -0,0 +1,44 @@
+/**
+ * LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
+ * Copyright (C) 2022 Ad5001
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+.pragma library
+
+.import "../objects.js" as Objects
+.import "create.js" as Create
+
+
+class DeleteObject extends Create.CreateNewObject {
+ // Action used at the deletion of an object. Basicly the same thing as creating a new object, except Redo & Undo are reversed.
+ type(){return 'DeleteObject'}
+
+ icon(){return 'delete'}
+
+ color(darkVer=false){return darkVer ? 'darkred' : 'salmon'}
+
+ undo() {
+ super.redo()
+ }
+
+ redo() {
+ super.undo()
+ }
+
+ getReadableString() {
+ return qsTr("%1 %2 deleted.").arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
+ }
+}
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.js
new file mode 100644
index 0000000..ee33a0d
--- /dev/null
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.js
@@ -0,0 +1,105 @@
+/**
+ * LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
+ * Copyright (C) 2022 Ad5001
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+.pragma library
+
+.import "../objects.js" as Objects
+.import "../mathlib.js" as MathLib
+.import "../objs/common.js" as Common
+.import "common.js" as C
+
+class EditedProperty extends C.Action {
+ // Action used everytime an object's property has been changed
+ type(){return 'EditedProperty'}
+
+ icon(){return 'modify'}
+
+ color(darkVer=false){return darkVer ? 'darkslateblue' : 'cyan'}
+
+ constructor(targetName = "", targetType = "Point", targetProperty = "visible", previousValue = false, newValue = true, valueIsExpressionNeedingImport = false) {
+ super(targetName, targetType)
+ this.targetProperty = targetProperty
+ this.targetPropertyReadable = qsTranslate("prop", this.targetProperty)
+ this.previousValue = previousValue
+ this.newValue = newValue
+ this.propertyType = Objects.types[targetType].properties()[targetProperty]
+ if(valueIsExpressionNeedingImport) {
+ if(this.propertyType == "Expression") {
+ this.previousValue = new MathLib.Expression(this.previousValue);
+ this.newValue = new MathLib.Expression(this.newValue);
+ } else if(this.propertyType == "Domain") {
+ this.previousValue = MathLib.parseDomain(this.previousValue);
+ this.newValue = MathLib.parseDomain(this.newValue);
+ } else {
+ // Objects
+ this.previousValue = Objects.getObjectByName(this.previousValue);
+ this.newValue = Objects.getObjectByName(this.newValue);
+ }
+ }
+ }
+
+ undo() {
+ Objects.getObjectByName(this.targetName, this.targetType)[this.targetProperty] = this.previousValue
+ }
+
+ redo() {
+ 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 if(this.previousValue instanceof Common.DrawableObject) {
+ return [this.targetName, this.targetType, this.targetProperty, this.previousValue.name, this.newValue.name, true]
+ } else {
+ return [this.targetName, this.targetType, this.targetProperty, this.previousValue, this.newValue, false]
+ }
+ }
+
+ getReadableString() {
+ let prev = "";
+ let next = "";
+ if(this.propertyType instanceof Object) {
+ switch(this.propertyType.type) {
+ case "Enum":
+ prev = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.previousValue)]
+ next = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.newValue)]
+ break;
+ case "ObjectType":
+ prev = this.previousValue.name
+ next = this.newValue.name
+ break;
+ case "List":
+ prev = this.previousValue.join(",")
+ next = this.newValue.name.join(",")
+ break;
+ case "Dict":
+ prev = JSON.stringify(this.previousValue).replace("'", "\\'").replace('"', "'")
+ next = JSON.stringify(this.newValue).replace("'", "\\'").replace('"', "'")
+ break;
+ }
+ } else {
+ prev = this.previousValue == null ? "null" : this.previousValue.toString()
+ next = this.newValue == null ? "null" : this.newValue.toString()
+ }
+ return qsTr('%1 of %2 %3 changed from "%4" to "%5".')
+ .arg(this.targetPropertyReadable)
+ .arg(Objects.types[this.targetType].displayType())
+ .arg(this.targetName).arg(prev).arg(next)
+ }
+}
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/name.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/name.js
new file mode 100644
index 0000000..4ad78c6
--- /dev/null
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/name.js
@@ -0,0 +1,57 @@
+/**
+ * LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
+ * Copyright (C) 2022 Ad5001
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+.pragma library
+
+.import "editproperty.js" as EP
+.import "../objects.js" as Objects
+
+
+class NameChanged extends EP.EditedProperty {
+ // Action used everytime an object's property has been changed
+ type(){return 'NameChanged'}
+
+ icon(){return 'name'}
+
+
+ color(darkVer=false){return darkVer ? 'darkorange' : 'orange'}
+
+ constructor(targetName = "", targetType = "Point", newName = "") {
+ super(targetName, targetType, "name", targetName, newName)
+ }
+
+ export() {
+ return [this.targetName, this.targetType, this.newValue]
+ }
+
+ undo() {
+ Objects.getObjectByName(this.newValue, this.targetType)['name'] = this.previousValue
+ }
+
+ redo() {
+ Objects.getObjectByName(this.previousValue, this.targetType)['name'] = this.newValue
+ }
+
+ getReadableString() {
+ return qsTr('Name of %1 %2 changed to %3.')
+ .arg(Objects.types[this.targetType].displayType())
+ .arg(this.targetName).arg(this.newValue)
+ }
+}
+
+
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/visibility.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/visibility.js
new file mode 100644
index 0000000..85ce611
--- /dev/null
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/visibility.js
@@ -0,0 +1,52 @@
+/**
+ * LogarithmPlotter - 2D plotter software to make BODE plots, sequences and repartition functions.
+ * Copyright (C) 2022 Ad5001
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+.pragma library
+
+.import "editproperty.js" as EP
+
+
+class EditedVisibility extends EP.EditedProperty {
+ // Action used when an object's shown or hidden.
+ type(){return 'EditedVisibility'}
+
+ icon(){return 'visibility'}
+
+ color(darkVer=false){
+ return this.newValue ?
+ (darkVer ? 'darkgray' : 'whitesmoke') :
+ (darkVer ? 'dimgray' : 'lightgray')
+ }
+
+ constructor(targetName = "", targetType = "Point", newValue = true) {
+ super(targetName, targetType, "visible", !newValue, newValue)
+ }
+
+ export() {
+ return [this.targetName, this.targetType, this.newValue]
+ }
+
+ getReadableString() {
+ if(this.newValue) {
+ return qsTr('%1 %2 shown.').arg(this.targetType).arg(this.targetName)
+ } else {
+ return qsTr('%1 %2 hidden.').arg(this.targetType).arg(this.targetName)
+ }
+ }
+}
+
diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js
index 7d60c66..ce1fe98 100644
--- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js
+++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js
@@ -20,255 +20,24 @@
// Each type of event is repertoried as an action that can be listed for everything that's undoable.
.pragma library
-.import "objects.js" as Objects
-.import "parameters.js" as P
-.import "objs/common.js" as Common
-.import "utils.js" as Utils
-.import "mathlib.js" as MathLib
+.import "history/common.js" as Common
+.import "history/create.js" as Create
+.import "history/delete.js" as Delete
+.import "history/editproperty.js" as EP
+.import "history/visibility.js" as V
+.import "history/name.js" as Name
+.import "history/color.js" as Color
var history = null;
-class Action {
- // Type of the action done.
- type(){return 'Unknown'}
-
- // Icon of the action to be used in history browser.
- icon(){return 'unknown'}
-
- // Color associated with the action.
- color(darkVer=false){return darkVer ? 'black' : 'white'}
-
- // TargetName is the name of the object that's targeted by the event.
- constructor(targetName = "", targetType = "Point") {
- this.targetName = targetName
- this.targetType = targetType
- }
-
- undo() {}
-
- redo() {}
-
- export() {
- return [this.targetName, this.targetType]
- }
-
- getReadableString() {
- return 'Unknown action'
- }
-}
-class CreateNewObject extends Action {
- // Action used for the creation of an object
- type(){return 'CreateNewObject'}
-
- icon(){return 'create'}
-
- color(darkVer=false){return darkVer ? 'green' : 'lime'}
-
- 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()
- Objects.currentObjects[this.targetType].splice(targetIndex, 1)
- }
-
- redo() {
- Objects.createNewRegisteredObject(this.targetType, this.targetProperties)
- }
-
- export() {
- return [this.targetName, this.targetType, this.targetProperties]
- }
-
- getReadableString() {
- return qsTr("New %1 %2 created.").arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
- }
-}
-
-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.
- type(){return 'DeleteObject'}
-
- icon(){return 'delete'}
-
- color(darkVer=false){return darkVer ? 'darkred' : 'salmon'}
-
- undo() {
- super.redo()
- }
-
- redo() {
- super.undo()
- }
-
- getReadableString() {
- return qsTr("%1 %2 deleted.").arg(Objects.types[this.targetType].displayType()).arg(this.targetName)
- }
-}
-
-class EditedProperty extends Action {
- // Action used everytime an object's property has been changed
- type(){return 'EditedProperty'}
-
- icon(){return 'modify'}
-
- color(darkVer=false){return darkVer ? 'darkslateblue' : 'cyan'}
-
- constructor(targetName = "", targetType = "Point", targetProperty = "visible", previousValue = false, newValue = true, valueIsExpressionNeedingImport = false) {
- super(targetName, targetType)
- this.targetProperty = targetProperty
- this.targetPropertyReadable = qsTranslate("prop", this.targetProperty)
- this.previousValue = previousValue
- this.newValue = newValue
- this.propertyType = Objects.types[targetType].properties()[targetProperty]
- if(valueIsExpressionNeedingImport) {
- if(this.propertyType == "Expression") {
- this.previousValue = new MathLib.Expression(this.previousValue);
- this.newValue = new MathLib.Expression(this.newValue);
- } else if(this.propertyType == "Domain") {
- this.previousValue = MathLib.parseDomain(this.previousValue);
- this.newValue = MathLib.parseDomain(this.newValue);
- } else {
- // Objects
- this.previousValue = Objects.getObjectByName(this.previousValue);
- this.newValue = Objects.getObjectByName(this.newValue);
- }
- }
- }
-
- undo() {
- Objects.getObjectByName(this.targetName, this.targetType)[this.targetProperty] = this.previousValue
- }
-
- redo() {
- 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 if(this.previousValue instanceof Common.DrawableObject) {
- return [this.targetName, this.targetType, this.targetProperty, this.previousValue.name, this.newValue.name, true]
- } else {
- return [this.targetName, this.targetType, this.targetProperty, this.previousValue, this.newValue, false]
- }
- }
-
- getReadableString() {
- let prev = "";
- let next = "";
- if(this.propertyType instanceof Object) {
- switch(this.propertyType.type) {
- case "Enum":
- prev = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.previousValue)]
- next = this.propertyType.translatedValues[this.propertyType.values.indexOf(this.newValue)]
- break;
- case "ObjectType":
- prev = this.previousValue.name
- next = this.newValue.name
- break;
- case "List":
- prev = this.previousValue.join(",")
- next = this.newValue.name.join(",")
- break;
- case "Dict":
- prev = JSON.stringify(this.previousValue).replace("'", "\\'").replace('"', "'")
- next = JSON.stringify(this.newValue).replace("'", "\\'").replace('"', "'")
- break;
- }
- } else {
- prev = this.previousValue == null ? "null" : this.previousValue.toString()
- next = this.newValue == null ? "null" : this.newValue.toString()
- }
- return qsTr('%1 of %2 %3 changed from "%4" to "%5".')
- .arg(this.targetPropertyReadable)
- .arg(Objects.types[this.targetType].displayType())
- .arg(this.targetName).arg(prev).arg(next)
- }
-}
-
-class EditedVisibility extends EditedProperty {
- // Action used everytime an object's property has been changed
- type(){return 'EditedVisibility'}
-
- icon(){return 'visibility'}
-
- color(darkVer=false){
- return this.newValue ?
- (darkVer ? 'darkgray' : 'whitesmoke') :
- (darkVer ? 'dimgray' : 'lightgray')
- }
-
- constructor(targetName = "", targetType = "Point", newValue = true) {
- super(targetName, targetType, "visible", !newValue, newValue)
- }
-
- export() {
- return [this.targetName, this.targetType, this.newValue]
- }
-
- getReadableString() {
- if(this.newValue) {
- return qsTr('%1 %2 shown.').arg(this.targetType).arg(this.targetName)
- } else {
- return qsTr('%1 %2 hidden.').arg(this.targetType).arg(this.targetName)
- }
- }
-}
-
-class NameChanged extends EditedProperty {
- // Action used everytime an object's property has been changed
- type(){return 'NameChanged'}
-
- icon(){return 'name'}
-
-
- color(darkVer=false){return darkVer ? 'darkorange' : 'orange'}
-
- constructor(targetName = "", targetType = "Point", newName = "") {
- super(targetName, targetType, "name", targetName, newName)
- }
-
- export() {
- return [this.targetName, this.targetType, this.newValue]
- }
-
- undo() {
- Objects.getObjectByName(this.newValue, this.targetType)['name'] = this.previousValue
- }
-
- redo() {
- Objects.getObjectByName(this.previousValue, this.targetType)['name'] = this.newValue
- }
-
- getReadableString() {
- return qsTr('Name of %1 %2 changed to %3.')
- .arg(Objects.types[this.targetType].displayType())
- .arg(this.targetName).arg(this.newValue)
- }
-}
-
-class ColorChanged extends EditedProperty {
- // Action used everytime an object's property has been changed
- type(){return 'ColorChanged'}
-
- icon(){return 'appearance'}
-
-
- color(darkVer=false){return darkVer ? 'purple' : 'plum'}
-
- getReadableString() {
- return qsTr('%1 of %2 %3 changed from "%4" to "%5".')
- .arg(QT_TRANSLATE_NOOP('prop','color'))
- .arg(Objects.types[this.targetType].displayType())
- .arg(this.targetName).arg(this.previousValue).arg(this.newValue)
- }
-}
+var Action = Common.Action
+var CreateNewObject = Create.CreateNewObject
+var DeleteObject = Delete.DeleteObject
+var EditedProperty = EP.EditedProperty
+var EditedVisibility = V.EditedVisibility
+var NameChanged = Name.NameChanged
+var ColorChanged = Color.ColorChanged
var Actions = {
"Action": Action,