Skip to content

Commit 95a6dca

Browse files
committed
ipc: remove vscode:focusWindow
microsoft#10587
1 parent 8756db4 commit 95a6dca

8 files changed

Lines changed: 36 additions & 28 deletions

File tree

src/vs/code/electron-main/windows.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,6 @@ export class WindowsManager implements IWindowsMainService, IWindowEventService
231231
}
232232
});
233233

234-
ipc.on('vscode:focusWindow', (event, windowId: number) => {
235-
this.logService.log('IPC#vscode:focusWindow');
236-
237-
const vscodeWindow = this.getWindowById(windowId);
238-
if (vscodeWindow) {
239-
vscodeWindow.win.focus();
240-
}
241-
});
242-
243234
ipc.on('vscode:showWindow', (event, windowId: number) => {
244235
this.logService.log('IPC#vscode:showWindow');
245236

src/vs/platform/windows/common/windows.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface IWindowsService {
2525
toggleFullScreen(windowId: number): TPromise<void>;
2626
setRepresentedFilename(windowId: number, fileName: string): TPromise<void>;
2727
getRecentlyOpen(windowId: number): TPromise<{ files: string[]; folders: string[]; }>;
28+
focusWindow(windowId: number): TPromise<void>;
2829

2930
// Global methods
3031
// TODO@joao: rename, shouldn't this be openWindow?
@@ -48,4 +49,5 @@ export interface IWindowService {
4849
toggleFullScreen(): TPromise<void>;
4950
setRepresentedFilename(fileName: string): TPromise<void>;
5051
getRecentlyOpen(): TPromise<{ files: string[]; folders: string[]; }>;
52+
focusWindow(): TPromise<void>;
5153
}

src/vs/platform/windows/common/windowsIpc.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface IWindowsChannel extends IChannel {
1919
call(command: 'toggleFullScreen', arg: number): TPromise<void>;
2020
call(command: 'setRepresentedFilename', arg: [number, string]): TPromise<void>;
2121
call(command: 'getRecentlyOpen', arg: number): TPromise<{ files: string[]; folders: string[]; }>;
22+
call(command: 'focusWindow', arg: number): TPromise<void>;
2223
call(command: 'windowOpen', arg: [string[], boolean]): TPromise<void>;
2324
call(command: 'openNewWindow'): TPromise<void>;
2425
call(command: string, arg?: any): TPromise<any>;
@@ -40,6 +41,7 @@ export class WindowsChannel implements IWindowsChannel {
4041
case 'toggleFullScreen': return this.service.toggleFullScreen(arg);
4142
case 'setRepresentedFilename': return this.service.setRepresentedFilename(arg[0], arg[1]);
4243
case 'getRecentlyOpen': return this.service.getRecentlyOpen(arg);
44+
case 'focusWindow': return this.service.focusWindow(arg);
4345
case 'windowOpen': return this.service.windowOpen(arg[0], arg[1]);
4446
case 'openNewWindow': return this.service.openNewWindow();
4547
}
@@ -92,6 +94,10 @@ export class WindowsChannelClient implements IWindowsService {
9294
return this.channel.call('getRecentlyOpen', windowId);
9395
}
9496

97+
focusWindow(windowId: number): TPromise<void> {
98+
return this.channel.call('focusWindow', windowId);
99+
}
100+
95101
windowOpen(paths: string[], forceNewWindow?: boolean): TPromise<void> {
96102
return this.channel.call('windowOpen', [paths, forceNewWindow]);
97103
}

src/vs/platform/windows/electron-browser/windowService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ export class WindowService implements IWindowService {
5656
getRecentlyOpen(): TPromise<{ files: string[]; folders: string[]; }> {
5757
return this.windowsService.getRecentlyOpen(this.windowId);
5858
}
59+
60+
focusWindow(): TPromise<void> {
61+
return this.windowsService.focusWindow(this.windowId);
62+
}
5963
}

src/vs/platform/windows/electron-main/windowsService.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ export class WindowsService implements IWindowsService {
107107
return TPromise.as({ files: [], folders: [] });
108108
}
109109

110+
focusWindow(windowId: number): TPromise<void> {
111+
const vscodeWindow = this.windowsMainService.getWindowById(windowId);
112+
113+
if (vscodeWindow) {
114+
vscodeWindow.win.focus();
115+
}
116+
117+
return TPromise.as(null);
118+
}
119+
110120
windowOpen(paths: string[], forceNewWindow?: boolean): TPromise<void> {
111121
if (!paths || !paths.length) {
112122
return TPromise.as(null);

src/vs/workbench/browser/parts/editor/sideBySideEditorControl.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { NoTabsTitleControl } from 'vs/workbench/browser/parts/editor/noTabsTitl
3636
import { IEditorStacksModel, IStacksModelChangeEvent, IWorkbenchEditorConfiguration, IEditorGroup, EditorOptions, TextEditorOptions, IEditorIdentifier } from 'vs/workbench/common/editor';
3737
import { ITitleAreaControl } from 'vs/workbench/browser/parts/editor/titleControl';
3838
import { extractResources } from 'vs/base/browser/dnd';
39+
import { IWindowService } from 'vs/platform/windows/common/windows';
3940

4041
export enum Rochade {
4142
NONE,
@@ -147,7 +148,8 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
147148
@IConfigurationService private configurationService: IConfigurationService,
148149
@IContextKeyService private contextKeyService: IContextKeyService,
149150
@IExtensionService private extensionService: IExtensionService,
150-
@IInstantiationService private instantiationService: IInstantiationService
151+
@IInstantiationService private instantiationService: IInstantiationService,
152+
@IWindowService private windowService: IWindowService
151153
) {
152154
this.stacks = editorGroupService.getStacksModel();
153155
this.toDispose = [];
@@ -1003,10 +1005,8 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
10031005
// Check for URI transfer
10041006
else {
10051007
if (droppedResources.length) {
1006-
window.focus(); // make sure this window has focus so that the open call reaches the right window!
1007-
1008-
// Open all
1009-
editorService.openEditors(droppedResources.map(resource => { return { input: { resource, options: { pinned: true } }, position: splitEditor ? freeGroup : position }; }))
1008+
$this.windowService.focusWindow()
1009+
.then(() => editorService.openEditors(droppedResources.map(resource => { return { input: { resource, options: { pinned: true } }, position: splitEditor ? freeGroup : position }; })))
10101010
.then(() => {
10111011
if (splitEditor && splitTo !== freeGroup) {
10121012
groupService.moveGroup(freeGroup, splitTo);

src/vs/workbench/browser/parts/editor/tabsTitleControl.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
2828
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
2929
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
3030
import { IMenuService } from 'vs/platform/actions/common/actions';
31+
import { IWindowService } from 'vs/platform/windows/common/windows';
3132
import { TitleControl } from 'vs/workbench/browser/parts/editor/titleControl';
3233
import { IQuickOpenService } from 'vs/workbench/services/quickopen/common/quickOpenService';
3334
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
@@ -65,7 +66,8 @@ export class TabsTitleControl extends TitleControl {
6566
@ITelemetryService telemetryService: ITelemetryService,
6667
@IMessageService messageService: IMessageService,
6768
@IMenuService menuService: IMenuService,
68-
@IQuickOpenService quickOpenService: IQuickOpenService
69+
@IQuickOpenService quickOpenService: IQuickOpenService,
70+
@IWindowService private windowService: IWindowService
6971
) {
7072
super(contextMenuService, instantiationService, configurationService, editorService, editorGroupService, contextKeyService, keybindingService, telemetryService, messageService, menuService, quickOpenService);
7173

@@ -582,10 +584,10 @@ export class TabsTitleControl extends TitleControl {
582584
input: { resource, options: { pinned: true, index: targetIndex } },
583585
position: targetPosition
584586
};
585-
})).done(() => {
587+
})).then(() => {
586588
this.editorGroupService.focusGroup(targetPosition);
587-
window.focus();
588-
}, errors.onUnexpectedError);
589+
return this.windowService.focusWindow();
590+
}).done(null, errors.onUnexpectedError);
589591
}
590592
}
591593

src/vs/workbench/electron-browser/window.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,12 @@ export class ElectronWindow {
119119
});
120120

121121
// Handle window.open() calls
122+
const $this = this;
122123
(<any>window).open = function (url: string, target: string, features: string, replace: boolean) {
123124
$this.openExternal(url);
124125

125126
return null;
126127
};
127-
128-
// Patch focus to also focus the entire window
129-
const originalFocus = window.focus;
130-
const $this = this;
131-
window.focus = function () {
132-
originalFocus.call(this, arguments);
133-
$this.focus();
134-
};
135128
}
136129

137130
private includesFolder(resources: URI[]): TPromise<boolean> {
@@ -161,8 +154,8 @@ export class ElectronWindow {
161154
return dialog.showSaveDialog(this.win, options); // https://github.com/electron/electron/issues/4936
162155
}
163156

164-
public focus(): void {
165-
ipc.send('vscode:focusWindow', this.windowId); // handled from browser process
157+
focus(): TPromise<void> {
158+
return this.windowService.focusWindow();
166159
}
167160

168161
public showItemInFolder(path: string): void {

0 commit comments

Comments
 (0)