提交 5139e261 编写于 作者: I isidor

open editors: use context for actions

上级 d88a714d
......@@ -407,8 +407,8 @@ export class CloseEditorAction extends Action {
super(id, label, 'close-editor-action');
}
public run(position: Position): TPromise<any> {
public run(editorIdentifier: IEditorIdentifier): TPromise<any> {
let position = editorIdentifier ? this.editorService.getStacksModel().positionOfGroup(editorIdentifier.group) : null;
// Close Active Editor
if (typeof position !== 'number') {
let activeEditor = this.editorService.getActiveEditor();
......@@ -417,10 +417,17 @@ export class CloseEditorAction extends Action {
}
}
// Close Editor at Position
let visibleEditors = this.editorService.getVisibleEditors();
if (visibleEditors[position]) {
return this.editorService.closeEditor(position, visibleEditors[position].input);
let input = editorIdentifier ? editorIdentifier.editor : null;
if (!input) {
// Get Top Editor at Position
let visibleEditors = this.editorService.getVisibleEditors();
if (visibleEditors[position]) {
input = visibleEditors[position].input;
}
}
if (input) {
return this.editorService.closeEditor(position, input);
}
return TPromise.as(false);
......@@ -436,7 +443,8 @@ export class CloseEditorsInGroupAction extends Action {
super(id, label);
}
public run(position: Position): TPromise<any> {
public run(editorIdentifier: IEditorIdentifier): TPromise<any> {
let position = editorIdentifier ? this.editorService.getStacksModel().positionOfGroup(editorIdentifier.group) : null;
if (typeof position !== 'number') {
let activeEditor = this.editorService.getActiveEditor();
if (activeEditor) {
......@@ -513,7 +521,8 @@ export class CloseEditorsInOtherGroupsAction extends Action {
super(id, label);
}
public run(position: Position): TPromise<any> {
public run(editorIdentifier: IEditorIdentifier): TPromise<any> {
let position = editorIdentifier ? this.editorService.getStacksModel().positionOfGroup(editorIdentifier.group) : null;
if (typeof position !== 'number') {
let activeEditor = this.editorService.getActiveEditor();
if (activeEditor) {
......@@ -538,10 +547,19 @@ export class CloseOtherEditorsInGroupAction extends Action {
super(id, label);
}
public run(): TPromise<any> {
public run(editorIdentifier: IEditorIdentifier): TPromise<any> {
let position = editorIdentifier ? this.editorService.getStacksModel().positionOfGroup(editorIdentifier.group) : null;
let input = editorIdentifier ? editorIdentifier.editor : null;
// If position or input are not passed in take the position and input of the active editor.
const active = this.editorService.getActiveEditor();
if (active) {
return this.editorService.closeEditors(active.position, active.input);
position = typeof position === 'number' ? position : active.position;
input = input ? input : active.input;
}
if (typeof position === 'number' && input) {
return this.editorService.closeEditors(position, input);
}
return TPromise.as(false);
......@@ -557,7 +575,8 @@ export class CloseAllEditorsInGroupAction extends Action {
super(id, label, 'action-close-all-files');
}
public run(position: Position): TPromise<any> {
public run(editorIdentifier: IEditorIdentifier): TPromise<any> {
let position = editorIdentifier ? this.editorService.getStacksModel().positionOfGroup(editorIdentifier.group) : null;
if (typeof position !== 'number') {
let activeEditor = this.editorService.getActiveEditor();
if (activeEditor) {
......@@ -580,7 +599,8 @@ export class MoveGroupLeftAction extends Action {
super(id, label);
}
public run(position: Position): TPromise<any> {
public run(editorIdentifier: IEditorIdentifier): TPromise<any> {
let position = editorIdentifier ? this.editorService.getStacksModel().positionOfGroup(editorIdentifier.group) : null;
if (typeof position !== 'number') {
let activeEditor = this.editorService.getActiveEditor();
if (activeEditor && (activeEditor.position === Position.CENTER || activeEditor.position === Position.RIGHT)) {
......@@ -608,7 +628,8 @@ export class MoveGroupRightAction extends Action {
super(id, label);
}
public run(position: Position): TPromise<any> {
public run(editorIdentifier: IEditorIdentifier): TPromise<any> {
let position = editorIdentifier ? this.editorService.getStacksModel().positionOfGroup(editorIdentifier.group) : null;
if (typeof position !== 'number') {
let activeEditor = this.editorService.getActiveEditor();
let editors = this.editorService.getVisibleEditors();
......@@ -992,4 +1013,4 @@ export class QuickOpenNavigatePreviousAction extends BaseQuickOpenNavigateAction
interface IEditorPickOpenEntry extends IPickOpenEntry {
identifier: IEditorIdentifier;
}
\ No newline at end of file
}
......@@ -1025,7 +1025,8 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
const toolbar = this.doCreateToolbar(div, position);
this.editorTitleToolbar[position] = toolbar;
this.editorTitleToolbar[position].setActions([this.closeEditorActions[position]])();
this.editorTitleToolbar[position].context = position;
const group = this.editorService.getStacksModel().getGroup(position);
this.editorTitleToolbar[position].context = { group };
});
// Left Title Labe
......@@ -1046,7 +1047,8 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
}, (div) => {
const toolbar = this.doCreateToolbar(div, position);
this.editorActionsToolbar[position] = toolbar;
this.editorActionsToolbar[position].context = position;
const group = this.editorService.getStacksModel().getGroup(position);
this.editorActionsToolbar[position].context = { group };
});
}
......@@ -1173,7 +1175,7 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
public updateTitleArea(state: ITitleAreaState): void;
public updateTitleArea(input: EditorInput): void;
public updateTitleArea(arg1: any): void {
// Update all title areas that relate to given input if provided
if (arg1 instanceof EditorInput) {
const input: EditorInput = arg1;
......@@ -1209,6 +1211,9 @@ export class SideBySideEditorControl implements ISideBySideEditorControl, IVerti
const activePosition = this.lastActivePosition;
states.forEach(state => {
const group = this.editorService.getStacksModel().groups[state.position];
this.editorTitleToolbar[state.position].context = { group };
this.editorActionsToolbar[state.position].context = { group };
let editor = this.visibleEditors[state.position];
let input = editor ? editor.input : null;
......
......@@ -14,7 +14,7 @@ import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/c
import {dispose, IDisposable} from 'vs/base/common/lifecycle';
import {IEditorRegistry, Extensions} from 'vs/workbench/browser/parts/editor/baseEditor';
import {Registry} from 'vs/platform/platform';
import {Position, Direction} from 'vs/platform/editor/common/editor';
import {Position, Direction, IEditorInput} from 'vs/platform/editor/common/editor';
export interface IEditorGroup {
......@@ -72,7 +72,7 @@ export interface IEditorStacksModel {
export interface IEditorIdentifier {
group: IEditorGroup;
editor: EditorInput;
editor: IEditorInput;
}
export type GroupIdentifier = number;
......
......@@ -185,7 +185,7 @@ export class Renderer implements IRenderer {
private renderEditorGroup(tree: ITree, editorGroup: IEditorGroup, templateData: IOpenEditorTemplateData): void {
templateData.name.textContent = editorGroup.label;
templateData.actionBar.context = this.model.positionOfGroup(editorGroup);
templateData.actionBar.context = { group: editorGroup };
}
private renderOpenEditor(tree: ITree, editor: OpenEditor, templateData: IOpenEditorTemplateData): void {
......@@ -195,7 +195,7 @@ export class Renderer implements IRenderer {
templateData.root.title = resource ? resource.fsPath : '';
templateData.name.textContent = editor.editorInput.getName();
templateData.description.textContent = editor.editorInput.getDescription();
templateData.actionBar.context = this.model.positionOfGroup(editor.editorGroup);
templateData.actionBar.context = { group: editor.editorGroup, editor: editor.editorInput };
}
public disposeTemplate(tree: ITree, templateId: string, templateData: any): void {
......@@ -291,7 +291,8 @@ export class Controller extends treedefaults.DefaultController {
event.stopPropagation();
tree.setFocus(element);
const editorGroup = element instanceof EditorGroup ? element : (<OpenEditor>element).editorGroup;
const group = element instanceof EditorGroup ? element : (<OpenEditor>element).editorGroup;
const editor = element instanceof OpenEditor ? (<OpenEditor>element).editorInput : undefined;
let anchor = { x: event.posx + 1, y: event.posy };
this.contextMenuService.showContextMenu({
......@@ -310,7 +311,7 @@ export class Controller extends treedefaults.DefaultController {
tree.DOMFocus();
}
},
getActionsContext: () => this.model.positionOfGroup(editorGroup)
getActionsContext: () => ({ group, editor })
});
return true;
......
......@@ -1375,7 +1375,7 @@ suite('Editor Stacks Model', () => {
assert.equal(previous.editor, input6);
model.setActive(<EditorGroup>previous.group);
(<EditorGroup>previous.group).setActive(previous.editor);
(<EditorGroup>previous.group).setActive(<EditorInput>previous.editor);
let next = model.next();
assert.equal(next.group, group1);
......@@ -1389,7 +1389,7 @@ suite('Editor Stacks Model', () => {
assert.equal(next.editor, input4);
model.setActive(<EditorGroup>next.group);
(<EditorGroup>next.group).setActive(next.editor);
(<EditorGroup>next.group).setActive(<EditorInput>next.editor);
previous = model.previous();
assert.equal(previous.group, group1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册