|
| 1 | +import { nls } from "@theia/core"; |
| 2 | +import { AbstractDialog, Dialog, DialogProps, Message } from "@theia/core/lib/browser"; |
| 3 | +import { inject } from "@theia/core/shared/inversify"; |
| 4 | + |
| 5 | +export class TempSketchDialog extends AbstractDialog<TempSketchDialog.Options> { |
| 6 | + protected readonly dontSaveButton: HTMLButtonElement; |
| 7 | + protected _value: TempSketchDialog.Options = 'Cancel'; |
| 8 | + |
| 9 | + get value(): TempSketchDialog.Options { |
| 10 | + return this._value; |
| 11 | + } |
| 12 | + |
| 13 | + constructor( |
| 14 | + @inject(DialogProps) props: DialogProps |
| 15 | + ) { |
| 16 | + super(props); |
| 17 | + const messageNode = document.createElement('div'); |
| 18 | + messageNode.textContent = nls.localize('arduino/sketch/saveTempSketch', 'Save your sketch to open it again later.'); |
| 19 | + this.contentNode.appendChild(messageNode); |
| 20 | + this.dontSaveButton = this.createButton(nls.localizeByDefault(TempSketchDialog.Values["Don't Save"])); |
| 21 | + this.dontSaveButton.classList.add('secondary'); |
| 22 | + this.controlPanel.appendChild(this.dontSaveButton); |
| 23 | + this.appendCloseButton(Dialog.CANCEL); |
| 24 | + this.appendAcceptButton(nls.localizeByDefault(TempSketchDialog.Values['Save As...'])); |
| 25 | + } |
| 26 | + |
| 27 | + protected onAfterAttach(msg: Message): void { |
| 28 | + super.onAfterAttach(msg); |
| 29 | + this.addAction(this.dontSaveButton, () => this.dontSave(), 'click'); |
| 30 | + } |
| 31 | + |
| 32 | + protected addAcceptAction<K extends keyof HTMLElementEventMap>(element: HTMLElement, ...additionalEventTypes: K[]): void { |
| 33 | + this.addAction(element, () => this.doSave(), 'click'); |
| 34 | + } |
| 35 | + |
| 36 | + protected dontSave(): void { |
| 37 | + this._value = TempSketchDialog.Values["Don't Save"]; |
| 38 | + this.accept(); |
| 39 | + } |
| 40 | + |
| 41 | + protected doSave(): void { |
| 42 | + this._value = TempSketchDialog.Values['Save As...']; |
| 43 | + this.accept(); |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +export namespace TempSketchDialog { |
| 48 | + export const enum Values { |
| 49 | + "Don't Save" = "Don't Save", |
| 50 | + Cancel = 'Cancel', |
| 51 | + 'Save As...' = 'Save As...', |
| 52 | + }; |
| 53 | + export type Options = keyof typeof Values; |
| 54 | +} |
0 commit comments