diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index bcc5f7a97ad88..335b1c152c0cb 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -47,12 +47,11 @@ import { IWindowsMainService } from "vs/platform/windows/electron-main/windows"; import { IHistoryMainService } from "vs/platform/history/common/history"; import { isUndefinedOrNull } from 'vs/base/common/types'; import { CodeWindow } from "vs/code/electron-main/window"; -import { isParent } from 'vs/platform/files/common/files'; -import { isEqual } from 'vs/base/common/paths'; import { KeyboardLayoutMonitor } from "vs/code/electron-main/keyboard"; import URI from 'vs/base/common/uri'; import { WorkspacesChannel } from "vs/platform/workspaces/common/workspacesIpc"; -import { IWorkspacesMainService } from "vs/platform/workspaces/common/workspaces"; +import { IWorkspacesMainService, IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces"; +import { findWindowOnWorkspaceOrFolder } from "vs/code/node/windowsFinder"; export class CodeApplication { private toDispose: IDisposable[]; @@ -205,24 +204,24 @@ export class CodeApplication { }); }); - ipc.on('vscode:broadcast', (event, windowId: number, target: string, broadcast: { channel: string; payload: any; }) => { + ipc.on('vscode:broadcast', (event, windowId: number, target: IWorkspaceIdentifier | string, broadcast: { channel: string; payload: any; }) => { if (this.windowsMainService && broadcast.channel && !isUndefinedOrNull(broadcast.payload)) { this.logService.log('IPC#vscode:broadcast', target, broadcast.channel, broadcast.payload); // Handle specific events on main side this.onBroadcast(broadcast.channel, broadcast.payload); - // Send to windows + // Send to specific window if target is provided if (target) { - const otherWindowsWithTarget = this.windowsMainService.getWindows().filter(w => w.id !== windowId && typeof w.openedFolderPath === 'string'); - const directTargetMatch = otherWindowsWithTarget.filter(w => isEqual(target, w.openedFolderPath, !platform.isLinux /* ignorecase */)); - const parentTargetMatch = otherWindowsWithTarget.filter(w => isParent(target, w.openedFolderPath, !platform.isLinux /* ignorecase */)); - - const targetWindow = directTargetMatch.length ? directTargetMatch[0] : parentTargetMatch[0]; // prefer direct match over parent match + const otherWindowsWithTarget = this.windowsMainService.getWindows().filter(w => w.id !== windowId && (w.openedWorkspace || w.openedFolderPath)); + const targetWindow = findWindowOnWorkspaceOrFolder(otherWindowsWithTarget, target); if (targetWindow) { targetWindow.send('vscode:broadcast', broadcast); } - } else { + } + + // Otherwise send to all windows + else { this.windowsMainService.sendToAll('vscode:broadcast', broadcast, [windowId]); } } diff --git a/src/vs/code/node/windowsFinder.ts b/src/vs/code/node/windowsFinder.ts index 588a42f6c0e16..94c5d36e84459 100644 --- a/src/vs/code/node/windowsFinder.ts +++ b/src/vs/code/node/windowsFinder.ts @@ -11,6 +11,7 @@ import * as platform from 'vs/base/common/platform'; import * as paths from 'vs/base/common/paths'; import { OpenContext } from 'vs/platform/windows/common/windows'; import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces"; +import { isParent } from "vs/platform/files/common/files"; export interface ISimpleWindow { openedWorkspace?: IWorkspaceIdentifier; @@ -165,4 +166,24 @@ export function findExtensionDevelopmentWindow(windows: } return null; +} + +export function findWindowOnWorkspaceOrFolder(windows: W[], target: IWorkspaceIdentifier | string): W { + const directTargetMatch = windows.filter(w => { + if (typeof target === 'string') { + return paths.isEqual(target, w.openedFolderPath, !platform.isLinux /* ignorecase */); + } + + return w.openedWorkspace && w.openedWorkspace.id === target.id; + }); + + const parentTargetMatch = windows.filter(w => { + if (typeof target === 'string') { + return isParent(target, w.openedFolderPath, !platform.isLinux /* ignorecase */); + } + + return false; // not supported for workspace target + }); + + return directTargetMatch.length ? directTargetMatch[0] : parentTargetMatch[0]; // prefer direct match over parent match } \ No newline at end of file diff --git a/src/vs/platform/broadcast/electron-browser/broadcastService.ts b/src/vs/platform/broadcast/electron-browser/broadcastService.ts index 17696c4103199..03be908ca9dcf 100644 --- a/src/vs/platform/broadcast/electron-browser/broadcastService.ts +++ b/src/vs/platform/broadcast/electron-browser/broadcastService.ts @@ -9,6 +9,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation' import Event, { Emitter } from 'vs/base/common/event'; import { ipcRenderer as ipc } from 'electron'; +import { IWorkspaceIdentifier } from "vs/platform/workspaces/common/workspaces"; export const IBroadcastService = createDecorator('broadcastService'); @@ -20,7 +21,7 @@ export interface IBroadcast { export interface IBroadcastService { _serviceBrand: any; - broadcast(b: IBroadcast, target?: string): void; + broadcast(b: IBroadcast, target?: IWorkspaceIdentifier | string): void; onBroadcast: Event; } @@ -46,7 +47,7 @@ export class BroadcastService implements IBroadcastService { return this._onBroadcast.event; } - public broadcast(b: IBroadcast, target?: string): void { + public broadcast(b: IBroadcast, target?: IWorkspaceIdentifier | string): void { ipc.send('vscode:broadcast', this.windowId, target, { channel: b.channel, payload: b.payload diff --git a/src/vs/workbench/services/files/node/watcher/nsfw/watcherService.ts b/src/vs/workbench/services/files/node/watcher/nsfw/watcherService.ts index be60fdf3baeeb..b3f8c608892a3 100644 --- a/src/vs/workbench/services/files/node/watcher/nsfw/watcherService.ts +++ b/src/vs/workbench/services/files/node/watcher/nsfw/watcherService.ts @@ -115,7 +115,7 @@ export class FileWatcher { return; } - // Emit through broadcast service + // Emit through event emitter if (events.length > 0) { this.onFileChanges(toFileChangesEvent(events)); } diff --git a/src/vs/workbench/services/files/node/watcher/unix/watcherService.ts b/src/vs/workbench/services/files/node/watcher/unix/watcherService.ts index fa895f465eaa7..0f96d2c3b9c6e 100644 --- a/src/vs/workbench/services/files/node/watcher/unix/watcherService.ts +++ b/src/vs/workbench/services/files/node/watcher/unix/watcherService.ts @@ -89,7 +89,7 @@ export class FileWatcher { return; } - // Emit through broadcast service + // Emit through event emitter if (events.length > 0) { this.onFileChanges(toFileChangesEvent(events)); } diff --git a/src/vs/workbench/services/files/node/watcher/win32/watcherService.ts b/src/vs/workbench/services/files/node/watcher/win32/watcherService.ts index 518a08f22a3e6..54ba8d297fde8 100644 --- a/src/vs/workbench/services/files/node/watcher/win32/watcherService.ts +++ b/src/vs/workbench/services/files/node/watcher/win32/watcherService.ts @@ -55,7 +55,7 @@ export class FileWatcher { return; } - // Emit through broadcast service + // Emit through event emitter if (events.length > 0) { this.onFileChanges(toFileChangesEvent(events)); } diff --git a/src/vs/workbench/services/files/test/node/watcher.test.ts b/src/vs/workbench/services/files/test/node/watcher.test.ts index 023ebbb8843e9..a8c6b9ee80b2c 100644 --- a/src/vs/workbench/services/files/test/node/watcher.test.ts +++ b/src/vs/workbench/services/files/test/node/watcher.test.ts @@ -33,7 +33,7 @@ class TestFileWatcher { // Normalize let normalizedEvents = normalize(events); - // Emit through broadcast service + // Emit through event emitter if (normalizedEvents.length > 0) { this._onFileChanges.fire(toFileChangesEvent(normalizedEvents)); }