Add a command to open a new window as tab (Sierra tabs) (fixes #25919)

This commit is contained in:
Benjamin Pasero
2018-08-07 18:04:50 +02:00
parent ac60be30a7
commit 6f3f9edcfa
10 changed files with 76 additions and 6 deletions

View File

@@ -607,6 +607,7 @@ export class Menubar {
if (this.currentEnableNativeTabs) {
const hasMultipleWindows = this.windowsMainService.getWindowCount() > 1;
this.nativeTabMenuItems.push(this.createMenuItem(nls.localize('mNewTab', "New Tab"), 'workbench.action.newWindowTab'));
this.nativeTabMenuItems.push(this.createMenuItem(nls.localize('mShowPreviousTab', "Show Previous Tab"), 'workbench.action.showPreviousWindowTab', hasMultipleWindows));
this.nativeTabMenuItems.push(this.createMenuItem(nls.localize('mShowNextTab', "Show Next Tab"), 'workbench.action.showNextWindowTab', hasMultipleWindows));
this.nativeTabMenuItems.push(this.createMenuItem(nls.localize('mMoveTabToNewWindow', "Move Tab to New Window"), 'workbench.action.moveWindowTabToNewWindow', hasMultipleWindows));

View File

@@ -500,6 +500,12 @@ export class CodeWindow implements ICodeWindow {
});
}
addTabbedWindow(window: ICodeWindow): void {
if (isMacintosh) {
this._win.addTabbedWindow(window.win);
}
}
load(config: IWindowConfiguration, isReload?: boolean, disableExtensions?: boolean): void {
// If this is the first time the window is loaded, we associate the paths

View File

@@ -81,6 +81,7 @@ interface IOpenBrowserWindowOptions {
filesToWait?: IPathsToWaitFor;
forceNewWindow?: boolean;
forceNewTabbedWindow?: boolean;
windowToUse?: ICodeWindow;
emptyWindowBackupFolder?: string;
@@ -546,7 +547,7 @@ export class WindowsManager implements IWindowsMainService {
// Special case: we started with --wait and we got back a folder to open. In this case
// we actually prefer to not open the folder but operate purely on the file.
if (typeof bestWindowOrFolder === 'string' && filesToWait) {
//TODO: #54483 Ben This should not happen
//TODO@Ben: #54483 This should not happen
console.error(`This should not happen`, bestWindowOrFolder, WindowsManager.WINDOWS);
bestWindowOrFolder = !openFilesInNewWindow ? this.getLastActiveWindow() : null;
}
@@ -580,7 +581,7 @@ export class WindowsManager implements IWindowsMainService {
// We found a suitable folder to open: add it to foldersToOpen
else if (typeof bestWindowOrFolder === 'string') {
//TODO: #54483 Ben This should not happen
//TODO@Ben: #54483 Ben This should not happen
// foldersToOpen.push(bestWindowOrFolder);
console.error(`This should not happen`, bestWindowOrFolder, WindowsManager.WINDOWS);
}
@@ -595,7 +596,8 @@ export class WindowsManager implements IWindowsMainService {
filesToCreate,
filesToDiff,
filesToWait,
forceNewWindow: true
forceNewWindow: true,
forceNewTabbedWindow: openConfig.forceNewTabbedWindow
}));
// Reset these because we handled them
@@ -700,6 +702,7 @@ export class WindowsManager implements IWindowsMainService {
filesToDiff,
filesToWait,
forceNewWindow: true,
forceNewTabbedWindow: openConfig.forceNewTabbedWindow,
emptyWindowBackupFolder
}));
@@ -720,7 +723,8 @@ export class WindowsManager implements IWindowsMainService {
userEnv: openConfig.userEnv,
cli: openConfig.cli,
initialStartup: openConfig.initialStartup,
forceNewWindow: openFolderInNewWindow
forceNewWindow: openFolderInNewWindow,
forceNewTabbedWindow: openConfig.forceNewTabbedWindow
}));
openFolderInNewWindow = true; // any other window to open must open in new window then
@@ -767,6 +771,7 @@ export class WindowsManager implements IWindowsMainService {
filesToDiff,
filesToWait,
forceNewWindow,
forceNewTabbedWindow: openConfig.forceNewTabbedWindow,
windowToUse
});
@@ -1128,6 +1133,7 @@ export class WindowsManager implements IWindowsMainService {
}
private openInBrowserWindow(options: IOpenBrowserWindowOptions): ICodeWindow {
// Build IWindowConfiguration from config and options
const configuration: IWindowConfiguration = mixin({}, options.cli); // inherit all properties from CLI
configuration.appRoot = this.environmentService.appRoot;
@@ -1152,7 +1158,7 @@ export class WindowsManager implements IWindowsMainService {
}
let window: ICodeWindow;
if (!options.forceNewWindow) {
if (!options.forceNewWindow && !options.forceNewTabbedWindow) {
window = options.windowToUse || this.getLastActiveWindow();
if (window) {
window.focus();
@@ -1179,12 +1185,21 @@ export class WindowsManager implements IWindowsMainService {
state.mode = WindowMode.Normal;
}
// Create the window
window = this.instantiationService.createInstance(CodeWindow, {
state,
extensionDevelopmentPath: configuration.extensionDevelopmentPath,
isExtensionTestHost: !!configuration.extensionTestsPath
});
// Add as window tab if configured (macOS only)
if (options.forceNewTabbedWindow) {
const activeWindow = this.getLastActiveWindow();
if (activeWindow) {
activeWindow.addTabbedWindow(window);
}
}
// Add to our list of windows
WindowsManager.WINDOWS.push(window);
@@ -1475,6 +1490,10 @@ export class WindowsManager implements IWindowsMainService {
return this.open({ context, cli: this.environmentService.args, forceNewWindow: true, forceEmpty: true });
}
openNewTabbedWindow(context: OpenContext): ICodeWindow[] {
return this.open({ context, cli: this.environmentService.args, forceNewTabbedWindow: true, forceEmpty: true });
}
waitForWindowCloseOrLoad(windowId: number): TPromise<void> {
return new TPromise<void>(c => {
function handler(id: number) {