From 9faa346699aa4a4b5238c9bf19adc1c2fe2d8003 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Thu, 3 Jan 2019 17:20:02 +0300 Subject: [PATCH] better messageboxes --- app/src/entry.ts | 2 ++ .../src/services/electron.service.ts | 16 +++++++++++ .../src/components/settingsTab.component.pug | 4 +++ .../editConnectionModal.component.ts | 13 +++++++-- .../components/sshSettingsTab.component.ts | 28 +++++++++++++++---- .../appearanceSettingsTab.component.ts | 15 ++++++++-- .../components/shellSettingsTab.component.ts | 11 +++++--- .../src/components/terminalTab.component.ts | 10 ++++++- 8 files changed, 84 insertions(+), 15 deletions(-) diff --git a/app/src/entry.ts b/app/src/entry.ts index 34b92ba8..08ca10ed 100644 --- a/app/src/entry.ts +++ b/app/src/entry.ts @@ -15,6 +15,8 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic' import { getRootModule } from './app.module' import { findPlugins, loadPlugins, IPluginInfo } from './plugins' +;(process as any).enablePromiseAPI = true + if (process.platform === 'win32') { process.env.HOME = process.env.HOMEDRIVE + process.env.HOMEPATH } diff --git a/terminus-core/src/services/electron.service.ts b/terminus-core/src/services/electron.service.ts index 89920f22..3a415cc4 100644 --- a/terminus-core/src/services/electron.service.ts +++ b/terminus-core/src/services/electron.service.ts @@ -1,6 +1,11 @@ import { Injectable } from '@angular/core' import { TouchBar, BrowserWindow, Menu, MenuItem } from 'electron' +export interface MessageBoxResponse { + response: number + checkboxChecked?: boolean +} + @Injectable({ providedIn: 'root' }) export class ElectronService { app: any @@ -54,4 +59,15 @@ export class ElectronService { this.remote.Menu.sendActionToFirstResponder('hide:') } } + + showMessageBox ( + browserWindow: Electron.BrowserWindow, + options: Electron.MessageBoxOptions + ): Promise { + return new Promise(resolve => { + this.dialog.showMessageBox(browserWindow, options, (response, checkboxChecked) => { + resolve({ response, checkboxChecked }) + }) + }) + } } diff --git a/terminus-settings/src/components/settingsTab.component.pug b/terminus-settings/src/components/settingsTab.component.pug index 27c27ec9..cf321e1c 100644 --- a/terminus-settings/src/components/settingsTab.component.pug +++ b/terminus-settings/src/components/settingsTab.component.pug @@ -3,6 +3,7 @@ button.btn.btn-outline-warning.btn-block(*ngIf='config.restartRequested', '(clic ngb-tabset.vertical(type='pills', [activeId]='activeTab') ngb-tab(id='application') ng-template(ngbTabTitle) + i.fas.fa-fw.fa-window-maximize.mr-2 | Application ng-template(ngbTabContent) .d-flex.align-items-center.mb-4 @@ -247,6 +248,7 @@ ngb-tabset.vertical(type='pills', [activeId]='activeTab') ngb-tab(id='hotkeys') ng-template(ngbTabTitle) + i.fas.fa-fw.fa-keyboard.mr-2 | Hotkeys ng-template(ngbTabContent) h3.mb-3 Hotkeys @@ -274,6 +276,7 @@ ngb-tabset.vertical(type='pills', [activeId]='activeTab') ngb-tab(*ngFor='let provider of settingsProviders', [id]='provider.id') ng-template(ngbTabTitle) + i(class='fas fa-fw mr-2 fa-{{provider.icon || "puzzle-piece"}}') | {{provider.title}} ng-template(ngbTabContent) settings-tab-body([provider]='provider') @@ -281,6 +284,7 @@ ngb-tabset.vertical(type='pills', [activeId]='activeTab') ngb-tab(id='config-file') ng-template(ngbTabTitle) + i.fas.fa-fw.fa-code.mr-2 | Config file ng-template.test(ngbTabContent) .d-flex.flex-column.w-100.h-100 diff --git a/terminus-ssh/src/components/editConnectionModal.component.ts b/terminus-ssh/src/components/editConnectionModal.component.ts index ea0bded5..a550a8a9 100644 --- a/terminus-ssh/src/components/editConnectionModal.component.ts +++ b/terminus-ssh/src/components/editConnectionModal.component.ts @@ -66,8 +66,17 @@ export class EditConnectionModalComponent { } } - deleteScript (script: LoginScript) { - if (confirm(`Delete?`)) { + async deleteScript (script: LoginScript) { + if ((await this.electron.showMessageBox( + this.hostApp.getWindow(), + { + type: 'warning', + message: 'Delete this script?', + detail: script.expect, + buttons: ['Keep', 'Delete'], + defaultId: 1, + } + )).response === 1) { this.connection.scripts = this.connection.scripts.filter(x => x !== script) } } diff --git a/terminus-ssh/src/components/sshSettingsTab.component.ts b/terminus-ssh/src/components/sshSettingsTab.component.ts index e5ee994e..a1f3591e 100644 --- a/terminus-ssh/src/components/sshSettingsTab.component.ts +++ b/terminus-ssh/src/components/sshSettingsTab.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' -import { ConfigService } from 'terminus-core' +import { ConfigService, ElectronService, HostAppService } from 'terminus-core' import { SSHConnection, ISSHConnectionGroup } from '../api' import { EditConnectionModalComponent } from './editConnectionModal.component' import { PromptModalComponent } from './promptModal.component' @@ -15,6 +15,8 @@ export class SSHSettingsTabComponent { constructor ( public config: ConfigService, + private electron: ElectronService, + private hostApp: HostAppService, private ngbModal: NgbModal, ) { this.connections = this.config.store.ssh.connections @@ -49,8 +51,16 @@ export class SSHSettingsTabComponent { }) } - deleteConnection (connection: SSHConnection) { - if (confirm(`Delete "${connection.name}"?`)) { + async deleteConnection (connection: SSHConnection) { + if ((await this.electron.showMessageBox( + this.hostApp.getWindow(), + { + type: 'warning', + message: `Delete "${connection.name}"?`, + buttons: ['Keep', 'Delete'], + defaultId: 1, + } + )).response === 1) { this.connections = this.connections.filter(x => x !== connection) this.config.store.ssh.connections = this.connections this.config.save() @@ -73,8 +83,16 @@ export class SSHSettingsTabComponent { }) } - deleteGroup (group: ISSHConnectionGroup) { - if (confirm(`Delete "${group}"?`)) { + async deleteGroup (group: ISSHConnectionGroup) { + if ((await this.electron.showMessageBox( + this.hostApp.getWindow(), + { + type: 'warning', + message: `Delete "${group}"?`, + buttons: ['Keep', 'Delete'], + defaultId: 1, + } + )).response === 1) { for (let connection of this.connections.filter(x => x.group === group.name)) { connection.group = null } diff --git a/terminus-terminal/src/components/appearanceSettingsTab.component.ts b/terminus-terminal/src/components/appearanceSettingsTab.component.ts index e798a659..de3b4989 100644 --- a/terminus-terminal/src/components/appearanceSettingsTab.component.ts +++ b/terminus-terminal/src/components/appearanceSettingsTab.component.ts @@ -5,7 +5,7 @@ import deepEqual = require('deep-equal') const fontManager = require('font-manager') import { Component, Inject } from '@angular/core' -import { ConfigService, HostAppService, Platform } from 'terminus-core' +import { ConfigService, HostAppService, Platform, ElectronService } from 'terminus-core' import { TerminalColorSchemeProvider, ITerminalColorScheme } from '../api' @Component({ @@ -22,6 +22,7 @@ export class AppearanceSettingsTabComponent { constructor ( @Inject(TerminalColorSchemeProvider) private colorSchemeProviders: TerminalColorSchemeProvider[], private hostApp: HostAppService, + private electron: ElectronService, public config: ConfigService, ) { } @@ -71,8 +72,16 @@ export class AppearanceSettingsTabComponent { this.editingColorScheme = null } - deleteScheme (scheme: ITerminalColorScheme) { - if (confirm(`Delete "${scheme.name}"?`)) { + async deleteScheme (scheme: ITerminalColorScheme) { + if ((await this.electron.showMessageBox( + this.hostApp.getWindow(), + { + type: 'warning', + message: `Delete "${scheme.name}"?`, + buttons: ['Keep', 'Delete'], + defaultId: 1, + } + )).response === 1) { let schemes = this.config.store.terminal.customColorSchemes schemes = schemes.filter(x => x !== scheme) this.config.store.terminal.customColorSchemes = schemes diff --git a/terminus-terminal/src/components/shellSettingsTab.component.ts b/terminus-terminal/src/components/shellSettingsTab.component.ts index 26ca6ee9..ede4f51c 100644 --- a/terminus-terminal/src/components/shellSettingsTab.component.ts +++ b/terminus-terminal/src/components/shellSettingsTab.component.ts @@ -48,10 +48,13 @@ export class ShellSettingsTabComponent { pickWorkingDirectory () { let shell = this.shells.find(x => x.id === this.config.store.terminal.shell) console.log(shell) - let paths = this.electron.dialog.showOpenDialog({ - defaultPath: shell.fsBase, - properties: ['openDirectory', 'showHiddenFiles'], - }) + let paths = this.electron.dialog.showOpenDialog( + this.hostApp.getWindow(), + { + defaultPath: shell.fsBase, + properties: ['openDirectory', 'showHiddenFiles'], + } + ) if (paths) { this.config.store.terminal.workingDirectory = paths[0] } diff --git a/terminus-terminal/src/components/terminalTab.component.ts b/terminus-terminal/src/components/terminalTab.component.ts index b4961a8c..61b49aee 100644 --- a/terminus-terminal/src/components/terminalTab.component.ts +++ b/terminus-terminal/src/components/terminalTab.component.ts @@ -380,7 +380,15 @@ export class TerminalTabComponent extends BaseTabComponent { if (children.length === 0) { return true } - return confirm(`"${children[0].command}" is still running. Close?`) + return (await this.electron.showMessageBox( + this.hostApp.getWindow(), + { + type: 'warning', + message: `"${children[0].command}" is still running. Close?`, + buttons: ['Cancel', 'Kill'], + defaultId: 1, + } + )).response === 1 } async saveAsProfile () {