From 9a8bad4851d0f5605a8618df56dc5a10681215ae Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sun, 1 Apr 2018 19:50:43 +0200 Subject: [PATCH] touchbar improvements --- terminus-core/src/api/toolbarButtonProvider.ts | 1 + terminus-core/src/services/touchbar.service.ts | 12 +++++++++--- terminus-settings/src/buttonProvider.ts | 1 + terminus-ssh/src/buttonProvider.ts | 3 ++- terminus-terminal/src/buttonProvider.ts | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/terminus-core/src/api/toolbarButtonProvider.ts b/terminus-core/src/api/toolbarButtonProvider.ts index bb317028..48adb20e 100644 --- a/terminus-core/src/api/toolbarButtonProvider.ts +++ b/terminus-core/src/api/toolbarButtonProvider.ts @@ -1,6 +1,7 @@ export interface IToolbarButton { icon: string title: string + touchBarTitle?: string weight?: number click: () => void } diff --git a/terminus-core/src/services/touchbar.service.ts b/terminus-core/src/services/touchbar.service.ts index e97c7faa..c8ebafda 100644 --- a/terminus-core/src/services/touchbar.service.ts +++ b/terminus-core/src/services/touchbar.service.ts @@ -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 + } } diff --git a/terminus-settings/src/buttonProvider.ts b/terminus-settings/src/buttonProvider.ts index 3f2c23db..3ac20614 100644 --- a/terminus-settings/src/buttonProvider.ts +++ b/terminus-settings/src/buttonProvider.ts @@ -17,6 +17,7 @@ export class ButtonProvider extends ToolbarButtonProvider { return [{ icon: 'sliders', title: 'Settings', + touchBarTitle: '⚙️', weight: 10, click: () => this.open(), }] diff --git a/terminus-ssh/src/buttonProvider.ts b/terminus-ssh/src/buttonProvider.ts index f94279ea..44e37eae 100644 --- a/terminus-ssh/src/buttonProvider.ts +++ b/terminus-ssh/src/buttonProvider.ts @@ -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() } diff --git a/terminus-terminal/src/buttonProvider.ts b/terminus-terminal/src/buttonProvider.ts index 78bb8de8..d912f142 100644 --- a/terminus-terminal/src/buttonProvider.ts +++ b/terminus-terminal/src/buttonProvider.ts @@ -56,6 +56,7 @@ export class ButtonProvider extends ToolbarButtonProvider { return [{ icon: 'plus', title: 'New terminal', + touchBarTitle: 'New', click: async () => { this.openNewTab() }