From 324bf9231671043a535d1f5a98aa3cb4efb3571b Mon Sep 17 00:00:00 2001 From: isidor Date: Fri, 13 May 2016 12:17:08 +0200 Subject: [PATCH] open editors: context menu actions for closing --- .../files/browser/views/openEditorsViewer.ts | 79 ++++++++++++++++++- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/parts/files/browser/views/openEditorsViewer.ts b/src/vs/workbench/parts/files/browser/views/openEditorsViewer.ts index 0e76195f322..1e4d3b6ed78 100644 --- a/src/vs/workbench/parts/files/browser/views/openEditorsViewer.ts +++ b/src/vs/workbench/parts/files/browser/views/openEditorsViewer.ts @@ -11,7 +11,7 @@ import {IAction, Action} from 'vs/base/common/actions'; import treedefaults = require('vs/base/parts/tree/browser/treeDefaults'); import tree = require('vs/base/parts/tree/browser/tree'); import {IActionProvider} from 'vs/base/parts/tree/browser/actionsRenderer'; -import {IActionItem, ActionBar} from 'vs/base/browser/ui/actionbar/actionbar'; +import {IActionItem, ActionBar, Separator} from 'vs/base/browser/ui/actionbar/actionbar'; import {IKeyboardEvent} from 'vs/base/browser/keyboardEvent'; import dom = require('vs/base/browser/dom'); import {IMouseEvent} from 'vs/base/browser/mouseEvent'; @@ -254,7 +254,8 @@ export class Controller extends treedefaults.DefaultController { if (event.target && event.target.tagName && event.target.tagName.toLowerCase() === 'input') { return false; } - if (!(element instanceof OpenEditor)) { + // Check if clicked on some element + if (element === tree.getInput()) { return false; } @@ -326,11 +327,26 @@ export class ActionProvider implements IActionProvider { } public hasSecondaryActions(tree: tree.ITree, element: any): boolean { - return element instanceof OpenEditor; + return element instanceof OpenEditor || element instanceof EditorGroup; } public getSecondaryActions(tree: tree.ITree, element: any): TPromise { - return TPromise.as([]); + const result = []; + if (element instanceof EditorGroup) { + result.push(this.instantiationService.createInstance(CloseAllEditorsInGroupAction)); + } else { + result.push(this.instantiationService.createInstance(CloseOpenEditorAction)); + result.push(new Separator()); + result.push(this.instantiationService.createInstance(CloseOtherEditorsInGroupAction)); + result.push(this.instantiationService.createInstance(CloseAllEditorsInGroupAction)); + result.push(new Separator()); + } + + result.push(this.instantiationService.createInstance(CloseEditorsInOtherGroupsAction)); + result.push(new Separator()); + result.push(this.instantiationService.createInstance(CloseAllEditorsAction)); + + return TPromise.as(result); } public getActionItem(tree: tree.ITree, element: any, action: IAction): IActionItem { @@ -351,3 +367,58 @@ class CloseOpenEditorAction extends Action { return this.editorService.closeEditor(position, openEditor.editorInput); } } + +class CloseOtherEditorsInGroupAction extends Action { + + public static ID = 'workbench.files.action.closeOtherEditorsInGroup'; + + constructor(@IWorkbenchEditorService private editorService: IWorkbenchEditorService) { + super(CloseOtherEditorsInGroupAction.ID, nls.localize('closeOtherEditorsInGroup', "Close Other Editors in Group")); + } + + public run(openEditor: OpenEditor): TPromise { + const position = this.editorService.getStacksModel().positionOfGroup(openEditor.editorGroup); + return this.editorService.closeEditors(position, openEditor.editorInput); + } +} + +class CloseAllEditorsInGroupAction extends Action { + + public static ID = 'workbench.files.action.closeAllEditorsInGroup'; + + constructor(@IWorkbenchEditorService private editorService: IWorkbenchEditorService) { + super(CloseAllEditorsInGroupAction.ID, nls.localize('closeAllEditorsInGroup', "Close All Editors in Group")); + } + + public run(openEditor: OpenEditor): TPromise { + const position = this.editorService.getStacksModel().positionOfGroup(openEditor.editorGroup); + return this.editorService.closeEditors(position); + } +} + +class CloseEditorsInOtherGroupsAction extends Action { + + public static ID = 'workbench.files.action.closeEditorsInOtherGroups'; + + constructor(@IWorkbenchEditorService private editorService: IWorkbenchEditorService) { + super(CloseEditorsInOtherGroupsAction.ID, nls.localize('closeEditorsInOtherGroups', "Close Editors in Other Groups")); + } + + public run(openEditor: OpenEditor): TPromise { + const position = this.editorService.getStacksModel().positionOfGroup(openEditor.editorGroup); + return this.editorService.closeAllEditors(position); + } +} + +class CloseAllEditorsAction extends Action { + + public static ID = 'workbench.files.action.closeAllEditors'; + + constructor(@IWorkbenchEditorService private editorService: IWorkbenchEditorService) { + super(CloseAllEditorsAction.ID, nls.localize('closeAllEditors', "Close All Editors")); + } + + public run(): TPromise { + return this.editorService.closeAllEditors(); + } +} -- GitLab