1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-24 19:13:31 +03:00

better messageboxes

This commit is contained in:
Eugene Pankov 2019-01-03 17:20:02 +03:00
parent d5b6a686f8
commit 9faa346699
8 changed files with 84 additions and 15 deletions

View File

@ -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
}

View File

@ -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<MessageBoxResponse> {
return new Promise(resolve => {
this.dialog.showMessageBox(browserWindow, options, (response, checkboxChecked) => {
resolve({ response, checkboxChecked })
})
})
}
}

View File

@ -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

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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

View File

@ -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]
}

View File

@ -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 () {