mirror of
https://github.com/Microsoft/vscode
synced 2024-10-13 06:48:17 +00:00
support workspace identifier in broadcasting API
This commit is contained in:
parent
de02dda6ad
commit
a5f3583393
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<W extends ISimpleWindow>(windows:
|
|||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function findWindowOnWorkspaceOrFolder<W extends ISimpleWindow>(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
|
||||
}
|
|
@ -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<IBroadcastService>('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<IBroadcast>;
|
||||
}
|
||||
|
@ -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
|
||||
|
|
|
@ -115,7 +115,7 @@ export class FileWatcher {
|
|||
return;
|
||||
}
|
||||
|
||||
// Emit through broadcast service
|
||||
// Emit through event emitter
|
||||
if (events.length > 0) {
|
||||
this.onFileChanges(toFileChangesEvent(events));
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ export class FileWatcher {
|
|||
return;
|
||||
}
|
||||
|
||||
// Emit through broadcast service
|
||||
// Emit through event emitter
|
||||
if (events.length > 0) {
|
||||
this.onFileChanges(toFileChangesEvent(events));
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ export class FileWatcher {
|
|||
return;
|
||||
}
|
||||
|
||||
// Emit through broadcast service
|
||||
// Emit through event emitter
|
||||
if (events.length > 0) {
|
||||
this.onFileChanges(toFileChangesEvent(events));
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue