提交 5b20fcb6 编写于 作者: B Benjamin Pasero

better implementation of "remove from history" action

上级 126caa4c
......@@ -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++) {
......
......@@ -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<any> {
// 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';
......
......@@ -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<any> {
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 <IHistoryPickEntry>{
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
......@@ -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 = <IWorkbenchActionRegistry>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
......@@ -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)[] {
......
......@@ -36,7 +36,7 @@ export interface IHistoryService {
/**
* Removes an entry from history.
*/
remove(input: IEditorInput): void;
remove(input: IEditorInput | IResourceInput): void;
/**
* Clears all history.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册