finish undo/redo rework

* "Undo(Redo) last brushstroke" -> "Undo(Redo)".
* Sync `_updateActionSensitivity` menu method with the new undo/redo behavior.
* Smooth button action is no longer destructive.
* Clean undone smooth transformations when doing a new smooth transformation.
This commit is contained in:
abakkk 2020-10-04 22:48:40 +02:00
parent 236e4db236
commit 28def0059d
4 changed files with 15 additions and 15 deletions

View File

@ -413,6 +413,9 @@ const _DrawingElement = new Lang.Class({
this.transformations.push({ type: Transformations.SMOOTH, undoable: true, this.transformations.push({ type: Transformations.SMOOTH, undoable: true,
undo: () => this.points = oldPoints, undo: () => this.points = oldPoints,
redo: () => this.points = newPoints }); redo: () => this.points = newPoints });
if (this._undoneTransformations)
this._undoneTransformations = this._undoneTransformations.filter(transformation => transformation.type != Transformations.SMOOTH);
}, },
addPoint: function() { addPoint: function() {
@ -636,6 +639,10 @@ const _DrawingElement = new Lang.Class({
delete this._undoneTransformations; delete this._undoneTransformations;
}, },
get canUndo() {
return this._undoneTransformations && this._undoneTransformations.length ? true : false;
},
// The figure rotation center before transformations (original). // The figure rotation center before transformations (original).
// this.textWidth is computed during Cairo building. // this.textWidth is computed during Cairo building.
_getOriginalCenter: function() { _getOriginalCenter: function() {

View File

@ -10,7 +10,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Draw On Your Screen\n" "Project-Id-Version: Draw On Your Screen\n"
"Report-Msgid-Bugs-To: https://framagit.org/abakkk/DrawOnYourScreen/issues\n" "Report-Msgid-Bugs-To: https://framagit.org/abakkk/DrawOnYourScreen/issues\n"
"POT-Creation-Date: 2020-09-19 15:32+0200\n" "POT-Creation-Date: 2020-10-04 22:45+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -265,12 +265,6 @@ msgctxt "drawing-tool"
msgid "Mirror" msgid "Mirror"
msgstr "" msgstr ""
msgid "Undo"
msgstr ""
msgid "Redo"
msgstr ""
msgid "Erase" msgid "Erase"
msgstr "" msgstr ""
@ -586,7 +580,7 @@ msgstr ""
msgid "Add images from the clipboard" msgid "Add images from the clipboard"
msgstr "" msgstr ""
msgid "Redo last brushstroke" msgid "Redo"
msgstr "" msgstr ""
msgid "Save drawing" msgid "Save drawing"
@ -710,5 +704,5 @@ msgstr ""
msgid "Square drawing area" msgid "Square drawing area"
msgstr "" msgstr ""
msgid "Undo last brushstroke" msgid "Undo"
msgstr "" msgstr ""

View File

@ -230,12 +230,11 @@ var DrawingMenu = new Lang.Class({
this.menu.removeAll(); this.menu.removeAll();
let groupItem = new PopupMenu.PopupBaseMenuItem({ reactive: false, can_focus: false, style_class: 'draw-on-your-screen-menu-group-item' }); let groupItem = new PopupMenu.PopupBaseMenuItem({ reactive: false, can_focus: false, style_class: 'draw-on-your-screen-menu-group-item' });
this.undoButton = new ActionButton(_("Undo"), 'edit-undo-symbolic', this.area.undo.bind(this.area), this._updateActionSensitivity.bind(this)); this.undoButton = new ActionButton(getSummary('undo'), 'edit-undo-symbolic', this.area.undo.bind(this.area), this._updateActionSensitivity.bind(this));
this.redoButton = new ActionButton(_("Redo"), 'edit-redo-symbolic', this.area.redo.bind(this.area), this._updateActionSensitivity.bind(this)); this.redoButton = new ActionButton(getSummary('redo'), 'edit-redo-symbolic', this.area.redo.bind(this.area), this._updateActionSensitivity.bind(this));
this.eraseButton = new ActionButton(_("Erase"), 'edit-clear-all-symbolic', this.area.deleteLastElement.bind(this.area), this._updateActionSensitivity.bind(this)); this.eraseButton = new ActionButton(_("Erase"), 'edit-clear-all-symbolic', this.area.deleteLastElement.bind(this.area), this._updateActionSensitivity.bind(this));
this.smoothButton = new ActionButton(_("Smooth"), Files.Icons.SMOOTH, this.area.smoothLastElement.bind(this.area), this._updateActionSensitivity.bind(this)); this.smoothButton = new ActionButton(_("Smooth"), Files.Icons.SMOOTH, this.area.smoothLastElement.bind(this.area), this._updateActionSensitivity.bind(this));
this.eraseButton.child.add_style_class_name('draw-on-your-screen-menu-destructive-button'); this.eraseButton.child.add_style_class_name('draw-on-your-screen-menu-destructive-button');
this.smoothButton.child.add_style_class_name('draw-on-your-screen-menu-destructive-button');
getActor(groupItem).add_child(this.undoButton); getActor(groupItem).add_child(this.undoButton);
getActor(groupItem).add_child(this.redoButton); getActor(groupItem).add_child(this.redoButton);
getActor(groupItem).add_child(this.eraseButton); getActor(groupItem).add_child(this.eraseButton);
@ -309,7 +308,7 @@ var DrawingMenu = new Lang.Class({
_updateActionSensitivity: function() { _updateActionSensitivity: function() {
this.undoButton.child.reactive = this.area.elements.length > 0; this.undoButton.child.reactive = this.area.elements.length > 0;
this.redoButton.child.reactive = this.area.undoneElements.length > 0; this.redoButton.child.reactive = this.area.undoneElements.length > 0 || (this.area.elements.length && this.area.elements[this.area.elements.length - 1].canUndo);
this.eraseButton.child.reactive = this.area.elements.length > 0; this.eraseButton.child.reactive = this.area.elements.length > 0;
this.smoothButton.child.reactive = this.area.elements.length > 0 && this.area.elements[this.area.elements.length - 1].shape == this.drawingTools.NONE; this.smoothButton.child.reactive = this.area.elements.length > 0 && this.area.elements[this.area.elements.length - 1].shape == this.drawingTools.NONE;
this.saveButton.child.reactive = this.area.elements.length > 0; this.saveButton.child.reactive = this.area.elements.length > 0;

View File

@ -170,7 +170,7 @@
</key> </key>
<key type="as" name="redo"> <key type="as" name="redo">
<default>["&lt;Primary&gt;&lt;Shift&gt;z"]</default> <default>["&lt;Primary&gt;&lt;Shift&gt;z"]</default>
<summary>Redo last brushstroke</summary> <summary>Redo</summary>
</key> </key>
<key type="as" name="save-as-json"> <key type="as" name="save-as-json">
<default>["&lt;Primary&gt;s"]</default> <default>["&lt;Primary&gt;s"]</default>
@ -340,7 +340,7 @@
</key> </key>
<key type="as" name="undo"> <key type="as" name="undo">
<default>["&lt;Primary&gt;z"]</default> <default>["&lt;Primary&gt;z"]</default>
<summary>Undo last brushstroke</summary> <summary>Undo</summary>
</key> </key>
</schema> </schema>
</schemalist> </schemalist>