parent
81f4334e22
commit
a6f3aa89cd
2 changed files with 76 additions and 67 deletions
|
@ -7,21 +7,15 @@ import DOM = require('vs/base/browser/dom');
|
|||
import lifecycle = require('vs/base/common/lifecycle');
|
||||
import nls = require('vs/nls');
|
||||
import os = require('os');
|
||||
import platform = require('vs/base/common/platform');
|
||||
import xterm = require('xterm');
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {Dimension} from 'vs/base/browser/builder';
|
||||
import {IAction} from 'vs/base/common/actions';
|
||||
import {Separator} from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
|
||||
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
|
||||
import {IKeybindingService, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybinding';
|
||||
import {IMessageService, Severity} from 'vs/platform/message/common/message';
|
||||
import {ITerminalFont} from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper';
|
||||
import {ITerminalProcess, ITerminalService} from 'vs/workbench/parts/terminal/electron-browser/terminal';
|
||||
import {CopyTerminalSelectionAction, TerminalPasteAction, CreateNewTerminalAction} from 'vs/workbench/parts/terminal/electron-browser/terminalActions';
|
||||
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
|
||||
import {StandardMouseEvent} from 'vs/base/browser/mouseEvent';
|
||||
|
||||
export class TerminalInstance {
|
||||
|
||||
|
@ -76,60 +70,6 @@ export class TerminalInstance {
|
|||
this.onExitCallback(this);
|
||||
}
|
||||
});
|
||||
this.toDispose.push(DOM.addDisposableListener(this.parentDomElement, 'mousedown', (event: MouseEvent) => {
|
||||
if (event.which === 2 && platform.isLinux) {
|
||||
// Drop selection and focus terminal on Linux to enable middle button paste when click
|
||||
// occurs on the selection itself.
|
||||
this.focus(true);
|
||||
} else if (event.which === 3) {
|
||||
// Trigger the context menu on right click
|
||||
let anchor: HTMLElement | { x: number, y: number } = this.parentDomElement;
|
||||
if (event instanceof MouseEvent) {
|
||||
const standardEvent = new StandardMouseEvent(event);
|
||||
anchor = { x: standardEvent.posx, y: standardEvent.posy };
|
||||
}
|
||||
|
||||
// TODO: Move these into panel and pass them in so they're shared between instances
|
||||
let newTerminalAction = this.instantiationService.createInstance(CreateNewTerminalAction, CreateNewTerminalAction.ID, nls.localize('createNewTerminal', "New terminal"));
|
||||
let copyAction = this.instantiationService.createInstance(CopyTerminalSelectionAction, CopyTerminalSelectionAction.ID, nls.localize('copy', "Copy"));
|
||||
let pasteAction = this.instantiationService.createInstance(TerminalPasteAction, TerminalPasteAction.ID, nls.localize('paste', "Paste"));
|
||||
|
||||
const actions: IAction[] = [
|
||||
newTerminalAction,
|
||||
new Separator(),
|
||||
copyAction,
|
||||
pasteAction
|
||||
];
|
||||
|
||||
contextMenuService.showContextMenu({
|
||||
getAnchor: () => anchor,
|
||||
getActions: () => TPromise.as(actions),
|
||||
getActionsContext: () => this.parentDomElement,
|
||||
getKeyBinding: (action) => {
|
||||
const opts = this.keybindingService.lookupKeybindings(action.id);
|
||||
if (opts.length > 0) {
|
||||
return opts[0]; // only take the first one
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
// TODO: This and all parentDomElement handlers should be handled in the panel!
|
||||
// Currently this line is stopping the other terminal instances from reacting to the
|
||||
// event.
|
||||
event.stopImmediatePropagation();
|
||||
}));
|
||||
this.toDispose.push(DOM.addDisposableListener(this.parentDomElement, 'mouseup', (event) => {
|
||||
if (event.which !== 3) {
|
||||
this.focus();
|
||||
}
|
||||
}));
|
||||
this.toDispose.push(DOM.addDisposableListener(this.parentDomElement, 'keyup', (event: KeyboardEvent) => {
|
||||
// Keep terminal open on escape
|
||||
if (event.keyCode === 27) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
}));
|
||||
|
||||
this.xterm.open(this.terminalDomElement);
|
||||
|
||||
|
|
|
@ -4,26 +4,29 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import DOM = require('vs/base/browser/dom');
|
||||
import {getBaseThemeId} from 'vs/platform/theme/common/themes';
|
||||
import lifecycle = require('vs/base/common/lifecycle');
|
||||
import nls = require('vs/nls');
|
||||
import platform = require('vs/base/common/platform');
|
||||
import {Action, IAction} from 'vs/base/common/actions';
|
||||
import {Builder, Dimension} from 'vs/base/browser/builder';
|
||||
import {KillTerminalAction, CreateNewTerminalAction, SwitchTerminalInstanceAction, SwitchTerminalInstanceActionItem} from 'vs/workbench/parts/terminal/electron-browser/terminalActions';
|
||||
import {getBaseThemeId} from 'vs/platform/theme/common/themes';
|
||||
import {IActionItem} from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
|
||||
import {IKeybindingService, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybinding';
|
||||
import {IContextMenuService} from 'vs/platform/contextview/browser/contextView';
|
||||
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
|
||||
import {IKeybindingService, IKeybindingContextKey} from 'vs/platform/keybinding/common/keybinding';
|
||||
import {IMessageService} from 'vs/platform/message/common/message';
|
||||
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
|
||||
import {ITerminalFont, TerminalConfigHelper} from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper';
|
||||
import {ITerminalProcess, ITerminalService, TERMINAL_PANEL_ID} from 'vs/workbench/parts/terminal/electron-browser/terminal';
|
||||
import {IThemeService} from 'vs/workbench/services/themes/common/themeService';
|
||||
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
|
||||
import {KillTerminalAction, CreateNewTerminalAction, SwitchTerminalInstanceAction, SwitchTerminalInstanceActionItem, CopyTerminalSelectionAction, TerminalPasteAction} from 'vs/workbench/parts/terminal/electron-browser/terminalActions';
|
||||
import {Panel} from 'vs/workbench/browser/panel';
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
import {ITerminalFont, TerminalConfigHelper} from 'vs/workbench/parts/terminal/electron-browser/terminalConfigHelper';
|
||||
import {Separator} from 'vs/base/browser/ui/actionbar/actionbar';
|
||||
import {StandardMouseEvent} from 'vs/base/browser/mouseEvent';
|
||||
import {TerminalInstance} from 'vs/workbench/parts/terminal/electron-browser/terminalInstance';
|
||||
import {TPromise} from 'vs/base/common/winjs.base';
|
||||
|
||||
export class TerminalPanel extends Panel {
|
||||
|
||||
|
@ -31,6 +34,7 @@ export class TerminalPanel extends Panel {
|
|||
private terminalInstances: TerminalInstance[] = [];
|
||||
|
||||
private actions: IAction[];
|
||||
private contextMenuActions: IAction[];
|
||||
private parentDomElement: HTMLElement;
|
||||
private terminalContainer: HTMLElement;
|
||||
private currentBaseThemeId: string;
|
||||
|
@ -70,15 +74,28 @@ export class TerminalPanel extends Panel {
|
|||
this.instantiationService.createInstance(CreateNewTerminalAction, CreateNewTerminalAction.ID, CreateNewTerminalAction.PANEL_LABEL),
|
||||
this.instantiationService.createInstance(KillTerminalAction, KillTerminalAction.ID, KillTerminalAction.PANEL_LABEL)
|
||||
];
|
||||
|
||||
this.actions.forEach(a => {
|
||||
this.toDispose.push(a);
|
||||
});
|
||||
}
|
||||
|
||||
return this.actions;
|
||||
}
|
||||
|
||||
private getContextMenuActions(): IAction[] {
|
||||
if (!this.contextMenuActions) {
|
||||
this.contextMenuActions = [
|
||||
this.instantiationService.createInstance(CreateNewTerminalAction, CreateNewTerminalAction.ID, nls.localize('createNewTerminal', "New terminal")),
|
||||
new Separator(),
|
||||
this.instantiationService.createInstance(CopyTerminalSelectionAction, CopyTerminalSelectionAction.ID, nls.localize('copy', "Copy")),
|
||||
this.instantiationService.createInstance(TerminalPasteAction, TerminalPasteAction.ID, nls.localize('paste', "Paste"))
|
||||
];
|
||||
this.contextMenuActions.forEach(a => {
|
||||
this.toDispose.push(a);
|
||||
});
|
||||
}
|
||||
return this.contextMenuActions;
|
||||
}
|
||||
|
||||
public getActionItem(action: Action): IActionItem {
|
||||
if (action.id === SwitchTerminalInstanceAction.ID) {
|
||||
return this.instantiationService.createInstance(SwitchTerminalInstanceActionItem, action);
|
||||
|
@ -101,11 +118,63 @@ export class TerminalPanel extends Panel {
|
|||
this.parentDomElement.appendChild(this.fontStyleElement);
|
||||
this.parentDomElement.appendChild(this.terminalContainer);
|
||||
|
||||
this.attachEventListeners();
|
||||
|
||||
this.configurationHelper = new TerminalConfigHelper(platform.platform, this.configurationService, parent);
|
||||
|
||||
return this.terminalService.createNew();
|
||||
}
|
||||
|
||||
private attachEventListeners(): void {
|
||||
this.toDispose.push(DOM.addDisposableListener(this.parentDomElement, 'mousedown', (event: MouseEvent) => {
|
||||
if (this.terminalInstances.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.which === 2 && platform.isLinux) {
|
||||
// Drop selection and focus terminal on Linux to enable middle button paste when click
|
||||
// occurs on the selection itself.
|
||||
this.terminalInstances[this.terminalService.getActiveTerminalIndex()].focus(true);
|
||||
} else if (event.which === 3) {
|
||||
// Trigger the context menu on right click
|
||||
let anchor: HTMLElement | { x: number, y: number } = this.parentDomElement;
|
||||
if (event instanceof MouseEvent) {
|
||||
const standardEvent = new StandardMouseEvent(event);
|
||||
anchor = { x: standardEvent.posx, y: standardEvent.posy };
|
||||
}
|
||||
|
||||
this.contextMenuService.showContextMenu({
|
||||
getAnchor: () => anchor,
|
||||
getActions: () => TPromise.as(this.getContextMenuActions()),
|
||||
getActionsContext: () => this.parentDomElement,
|
||||
getKeyBinding: (action) => {
|
||||
const opts = this.keybindingService.lookupKeybindings(action.id);
|
||||
if (opts.length > 0) {
|
||||
return opts[0]; // only take the first one
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
event.stopImmediatePropagation();
|
||||
}));
|
||||
this.toDispose.push(DOM.addDisposableListener(this.parentDomElement, 'mouseup', (event) => {
|
||||
if (this.terminalInstances.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.which !== 3) {
|
||||
this.terminalInstances[this.terminalService.getActiveTerminalIndex()].focus();
|
||||
}
|
||||
}));
|
||||
this.toDispose.push(DOM.addDisposableListener(this.parentDomElement, 'keyup', (event: KeyboardEvent) => {
|
||||
if (event.keyCode === 27) {
|
||||
// Keep terminal open on escape
|
||||
event.stopPropagation();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public createNewTerminalInstance(terminalProcess: ITerminalProcess, terminalFocusContextKey: IKeybindingContextKey<boolean>): TPromise<void> {
|
||||
return this.createTerminal(terminalProcess, terminalFocusContextKey).then(() => {
|
||||
this.updateConfig();
|
||||
|
|
Loading…
Reference in a new issue