Add set project scheduler command and update scene document to include scheduler
This commit is contained in:
49
src/commands/set-project-scheduler-command.ts
Normal file
49
src/commands/set-project-scheduler-command.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { createOpaqueId } from "../core/ids";
|
||||
import {
|
||||
cloneProjectScheduler,
|
||||
type ProjectScheduler
|
||||
} from "../scheduler/project-scheduler";
|
||||
|
||||
import type { EditorCommand } from "./command";
|
||||
|
||||
interface SetProjectSchedulerCommandOptions {
|
||||
label: string;
|
||||
scheduler: ProjectScheduler;
|
||||
}
|
||||
|
||||
export function createSetProjectSchedulerCommand(
|
||||
options: SetProjectSchedulerCommandOptions
|
||||
): EditorCommand {
|
||||
const nextScheduler = cloneProjectScheduler(options.scheduler);
|
||||
let previousScheduler: ProjectScheduler | null = null;
|
||||
|
||||
return {
|
||||
id: createOpaqueId("command"),
|
||||
label: options.label,
|
||||
execute(context) {
|
||||
const currentProjectDocument = context.getProjectDocument();
|
||||
|
||||
if (previousScheduler === null) {
|
||||
previousScheduler = cloneProjectScheduler(
|
||||
currentProjectDocument.scheduler
|
||||
);
|
||||
}
|
||||
|
||||
context.setProjectDocument({
|
||||
...currentProjectDocument,
|
||||
scheduler: cloneProjectScheduler(nextScheduler)
|
||||
});
|
||||
},
|
||||
undo(context) {
|
||||
if (previousScheduler === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentProjectDocument = context.getProjectDocument();
|
||||
context.setProjectDocument({
|
||||
...currentProjectDocument,
|
||||
scheduler: cloneProjectScheduler(previousScheduler)
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user