update menus to reflect undo state
This commit is contained in:
parent
3697b3371c
commit
ad17f2531e
78
src/main.js
78
src/main.js
|
|
@ -3,7 +3,7 @@ import * as fitCurve from '/fit-curve.js';
|
||||||
import { Bezier } from "/bezier.js";
|
import { Bezier } from "/bezier.js";
|
||||||
import { Quadtree } from './quadtree.js';
|
import { Quadtree } from './quadtree.js';
|
||||||
import { createNewFileDialog, showNewFileDialog, closeDialog } from './newfile.js';
|
import { createNewFileDialog, showNewFileDialog, closeDialog } from './newfile.js';
|
||||||
import { titleCase, getMousePositionFraction, getKeyframesSurrounding, invertPixels, lerpColor, lerp } from './utils.js';
|
import { titleCase, getMousePositionFraction, getKeyframesSurrounding, invertPixels, lerpColor, lerp, camelToWords } from './utils.js';
|
||||||
const { writeTextFile: writeTextFile, readTextFile: readTextFile, writeFile: writeFile }= window.__TAURI__.fs;
|
const { writeTextFile: writeTextFile, readTextFile: readTextFile, writeFile: writeFile }= window.__TAURI__.fs;
|
||||||
const {
|
const {
|
||||||
open: openFileDialog,
|
open: openFileDialog,
|
||||||
|
|
@ -154,6 +154,7 @@ let actions = {
|
||||||
}
|
}
|
||||||
undoStack.push({name: "addShape", action: action})
|
undoStack.push({name: "addShape", action: action})
|
||||||
actions.addShape.execute(action)
|
actions.addShape.execute(action)
|
||||||
|
updateMenu()
|
||||||
},
|
},
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
let object = pointerList[action.parent]
|
let object = pointerList[action.parent]
|
||||||
|
|
@ -238,6 +239,7 @@ let actions = {
|
||||||
}
|
}
|
||||||
undoStack.push({name: "colorShape", action: action})
|
undoStack.push({name: "colorShape", action: action})
|
||||||
actions.colorShape.execute(action)
|
actions.colorShape.execute(action)
|
||||||
|
updateMenu()
|
||||||
},
|
},
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
let shape = pointerList[action.shape]
|
let shape = pointerList[action.shape]
|
||||||
|
|
@ -263,6 +265,7 @@ let actions = {
|
||||||
}
|
}
|
||||||
undoStack.push({name: "addImageObject", action: action})
|
undoStack.push({name: "addImageObject", action: action})
|
||||||
actions.addImageObject.execute(action)
|
actions.addImageObject.execute(action)
|
||||||
|
updateMenu()
|
||||||
},
|
},
|
||||||
execute: async (action) => {
|
execute: async (action) => {
|
||||||
let imageObject = new GraphicsObject(action.objectUuid)
|
let imageObject = new GraphicsObject(action.objectUuid)
|
||||||
|
|
@ -327,6 +330,7 @@ let actions = {
|
||||||
}
|
}
|
||||||
undoStack.push({name: "editFrame", action: action})
|
undoStack.push({name: "editFrame", action: action})
|
||||||
actions.editFrame.execute(action)
|
actions.editFrame.execute(action)
|
||||||
|
updateMenu()
|
||||||
},
|
},
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
let frame = pointerList[action.frame]
|
let frame = pointerList[action.frame]
|
||||||
|
|
@ -354,6 +358,7 @@ let actions = {
|
||||||
}
|
}
|
||||||
undoStack.push({name: 'addFrame', action: action})
|
undoStack.push({name: 'addFrame', action: action})
|
||||||
actions.addFrame.execute(action)
|
actions.addFrame.execute(action)
|
||||||
|
updateMenu()
|
||||||
},
|
},
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
let layer = pointerList[action.layer]
|
let layer = pointerList[action.layer]
|
||||||
|
|
@ -397,6 +402,7 @@ let actions = {
|
||||||
}
|
}
|
||||||
undoStack.push({name: 'addKeyframe', action: action})
|
undoStack.push({name: 'addKeyframe', action: action})
|
||||||
actions.addKeyframe.execute(action)
|
actions.addKeyframe.execute(action)
|
||||||
|
updateMenu()
|
||||||
},
|
},
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
let object = pointerList[action.object]
|
let object = pointerList[action.object]
|
||||||
|
|
@ -449,6 +455,7 @@ let actions = {
|
||||||
}
|
}
|
||||||
undoStack.push({name: 'addMotionTween', action: action})
|
undoStack.push({name: 'addMotionTween', action: action})
|
||||||
actions.addMotionTween.execute(action)
|
actions.addMotionTween.execute(action)
|
||||||
|
updateMenu()
|
||||||
},
|
},
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
let layer = pointerList[action.layer]
|
let layer = pointerList[action.layer]
|
||||||
|
|
@ -491,6 +498,7 @@ let actions = {
|
||||||
}
|
}
|
||||||
undoStack.push({name: 'addShapeTween', action: action})
|
undoStack.push({name: 'addShapeTween', action: action})
|
||||||
actions.addShapeTween.execute(action)
|
actions.addShapeTween.execute(action)
|
||||||
|
updateMenu()
|
||||||
},
|
},
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
let layer = pointerList[action.layer]
|
let layer = pointerList[action.layer]
|
||||||
|
|
@ -538,6 +546,7 @@ let actions = {
|
||||||
}
|
}
|
||||||
undoStack.push({name: 'group', action: action})
|
undoStack.push({name: 'group', action: action})
|
||||||
actions.group.execute(action)
|
actions.group.execute(action)
|
||||||
|
updateMenu()
|
||||||
},
|
},
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
// your code here
|
// your code here
|
||||||
|
|
@ -599,6 +608,7 @@ let actions = {
|
||||||
}
|
}
|
||||||
undoStack.push({name: 'sendToBack', action: action})
|
undoStack.push({name: 'sendToBack', action: action})
|
||||||
actions.sendToBack.execute(action)
|
actions.sendToBack.execute(action)
|
||||||
|
updateMenu()
|
||||||
},
|
},
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
let frame = pointerList[action.frame]
|
let frame = pointerList[action.frame]
|
||||||
|
|
@ -654,6 +664,7 @@ let actions = {
|
||||||
}
|
}
|
||||||
undoStack.push({name: 'bringToFront', action: action})
|
undoStack.push({name: 'bringToFront', action: action})
|
||||||
actions.bringToFront.execute(action)
|
actions.bringToFront.execute(action)
|
||||||
|
updateMenu()
|
||||||
},
|
},
|
||||||
execute: (action) => {
|
execute: (action) => {
|
||||||
let frame = pointerList[action.frame]
|
let frame = pointerList[action.frame]
|
||||||
|
|
@ -864,8 +875,10 @@ function undo() {
|
||||||
actions[action.name].rollback(action.action)
|
actions[action.name].rollback(action.action)
|
||||||
redoStack.push(action)
|
redoStack.push(action)
|
||||||
updateUI()
|
updateUI()
|
||||||
|
updateMenu()
|
||||||
} else {
|
} else {
|
||||||
console.log("No actions to undo")
|
console.log("No actions to undo")
|
||||||
|
updateMenu()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -875,8 +888,10 @@ function redo() {
|
||||||
actions[action.name].execute(action.action)
|
actions[action.name].execute(action.action)
|
||||||
undoStack.push(action)
|
undoStack.push(action)
|
||||||
updateUI()
|
updateUI()
|
||||||
|
updateMenu()
|
||||||
} else {
|
} else {
|
||||||
console.log("No actions to redo")
|
console.log("No actions to redo")
|
||||||
|
updateMenu()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1450,6 +1465,9 @@ class GraphicsObject {
|
||||||
growBoundingBox(bbox, child.bbox())
|
growBoundingBox(bbox, child.bbox())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (bbox == undefined) {
|
||||||
|
bbox = {x:{min:0, max:0}, y:{min:0,max:0}}
|
||||||
|
}
|
||||||
bbox.x.max *= this.scale_x
|
bbox.x.max *= this.scale_x
|
||||||
bbox.y.max *= this.scale_y
|
bbox.y.max *= this.scale_y
|
||||||
bbox.x.min += this.x
|
bbox.x.min += this.x
|
||||||
|
|
@ -1697,10 +1715,56 @@ window.addEventListener("keydown", (e) => {
|
||||||
actions.group.create()
|
actions.group.create()
|
||||||
}
|
}
|
||||||
else if (e.key == "ArrowRight") {
|
else if (e.key == "ArrowRight") {
|
||||||
advanceFrame()
|
if (e.ctrlKey == true) {
|
||||||
|
advanceFrame()
|
||||||
|
} else if (context.selection) {
|
||||||
|
context.activeObject.currentFrame.saveState()
|
||||||
|
for (let item of context.selection) {
|
||||||
|
context.activeObject.currentFrame.keys[item.idx].x += 1
|
||||||
|
}
|
||||||
|
actions.editFrame.create(context.activeObject.currentFrame)
|
||||||
|
updateUI()
|
||||||
|
}
|
||||||
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
else if (e.key == "ArrowLeft") {
|
else if (e.key == "ArrowLeft") {
|
||||||
decrementFrame()
|
if (e.ctrlKey == true) {
|
||||||
|
decrementFrame()
|
||||||
|
} else if (context.selection) {
|
||||||
|
context.activeObject.currentFrame.saveState()
|
||||||
|
for (let item of context.selection) {
|
||||||
|
context.activeObject.currentFrame.keys[item.idx].x -= 1
|
||||||
|
}
|
||||||
|
actions.editFrame.create(context.activeObject.currentFrame)
|
||||||
|
updateUI()
|
||||||
|
}
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
else if (e.key == "ArrowUp") {
|
||||||
|
if (e.ctrlKey == true) {
|
||||||
|
// no action yet for ctrl+up
|
||||||
|
} else if (context.selection) {
|
||||||
|
context.activeObject.currentFrame.saveState()
|
||||||
|
for (let item of context.selection) {
|
||||||
|
context.activeObject.currentFrame.keys[item.idx].y -= 1
|
||||||
|
}
|
||||||
|
actions.editFrame.create(context.activeObject.currentFrame)
|
||||||
|
updateUI()
|
||||||
|
}
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
else if (e.key == "ArrowDown") {
|
||||||
|
if (e.ctrlKey == true) {
|
||||||
|
// no action yet for ctrl+down
|
||||||
|
} else if (context.selection) {
|
||||||
|
context.activeObject.currentFrame.saveState()
|
||||||
|
for (let item of context.selection) {
|
||||||
|
context.activeObject.currentFrame.keys[item.idx].y += 1
|
||||||
|
}
|
||||||
|
actions.editFrame.create(context.activeObject.currentFrame)
|
||||||
|
updateUI()
|
||||||
|
}
|
||||||
|
e.preventDefault()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -2844,13 +2908,13 @@ async function updateMenu() {
|
||||||
text: "Edit",
|
text: "Edit",
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
text: "Undo",
|
text: "Undo " + ((undoStack.length>0) ? camelToWords(undoStack[undoStack.length-1].name) : ""),
|
||||||
enabled: true,
|
enabled: undoStack.length > 0,
|
||||||
action: undo
|
action: undo
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: "Redo",
|
text: "Redo " + ((redoStack.length>0) ? camelToWords(redoStack[redoStack.length-1].name) : ""),
|
||||||
enabled: true,
|
enabled: redoStack.length > 0,
|
||||||
action: redo
|
action: redo
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
10
src/utils.js
10
src/utils.js
|
|
@ -122,4 +122,12 @@ function lerpColor(color1, color2, t) {
|
||||||
return rgbToHex(r, g, b);
|
return rgbToHex(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { titleCase, getMousePositionFraction, getKeyframesSurrounding, invertPixels, lerp, lerpColor };
|
function camelToWords(camelCaseString) {
|
||||||
|
// Insert a space before each uppercase letter and make it lowercase
|
||||||
|
const words = camelCaseString.replace(/([A-Z])/g, ' $1').toLowerCase();
|
||||||
|
|
||||||
|
// Capitalize the first letter of each word
|
||||||
|
return words.replace(/\b\w/g, char => char.toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
export { titleCase, getMousePositionFraction, getKeyframesSurrounding, invertPixels, lerp, lerpColor, camelToWords };
|
||||||
Loading…
Reference in New Issue