diff --git a/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts b/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts index 7a4cbcf5a2d2fd2d3d1367b4efa358d0ff65b874..05d571eae275f7961a8d07651d111c241b602fd2 100644 --- a/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts +++ b/src/vs/base/parts/quickopen/browser/quickOpenWidget.ts @@ -680,11 +680,19 @@ export class QuickOpenWidget implements IModelProvider { } } - public refresh(input: IModel, autoFocus: IAutoFocus): void { + public refresh(input?: IModel, autoFocus?: IAutoFocus): void { if (!this.isVisible()) { return; } + if (!input) { + input = this.tree.getInput(); + } + + if (!input) { + return; + } + // Apply height & Refresh this.treeContainer.style({ height: `${this.getHeight(input)}px` }); this.tree.refresh().done(() => { @@ -693,9 +701,11 @@ export class QuickOpenWidget implements IModelProvider { this.tree.layout(); // Handle auto focus - let doAutoFocus = autoFocus && input && input.entries.some(e => this.isElementVisible(input, e)); - if (doAutoFocus) { - this.autoFocus(input, autoFocus); + if (autoFocus) { + let doAutoFocus = autoFocus && input && input.entries.some(e => this.isElementVisible(input, e)); + if (doAutoFocus) { + this.autoFocus(input, autoFocus); + } } }, errors.onUnexpectedError); } diff --git a/src/vs/platform/quickOpen/common/quickOpen.ts b/src/vs/platform/quickOpen/common/quickOpen.ts index 39f2d8e4a3479264d2d6455bd586fe01a847e8ba..2216f21d52872fa488a18e94d14b0b0d6c33cb4b 100644 --- a/src/vs/platform/quickOpen/common/quickOpen.ts +++ b/src/vs/platform/quickOpen/common/quickOpen.ts @@ -18,6 +18,10 @@ export interface IFilePickOpenEntry extends IPickOpenEntry { fileKind?: FileKind; } +export interface IPickOpenAction extends IAction { + run(item: IPickOpenItem): TPromise; +} + export interface IPickOpenEntry { id?: string; label: string; @@ -29,6 +33,11 @@ export interface IPickOpenEntry { action?: IAction; } +export interface IPickOpenItem { + remove: () => void; + getResource: () => uri; +} + export interface ISeparator { border?: boolean; label?: string; diff --git a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts index c819a7e4abb6bb38dfab83eeb1c4e791b063318f..5aaae0803a1c3ba9f2fd2b42329cfd32de037c07 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickOpenController.ts @@ -39,7 +39,7 @@ import { KeyMod } from 'vs/base/common/keyCodes'; import { QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry, IWorkbenchQuickOpenConfiguration } from 'vs/workbench/browser/quickopen'; import errors = require('vs/base/common/errors'); import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { IPickOpenEntry, IFilePickOpenEntry, IInputOptions, IQuickOpenService, IPickOptions, IShowOptions } from 'vs/platform/quickOpen/common/quickOpen'; +import { IPickOpenEntry, IFilePickOpenEntry, IInputOptions, IQuickOpenService, IPickOptions, IShowOptions, IPickOpenItem } from 'vs/platform/quickOpen/common/quickOpen'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IMessageService, Severity } from 'vs/platform/message/common/message'; @@ -359,9 +359,9 @@ export class QuickOpenController extends Component implements IQuickOpenService // Model const model = new QuickOpenModel([], new PickOpenActionProvider()); - const entries = picks.map((e, index) => this.instantiationService.createInstance(PickOpenEntry, e, index, () => progress(e))); + const entries = picks.map((e, index) => this.instantiationService.createInstance(PickOpenEntry, e, index, () => progress(e), () => this.pickOpenWidget.refresh())); if (picks.length === 0) { - entries.push(this.instantiationService.createInstance(PickOpenEntry, { label: nls.localize('emptyPicks', "There are no entries to pick from") }, 0, null)); + entries.push(this.instantiationService.createInstance(PickOpenEntry, { label: nls.localize('emptyPicks', "There are no entries to pick from") }, 0, null, null)); } model.setEntries(entries); @@ -1060,7 +1060,7 @@ class PlaceholderQuickOpenEntry extends QuickOpenEntryGroup { } } -class PickOpenEntry extends PlaceholderQuickOpenEntry { +class PickOpenEntry extends PlaceholderQuickOpenEntry implements IPickOpenItem { private _shouldRunWithContext: IEntryRunContext; private description: string; private detail: string; @@ -1070,11 +1070,13 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry { private resource: URI; private fileKind: FileKind; private _action: IAction; + private removed: boolean; constructor( item: IPickOpenEntry, private _index: number, private onPreview: () => void, + private onRemove: () => void, @IModeService private modeService: IModeService, @IModelService private modelService: IModelService ) { @@ -1092,6 +1094,17 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry { this.fileKind = fileItem.fileKind; } + public remove(): void { + super.setHidden(true); + this.removed = true; + + this.onRemove(); + } + + public isHidden(): boolean { + return this.removed || super.isHidden(); + } + public get action(): IAction { return this._action; } @@ -1130,6 +1143,10 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry { return this.alwaysShow; } + public getResource(): URI { + return this.resource; + } + public run(mode: Mode, context: IEntryRunContext): boolean { if (mode === Mode.OPEN) { this._shouldRunWithContext = context; diff --git a/src/vs/workbench/electron-browser/actions.ts b/src/vs/workbench/electron-browser/actions.ts index c5bf8d3711c3bd51c175a0f63638ca73f127879e..75dd0b3c664831112bb95632595212f366f369bb 100644 --- a/src/vs/workbench/electron-browser/actions.ts +++ b/src/vs/workbench/electron-browser/actions.ts @@ -26,7 +26,7 @@ import { IExtensionManagementService, LocalExtensionType, ILocalExtension } from import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration'; import paths = require('vs/base/common/paths'); import { isMacintosh, isLinux } from 'vs/base/common/platform'; -import { IQuickOpenService, IFilePickOpenEntry, ISeparator } from 'vs/platform/quickOpen/common/quickOpen'; +import { IQuickOpenService, IFilePickOpenEntry, ISeparator, IPickOpenAction, IPickOpenItem } from 'vs/platform/quickOpen/common/quickOpen'; import { KeyMod } from 'vs/base/common/keyCodes'; import * as browser from 'vs/base/browser/browser'; import { IIntegrityService } from 'vs/platform/integrity/common/integrity'; @@ -735,7 +735,7 @@ export abstract class BaseOpenRecentAction extends Action { } } -class RemoveFromRecentlyOpened extends Action { +class RemoveFromRecentlyOpened extends Action implements IPickOpenAction { public static ID = 'workbench.action.removeFromRecentlyOpened'; public static LABEL = nls.localize('remove', "Remove"); @@ -750,10 +750,9 @@ class RemoveFromRecentlyOpened extends Action { this.class = 'action-remove-from-recently-opened'; } - public run({ resource }: { resource: URI }): TPromise { - return this.windowsService.removeFromRecentlyOpened([resource.fsPath]).then(() => { - const reopenAction = this.instantiationService.createInstance(OpenRecentAction, OpenRecentAction.ID, OpenRecentAction.LABEL); - reopenAction.run().then(() => reopenAction.dispose()); + public run(item: IPickOpenItem): TPromise { + return this.windowsService.removeFromRecentlyOpened([item.getResource().fsPath]).then(() => { + item.remove(); return true; });