From 129a7c1a09909c497d5541088aaf9a71250c9317 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sat, 11 Apr 2020 12:37:46 +0200 Subject: [PATCH] use the new selector for profiles --- .../components/selectorModal.component.pug | 11 +++++-- .../components/selectorModal.component.scss | 9 ++++++ .../src/components/selectorModal.component.ts | 4 +++ terminus-terminal/src/buttonProvider.ts | 30 ++++++++++++------- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/terminus-core/src/components/selectorModal.component.pug b/terminus-core/src/components/selectorModal.component.pug index a0854b76..27748d2b 100644 --- a/terminus-core/src/components/selectorModal.component.pug +++ b/terminus-core/src/components/selectorModal.component.pug @@ -14,6 +14,13 @@ [class.active]='selectedIndex == i', *ngFor='let option of filteredOptions; let i = index' ) - i(class='fa-fw fas mr-1 fa-{{option.icon}}') - .mr-2 {{getOptionText(option)}} + i.icon( + class='fa-fw fas fa-{{option.icon}}', + *ngIf='!iconIsSVG(option.icon)' + ) + .icon( + [fastHtmlBind]='option.icon', + *ngIf='iconIsSVG(option.icon)' + ) + .mr-2.title {{getOptionText(option)}} .text-muted {{option.description}} diff --git a/terminus-core/src/components/selectorModal.component.scss b/terminus-core/src/components/selectorModal.component.scss index 2066a9ce..de8d648e 100644 --- a/terminus-core/src/components/selectorModal.component.scss +++ b/terminus-core/src/components/selectorModal.component.scss @@ -2,3 +2,12 @@ max-height: 70vh; overflow: auto; } + +.icon { + width: 1.25rem; + margin-right: 0.25rem; +} + +.title { + margin-left: 10px; +} diff --git a/terminus-core/src/components/selectorModal.component.ts b/terminus-core/src/components/selectorModal.component.ts index 2cfaa652..23cb69d5 100644 --- a/terminus-core/src/components/selectorModal.component.ts +++ b/terminus-core/src/components/selectorModal.component.ts @@ -71,4 +71,8 @@ export class SelectorModalComponent { close (): void { this.modalInstance.dismiss() } + + iconIsSVG (icon: string): boolean { + return icon?.startsWith('<') + } } diff --git a/terminus-terminal/src/buttonProvider.ts b/terminus-terminal/src/buttonProvider.ts index 71035e16..3ba0d4bd 100644 --- a/terminus-terminal/src/buttonProvider.ts +++ b/terminus-terminal/src/buttonProvider.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import * as fs from 'mz/fs' import { Injectable } from '@angular/core' -import { ToolbarButtonProvider, ToolbarButton, ElectronService, ConfigService } from 'terminus-core' +import { ToolbarButtonProvider, ToolbarButton, ElectronService, ConfigService, SelectorOption, AppService } from 'terminus-core' import { TerminalService } from './services/terminal.service' @@ -10,6 +10,7 @@ import { TerminalService } from './services/terminal.service' export class ButtonProvider extends ToolbarButtonProvider { constructor ( electron: ElectronService, + private app: AppService, private config: ConfigService, private terminal: TerminalService, ) { @@ -28,27 +29,36 @@ export class ButtonProvider extends ToolbarButtonProvider { } } + async activate () { + const options: SelectorOption[] = [] + const profiles = await this.terminal.getProfiles({ skipDefault: !this.config.store.terminal.showDefaultProfiles }) + + for (const profile of profiles) { + options.push({ + icon: profile.icon, + name: profile.name, + description: '',//TODO + callback: () => this.terminal.openTab(profile), + }) + } + + await this.app.showSelector('Select profile', options) + } + provide (): ToolbarButton[] { return [ { icon: require('./icons/plus.svg'), title: 'New terminal', touchBarNSImage: 'NSTouchBarAddDetailTemplate', - click: async () => { + click: () => { this.terminal.openTab() }, }, { icon: require('./icons/profiles.svg'), title: 'New terminal with profile', - submenu: async () => { - const profiles = await this.terminal.getProfiles({ skipDefault: !this.config.store.terminal.showDefaultProfiles }) - return profiles.map(profile => ({ - icon: profile.icon, - title: profile.name, - click: () => this.terminal.openTab(profile), - })) - }, + click: () => this.activate(), }, ] }