Skip to content
This repository has been archived by the owner on May 21, 2023. It is now read-only.

Commit

Permalink
Feat: Add Close Commands (#21)
Browse files Browse the repository at this point in the history
* - Updated export errors to be more generalized

* - Added `editor.close` command which closes the currently active file

* - Added `workspace.close` which closes the currently opened workspace
  • Loading branch information
novacbn authored Jul 10, 2022
1 parent 75c98fa commit 78b40c9
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import type {IAppContext, IKeybindEvent} from "@svelte-in-motion/extension";
import {define_extension} from "@svelte-in-motion/extension";

import {NoEditorUserError, NoWorkspaceUserError} from "../util/errors";

export const EXTENSION_EDITOR = define_extension({
identifier: "dev.nbn.sim.editor",
is_builtin: true,

on_activate(app: IAppContext) {
const {commands, keybinds} = app;

commands.push({
identifier: "editor.close",
is_visible: () => !!app.workspace?.editor,
on_execute: this.command_close.bind(this),
});

commands.push({
identifier: "editor.ui.file_tree.toggle",
is_visible: () => !!app.workspace,
Expand All @@ -33,6 +41,16 @@ export const EXTENSION_EDITOR = define_extension({
});
},

command_close(app: IAppContext) {
const {workspace} = app;
if (!workspace) throw new NoWorkspaceUserError();

const {editor} = workspace;
if (!editor) throw new NoEditorUserError();

location.hash = `#/workspace/${workspace.identifier}`;
},

command_ui_file_tree_toggle(app: IAppContext) {
const {preferences} = app;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import {define_extension} from "@svelte-in-motion/extension";
import {ICodecNames, IPixelFormatNames} from "@svelte-in-motion/encoding";
import {Default, Description, Label, Minimum, Namespace, Placeholder} from "@svelte-in-motion/type";
import {typeOf} from "@svelte-in-motion/type";
import {
PromptDismissError,
UserError,
download_blob,
download_buffer,
} from "@svelte-in-motion/utilities";
import {PromptDismissError, download_blob, download_buffer} from "@svelte-in-motion/utilities";

import {NoEditorUserError, NoPreviewUserError, NoWorkspaceUserError} from "../util/errors";
import {zip_frames} from "../util/io";

interface IFramesExportConfiguration {
Expand Down Expand Up @@ -57,22 +53,6 @@ interface IVideoExportConfiguration {
Namespace<"ui-prompt-form-video-export-pixel_format-${identifier}-label">;
}

class ExportUserError extends UserError {
name = ExportUserError.name;
}

class ExportNoEditorUserError extends ExportUserError {
name = ExportNoEditorUserError.name;
}

class ExportNoPreviewUserError extends ExportUserError {
name = ExportNoPreviewUserError.name;
}

class ExportNoWorkspaceUserError extends ExportUserError {
name = ExportNoWorkspaceUserError.name;
}

export const EXTENSION_EXPORT = define_extension({
identifier: "dev.nbn.sim.export",
is_builtin: true,
Expand Down Expand Up @@ -108,12 +88,12 @@ export const EXTENSION_EXPORT = define_extension({
async command_prompt_frames(app: IAppContext) {
const {notifications, prompts, renders, workspace} = app;

if (!workspace) throw new ExportNoWorkspaceUserError();
if (!workspace) throw new NoWorkspaceUserError();

const {configuration, editor, preview} = workspace;

if (!editor) throw new ExportNoEditorUserError();
if (!preview) throw new ExportNoPreviewUserError();
if (!editor) throw new NoEditorUserError();
if (!preview) throw new NoPreviewUserError();

const {maxframes} = get(configuration);

Expand Down Expand Up @@ -175,12 +155,12 @@ export const EXTENSION_EXPORT = define_extension({
async command_prompt_video(app: IAppContext) {
const {agent, jobs, notifications, prompts, workspace} = app;

if (!workspace) throw new ExportNoWorkspaceUserError();
if (!workspace) throw new NoWorkspaceUserError();

const {configuration, editor, preview} = workspace;

if (!editor) throw new ExportNoEditorUserError();
if (!preview) throw new ExportNoPreviewUserError();
if (!editor) throw new NoEditorUserError();
if (!preview) throw new NoPreviewUserError();

const {file_path} = editor;
const $file_path = get(file_path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {Default, Description, Label, MinLength, Pattern} from "@svelte-in-motion
import {typeOf} from "@svelte-in-motion/type";
import {PromptDismissError} from "@svelte-in-motion/utilities";

import {NoWorkspaceUserError} from "../util/errors";

const EXPRESSION_NAME = /^[\w ]+$/;

interface IWorkspaceNewConfiguration {
Expand Down Expand Up @@ -50,6 +52,12 @@ export const EXTENSION_WORKSPACE = define_extension({
on_activate(app: IAppContext) {
const {commands, keybinds, workspaces} = app;

commands.push({
identifier: "workspace.close",
is_visible: () => !!app.workspace,
on_execute: this.command_close.bind(this),
});

commands.push({
identifier: "workspace.prompt.new",
on_execute: this.command_prompt_new.bind(this),
Expand Down Expand Up @@ -87,6 +95,13 @@ export const EXTENSION_WORKSPACE = define_extension({
});
},

command_close(app: IAppContext) {
const {workspace} = app;
if (!workspace) throw new NoWorkspaceUserError();

location.hash = ``;
},

async command_prompt_new(app: IAppContext) {
const {prompts} = app;

Expand Down
13 changes: 13 additions & 0 deletions packages/@svelte-in-motion-builtin-extensions/src/util/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {UserError} from "@svelte-in-motion/utilities";

export class NoEditorUserError extends UserError {
name = NoEditorUserError.name;
}

export class NoPreviewUserError extends UserError {
name = NoPreviewUserError.name;
}

export class NoWorkspaceUserError extends UserError {
name = NoWorkspaceUserError.name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ commands-export-prompt-frames-description = Prompts for exporting the currently
commands-export-prompt-frames-label = Export: Frames
commands-export-prompt-video-description = Prompts for exporting the currently loaded File as a Video.
commands-export-prompt-video-label = Export: Video
commands-editor-close-description = Closes the currently opened File.
commands-editor-close-label = Editor: Close
commands-editor-ui-file_tree-toggle-description = Toggles the File Tree UI from view.
commands-editor-ui-file_tree-toggle-label = Editor: Toggle File Tree UI
commands-editor-ui-script-toggle-description = Toggles the Script Editor UI from view.
Expand All @@ -26,6 +28,8 @@ commands-preview-ui-timeline-toggle-description = Toggles the Timeline UI from v
commands-preview-ui-timeline-toggle-label = Preview: Toggle Timeline UI
commands-preview-ui-viewport-toggle-description = Toggles the Viewport UI from view.
commands-preview-ui-viewport-toggle-label = Preview: Toggle Viewport UI
commands-workspace-close-description = Closes the currently opened Workspace.
commands-workspace-close-label = Workspaces: Close
commands-workspace-prompt-new_from_template-description = Prompts for creating a new Workspace from a Template.
commands-workspace-prompt-new_from_template-label = Workspaces: New from Template
commands-workspace-prompt-new-description = Prompts for creating a new Workspace.
Expand All @@ -36,12 +40,12 @@ commands-workspace-prompt-open_recent-label = Workspaces: Open Recent
templates-welcome-label = Welcome to Svelte-In-Motion
templates-welcome-description = Simple welcome message template to introduce syntax and concepts.
errors-export_no_editor_user_error-label= Export Error
errors-export_no_editor_user_error-description = No File is currently loaded.
errors-export_no_preview_user_error-label= Export Error
errors-export_no_preview_user_error-description = No Preview is currently loaded.
errors-export_no_workspace_user_error-label= Export Error
errors-export_no_workspace_user_error-description = No Workspace is currently loaded.
errors-no_editor_user_error-label= Error
errors-no_editor_user_error-description = No File is currently loaded.
errors-no_preview_user_error-label= Error
errors-no_preview_user_error-description = No Preview is currently loaded.
errors-no_workspace_user_error-label= Error
errors-no_workspace_user_error-description = No Workspace is currently loaded.
ui-view-dashboard-brand-label = Svelte-In-Motion
ui-view-dashboard-start-label = Start
Expand Down

0 comments on commit 78b40c9

Please sign in to comment.