Add support for closing document tabs (#215)

* Can only remove last document successfully

* Correctly update the layer tree panel

* Remove comments

* Add support for randomly closing docs

* Create new doc after closing last doc

* Update layer panel when creating new docs

* Fix bug that crashed the program when first doc was closed

* Refactor to make code simpler and increase readability

* Add shortcut to close active doc (Shift + C)

* Add a confirmation dialog box before closing tabs

* New docs get the correct title

* Remove comments and fix typos

* Disable 'eslint-no-alert'

* Refactor and fix document title bug

* Rename the FrontendMessage and ReponseType for showing close confirmation modal

* Change the message displayed in the close confirmation modal

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
akshay1992kalbhor
2021-06-22 14:28:02 +05:30
committed by GitHub
parent 8a56d6cf46
commit 0b0873262c
7 changed files with 118 additions and 5 deletions

View File

@@ -18,7 +18,9 @@ export enum ResponseType {
SetActiveTool = "SetActiveTool",
SetActiveDocument = "SetActiveDocument",
NewDocument = "NewDocument",
CloseDocument = "CloseDocument",
UpdateWorkingColors = "UpdateWorkingColors",
PromptCloseConfirmationModal = "PromptCloseConfirmationModal",
}
export function attachResponseHandlerToPage() {
@@ -58,12 +60,16 @@ function parseResponse(responseType: string, data: any): Response {
return newSetActiveDocument(data.SetActiveDocument);
case "NewDocument":
return newNewDocument(data.NewDocument);
case "CloseDocument":
return newCloseDocument(data.CloseDocument);
case "UpdateCanvas":
return newUpdateCanvas(data.UpdateCanvas);
case "ExportDocument":
return newExportDocument(data.ExportDocument);
case "UpdateWorkingColors":
return newUpdateWorkingColors(data.UpdateWorkingColors);
case "PromptCloseConfirmationModal":
return {};
default:
throw new Error(`Unrecognized origin/responseType pair: ${origin}, ${responseType}`);
}
@@ -71,6 +77,13 @@ function parseResponse(responseType: string, data: any): Response {
export type Response = SetActiveTool | UpdateCanvas | DocumentChanged | CollapseFolder | ExpandFolder | UpdateWorkingColors;
export interface CloseDocument {
document_index: number;
}
function newCloseDocument(input: any): CloseDocument {
return { document_index: input.document_index };
}
export interface Color {
red: number;
green: number;