提交 7180bb92 编写于 作者: C Christof Marti

Use QuickInput (#29096)

上级 5d8c7829
...@@ -9,7 +9,7 @@ import 'vs/css!./media/actions'; ...@@ -9,7 +9,7 @@ import 'vs/css!./media/actions';
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { Action, IAction } from 'vs/base/common/actions'; import { Action } from 'vs/base/common/actions';
import { IWindowService, IWindowsService, MenuBarVisibility } from 'vs/platform/windows/common/windows'; import { IWindowService, IWindowsService, MenuBarVisibility } from 'vs/platform/windows/common/windows';
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import product from 'vs/platform/node/product'; import product from 'vs/platform/node/product';
...@@ -20,10 +20,8 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' ...@@ -20,10 +20,8 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration'; import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { isMacintosh, isLinux, language } from 'vs/base/common/platform'; import { isMacintosh, isLinux, language } from 'vs/base/common/platform';
import { IQuickOpenService, IFilePickOpenEntry, ISeparator, IPickOpenAction, IPickOpenItem } from 'vs/platform/quickOpen/common/quickOpen';
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';
import { IEntryRunContext } from 'vs/base/parts/quickopen/common/quickOpen';
import { ITimerService, IStartupMetrics } from 'vs/workbench/services/timer/common/timerService'; import { ITimerService, IStartupMetrics } from 'vs/workbench/services/timer/common/timerService';
import { IEditorGroupsService, GroupDirection, GroupLocation, IFindGroupScope } from 'vs/workbench/services/group/common/editorGroupsService'; import { IEditorGroupsService, GroupDirection, GroupLocation, IFindGroupScope } from 'vs/workbench/services/group/common/editorGroupsService';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService'; import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
...@@ -37,7 +35,6 @@ import { IViewlet } from 'vs/workbench/common/viewlet'; ...@@ -37,7 +35,6 @@ import { IViewlet } from 'vs/workbench/common/viewlet';
import { IPanel } from 'vs/workbench/common/panel'; import { IPanel } from 'vs/workbench/common/panel';
import { IWorkspaceIdentifier, getWorkspaceLabel, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces'; import { IWorkspaceIdentifier, getWorkspaceLabel, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { FileKind } from 'vs/platform/files/common/files'; import { FileKind } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IExtensionService, ActivationTimes } from 'vs/workbench/services/extensions/common/extensions'; import { IExtensionService, ActivationTimes } from 'vs/workbench/services/extensions/common/extensions';
import { getEntries } from 'vs/base/common/performance'; import { getEntries } from 'vs/base/common/performance';
import { IssueType } from 'vs/platform/issue/common/issue'; import { IssueType } from 'vs/platform/issue/common/issue';
...@@ -53,7 +50,7 @@ import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay'; ...@@ -53,7 +50,7 @@ import { IUriDisplayService } from 'vs/platform/uriDisplay/common/uriDisplay';
import { dirname } from 'vs/base/common/resources'; import { dirname } from 'vs/base/common/resources';
import { IModelService } from 'vs/editor/common/services/modelService'; import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService'; import { IModeService } from 'vs/editor/common/services/modeService';
import { IQuickInputService, IQuickPickItem, IQuickInputButton } from 'vs/platform/quickinput/common/quickInput'; import { IQuickInputService, IQuickPickItem, IQuickInputButton, IQuickPickSeparator, IKeyMods } from 'vs/platform/quickinput/common/quickInput';
import { getIconClasses } from 'vs/workbench/browser/labels'; import { getIconClasses } from 'vs/workbench/browser/labels';
// --- actions // --- actions
...@@ -654,7 +651,6 @@ export class SwitchWindow extends BaseSwitchWindow { ...@@ -654,7 +651,6 @@ export class SwitchWindow extends BaseSwitchWindow {
@IKeybindingService keybindingService: IKeybindingService, @IKeybindingService keybindingService: IKeybindingService,
@IModelService modelService: IModelService, @IModelService modelService: IModelService,
@IModeService modeService: IModeService, @IModeService modeService: IModeService,
@IInstantiationService instantiationService: IInstantiationService
) { ) {
super(id, label, windowsService, windowService, quickInputService, keybindingService, modelService, modeService); super(id, label, windowsService, windowService, quickInputService, keybindingService, modelService, modeService);
} }
...@@ -678,7 +674,6 @@ export class QuickSwitchWindow extends BaseSwitchWindow { ...@@ -678,7 +674,6 @@ export class QuickSwitchWindow extends BaseSwitchWindow {
@IKeybindingService keybindingService: IKeybindingService, @IKeybindingService keybindingService: IKeybindingService,
@IModelService modelService: IModelService, @IModelService modelService: IModelService,
@IModeService modeService: IModeService, @IModeService modeService: IModeService,
@IInstantiationService instantiationService: IInstantiationService
) { ) {
super(id, label, windowsService, windowService, quickInputService, keybindingService, modelService, modeService); super(id, label, windowsService, windowService, quickInputService, keybindingService, modelService, modeService);
} }
...@@ -692,16 +687,23 @@ export const inRecentFilesPickerContextKey = 'inRecentFilesPicker'; ...@@ -692,16 +687,23 @@ export const inRecentFilesPickerContextKey = 'inRecentFilesPicker';
export abstract class BaseOpenRecentAction extends Action { export abstract class BaseOpenRecentAction extends Action {
private removeFromRecentlyOpened: IQuickInputButton = {
iconClass: 'action-remove-from-recently-opened',
tooltip: nls.localize('remove', "Remove from Recently Opened")
};
constructor( constructor(
id: string, id: string,
label: string, label: string,
private windowService: IWindowService, private windowService: IWindowService,
private quickOpenService: IQuickOpenService, private windowsService: IWindowsService,
private quickInputService: IQuickInputService,
private contextService: IWorkspaceContextService, private contextService: IWorkspaceContextService,
private environmentService: IEnvironmentService, private environmentService: IEnvironmentService,
private uriDisplayService: IUriDisplayService, private uriDisplayService: IUriDisplayService,
private keybindingService: IKeybindingService, private keybindingService: IKeybindingService,
private instantiationService: IInstantiationService private modelService: IModelService,
private modeService: IModeService,
) { ) {
super(id, label); super(id, label);
} }
...@@ -715,7 +717,7 @@ export abstract class BaseOpenRecentAction extends Action { ...@@ -715,7 +717,7 @@ export abstract class BaseOpenRecentAction extends Action {
private openRecent(recentWorkspaces: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)[], recentFiles: string[]): void { private openRecent(recentWorkspaces: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier)[], recentFiles: string[]): void {
function toPick(workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | string, separator: ISeparator, fileKind: FileKind, environmentService: IEnvironmentService, uriDisplayService: IUriDisplayService, action: IAction): IFilePickOpenEntry { const toPick = (workspace: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | string, fileKind: FileKind, environmentService: IEnvironmentService, uriDisplayService: IUriDisplayService, buttons: IQuickInputButton[]) => {
let resource: URI; let resource: URI;
let label: string; let label: string;
let description: string; let description: string;
...@@ -734,63 +736,51 @@ export abstract class BaseOpenRecentAction extends Action { ...@@ -734,63 +736,51 @@ export abstract class BaseOpenRecentAction extends Action {
} }
return { return {
resource, iconClasses: getIconClasses(this.modelService, this.modeService, resource, fileKind),
fileKind,
label, label,
description, description,
separator, buttons,
run: context => { workspace,
setTimeout(() => { resource,
// Bug: somehow when not running this code in a timeout, it is not possible to use this picker fileKind,
// with quick navigate keys (not able to trigger quick navigate once running it once).
runPick(resource, fileKind === FileKind.FILE, context);
});
},
action
}; };
} };
const runPick = (resource: URI, isFile: boolean, context: IEntryRunContext) => { const runPick = (resource: URI, isFile: boolean, keyMods: IKeyMods) => {
const forceNewWindow = context.keymods.ctrlCmd; const forceNewWindow = keyMods.ctrlCmd;
this.windowService.openWindow([resource], { forceNewWindow, forceOpenWorkspaceAsFile: isFile }); return this.windowService.openWindow([resource], { forceNewWindow, forceOpenWorkspaceAsFile: isFile });
}; };
const workspacePicks: IFilePickOpenEntry[] = recentWorkspaces.map((workspace, index) => toPick(workspace, index === 0 ? { label: nls.localize('workspaces', "workspaces") } : void 0, isSingleFolderWorkspaceIdentifier(workspace) ? FileKind.FOLDER : FileKind.ROOT_FOLDER, this.environmentService, this.uriDisplayService, !this.isQuickNavigate() ? this.instantiationService.createInstance(RemoveFromRecentlyOpened, workspace) : void 0)); const workspacePicks = recentWorkspaces.map(workspace => toPick(workspace, isSingleFolderWorkspaceIdentifier(workspace) ? FileKind.FOLDER : FileKind.ROOT_FOLDER, this.environmentService, this.uriDisplayService, !this.isQuickNavigate() ? [this.removeFromRecentlyOpened] : void 0));
const filePicks: IFilePickOpenEntry[] = recentFiles.map((p, index) => toPick(p, index === 0 ? { label: nls.localize('files', "files"), border: true } : void 0, FileKind.FILE, this.environmentService, this.uriDisplayService, !this.isQuickNavigate() ? this.instantiationService.createInstance(RemoveFromRecentlyOpened, p) : void 0)); const filePicks = recentFiles.map(p => toPick(p, FileKind.FILE, this.environmentService, this.uriDisplayService, !this.isQuickNavigate() ? [this.removeFromRecentlyOpened] : void 0));
// focus second entry if the first recent workspace is the current workspace // focus second entry if the first recent workspace is the current workspace
let autoFocusSecondEntry: boolean = recentWorkspaces[0] && this.contextService.isCurrentWorkspace(recentWorkspaces[0]); let autoFocusSecondEntry: boolean = recentWorkspaces[0] && this.contextService.isCurrentWorkspace(recentWorkspaces[0]);
this.quickOpenService.pick([...workspacePicks, ...filePicks], { let keyMods: IKeyMods;
const workspaceSeparator: IQuickPickSeparator = { type: 'separator', label: nls.localize('workspaces', "workspaces") };
const fileSeparator: IQuickPickSeparator = { type: 'separator', label: nls.localize('files', "files"), border: true };
const picks = [workspaceSeparator, ...workspacePicks, fileSeparator, ...filePicks];
this.quickInputService.pick(picks, {
contextKey: inRecentFilesPickerContextKey, contextKey: inRecentFilesPickerContextKey,
autoFocus: { autoFocusFirstEntry: !autoFocusSecondEntry, autoFocusSecondEntry: autoFocusSecondEntry }, activeItem: [...workspacePicks, ...filePicks][autoFocusSecondEntry ? 1 : 0],
placeHolder: isMacintosh ? nls.localize('openRecentPlaceHolderMac', "Select to open (hold Cmd-key to open in new window)") : nls.localize('openRecentPlaceHolder', "Select to open (hold Ctrl-key to open in new window)"), placeHolder: isMacintosh ? nls.localize('openRecentPlaceHolderMac', "Select to open (hold Cmd-key to open in new window)") : nls.localize('openRecentPlaceHolder', "Select to open (hold Ctrl-key to open in new window)"),
matchOnDescription: true, matchOnDescription: true,
quickNavigateConfiguration: this.isQuickNavigate() ? { keybindings: this.keybindingService.lookupKeybindings(this.id) } : void 0 onKeyMods: mods => keyMods = mods,
}).done(null, errors.onUnexpectedError); quickNavigate: this.isQuickNavigate() ? { keybindings: this.keybindingService.lookupKeybindings(this.id) } : void 0,
} onDidTriggerItemButton: context => {
} this.windowsService.removeFromRecentlyOpened([context.item.workspace]).then(() => {
context.removeItem();
class RemoveFromRecentlyOpened extends Action implements IPickOpenAction { }).then(null, errors.onUnexpectedError);
}
static readonly ID = 'workbench.action.removeFromRecentlyOpened'; })
static readonly LABEL = nls.localize('remove', "Remove from Recently Opened"); .then(pick => {
if (pick) {
constructor( return runPick(pick.resource, pick.fileKind === FileKind.FILE, keyMods);
private path: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | string), }
@IWindowsService private windowsService: IWindowsService return null;
) { })
super(RemoveFromRecentlyOpened.ID, RemoveFromRecentlyOpened.LABEL); .done(null, errors.onUnexpectedError);
this.class = 'action-remove-from-recently-opened';
}
run(item: IPickOpenItem): TPromise<boolean> {
return this.windowsService.removeFromRecentlyOpened([this.path]).then(() => {
item.remove();
return true;
});
} }
} }
...@@ -803,14 +793,16 @@ export class OpenRecentAction extends BaseOpenRecentAction { ...@@ -803,14 +793,16 @@ export class OpenRecentAction extends BaseOpenRecentAction {
id: string, id: string,
label: string, label: string,
@IWindowService windowService: IWindowService, @IWindowService windowService: IWindowService,
@IQuickOpenService quickOpenService: IQuickOpenService, @IWindowsService windowsService: IWindowsService,
@IQuickInputService quickInputService: IQuickInputService,
@IWorkspaceContextService contextService: IWorkspaceContextService, @IWorkspaceContextService contextService: IWorkspaceContextService,
@IEnvironmentService environmentService: IEnvironmentService, @IEnvironmentService environmentService: IEnvironmentService,
@IKeybindingService keybindingService: IKeybindingService, @IKeybindingService keybindingService: IKeybindingService,
@IInstantiationService instantiationService: IInstantiationService, @IModelService modelService: IModelService,
@IModeService modeService: IModeService,
@IUriDisplayService uriDisplayService: IUriDisplayService @IUriDisplayService uriDisplayService: IUriDisplayService
) { ) {
super(id, label, windowService, quickOpenService, contextService, environmentService, uriDisplayService, keybindingService, instantiationService); super(id, label, windowService, windowsService, quickInputService, contextService, environmentService, uriDisplayService, keybindingService, modelService, modeService);
} }
protected isQuickNavigate(): boolean { protected isQuickNavigate(): boolean {
...@@ -827,14 +819,16 @@ export class QuickOpenRecentAction extends BaseOpenRecentAction { ...@@ -827,14 +819,16 @@ export class QuickOpenRecentAction extends BaseOpenRecentAction {
id: string, id: string,
label: string, label: string,
@IWindowService windowService: IWindowService, @IWindowService windowService: IWindowService,
@IQuickOpenService quickOpenService: IQuickOpenService, @IWindowsService windowsService: IWindowsService,
@IQuickInputService quickInputService: IQuickInputService,
@IWorkspaceContextService contextService: IWorkspaceContextService, @IWorkspaceContextService contextService: IWorkspaceContextService,
@IEnvironmentService environmentService: IEnvironmentService, @IEnvironmentService environmentService: IEnvironmentService,
@IKeybindingService keybindingService: IKeybindingService, @IKeybindingService keybindingService: IKeybindingService,
@IInstantiationService instantiationService: IInstantiationService, @IModelService modelService: IModelService,
@IModeService modeService: IModeService,
@IUriDisplayService uriDisplayService: IUriDisplayService @IUriDisplayService uriDisplayService: IUriDisplayService
) { ) {
super(id, label, windowService, quickOpenService, contextService, environmentService, uriDisplayService, keybindingService, instantiationService); super(id, label, windowService, windowsService, quickInputService, contextService, environmentService, uriDisplayService, keybindingService, modelService, modeService);
} }
protected isQuickNavigate(): boolean { protected isQuickNavigate(): boolean {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册