提交 93a1637b 编写于 作者: B Benjamin Pasero

picker: allow to remove an item easily

上级 3c997dc3
......@@ -680,11 +680,19 @@ export class QuickOpenWidget implements IModelProvider {
}
}
public refresh(input: IModel<any>, autoFocus: IAutoFocus): void {
public refresh(input?: IModel<any>, 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);
}
......
......@@ -18,6 +18,10 @@ export interface IFilePickOpenEntry extends IPickOpenEntry {
fileKind?: FileKind;
}
export interface IPickOpenAction extends IAction {
run(item: IPickOpenItem): TPromise<any>;
}
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;
......
......@@ -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;
......
......@@ -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<boolean> {
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<boolean> {
return this.windowsService.removeFromRecentlyOpened([item.getResource().fsPath]).then(() => {
item.remove();
return true;
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册