提交 2675ffea 编写于 作者: D Daniel Imms

Move parts of terminalService up to common/browser

上级 3760c273
......@@ -3,13 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ITerminalService } from 'vs/workbench/contrib/terminal/common/terminal';
import { ITerminalService, TERMINAL_PANEL_ID } from 'vs/workbench/contrib/terminal/common/terminal';
import { TerminalService as CommonTerminalService } from 'vs/workbench/contrib/terminal/common/terminalService';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { TerminalPanel } from 'vs/workbench/contrib/terminal/browser/terminalPanel';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { INotificationService } from 'vs/platform/notification/common/notification';
export abstract class TerminalService extends CommonTerminalService implements ITerminalService {
......@@ -18,8 +21,43 @@ export abstract class TerminalService extends CommonTerminalService implements I
@IPanelService panelService: IPanelService,
@IPartService partService: IPartService,
@ILifecycleService lifecycleService: ILifecycleService,
@IStorageService storageService: IStorageService
@IStorageService storageService: IStorageService,
@INotificationService notificationService: INotificationService,
@IDialogService dialogService: IDialogService
) {
super(contextKeyService, panelService, partService, lifecycleService, storageService);
super(contextKeyService, panelService, partService, lifecycleService, storageService, notificationService, dialogService);
}
public focusFindWidget(): Promise<void> {
return this.showPanel(false).then(() => {
const panel = this._panelService.getActivePanel() as TerminalPanel;
panel.focusFindWidget();
this._findWidgetVisible.set(true);
});
}
public hideFindWidget(): void {
const panel = this._panelService.getActivePanel() as TerminalPanel;
if (panel && panel.getId() === TERMINAL_PANEL_ID) {
panel.hideFindWidget();
this._findWidgetVisible.reset();
panel.focus();
}
}
public findNext(): void {
const panel = this._panelService.getActivePanel() as TerminalPanel;
if (panel && panel.getId() === TERMINAL_PANEL_ID) {
panel.showFindWidget();
panel.getFindWidget().find(false);
}
}
public findPrevious(): void {
const panel = this._panelService.getActivePanel() as TerminalPanel;
if (panel && panel.getId() === TERMINAL_PANEL_ID) {
panel.showFindWidget();
panel.getFindWidget().find(true);
}
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { Event, Emitter } from 'vs/base/common/event';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
......@@ -12,6 +13,8 @@ import { ITerminalService, ITerminalInstance, IShellLaunchConfig, ITerminalConfi
import { IStorageService } from 'vs/platform/storage/common/storage';
import { URI } from 'vs/base/common/uri';
import { FindReplaceState } from 'vs/editor/contrib/find/findState';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
export abstract class TerminalService implements ITerminalService {
public _serviceBrand: any;
......@@ -60,7 +63,9 @@ export abstract class TerminalService implements ITerminalService {
@IPanelService protected readonly _panelService: IPanelService,
@IPartService private readonly _partService: IPartService,
@ILifecycleService lifecycleService: ILifecycleService,
@IStorageService protected readonly _storageService: IStorageService
@IStorageService protected readonly _storageService: IStorageService,
@INotificationService protected readonly _notificationService: INotificationService,
@IDialogService private readonly _dialogService: IDialogService
) {
this._activeTabIndex = 0;
this._isShuttingDown = false;
......@@ -88,11 +93,8 @@ export abstract class TerminalService implements ITerminalService {
this.onInstancesChanged(() => updateTerminalContextKeys());
}
protected abstract _showTerminalCloseConfirmation(): Promise<boolean>;
protected abstract _showNotEnoughSpaceToast(): void;
public abstract createTerminal(shell?: IShellLaunchConfig, wasNewTerminalAction?: boolean): ITerminalInstance;
public abstract createInstance(terminalFocusContextKey: IContextKey<boolean>, configHelper: ITerminalConfigHelper, container: HTMLElement, shellLaunchConfig: IShellLaunchConfig, doCreateProcess: boolean): ITerminalInstance;
public abstract getActiveOrCreateInstance(wasNewTerminalAction?: boolean): ITerminalInstance;
public abstract selectDefaultWindowsShell(): Promise<string | undefined>;
public abstract setContainers(panelContainer: HTMLElement, terminalContainer: HTMLElement): void;
public abstract requestExtHostProcess(proxy: ITerminalProcessExtHostProxy, shellLaunchConfig: IShellLaunchConfig, activeWorkspaceRootUri: URI, cols: number, rows: number): void;
......@@ -101,6 +103,11 @@ export abstract class TerminalService implements ITerminalService {
return this.createTerminal({ name, isRendererOnly: true });
}
public getActiveOrCreateInstance(wasNewTerminalAction?: boolean): ITerminalInstance {
const activeInstance = this.getActiveInstance();
return activeInstance ? activeInstance : this.createTerminal(undefined, wasNewTerminalAction);
}
private _onBeforeShutdown(): boolean | Promise<boolean> {
if (this.terminalInstances.length === 0) {
// No terminal instances, don't veto
......@@ -373,4 +380,22 @@ export abstract class TerminalService implements ITerminalService {
public setWorkspaceShellAllowed(isAllowed: boolean): void {
this.configHelper.setWorkspaceShellAllowed(isAllowed);
}
protected _showTerminalCloseConfirmation(): Promise<boolean> {
let message;
if (this.terminalInstances.length === 1) {
message = nls.localize('terminalService.terminalCloseConfirmationSingular', "There is an active terminal session, do you want to kill it?");
} else {
message = nls.localize('terminalService.terminalCloseConfirmationPlural', "There are {0} active terminal sessions, do you want to kill them?", this.terminalInstances.length);
}
return this._dialogService.confirm({
message,
type: 'warning',
}).then(res => !res.confirmed);
}
protected _showNotEnoughSpaceToast(): void {
this._notificationService.info(nls.localize('terminal.minWidth', "Not enough space to split terminal."));
}
}
......@@ -12,13 +12,12 @@ import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { ITerminalInstance, ITerminalService, IShellLaunchConfig, ITerminalConfigHelper, NEVER_SUGGEST_SELECT_WINDOWS_SHELL_STORAGE_KEY, TERMINAL_PANEL_ID, ITerminalProcessExtHostProxy } from 'vs/workbench/contrib/terminal/common/terminal';
import { ITerminalInstance, ITerminalService, IShellLaunchConfig, ITerminalConfigHelper, NEVER_SUGGEST_SELECT_WINDOWS_SHELL_STORAGE_KEY, ITerminalProcessExtHostProxy } from 'vs/workbench/contrib/terminal/common/terminal';
import { TerminalService as BrowserTerminalService } from 'vs/workbench/contrib/terminal/browser/terminalService';
import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/electron-browser/terminalConfigHelper';
import Severity from 'vs/base/common/severity';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { getDefaultShell } from 'vs/workbench/contrib/terminal/node/terminal';
import { TerminalPanel } from 'vs/workbench/contrib/terminal/browser/terminalPanel';
import { TerminalTab } from 'vs/workbench/contrib/terminal/browser/terminalTab';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { INotificationService } from 'vs/platform/notification/common/notification';
......@@ -43,12 +42,12 @@ export class TerminalService extends BrowserTerminalService implements ITerminal
@IConfigurationService private readonly _configurationService: IConfigurationService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IQuickInputService private readonly _quickInputService: IQuickInputService,
@INotificationService private readonly _notificationService: INotificationService,
@IDialogService private readonly _dialogService: IDialogService,
@INotificationService notificationService: INotificationService,
@IDialogService dialogService: IDialogService,
@IExtensionService private readonly _extensionService: IExtensionService,
@IWindowService private readonly _windowService: IWindowService,
) {
super(contextKeyService, panelService, partService, lifecycleService, storageService);
super(contextKeyService, panelService, partService, lifecycleService, storageService, notificationService, dialogService);
this._terminalTabs = [];
this._configHelper = this._instantiationService.createInstance(TerminalConfigHelper);
......@@ -112,39 +111,6 @@ export class TerminalService extends BrowserTerminalService implements ITerminal
});
}
public focusFindWidget(): Promise<void> {
return this.showPanel(false).then(() => {
const panel = this._panelService.getActivePanel() as TerminalPanel;
panel.focusFindWidget();
this._findWidgetVisible.set(true);
});
}
public hideFindWidget(): void {
const panel = this._panelService.getActivePanel() as TerminalPanel;
if (panel && panel.getId() === TERMINAL_PANEL_ID) {
panel.hideFindWidget();
this._findWidgetVisible.reset();
panel.focus();
}
}
public findNext(): void {
const panel = this._panelService.getActivePanel() as TerminalPanel;
if (panel && panel.getId() === TERMINAL_PANEL_ID) {
panel.showFindWidget();
panel.getFindWidget().find(false);
}
}
public findPrevious(): void {
const panel = this._panelService.getActivePanel() as TerminalPanel;
if (panel && panel.getId() === TERMINAL_PANEL_ID) {
panel.showFindWidget();
panel.getFindWidget().find(true);
}
}
private _suggestShellChange(wasNewTerminalAction?: boolean): void {
// Only suggest on Windows since $SHELL works great for macOS/Linux
if (!platform.isWindows) {
......@@ -277,29 +243,6 @@ export class TerminalService extends BrowserTerminalService implements ITerminal
});
}
public getActiveOrCreateInstance(wasNewTerminalAction?: boolean): ITerminalInstance {
const activeInstance = this.getActiveInstance();
return activeInstance ? activeInstance : this.createTerminal(undefined, wasNewTerminalAction);
}
protected _showTerminalCloseConfirmation(): Promise<boolean> {
let message;
if (this.terminalInstances.length === 1) {
message = nls.localize('terminalService.terminalCloseConfirmationSingular', "There is an active terminal session, do you want to kill it?");
} else {
message = nls.localize('terminalService.terminalCloseConfirmationPlural', "There are {0} active terminal sessions, do you want to kill them?", this.terminalInstances.length);
}
return this._dialogService.confirm({
message,
type: 'warning',
}).then(res => !res.confirmed);
}
protected _showNotEnoughSpaceToast(): void {
this._notificationService.info(nls.localize('terminal.minWidth', "Not enough space to split terminal."));
}
public setContainers(panelContainer: HTMLElement, terminalContainer: HTMLElement): void {
this._configHelper.panelContainer = panelContainer;
this._terminalContainer = terminalContainer;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册