提交 76bc7c04 编写于 作者: D Daniel Imms 提交者: GitHub

Merge pull request #28464 from jammerware/topic/issue-10023

Topic/issue 10023
......@@ -330,4 +330,9 @@ export interface ITerminalInstance {
* Experimental: Call to enable onData to be passed over IPC to the extension host.
*/
enableApiOnData(): void;
/**
* Sets the title of the terminal instance.
*/
setTitle(title: string): void;
}
......@@ -18,7 +18,7 @@ import { TERMINAL_DEFAULT_SHELL_LINUX, TERMINAL_DEFAULT_SHELL_OSX, TERMINAL_DEFA
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { KillTerminalAction, CopyTerminalSelectionAction, CreateNewTerminalAction, FocusActiveTerminalAction, FocusNextTerminalAction, FocusPreviousTerminalAction, FocusTerminalAtIndexAction, SelectDefaultShellWindowsTerminalAction, RunSelectedTextInTerminalAction, RunActiveFileInTerminalAction, ScrollDownTerminalAction, ScrollDownPageTerminalAction, ScrollToBottomTerminalAction, ScrollUpTerminalAction, ScrollUpPageTerminalAction, ScrollToTopTerminalAction, TerminalPasteAction, ToggleTerminalAction, ClearTerminalAction, AllowWorkspaceShellTerminalCommand, DisallowWorkspaceShellTerminalCommand, SelectAllTerminalAction } from 'vs/workbench/parts/terminal/electron-browser/terminalActions';
import { KillTerminalAction, CopyTerminalSelectionAction, CreateNewTerminalAction, FocusActiveTerminalAction, FocusNextTerminalAction, FocusPreviousTerminalAction, FocusTerminalAtIndexAction, SelectDefaultShellWindowsTerminalAction, RunSelectedTextInTerminalAction, RunActiveFileInTerminalAction, ScrollDownTerminalAction, ScrollDownPageTerminalAction, ScrollToBottomTerminalAction, ScrollUpTerminalAction, ScrollUpPageTerminalAction, ScrollToTopTerminalAction, TerminalPasteAction, ToggleTerminalAction, ClearTerminalAction, AllowWorkspaceShellTerminalCommand, DisallowWorkspaceShellTerminalCommand, RenameTerminalAction, SelectAllTerminalAction } from 'vs/workbench/parts/terminal/electron-browser/terminalActions';
import { Registry } from 'vs/platform/platform';
import { ShowAllCommandsAction } from 'vs/workbench/parts/quickopen/browser/commandsHandler';
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
......@@ -276,5 +276,6 @@ if (platform.isWindows) {
}
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(AllowWorkspaceShellTerminalCommand, AllowWorkspaceShellTerminalCommand.ID, AllowWorkspaceShellTerminalCommand.LABEL), 'Terminal: Allow Workspace Shell Configuration', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(DisallowWorkspaceShellTerminalCommand, DisallowWorkspaceShellTerminalCommand.ID, DisallowWorkspaceShellTerminalCommand.LABEL), 'Terminal: Disallow Workspace Shell Configuration', category);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(RenameTerminalAction, RenameTerminalAction.ID, RenameTerminalAction.LABEL), 'Terminal: Rename', category);
registerColors();
......@@ -17,6 +17,7 @@ import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { attachSelectBoxStyler } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
export class ToggleTerminalAction extends TogglePanelAction {
......@@ -554,3 +555,31 @@ export class DisallowWorkspaceShellTerminalCommand extends Action {
return TPromise.as(void 0);
}
}
export class RenameTerminalAction extends Action {
public static ID = 'workbench.action.terminal.rename';
public static LABEL = nls.localize('workbench.action.terminal.rename', "Rename");
constructor(
id: string, label: string,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@ITerminalService private terminalService: ITerminalService
) {
super(id, label);
}
public run(): TPromise<any> {
const terminalInstance = this.terminalService.getActiveInstance();
if (!terminalInstance) {
return TPromise.as(void 0);
}
return this.quickOpenService.input({
prompt: nls.localize('workbench.action.terminal.rename.prompt', "Enter terminal name"),
}).then(name => {
if (name) {
terminalInstance.setTitle(name);
}
});
}
}
......@@ -76,6 +76,7 @@ export class TerminalInstance implements ITerminalInstance {
private _terminalHasTextContextKey: IContextKey<boolean>;
private _cols: number;
private _rows: number;
private _messageTitleListener: (message: { type: string, content: string }) => void;
private _widgetManager: TerminalWidgetManager;
private _linkHandler: TerminalLinkHandler;
......@@ -494,12 +495,13 @@ export class TerminalInstance implements ITerminalInstance {
});
if (!shell.name) {
// Only listen for process title changes when a name is not provided
this._process.on('message', (message) => {
this._messageTitleListener = (message) => {
if (message.type === 'title') {
this._title = message.content ? message.content : '';
this._onTitleChanged.fire(this._title);
}
});
};
this._process.on('message', this._messageTitleListener);
}
this._process.on('message', (message) => {
if (message.type === 'pid') {
......@@ -780,6 +782,20 @@ export class TerminalInstance implements ITerminalInstance {
public static setTerminalProcessFactory(factory: ITerminalProcessFactory): void {
this._terminalProcessFactory = factory;
}
public setTitle(title: string): void {
const didTitleChange = title !== this._title;
if (didTitleChange) {
this._onTitleChanged.fire(title);
}
// If the title was not set by the API, unregister the handler that
// automatically updates the terminal name
if (this._process && this._messageTitleListener) {
this._process.removeListener('message', this._messageTitleListener);
this._messageTitleListener = null;
}
}
}
registerThemingParticipant((theme: ITheme, collector: ICssStyleCollector) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册