Allow extra information in history
Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
parent
82ca6269d2
commit
941d44b365
5 changed files with 29 additions and 10 deletions
|
@ -327,7 +327,7 @@
|
|||
<script src="js/lib/events.js?v=2ab7933" type="text/javascript"></script>
|
||||
<script src="js/lib/input.js?v=09298ac" type="text/javascript"></script>
|
||||
<script src="js/lib/layers.js?v=a1f8aea" type="text/javascript"></script>
|
||||
<script src="js/lib/commands.js?v=00464cb" type="text/javascript"></script>
|
||||
<script src="js/lib/commands.js?v=37e5ebf" type="text/javascript"></script>
|
||||
|
||||
<script src="js/lib/toolbar.js?v=ca3fccf" type="text/javascript"></script>
|
||||
<script src="js/lib/ui.js?v=76ede2b" type="text/javascript"></script>
|
||||
|
@ -347,7 +347,7 @@
|
|||
src="js/ui/floating/history.js?v=fc92d14"
|
||||
type="text/javascript"></script>
|
||||
<script
|
||||
src="js/ui/floating/layers.js?v=486b9fc"
|
||||
src="js/ui/floating/layers.js?v=8e66543"
|
||||
type="text/javascript"></script>
|
||||
|
||||
<!-- Load Tools -->
|
||||
|
|
|
@ -9,12 +9,21 @@
|
|||
* @property {{[key: string]: any}} state The state of the current command instance
|
||||
*/
|
||||
|
||||
/**
|
||||
* Extra command information
|
||||
*
|
||||
* @typedef CommandExtraParams
|
||||
* @property {boolean} recordHistory The title passed to the command being run
|
||||
* @property {Record<string, any>} extra Extra information to be stored in the history entry
|
||||
*/
|
||||
|
||||
/**
|
||||
* A command, which is run, then returns a CommandEntry object that can be used to manually undo/redo it
|
||||
*
|
||||
* @callback Command
|
||||
* @param {string} title The title passed to the command being run
|
||||
* @param {*} options A options object for the command
|
||||
* @param {any} options A options object for the command
|
||||
* @param {CommandExtraParams} extra A options object for the command
|
||||
* @returns {Promise<CommandEntry>}
|
||||
*/
|
||||
|
||||
|
|
|
@ -74,10 +74,15 @@ const commands = makeReadOnly(
|
|||
* @param {string} name Command identifier (name)
|
||||
* @param {CommandDoCallback} run A method that performs the action for the first time
|
||||
* @param {CommandUndoCallback} undo A method that reverses what the run method did
|
||||
* @param {CommandDoCallback} redo A method that redoes the action after undone (default: run)
|
||||
* @param {object} options Extra options
|
||||
* @param {CommandDoCallback} options.redo A method that redoes the action after undone (default: run)
|
||||
* @returns {Command}
|
||||
*/
|
||||
createCommand(name, run, undo, redo = run) {
|
||||
createCommand(name, run, undo, options = {}) {
|
||||
defaultOpt(options, {
|
||||
redo: run,
|
||||
});
|
||||
|
||||
const command = async function runWrapper(title, options, extra) {
|
||||
// Create copy of options and state object
|
||||
const copy = {};
|
||||
|
@ -89,6 +94,7 @@ const commands = makeReadOnly(
|
|||
id: guid(),
|
||||
title,
|
||||
state,
|
||||
extra: extra.extra,
|
||||
};
|
||||
|
||||
// Attempt to run command
|
||||
|
@ -176,11 +182,13 @@ const commands = makeReadOnly(
|
|||
* @param {string} name The name of the command to run
|
||||
* @param {string} title The display name of the command on the history panel view
|
||||
* @param {any} options The options to be sent to the command to be run
|
||||
* @param {CommandExtraParams} extra Extra running options
|
||||
* @return {Promise<{undo: () => void, redo: () => void}>} The command's return value
|
||||
*/
|
||||
async runCommand(name, title, options = null, extra = {}) {
|
||||
defaultOpt(extra, {
|
||||
recordHistory: true,
|
||||
extra: {},
|
||||
});
|
||||
if (!this._types[name])
|
||||
throw new ReferenceError(`[commands] Command '${name}' does not exist`);
|
||||
|
|
|
@ -531,9 +531,11 @@ commands.createCommand(
|
|||
state.drawCommand.undo();
|
||||
state.delCommand.undo();
|
||||
},
|
||||
(title, options, state) => {
|
||||
state.drawCommand.redo();
|
||||
state.delCommand.redo();
|
||||
{
|
||||
redo: (title, options, state) => {
|
||||
state.drawCommand.redo();
|
||||
state.delCommand.redo();
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
<iframe
|
||||
id="openoutpaint"
|
||||
style="width: 100%; height: 800px"
|
||||
src="../index.html?v=90a7170"
|
||||
src="../index.html?v=90a7170"
|
||||
src="../index.html?v=95a96ad"
|
||||
src="../index.html?v=95a96ad"
|
||||
frameborder="0"></iframe>
|
||||
<button id="add-res">Add Resource</button>
|
||||
<script>
|
||||
|
|
Loading…
Reference in a new issue