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

open editors: use context for actions

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