tabby/terminus-settings/src/buttonProvider.ts
Eugene Pankov e0e24878e2 SVG icons
2018-08-09 15:13:31 +02:00

36 lines
1.1 KiB
TypeScript

import { Injectable } from '@angular/core'
import { DomSanitizer } from '@angular/platform-browser'
import { ToolbarButtonProvider, IToolbarButton, AppService, HostAppService } from 'terminus-core'
import { SettingsTabComponent } from './components/settingsTab.component'
@Injectable()
export class ButtonProvider extends ToolbarButtonProvider {
constructor (
hostApp: HostAppService,
private app: AppService,
private domSanitizer: DomSanitizer,
) {
super()
hostApp.preferencesMenu$.subscribe(() => this.open())
}
provide (): IToolbarButton[] {
return [{
icon: this.domSanitizer.bypassSecurityTrustHtml(require('./icons/cog.svg')),
title: 'Settings',
touchBarTitle: '⚙️',
weight: 10,
click: () => this.open(),
}]
}
open (): void {
let settingsTab = this.app.tabs.find((tab) => tab instanceof SettingsTabComponent)
if (settingsTab) {
this.app.selectTab(settingsTab)
} else {
this.app.openNewTab(SettingsTabComponent)
}
}
}