提交 e096ce1b 编写于 作者: B Benjamin Pasero

debt - implement focusWindow() via host

上级 817eb6b0
......@@ -76,6 +76,17 @@ export class ElectronMainService implements AddContextToFunctions<IElectronServi
}
}
async focusWindow(windowId: number): Promise<void> {
const window = this.windowsMainService.getWindowById(windowId);
if (window) {
if (isMacintosh) {
window.win.show();
} else {
window.win.focus();
}
}
}
//#endregion
//#region Dialog
......
......@@ -16,8 +16,11 @@ export interface IElectronService {
// Window
windowCount(): Promise<number>;
openEmptyWindow(options?: { reuse?: boolean, remoteAuthority?: string }): Promise<void>;
toggleFullScreen(): Promise<void>;
handleTitleDoubleClick(): Promise<void>;
isMaximized(): Promise<boolean>;
......@@ -25,6 +28,8 @@ export interface IElectronService {
unmaximizeWindow(): Promise<void>;
minimizeWindow(): Promise<void>;
focusWindow(): Promise<void>;
// Dialogs
showMessageBox(options: MessageBoxOptions): Promise<MessageBoxReturnValue>;
showSaveDialog(options: SaveDialogOptions): Promise<SaveDialogReturnValue>;
......
......@@ -86,7 +86,6 @@ export interface IWindowsService {
removeFromRecentlyOpened(paths: URI[]): Promise<void>;
clearRecentlyOpened(): Promise<void>;
getRecentlyOpened(windowId: number): Promise<IRecentlyOpened>;
focusWindow(windowId: number): Promise<void>;
isFocused(windowId: number): Promise<boolean>;
// Global methods
......@@ -152,7 +151,6 @@ export interface IWindowService {
getRecentlyOpened(): Promise<IRecentlyOpened>;
addRecentlyOpened(recents: IRecent[]): Promise<void>;
removeFromRecentlyOpened(paths: URI[]): Promise<void>;
focusWindow(): Promise<void>;
openWindow(uris: IURIToOpen[], options?: IOpenSettings): Promise<void>;
isFocused(): Promise<boolean>;
}
......
......@@ -56,7 +56,6 @@ export class WindowsChannel implements IServerChannel {
case 'removeFromRecentlyOpened': return this.service.removeFromRecentlyOpened(arg.map(URI.revive));
case 'clearRecentlyOpened': return this.service.clearRecentlyOpened();
case 'getRecentlyOpened': return this.service.getRecentlyOpened(arg);
case 'focusWindow': return this.service.focusWindow(arg);
case 'isFocused': return this.service.isFocused(arg);
case 'openWindow': {
const urisToOpen: IURIToOpen[] = arg[1];
......
......@@ -50,10 +50,6 @@ export class WindowsService implements IWindowsService {
return recentlyOpened;
}
focusWindow(windowId: number): Promise<void> {
return this.channel.call('focusWindow', windowId);
}
isFocused(windowId: number): Promise<boolean> {
return this.channel.call('isFocused', windowId);
}
......
......@@ -16,7 +16,7 @@ import { IRecentlyOpened, IRecent } from 'vs/platform/history/common/history';
import { IHistoryMainService } from 'vs/platform/history/electron-main/historyMainService';
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { Schemas } from 'vs/base/common/network';
import { isMacintosh, IProcessEnvironment } from 'vs/base/common/platform';
import { IProcessEnvironment } from 'vs/base/common/platform';
import { ILogService } from 'vs/platform/log/common/log';
// @deprecated this should eventually go away and be implemented by host & electron service
......@@ -96,16 +96,6 @@ export class LegacyWindowsMainService extends Disposable implements IWindowsServ
return this.withWindow(windowId, codeWindow => this.historyMainService.getRecentlyOpened(codeWindow.config.workspace, codeWindow.config.folderUri, codeWindow.config.filesToOpenOrCreate), () => this.historyMainService.getRecentlyOpened())!;
}
async focusWindow(windowId: number): Promise<void> {
this.logService.trace('windowsService#focusWindow', windowId);
if (isMacintosh) {
return this.withWindow(windowId, codeWindow => codeWindow.win.show());
} else {
return this.withWindow(windowId, codeWindow => codeWindow.win.focus());
}
}
async isFocused(windowId: number): Promise<boolean> {
this.logService.trace('windowsService#isFocused', windowId);
......
......@@ -32,6 +32,7 @@ import { IRecentFile } from 'vs/platform/history/common/history';
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
import { withNullAsUndefined } from 'vs/base/common/types';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import { IHostService } from 'vs/workbench/services/host/browser/host';
export interface IDraggedResource {
resource: URI;
......@@ -166,7 +167,8 @@ export class ResourcesDropHandler {
@IUntitledEditorService private readonly untitledEditorService: IUntitledEditorService,
@IEditorService private readonly editorService: IEditorService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IWorkspaceEditingService private readonly workspaceEditingService: IWorkspaceEditingService
@IWorkspaceEditingService private readonly workspaceEditingService: IWorkspaceEditingService,
@IHostService private readonly hostService: IHostService
) {
}
......@@ -177,7 +179,7 @@ export class ResourcesDropHandler {
}
// Make the window active to handle the drop properly within
await this.windowService.focusWindow();
await this.hostService.focus();
// Check for special things being dropped
const isWorkspaceOpening = await this.doHandleDrop(untitledOrFileResources);
......@@ -292,7 +294,7 @@ export class ResourcesDropHandler {
}
// Pass focus to window
this.windowService.focusWindow();
this.hostService.focus();
// Open in separate windows if we drop workspaces or just one folder
if (urisToOpen.length > folderURIs.length || folderURIs.length === 1) {
......
......@@ -134,10 +134,6 @@ export class SimpleWindowService extends Disposable implements IWindowService {
return this.storageService.store(SimpleWindowService.RECENTLY_OPENED_KEY, JSON.stringify(toStoreData(data)), StorageScope.GLOBAL);
}
focusWindow(): Promise<void> {
return Promise.resolve();
}
async openWindow(_uris: IURIToOpen[], _options?: IOpenSettings): Promise<void> {
const { openFolderInNewWindow } = this.shouldOpenNewWindow(_options);
for (let i = 0; i < _uris.length; i++) {
......@@ -216,10 +212,6 @@ export class SimpleWindowsService implements IWindowsService {
});
}
focusWindow(_windowId: number): Promise<void> {
return Promise.resolve();
}
// Global methods
openWindow(_windowId: number, _uris: IURIToOpen[], _options: IOpenSettings): Promise<void> {
return Promise.resolve();
......
......@@ -22,7 +22,7 @@ import { IWorkspaceFolder, IWorkspaceContextService } from 'vs/platform/workspac
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { RunOnceScheduler } from 'vs/base/common/async';
import { generateUuid } from 'vs/base/common/uuid';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { IExtensionHostDebugService } from 'vs/platform/debug/common/extensionHostDebug';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { normalizeDriveLetter } from 'vs/base/common/labels';
......@@ -70,7 +70,7 @@ export class DebugSession implements IDebugSession {
options: IDebugSessionOptions | undefined,
@IDebugService private readonly debugService: IDebugService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@IWindowService private readonly windowService: IWindowService,
@IHostService private readonly hostService: IHostService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IViewletService private readonly viewletService: IViewletService,
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
......@@ -731,7 +731,7 @@ export class DebugSession implements IDebugSession {
}
if (this.configurationService.getValue<IDebugConfiguration>('debug').focusWindowOnBreak) {
this.windowService.focusWindow();
this.hostService.focus();
}
}
}
......
......@@ -20,7 +20,7 @@ import { IExtensionEnablementService, EnablementState, IExtensionManagementServe
import { getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData, areSameExtensions, getMaliciousExtensionsSet, groupByExtension, ExtensionIdentifierWithVersion } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { URI } from 'vs/base/common/uri';
import { IExtension, ExtensionState, IExtensionsWorkbenchService, AutoUpdateConfigurationKey, AutoCheckUpdatesConfigurationKey } from 'vs/workbench/contrib/extensions/common/extensions';
import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
......@@ -496,7 +496,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
@INotificationService private readonly notificationService: INotificationService,
@IURLService urlService: IURLService,
@IExtensionEnablementService private readonly extensionEnablementService: IExtensionEnablementService,
@IWindowService private readonly windowService: IWindowService,
@IHostService private readonly hostService: IHostService,
@IProgressService private readonly progressService: IProgressService,
@IExtensionManagementServerService private readonly extensionManagementServerService: IExtensionManagementServerService,
@IStorageService private readonly storageService: IStorageService,
......@@ -1070,7 +1070,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
const extension = local.filter(local => areSameExtensions(local.identifier, { id: extensionId }))[0];
if (extension) {
return this.windowService.focusWindow()
return this.hostService.focus()
.then(() => this.open(extension));
}
return this.queryGallery({ names: [extensionId], source: 'uri' }, CancellationToken.None).then(result => {
......@@ -1080,7 +1080,7 @@ export class ExtensionsWorkbenchService extends Disposable implements IExtension
const extension = result.firstPage[0];
return this.windowService.focusWindow().then(() => {
return this.hostService.focus().then(() => {
return this.open(extension);
});
});
......
......@@ -38,7 +38,7 @@ import { DesktopDragAndDropData, ExternalElementsDragAndDropData, ElementsDragAn
import { isMacintosh } from 'vs/base/common/platform';
import { IDialogService, IConfirmationResult, IConfirmation, getConfirmMessage } from 'vs/platform/dialogs/common/dialogs';
import { ITextFileService, ITextFileOperationResult } from 'vs/workbench/services/textfile/common/textfiles';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
import { URI } from 'vs/base/common/uri';
import { ITask, sequence } from 'vs/base/common/async';
......@@ -443,7 +443,7 @@ export class FileDragAndDrop implements ITreeDragAndDrop<ExplorerItem> {
@IConfigurationService private configurationService: IConfigurationService,
@IInstantiationService private instantiationService: IInstantiationService,
@ITextFileService private textFileService: ITextFileService,
@IWindowService private windowService: IWindowService,
@IHostService private hostService: IHostService,
@IWorkspaceEditingService private workspaceEditingService: IWorkspaceEditingService
) {
this.toDispose = [];
......@@ -610,7 +610,7 @@ export class FileDragAndDrop implements ITreeDragAndDrop<ExplorerItem> {
const result = await this.fileService.resolveAll(droppedResources);
// Pass focus to window
this.windowService.focusWindow();
this.hostService.focus();
// Handle folders by adding to workspace if we are in workspace context
const folders = result.filter(r => r.success && r.stat && r.stat.isDirectory).map(result => ({ uri: result.stat!.resource }));
......
......@@ -19,6 +19,7 @@ import { ICommandHandler } from 'vs/platform/commands/common/commands';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IElectronService } from 'vs/platform/electron/node/electron';
import { IHostService } from 'vs/workbench/services/host/browser/host';
export class CloseCurrentWindowAction extends Action {
......@@ -173,10 +174,10 @@ export abstract class BaseSwitchWindow extends Action {
private keybindingService: IKeybindingService,
private modelService: IModelService,
private modeService: IModeService,
private electronService: IElectronService
private electronService: IElectronService,
private hostService: IHostService
) {
super(id, label);
}
protected abstract isQuickNavigate(): boolean;
......@@ -211,7 +212,7 @@ export abstract class BaseSwitchWindow extends Action {
});
if (pick) {
this.windowsService.focusWindow(pick.payload);
this.hostService.focus();
}
}
}
......@@ -230,9 +231,10 @@ export class SwitchWindow extends BaseSwitchWindow {
@IKeybindingService keybindingService: IKeybindingService,
@IModelService modelService: IModelService,
@IModeService modeService: IModeService,
@IElectronService electronService: IElectronService
@IElectronService electronService: IElectronService,
@IHostService hostService: IHostService
) {
super(id, label, windowsService, windowService, quickInputService, keybindingService, modelService, modeService, electronService);
super(id, label, windowsService, windowService, quickInputService, keybindingService, modelService, modeService, electronService, hostService);
}
protected isQuickNavigate(): boolean {
......@@ -254,9 +256,10 @@ export class QuickSwitchWindow extends BaseSwitchWindow {
@IKeybindingService keybindingService: IKeybindingService,
@IModelService modelService: IModelService,
@IModeService modeService: IModeService,
@IElectronService electronService: IElectronService
@IElectronService electronService: IElectronService,
@IHostService hostService: IHostService
) {
super(id, label, windowsService, windowService, quickInputService, keybindingService, modelService, modeService, electronService);
super(id, label, windowsService, windowService, quickInputService, keybindingService, modelService, modeService, electronService, hostService);
}
protected isQuickNavigate(): boolean {
......
......@@ -61,6 +61,10 @@ export class BrowserHostService implements IHostService {
}
}
async focus(): Promise<void> {
window.focus();
}
//#endregion
async restart(): Promise<void> {
......
......@@ -29,6 +29,11 @@ export interface IHostService {
*/
toggleFullScreen(): Promise<void>;
/**
* Attempt to bring the window to the foreground and focus it.
*/
focus(): Promise<void>;
//#endregion
//#region Lifecycle
......
......@@ -25,6 +25,10 @@ export class DesktopHostService implements IHostService {
return this.electronService.toggleFullScreen();
}
focus(): Promise<void> {
return this.electronService.focusWindow();
}
//#endregion
restart(): Promise<void> {
......
......@@ -71,10 +71,6 @@ export class WindowService extends Disposable implements IWindowService {
return this.windowsService.removeFromRecentlyOpened(paths);
}
focusWindow(): Promise<void> {
return this.windowsService.focusWindow(this.windowId);
}
isFocused(): Promise<boolean> {
return this.windowsService.isFocused(this.windowId);
}
......
......@@ -1207,10 +1207,6 @@ export class TestWindowService implements IWindowService {
return Promise.resolve();
}
focusWindow(): Promise<void> {
return Promise.resolve();
}
openWindow(_uris: IURIToOpen[], _options?: IOpenSettings): Promise<void> {
return Promise.resolve();
}
......@@ -1289,10 +1285,6 @@ export class TestWindowsService implements IWindowsService {
});
}
focusWindow(_windowId: number): Promise<void> {
return Promise.resolve();
}
// Global methods
openWindow(_windowId: number, _uris: IURIToOpen[], _options: IOpenSettings): Promise<void> {
return Promise.resolve();
......@@ -1401,6 +1393,8 @@ export class TestHostService implements IHostService {
async reload(): Promise<void> { }
async closeWorkspace(): Promise<void> { }
async focus(): Promise<void> { }
async openEmptyWindow(options?: { reuse?: boolean, remoteAuthority?: string }): Promise<void> { }
async toggleFullScreen(): Promise<void> { }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册