From 28def0059d1991a7e0d23054954a47cc48a742ea Mon Sep 17 00:00:00 2001 From: abakkk Date: Sun, 4 Oct 2020 22:48:40 +0200 Subject: [PATCH] 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. --- elements.js | 7 +++++++ locale/draw-on-your-screen.pot | 12 +++--------- menu.js | 7 +++---- ....shell.extensions.draw-on-your-screen.gschema.xml | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/elements.js b/elements.js index 71599be..2bbcaeb 100644 --- a/elements.js +++ b/elements.js @@ -413,6 +413,9 @@ const _DrawingElement = new Lang.Class({ this.transformations.push({ type: Transformations.SMOOTH, undoable: true, undo: () => this.points = oldPoints, redo: () => this.points = newPoints }); + + if (this._undoneTransformations) + this._undoneTransformations = this._undoneTransformations.filter(transformation => transformation.type != Transformations.SMOOTH); }, addPoint: function() { @@ -636,6 +639,10 @@ const _DrawingElement = new Lang.Class({ delete this._undoneTransformations; }, + get canUndo() { + return this._undoneTransformations && this._undoneTransformations.length ? true : false; + }, + // The figure rotation center before transformations (original). // this.textWidth is computed during Cairo building. _getOriginalCenter: function() { diff --git a/locale/draw-on-your-screen.pot b/locale/draw-on-your-screen.pot index 3ad0099..5e87946 100644 --- a/locale/draw-on-your-screen.pot +++ b/locale/draw-on-your-screen.pot @@ -10,7 +10,7 @@ msgid "" msgstr "" "Project-Id-Version: Draw On Your Screen\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" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -265,12 +265,6 @@ msgctxt "drawing-tool" msgid "Mirror" msgstr "" -msgid "Undo" -msgstr "" - -msgid "Redo" -msgstr "" - msgid "Erase" msgstr "" @@ -586,7 +580,7 @@ msgstr "" msgid "Add images from the clipboard" msgstr "" -msgid "Redo last brushstroke" +msgid "Redo" msgstr "" msgid "Save drawing" @@ -710,5 +704,5 @@ msgstr "" msgid "Square drawing area" msgstr "" -msgid "Undo last brushstroke" +msgid "Undo" msgstr "" diff --git a/menu.js b/menu.js index 1753b82..4c1c8ea 100644 --- a/menu.js +++ b/menu.js @@ -230,12 +230,11 @@ var DrawingMenu = new Lang.Class({ this.menu.removeAll(); 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.redoButton = new ActionButton(_("Redo"), 'edit-redo-symbolic', this.area.redo.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(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.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.smoothButton.child.add_style_class_name('draw-on-your-screen-menu-destructive-button'); getActor(groupItem).add_child(this.undoButton); getActor(groupItem).add_child(this.redoButton); getActor(groupItem).add_child(this.eraseButton); @@ -309,7 +308,7 @@ var DrawingMenu = new Lang.Class({ _updateActionSensitivity: function() { 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.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; diff --git a/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml b/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml index e13b393..1b26430 100644 --- a/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml +++ b/schemas/org.gnome.shell.extensions.draw-on-your-screen.gschema.xml @@ -170,7 +170,7 @@ ["<Primary><Shift>z"] - Redo last brushstroke + Redo ["<Primary>s"] @@ -340,7 +340,7 @@ ["<Primary>z"] - Undo last brushstroke + Undo