Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new command to switch between workspaces #11630

Merged
merged 2 commits into from
Sep 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/vs/code/electron-main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ export class WindowsManager implements IWindowsService {
}
});

ipc.on('vscode:showWindow', (event, windowId: number) => {
this.logService.log('IPC#vscode:showWindow');

let vscodeWindow = this.getWindowById(windowId);
if (vscodeWindow) {
vscodeWindow.win.show();
}
});

ipc.on('vscode:setDocumentEdited', (event, windowId: number, edited: boolean) => {
this.logService.log('IPC#vscode:setDocumentEdited');

Expand Down Expand Up @@ -423,6 +432,14 @@ export class WindowsManager implements IWindowsService {
}
});

ipc.on('vscode:switchWindow', (event, windowId: number) => {
const windows = this.getWindows();
const window = this.getWindowById(windowId);
window.send('vscode:switchWindow', windows.map(w => {
return {path: w.openedWorkspacePath, title: w.win.getTitle(), id: w.id};
}));
});

this.updateService.on('update-downloaded', (update: IUpdate) => {
this.sendToFocused('vscode:telemetry', { eventName: 'update:downloaded', data: { version: update.version } });

Expand Down Expand Up @@ -1305,4 +1322,4 @@ export class WindowsManager implements IWindowsService {

return pathA === pathB;
}
}
}
37 changes: 34 additions & 3 deletions src/vs/workbench/electron-browser/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import {IConfigurationService} from 'vs/platform/configuration/common/configurat
import {CommandsRegistry} from 'vs/platform/commands/common/commands';
import paths = require('vs/base/common/paths');
import {isMacintosh} from 'vs/base/common/platform';
import {IPickOpenEntry, ISeparator} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IQuickOpenService, IPickOpenEntry, ISeparator} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {KeyMod} from 'vs/base/common/keyCodes';
import {ServicesAccessor} from 'vs/platform/instantiation/common/instantiation';
import * as browser from 'vs/base/browser/browser';
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';

import {ipcRenderer as ipc, webFrame, remote} from 'electron';

Expand Down Expand Up @@ -72,6 +71,38 @@ export class CloseWindowAction extends Action {
}
}

export class SwitchWindow extends Action {

public static ID = 'workbench.action.switchWindow';
public static LABEL = nls.localize('switchWindow', "Switch Window");

constructor(
id: string,
label: string,
@IWindowService private windowService: IWindowService,
@IQuickOpenService private quickOpenService: IQuickOpenService
) {
super(id, label);
}

public run(): TPromise<boolean> {
ipc.send('vscode:switchWindow', this.windowService.getWindowId());
ipc.once('vscode:switchWindow', (event, workspaces) => {
const picks: IPickOpenEntry[] = workspaces.map(w => {
return {
label: w.title,
run: () => {
ipc.send('vscode:showWindow', w.id);
}
};
});
this.quickOpenService.pick(picks, {placeHolder: nls.localize('switchWindowPlaceHolder', "Select a window")});
});

return TPromise.as(true);
}
}

export class CloseFolderAction extends Action {

public static ID = 'workbench.action.closeFolder';
Expand Down Expand Up @@ -489,4 +520,4 @@ CommandsRegistry.registerCommand('_workbench.open', function (accessor: Services
return editorService.openEditor({ resource }, column).then(() => {
return void 0;
});
});
});
5 changes: 3 additions & 2 deletions src/vs/workbench/electron-browser/main.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import platform = require('vs/base/common/platform');
import {IKeybindings} from 'vs/platform/keybinding/common/keybinding';
import {KeybindingsRegistry} from 'vs/platform/keybinding/common/keybindingsRegistry';
import {IWindowService} from 'vs/workbench/services/window/electron-browser/windowService';
import {CloseEditorAction, ReloadWindowAction, ShowStartupPerformance, ZoomResetAction, ZoomOutAction, ZoomInAction, ToggleDevToolsAction, ToggleFullScreenAction, ToggleMenuBarAction, OpenRecentAction, CloseFolderAction, CloseWindowAction, NewWindowAction, CloseMessagesAction} from 'vs/workbench/electron-browser/actions';
import {CloseEditorAction, ReloadWindowAction, ShowStartupPerformance, ZoomResetAction, ZoomOutAction, ZoomInAction, ToggleDevToolsAction, ToggleFullScreenAction, ToggleMenuBarAction, OpenRecentAction, CloseFolderAction, CloseWindowAction, SwitchWindow, NewWindowAction, CloseMessagesAction} from 'vs/workbench/electron-browser/actions';
import {MessagesVisibleContext, NoEditorsVisibleContext} from 'vs/workbench/electron-browser/workbench';

const closeEditorOrWindowKeybindings: IKeybindings = { primary: KeyMod.CtrlCmd | KeyCode.KEY_W, win: { primary: KeyMod.CtrlCmd | KeyCode.F4, secondary: [KeyMod.CtrlCmd | KeyCode.KEY_W] }};
Expand All @@ -27,6 +27,7 @@ const fileCategory = nls.localize('file', "File");
const workbenchActionsRegistry = <IWorkbenchActionRegistry>Registry.as(Extensions.WorkbenchActions);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(NewWindowAction, NewWindowAction.ID, NewWindowAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_N }), 'New Window');
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseWindowAction, CloseWindowAction.ID, CloseWindowAction.LABEL, { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_W }), 'Close Window');
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(SwitchWindow, SwitchWindow.ID, SwitchWindow.LABEL), 'Switch Window');
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(CloseFolderAction, CloseFolderAction.ID, CloseFolderAction.LABEL, { primary: KeyMod.chord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_F) }), 'File: Close Folder', fileCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(OpenRecentAction, OpenRecentAction.ID, OpenRecentAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_R, mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_R } }), 'File: Open Recent', fileCategory);
workbenchActionsRegistry.registerWorkbenchAction(new SyncActionDescriptor(ToggleDevToolsAction, ToggleDevToolsAction.ID, ToggleDevToolsAction.LABEL), 'Developer: Toggle Developer Tools', developerCategory);
Expand Down Expand Up @@ -147,4 +148,4 @@ configurationRegistry.registerConfiguration({
'description': nls.localize('updateChannel', "Configure whether you receive automatic updates from an update channel. Requires a restart after change.")
}
}
});
});