diff --git a/src/code/addButtons.ts b/src/code/addButtons.ts index 16635974..595cb131 100644 --- a/src/code/addButtons.ts +++ b/src/code/addButtons.ts @@ -3,6 +3,7 @@ import QuickdrawButton from "./buttons/quickdrawButton"; import WasabeeButton from "./buttons/wasabeeButton"; import SyncButton from "./buttons/syncButton"; import OpButton from "./buttons/opButton"; +import UndoButton from "./buttons/undoButton"; import LinkButton from "./buttons/linkButton"; import MarkerButton from "./buttons/markerButton"; import UploadButton from "./buttons/uploadButton"; @@ -24,6 +25,7 @@ export function addButtons() { WasabeeButton, OpButton, QuickdrawButton, + UndoButton, QuickDeleteButton, LinkButton, MarkerButton, diff --git a/src/code/buttons/undoButton.d.ts b/src/code/buttons/undoButton.d.ts new file mode 100644 index 00000000..ddeed722 --- /dev/null +++ b/src/code/buttons/undoButton.d.ts @@ -0,0 +1,4 @@ +import { WButton } from "../leafletClasses"; + +declare class UndoButton extends WButton {} +export default UndoButton; diff --git a/src/code/buttons/undoButton.js b/src/code/buttons/undoButton.js new file mode 100644 index 00000000..5765295e --- /dev/null +++ b/src/code/buttons/undoButton.js @@ -0,0 +1,61 @@ +import { WButton } from "../leafletClasses"; +import wX from "../wX"; +import { undoable, undo } from "../undo"; +import { postToFirebase } from "../firebase/logger"; + +const UndoButton = WButton.extend({ + statics: { + TYPE: "UndoButton", + }, + + needWritePermission: true, + + initialize: function (container) { + this.type = UndoButton.TYPE; + this.title = wX("toolbar.op.undo"); + + this.button = this._createButton({ + container: container, + className: "wasabee-toolbar-undo", + callback: () => { + console.log(this); + this.control.disableAllExcept(); + postToFirebase({ id: "analytics", action: "undo" }); + undo(); + }, + context: this, + title: this.title, + }); + }, + update: function () { + WButton.prototype.update.call(this); + console.log("UndoButton.update >> ", this); + if (undoable()) { + console.log(">> is undoable"); + this.enable(); + } else { + console.log(">> no undoable"); + this.disable(); + } + }, + disable: function () { + console.log("do disable:", this); + let btn = this.button; + console.log(btn); + btn.style.pointerEvents = "none"; + btn.style.cursor = "not-allowed"; + + btn.className = "wasabee-toolbar-undo-disable"; + }, + enable: function () { + console.log("do enable:", this); + let btn = this.button; + console.log(btn); + btn.style.pointerEvents = "auto"; + btn.style.cursor = "pointer"; + + btn.className = "wasabee-toolbar-undo"; + }, +}); + +export default UndoButton; diff --git a/src/code/css/toolbar.css b/src/code/css/toolbar.css index 095514c7..8000f1ed 100644 --- a/src/code/css/toolbar.css +++ b/src/code/css/toolbar.css @@ -136,6 +136,18 @@ background-image: url(../images/toolbar_quickdelete.svg); background-size: 60%; } +.wasabee-toolbar-undo { + background-image: url(../images/toolbar_undo.svg); + background-size: 60%; +} +.wasabee-toolbar-undo-disable { + background-image: url(../images/toolbar_undo_disable.svg); + background-size: 60%; +} +.wasabee-toolbar-redo { + background-image: url(../images/toolbar_redo.svg); + background-size: 60%; +} .wasabee-toolbar-link { background-image: url(../images/toolbar_addlinks.svg) } diff --git a/src/code/images/toolbar_quickdelete.svg b/src/code/images/toolbar_quickdelete.svg index 15035f46..439a91b7 100644 --- a/src/code/images/toolbar_quickdelete.svg +++ b/src/code/images/toolbar_quickdelete.svg @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/src/code/images/toolbar_redo.svg b/src/code/images/toolbar_redo.svg new file mode 100644 index 00000000..086a3adf --- /dev/null +++ b/src/code/images/toolbar_redo.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/code/images/toolbar_undo.svg b/src/code/images/toolbar_undo.svg new file mode 100644 index 00000000..2aa8c2d8 --- /dev/null +++ b/src/code/images/toolbar_undo.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/code/images/toolbar_undo_disable.svg b/src/code/images/toolbar_undo_disable.svg new file mode 100644 index 00000000..13705ee3 --- /dev/null +++ b/src/code/images/toolbar_undo_disable.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file