added tab split commands to context menu - fixes #1321

This commit is contained in:
Eugene Pankov 2020-04-21 09:17:26 +02:00
parent e65d5ba93b
commit ab1b8a4500
4 changed files with 35 additions and 7 deletions

View File

@ -14,6 +14,11 @@ export interface BaseTabProcess {
* Abstract base class for custom tab components * Abstract base class for custom tab components
*/ */
export abstract class BaseTabComponent { export abstract class BaseTabComponent {
/**
* Parent tab (usually a SplitTabComponent)
*/
parent: BaseTabComponent|null = null
/** /**
* Current tab title * Current tab title
*/ */

View File

@ -358,6 +358,7 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
this.attachTabView(tab) this.attachTabView(tab)
setImmediate(() => { setImmediate(() => {
tab.parent = this
this.layout() this.layout()
this.tabAdded.next(tab) this.tabAdded.next(tab)
this.focus(tab) this.focus(tab)
@ -374,11 +375,11 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
parent.children.splice(index, 1) parent.children.splice(index, 1)
this.detachTabView(tab) this.detachTabView(tab)
tab.parent = null
this.layout() this.layout()
this.tabRemoved.next(tab) this.tabRemoved.next(tab)
if (this.root.children.length === 0) { if (this.root.children.length === 0) {
this.destroy() this.destroy()
} else { } else {
@ -569,6 +570,7 @@ export class SplitTabComponent extends BaseTabComponent implements AfterViewInit
if (recovered) { if (recovered) {
const tab = this.tabsService.create(recovered.type, recovered.options) const tab = this.tabsService.create(recovered.type, recovered.options)
children.push(tab) children.push(tab)
tab.parent = this
this.attachTabView(tab) this.attachTabView(tab)
} else { } else {
state.ratios.splice(state.children.indexOf(childState), 0) state.ratios.splice(state.children.indexOf(childState), 0)

View File

@ -36,7 +36,7 @@ import { ConfigService } from './services/config.service'
import { StandardTheme, StandardCompactTheme, PaperTheme } from './theme' import { StandardTheme, StandardCompactTheme, PaperTheme } from './theme'
import { CoreConfigProvider } from './config' import { CoreConfigProvider } from './config'
import { AppHotkeyProvider } from './hotkeys' import { AppHotkeyProvider } from './hotkeys'
import { TaskCompletionContextMenu, CommonOptionsContextMenu, CloseContextMenu } from './tabContextMenu' import { TaskCompletionContextMenu, CommonOptionsContextMenu, TabManagementContextMenu } from './tabContextMenu'
import 'perfect-scrollbar/css/perfect-scrollbar.css' import 'perfect-scrollbar/css/perfect-scrollbar.css'
import 'ng2-dnd/bundles/style.css' import 'ng2-dnd/bundles/style.css'
@ -54,7 +54,7 @@ const PROVIDERS = [
{ provide: Theme, useClass: PaperTheme, multi: true }, { provide: Theme, useClass: PaperTheme, multi: true },
{ provide: ConfigProvider, useClass: CoreConfigProvider, multi: true }, { provide: ConfigProvider, useClass: CoreConfigProvider, multi: true },
{ provide: TabContextMenuItemProvider, useClass: CommonOptionsContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: CommonOptionsContextMenu, multi: true },
{ provide: TabContextMenuItemProvider, useClass: CloseContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: TabManagementContextMenu, multi: true },
{ provide: TabContextMenuItemProvider, useClass: TaskCompletionContextMenu, multi: true }, { provide: TabContextMenuItemProvider, useClass: TaskCompletionContextMenu, multi: true },
{ provide: TabRecoveryProvider, useClass: SplitTabRecoveryProvider, multi: true }, { provide: TabRecoveryProvider, useClass: SplitTabRecoveryProvider, multi: true },
{ provide: PERFECT_SCROLLBAR_CONFIG, useValue: { suppressScrollX: true } }, { provide: PERFECT_SCROLLBAR_CONFIG, useValue: { suppressScrollX: true } },

View File

@ -4,11 +4,12 @@ import { Subscription } from 'rxjs'
import { AppService } from './services/app.service' import { AppService } from './services/app.service'
import { BaseTabComponent } from './components/baseTab.component' import { BaseTabComponent } from './components/baseTab.component'
import { TabHeaderComponent } from './components/tabHeader.component' import { TabHeaderComponent } from './components/tabHeader.component'
import { SplitTabComponent, SplitDirection } from './components/splitTab.component'
import { TabContextMenuItemProvider } from './api/tabContextMenuProvider' import { TabContextMenuItemProvider } from './api/tabContextMenuProvider'
/** @hidden */ /** @hidden */
@Injectable() @Injectable()
export class CloseContextMenu extends TabContextMenuItemProvider { export class TabManagementContextMenu extends TabContextMenuItemProvider {
weight = -5 weight = -5
constructor ( constructor (
@ -19,7 +20,7 @@ export class CloseContextMenu extends TabContextMenuItemProvider {
} }
async getItems (tab: BaseTabComponent, tabHeader?: TabHeaderComponent): Promise<Electron.MenuItemConstructorOptions[]> { async getItems (tab: BaseTabComponent, tabHeader?: TabHeaderComponent): Promise<Electron.MenuItemConstructorOptions[]> {
let items = [ let items: Electron.MenuItemConstructorOptions[] = [
{ {
label: 'Close', label: 'Close',
click: () => this.zone.run(() => { click: () => this.zone.run(() => {
@ -59,6 +60,24 @@ export class CloseContextMenu extends TabContextMenuItemProvider {
}), }),
}, },
] ]
} else {
if (tab.parent instanceof SplitTabComponent) {
const directions: SplitDirection[] = ['r', 'b', 'l', 't']
items.push({
label: 'Split',
submenu: directions.map(dir => ({
label: {
r: 'Right',
b: 'Down',
l: 'Left',
t: 'Up',
}[dir],
click: () => this.zone.run(() => {
(tab.parent as SplitTabComponent).splitTab(tab, dir)
}),
})) as Electron.MenuItemConstructorOptions[],
})
}
} }
return items return items
} }
@ -87,8 +106,10 @@ export class CommonOptionsContextMenu extends TabContextMenuItemProvider {
} }
async getItems (tab: BaseTabComponent, tabHeader?: TabHeaderComponent): Promise<Electron.MenuItemConstructorOptions[]> { async getItems (tab: BaseTabComponent, tabHeader?: TabHeaderComponent): Promise<Electron.MenuItemConstructorOptions[]> {
let items: Electron.MenuItemConstructorOptions[] = []
if (tabHeader) { if (tabHeader) {
return [ items = [
...items,
{ {
label: 'Rename', label: 'Rename',
click: () => this.zone.run(() => tabHeader?.showRenameTabModal()), click: () => this.zone.run(() => tabHeader?.showRenameTabModal()),
@ -111,7 +132,7 @@ export class CommonOptionsContextMenu extends TabContextMenuItemProvider {
}, },
] ]
} }
return [] return items
} }
} }