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

picker: allow to remove an item easily

上级 3c997dc3
...@@ -680,11 +680,19 @@ export class QuickOpenWidget implements IModelProvider { ...@@ -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()) { if (!this.isVisible()) {
return; return;
} }
if (!input) {
input = this.tree.getInput();
}
if (!input) {
return;
}
// Apply height & Refresh // Apply height & Refresh
this.treeContainer.style({ height: `${this.getHeight(input)}px` }); this.treeContainer.style({ height: `${this.getHeight(input)}px` });
this.tree.refresh().done(() => { this.tree.refresh().done(() => {
...@@ -693,9 +701,11 @@ export class QuickOpenWidget implements IModelProvider { ...@@ -693,9 +701,11 @@ export class QuickOpenWidget implements IModelProvider {
this.tree.layout(); this.tree.layout();
// Handle auto focus // Handle auto focus
let doAutoFocus = autoFocus && input && input.entries.some(e => this.isElementVisible(input, e)); if (autoFocus) {
if (doAutoFocus) { let doAutoFocus = autoFocus && input && input.entries.some(e => this.isElementVisible(input, e));
this.autoFocus(input, autoFocus); if (doAutoFocus) {
this.autoFocus(input, autoFocus);
}
} }
}, errors.onUnexpectedError); }, errors.onUnexpectedError);
} }
......
...@@ -18,6 +18,10 @@ export interface IFilePickOpenEntry extends IPickOpenEntry { ...@@ -18,6 +18,10 @@ export interface IFilePickOpenEntry extends IPickOpenEntry {
fileKind?: FileKind; fileKind?: FileKind;
} }
export interface IPickOpenAction extends IAction {
run(item: IPickOpenItem): TPromise<any>;
}
export interface IPickOpenEntry { export interface IPickOpenEntry {
id?: string; id?: string;
label: string; label: string;
...@@ -29,6 +33,11 @@ export interface IPickOpenEntry { ...@@ -29,6 +33,11 @@ export interface IPickOpenEntry {
action?: IAction; action?: IAction;
} }
export interface IPickOpenItem {
remove: () => void;
getResource: () => uri;
}
export interface ISeparator { export interface ISeparator {
border?: boolean; border?: boolean;
label?: string; label?: string;
......
...@@ -39,7 +39,7 @@ import { KeyMod } from 'vs/base/common/keyCodes'; ...@@ -39,7 +39,7 @@ import { KeyMod } from 'vs/base/common/keyCodes';
import { QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry, IWorkbenchQuickOpenConfiguration } from 'vs/workbench/browser/quickopen'; import { QuickOpenHandler, QuickOpenHandlerDescriptor, IQuickOpenRegistry, Extensions, EditorQuickOpenEntry, IWorkbenchQuickOpenConfiguration } from 'vs/workbench/browser/quickopen';
import errors = require('vs/base/common/errors'); import errors = require('vs/base/common/errors');
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; 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 { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IMessageService, Severity } from 'vs/platform/message/common/message'; import { IMessageService, Severity } from 'vs/platform/message/common/message';
...@@ -359,9 +359,9 @@ export class QuickOpenController extends Component implements IQuickOpenService ...@@ -359,9 +359,9 @@ export class QuickOpenController extends Component implements IQuickOpenService
// Model // Model
const model = new QuickOpenModel([], new PickOpenActionProvider()); 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) { 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); model.setEntries(entries);
...@@ -1060,7 +1060,7 @@ class PlaceholderQuickOpenEntry extends QuickOpenEntryGroup { ...@@ -1060,7 +1060,7 @@ class PlaceholderQuickOpenEntry extends QuickOpenEntryGroup {
} }
} }
class PickOpenEntry extends PlaceholderQuickOpenEntry { class PickOpenEntry extends PlaceholderQuickOpenEntry implements IPickOpenItem {
private _shouldRunWithContext: IEntryRunContext; private _shouldRunWithContext: IEntryRunContext;
private description: string; private description: string;
private detail: string; private detail: string;
...@@ -1070,11 +1070,13 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry { ...@@ -1070,11 +1070,13 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry {
private resource: URI; private resource: URI;
private fileKind: FileKind; private fileKind: FileKind;
private _action: IAction; private _action: IAction;
private removed: boolean;
constructor( constructor(
item: IPickOpenEntry, item: IPickOpenEntry,
private _index: number, private _index: number,
private onPreview: () => void, private onPreview: () => void,
private onRemove: () => void,
@IModeService private modeService: IModeService, @IModeService private modeService: IModeService,
@IModelService private modelService: IModelService @IModelService private modelService: IModelService
) { ) {
...@@ -1092,6 +1094,17 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry { ...@@ -1092,6 +1094,17 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry {
this.fileKind = fileItem.fileKind; 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 { public get action(): IAction {
return this._action; return this._action;
} }
...@@ -1130,6 +1143,10 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry { ...@@ -1130,6 +1143,10 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry {
return this.alwaysShow; return this.alwaysShow;
} }
public getResource(): URI {
return this.resource;
}
public run(mode: Mode, context: IEntryRunContext): boolean { public run(mode: Mode, context: IEntryRunContext): boolean {
if (mode === Mode.OPEN) { if (mode === Mode.OPEN) {
this._shouldRunWithContext = context; this._shouldRunWithContext = context;
......
...@@ -26,7 +26,7 @@ import { IExtensionManagementService, LocalExtensionType, ILocalExtension } from ...@@ -26,7 +26,7 @@ import { IExtensionManagementService, LocalExtensionType, ILocalExtension } from
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration'; import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import paths = require('vs/base/common/paths'); import paths = require('vs/base/common/paths');
import { isMacintosh, isLinux } from 'vs/base/common/platform'; 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 { KeyMod } from 'vs/base/common/keyCodes';
import * as browser from 'vs/base/browser/browser'; import * as browser from 'vs/base/browser/browser';
import { IIntegrityService } from 'vs/platform/integrity/common/integrity'; import { IIntegrityService } from 'vs/platform/integrity/common/integrity';
...@@ -735,7 +735,7 @@ export abstract class BaseOpenRecentAction extends Action { ...@@ -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 ID = 'workbench.action.removeFromRecentlyOpened';
public static LABEL = nls.localize('remove', "Remove"); public static LABEL = nls.localize('remove', "Remove");
...@@ -750,10 +750,9 @@ class RemoveFromRecentlyOpened extends Action { ...@@ -750,10 +750,9 @@ class RemoveFromRecentlyOpened extends Action {
this.class = 'action-remove-from-recently-opened'; this.class = 'action-remove-from-recently-opened';
} }
public run({ resource }: { resource: URI }): TPromise<boolean> { public run(item: IPickOpenItem): TPromise<boolean> {
return this.windowsService.removeFromRecentlyOpened([resource.fsPath]).then(() => { return this.windowsService.removeFromRecentlyOpened([item.getResource().fsPath]).then(() => {
const reopenAction = this.instantiationService.createInstance(OpenRecentAction, OpenRecentAction.ID, OpenRecentAction.LABEL); item.remove();
reopenAction.run().then(() => reopenAction.dispose());
return true; return true;
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册