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 { export interface IToolbarButton {
icon: string icon: string
title: string title: string
touchBarTitle?: string
weight?: number weight?: number
click: () => void click: () => void
} }

View File

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

View File

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

View File

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