1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-23 13:13:49 +03:00

touchbar improvements

This commit is contained in:
Eugene Pankov 2018-04-01 19:50:43 +02:00
parent c3c983daf6
commit 9a8bad4851
5 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,7 @@
export interface IToolbarButton {
icon: string
title: string
touchBarTitle?: string
weight?: number
click: () => void
}

View File

@ -25,7 +25,7 @@ export class TouchbarService {
app.activeTabChange$.subscribe(() => this.update())
app.tabOpened$.subscribe(tab => {
let sub = tab.titleChange$.subscribe(title => {
this.tabSegments[app.tabs.indexOf(tab)].label = title
this.tabSegments[app.tabs.indexOf(tab)].label = this.shortenTitle(title)
this.tabsSegmentedControl.segments = this.tabSegments
})
this.titleSubscriptions.set(tab, sub)
@ -43,7 +43,7 @@ export class TouchbarService {
})
buttons.sort((a, b) => (a.weight || 0) - (b.weight || 0))
this.tabSegments = this.app.tabs.map(tab => ({
label: tab.title,
label: this.shortenTitle(tab.title),
}))
this.tabsSegmentedControl = new this.electron.TouchBar.TouchBarSegmentedControl({
segments: this.tabSegments,
@ -58,7 +58,7 @@ export class TouchbarService {
new this.electron.TouchBar.TouchBarSpacer({size: 'flexible'}),
new this.electron.TouchBar.TouchBarSpacer({size: 'small'}),
...buttons.map(button => new this.electron.TouchBar.TouchBarButton({
label: button.title,
label: this.shortenTitle(button.touchBarTitle || button.title),
// backgroundColor: '#0022cc',
click: () => this.zone.run(() => button.click()),
}))
@ -67,4 +67,10 @@ export class TouchbarService {
this.electron.app.window.setTouchBar(touchBar)
}
private shortenTitle (title: string): string {
if (title.length > 15) {
title = title.substring(0, 15) + '...'
}
return title
}
}

View File

@ -17,6 +17,7 @@ export class ButtonProvider extends ToolbarButtonProvider {
return [{
icon: 'sliders',
title: 'Settings',
touchBarTitle: '⚙️',
weight: 10,
click: () => this.open(),
}]

View File

@ -25,7 +25,8 @@ export class ButtonProvider extends ToolbarButtonProvider {
return [{
icon: 'globe',
weight: 5,
title: 'SSH',
title: 'SSH connections',
touchBarTitle: 'SSH',
click: async () => {
this.activate()
}

View File

@ -56,6 +56,7 @@ export class ButtonProvider extends ToolbarButtonProvider {
return [{
icon: 'plus',
title: 'New terminal',
touchBarTitle: 'New',
click: async () => {
this.openNewTab()
}