diff --git a/src/vs/workbench/browser/parts/editor/editor.contribution.ts b/src/vs/workbench/browser/parts/editor/editor.contribution.ts index 5a7925076db919b5ffaba13eea799663a21244e4..c40ec6a532b0c4a9884e5ab5a944d3543a43ea9d 100644 --- a/src/vs/workbench/browser/parts/editor/editor.contribution.ts +++ b/src/vs/workbench/browser/parts/editor/editor.contribution.ts @@ -33,7 +33,7 @@ import { NavigateBetweenGroupsAction, FocusActiveGroupAction, FocusFirstGroupAction, FocusSecondGroupAction, FocusThirdGroupAction, EvenGroupWidthsAction, MaximizeGroupAction, MinimizeOtherGroupsAction, FocusPreviousGroup, FocusNextGroup, ShowEditorsInLeftGroupAction, toEditorQuickOpenEntry, CloseLeftEditorsInGroupAction, CloseRightEditorsInGroupAction, OpenNextEditor, OpenPreviousEditor, NavigateBackwardsAction, NavigateForwardAction, ReopenClosedEditorAction, OpenPreviousRecentlyUsedEditorInGroupAction, NAVIGATE_IN_LEFT_GROUP_PREFIX, OpenPreviousEditorFromHistoryAction, ShowAllEditorsAction, NAVIGATE_ALL_EDITORS_GROUP_PREFIX, ClearEditorHistoryAction, ShowEditorsInCenterGroupAction, MoveEditorRightInGroupAction, - NAVIGATE_IN_CENTER_GROUP_PREFIX, ShowEditorsInRightGroupAction, NAVIGATE_IN_RIGHT_GROUP_PREFIX, RemoveFromEditorHistoryAction, FocusLastEditorInStackAction, OpenNextRecentlyUsedEditorInGroupAction, MoveEditorToLeftGroupAction, MoveEditorToRightGroupAction, MoveEditorLeftInGroupAction + NAVIGATE_IN_CENTER_GROUP_PREFIX, ShowEditorsInRightGroupAction, NAVIGATE_IN_RIGHT_GROUP_PREFIX, FocusLastEditorInStackAction, OpenNextRecentlyUsedEditorInGroupAction, MoveEditorToLeftGroupAction, MoveEditorToRightGroupAction, MoveEditorLeftInGroupAction } from 'vs/workbench/browser/parts/editor/editorActions'; import * as editorCommands from 'vs/workbench/browser/parts/editor/editorCommands'; @@ -228,7 +228,6 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateForwardAction, registry.registerWorkbenchAction(new SyncActionDescriptor(NavigateBackwardsAction, NavigateBackwardsAction.ID, NavigateBackwardsAction.LABEL, { primary: null, win: { primary: KeyMod.Alt | KeyCode.LeftArrow }, mac: { primary: KeyMod.WinCtrl | KeyCode.US_MINUS }, linux: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.US_MINUS } }), 'Go Back'); registry.registerWorkbenchAction(new SyncActionDescriptor(OpenPreviousEditorFromHistoryAction, OpenPreviousEditorFromHistoryAction.ID, OpenPreviousEditorFromHistoryAction.LABEL), 'Open Previous Editor from History'); registry.registerWorkbenchAction(new SyncActionDescriptor(ClearEditorHistoryAction, ClearEditorHistoryAction.ID, ClearEditorHistoryAction.LABEL), 'Clear Editor History'); -registry.registerWorkbenchAction(new SyncActionDescriptor(RemoveFromEditorHistoryAction, RemoveFromEditorHistoryAction.ID, RemoveFromEditorHistoryAction.LABEL), 'Remove From Editor History'); // Keybindings to focus a specific index in the tab folder if tabs are enabled for (let i = 0; i < 9; i++) { diff --git a/src/vs/workbench/browser/parts/editor/editorActions.ts b/src/vs/workbench/browser/parts/editor/editorActions.ts index 73709f8b3fd5c2c3d007b4a1851f409d5c66615e..14dfd5f035db9fe79eb2361435838ec456bdb4bd 100644 --- a/src/vs/workbench/browser/parts/editor/editorActions.ts +++ b/src/vs/workbench/browser/parts/editor/editorActions.ts @@ -1147,40 +1147,6 @@ export class ClearEditorHistoryAction extends Action { } } -export class RemoveFromEditorHistoryAction extends Action { - - public static ID = 'workbench.action.removeFromEditorHistory'; - public static LABEL = nls.localize('removeFromEditorHistory', "Remove From Editor History"); - - constructor( - id: string, - label: string, - @IEditorGroupService private editorGroupService: IEditorGroupService, - @IQuickOpenService private quickOpenService: IQuickOpenService, - @IHistoryService private historyService: IHistoryService - ) { - super(id, label); - } - - public run(): TPromise { - - // Listen for next editor to open - const unbind = this.editorGroupService.onEditorOpening(e => { - unbind.dispose(); // listen once - - e.prevent(); - this.historyService.remove(e.editorInput); - }); - - // Bring up quick open - this.quickOpenService.show().then(() => { - unbind.dispose(); // make sure to unbind if quick open is closing - }); - - return TPromise.as(true); - } -} - export class FocusLastEditorInStackAction extends Action { public static ID = 'workbench.action.openLastEditorInGroup'; diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index 83a2e0f6295d812d44b1fe22a8853d40ea2e95d3..eeb09445c807adeccb6650efdd511ecd6790ddce 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -6,7 +6,6 @@ 'use strict'; import 'vs/css!./media/quickopen'; -import 'vs/workbench/browser/parts/quickopen/quickopen.contribution'; import { TPromise, ValueCallback } from 'vs/base/common/winjs.base'; import nls = require('vs/nls'); import { Dimension, withElementById } from 'vs/base/browser/builder'; @@ -16,6 +15,7 @@ import DOM = require('vs/base/browser/dom'); import URI from 'vs/base/common/uri'; import uuid = require('vs/base/common/uuid'); import types = require('vs/base/common/types'); +import { Action } from 'vs/base/common/actions'; import { IIconLabelOptions } from 'vs/base/browser/ui/iconLabel/iconLabel'; import { CancellationToken } from 'vs/base/common/cancellation'; import { Mode, IEntryRunContext, IAutoFocus, IQuickNavigateConfiguration, IModel } from 'vs/base/parts/quickopen/common/quickOpen'; @@ -1110,4 +1110,44 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry { return false; } +} + +export class RemoveFromEditorHistoryAction extends Action { + + public static ID = 'workbench.action.removeFromEditorHistory'; + public static LABEL = nls.localize('removeFromEditorHistory', "Remove From Editor History"); + + constructor( + id: string, + label: string, + @IQuickOpenService private quickOpenService: IQuickOpenService, + @IInstantiationService private instantiationService: IInstantiationService, + @IHistoryService private historyService: IHistoryService + ) { + super(id, label); + } + + public run(): TPromise { + interface IHistoryPickEntry extends IFilePickOpenEntry { + input: IEditorInput | IResourceInput; + } + + const history = this.historyService.getHistory(); + const picks: IHistoryPickEntry[] = history.map(h => { + const entry = this.instantiationService.createInstance(EditorHistoryEntry, h); + + return { + input: h, + resource: entry.getResource(), + label: entry.getLabel(), + description: entry.getDescription() + }; + }); + + return this.quickOpenService.pick(picks, { placeHolder: nls.localize('pickHistory', "Select an editor entry to remove from history"), autoFocus: { autoFocusFirstEntry: true }, matchOnDescription: true }).then(pick => { + if (pick) { + this.historyService.remove(pick.input); + } + }); + } } \ No newline at end of file diff --git a/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts b/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts index e7cc045a78dee7343b9adba1d81c6cfabbd76a3c..c889aa5adedca14cd5f5307f4b4d9379eb651407 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts @@ -16,6 +16,7 @@ import { SyncActionDescriptor } from 'vs/platform/actions/common/actions'; import { KeyMod, KeyCode } from 'vs/base/common/keyCodes'; import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actionRegistry'; import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; +import { RemoveFromEditorHistoryAction } from 'vs/workbench/browser/parts/quickopen/quickOpenController'; export class GlobalQuickOpenAction extends Action { @@ -153,4 +154,5 @@ const registry = Registry.as(ActionExtensions.Workbenc registry.registerWorkbenchAction(new SyncActionDescriptor(GlobalQuickOpenAction, GlobalQuickOpenAction.ID, GlobalQuickOpenAction.LABEL, { primary: KeyMod.CtrlCmd | KeyCode.KEY_P, secondary: [KeyMod.CtrlCmd | KeyCode.KEY_E], mac: { primary: KeyMod.CtrlCmd | KeyCode.KEY_P, secondary: null } }), 'Go to File...'); registry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenNavigateNextAction, QuickOpenNavigateNextAction.ID, QuickOpenNavigateNextAction.LABEL, navigateKeybinding(false), condition), 'Navigate Next in Quick Open'); -registry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenNavigatePreviousAction, QuickOpenNavigatePreviousAction.ID, QuickOpenNavigatePreviousAction.LABEL, navigateKeybinding(true), condition, KeybindingsRegistry.WEIGHT.workbenchContrib(50)), 'Navigate Previous in Quick Open'); \ No newline at end of file +registry.registerWorkbenchAction(new SyncActionDescriptor(QuickOpenNavigatePreviousAction, QuickOpenNavigatePreviousAction.ID, QuickOpenNavigatePreviousAction.LABEL, navigateKeybinding(true), condition, KeybindingsRegistry.WEIGHT.workbenchContrib(50)), 'Navigate Previous in Quick Open'); +registry.registerWorkbenchAction(new SyncActionDescriptor(RemoveFromEditorHistoryAction, RemoveFromEditorHistoryAction.ID, RemoveFromEditorHistoryAction.LABEL), 'Remove From Editor History'); \ No newline at end of file diff --git a/src/vs/workbench/services/history/browser/history.ts b/src/vs/workbench/services/history/browser/history.ts index 2b08fa7a5536cff0fe3b0661d2128aa867082630..84ac57a6ad1de89688b5a08c5527073c7e7be0d0 100644 --- a/src/vs/workbench/services/history/browser/history.ts +++ b/src/vs/workbench/services/history/browser/history.ts @@ -406,13 +406,13 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic } } - public remove(input: IEditorInput): void { + public remove(input: IEditorInput | IResourceInput): void { this.removeFromHistory(input); this.removeFromStack(input); this.removeFromRecentlyClosedFiles(input); } - private removeFromHistory(input: IEditorInput, index?: number): void { + private removeFromHistory(input: IEditorInput | IResourceInput, index?: number): void { this.ensureLoaded(); if (typeof index !== 'number') { @@ -424,7 +424,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic } } - private indexOf(input: IEditorInput): number { + private indexOf(input: IEditorInput | IResourceInput): number { for (let i = 0; i < this.history.length; i++) { const entry = this.history[i]; if (this.matches(input, entry)) { @@ -567,7 +567,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic return s1.startLineNumber === s2.startLineNumber; // we consider the history entry same if we are on the same line } - private removeFromStack(input: IEditorInput): void { + private removeFromStack(input: IEditorInput | IResourceInput): void { this.stack.forEach((e, i) => { if (this.matches(input, e.input)) { this.stack.splice(i, 1); @@ -578,7 +578,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic }); } - private removeFromRecentlyClosedFiles(input: IEditorInput): void { + private removeFromRecentlyClosedFiles(input: IEditorInput | IResourceInput): void { this.recentlyClosedFiles.forEach((e, i) => { if (this.matchesFile(e.resource, input)) { this.recentlyClosedFiles.splice(i, 1); @@ -598,18 +598,35 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic return group.getEditors().some(e => this.matchesFile(resource, e)); } - private matches(typedInput: IEditorInput, input: IEditorInput | IResourceInput): boolean { - if (input instanceof EditorInput) { - return input.matches(typedInput); + private matches(inputA: IEditorInput | IResourceInput, inputB: IEditorInput | IResourceInput): boolean { + if (inputA instanceof EditorInput && inputB instanceof EditorInput) { + return inputA.matches(inputB); + } + + if (inputA instanceof EditorInput) { + return this.matchesFile((inputB as IResourceInput).resource, inputA); } - return this.matchesFile((input as IResourceInput).resource, typedInput); + if (inputB instanceof EditorInput) { + return this.matchesFile((inputA as IResourceInput).resource, inputB); + } + + const resourceInputA = inputA as IResourceInput; + const resourceInputB = inputB as IResourceInput; + + return resourceInputA && resourceInputB && resourceInputA.resource.toString() === resourceInputB.resource.toString(); } - private matchesFile(resource: URI, input: IEditorInput): boolean { - const fileInput = asFileEditorInput(input); + private matchesFile(resource: URI, input: IEditorInput | IResourceInput): boolean { + if (input instanceof EditorInput) { + const fileInput = asFileEditorInput(input); + + return fileInput && fileInput.getResource().toString() === resource.toString(); + } + + const resourceInput = input as IResourceInput; - return fileInput && fileInput.getResource().toString() === resource.toString(); + return resourceInput && resourceInput.resource.toString() === resource.toString(); } public getHistory(): (IEditorInput | IResourceInput)[] { diff --git a/src/vs/workbench/services/history/common/history.ts b/src/vs/workbench/services/history/common/history.ts index 7b4ae3f07ea8cdb6444b5e24b26d884704e80f4e..d76384abd5c99470e3d9074dfaeb43b23f84a03e 100644 --- a/src/vs/workbench/services/history/common/history.ts +++ b/src/vs/workbench/services/history/common/history.ts @@ -36,7 +36,7 @@ export interface IHistoryService { /** * Removes an entry from history. */ - remove(input: IEditorInput): void; + remove(input: IEditorInput | IResourceInput): void; /** * Clears all history.