提交 dc1746e7 编写于 作者: R rebornix

File: reopen with...

上级 8b46fd06
...@@ -48,6 +48,7 @@ export abstract class BaseEditor extends Composite implements IEditorPane { ...@@ -48,6 +48,7 @@ export abstract class BaseEditor extends Composite implements IEditorPane {
get input(): EditorInput | undefined { return this._input; } get input(): EditorInput | undefined { return this._input; }
protected _options: EditorOptions | undefined; protected _options: EditorOptions | undefined;
get options(): EditorOptions | undefined { return this._options; }
private _group?: IEditorGroup; private _group?: IEditorGroup;
get group(): IEditorGroup | undefined { return this._group; } get group(): IEditorGroup | undefined { return this._group; }
......
...@@ -69,6 +69,11 @@ export interface IEditorPane extends IComposite { ...@@ -69,6 +69,11 @@ export interface IEditorPane extends IComposite {
*/ */
readonly input: IEditorInput | undefined; readonly input: IEditorInput | undefined;
/**
* The assigned options of the editor.
*/
readonly options: EditorOptions | undefined;
/** /**
* The assigned group this editor is showing in. * The assigned group this editor is showing in.
*/ */
......
...@@ -343,8 +343,10 @@ export class CustomEditorContribution extends Disposable implements IWorkbenchCo ...@@ -343,8 +343,10 @@ export class CustomEditorContribution extends Disposable implements IWorkbenchCo
) { ) {
super(); super();
this._register(this.editorService.overrideOpenEditor((editor, options, group) => { this._register(this.editorService.overrideOpenEditor({
return this.onEditorOpening(editor, options, group); open: (editor, options, group) => {
return this.onEditorOpening(editor, options, group);
}
})); }));
this._register(this.editorService.onDidCloseEditor(({ editor }) => { this._register(this.editorService.onDidCloseEditor(({ editor }) => {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform'; import { Registry } from 'vs/platform/registry/common/platform';
import { ToggleAutoSaveAction, GlobalNewUntitledFileAction, FocusFilesExplorer, GlobalCompareResourcesAction, SaveAllAction, ShowActiveFileInExplorer, CollapseExplorerView, RefreshExplorerView, CompareWithClipboardAction, NEW_FILE_COMMAND_ID, NEW_FILE_LABEL, NEW_FOLDER_COMMAND_ID, NEW_FOLDER_LABEL, TRIGGER_RENAME_LABEL, MOVE_FILE_TO_TRASH_LABEL, COPY_FILE_LABEL, PASTE_FILE_LABEL, FileCopiedContext, renameHandler, moveFileToTrashHandler, copyFileHandler, pasteFileHandler, deleteFileHandler, cutFileHandler, DOWNLOAD_COMMAND_ID, openFilePreserveFocusHandler, DOWNLOAD_LABEL, ShowOpenedFileInNewWindow } from 'vs/workbench/contrib/files/browser/fileActions'; import { ToggleAutoSaveAction, GlobalNewUntitledFileAction, FocusFilesExplorer, GlobalCompareResourcesAction, SaveAllAction, ShowActiveFileInExplorer, CollapseExplorerView, RefreshExplorerView, CompareWithClipboardAction, NEW_FILE_COMMAND_ID, NEW_FILE_LABEL, NEW_FOLDER_COMMAND_ID, NEW_FOLDER_LABEL, TRIGGER_RENAME_LABEL, MOVE_FILE_TO_TRASH_LABEL, COPY_FILE_LABEL, PASTE_FILE_LABEL, FileCopiedContext, renameHandler, moveFileToTrashHandler, copyFileHandler, pasteFileHandler, deleteFileHandler, cutFileHandler, DOWNLOAD_COMMAND_ID, openFilePreserveFocusHandler, DOWNLOAD_LABEL, ShowOpenedFileInNewWindow, ReopenResourcesAction } from 'vs/workbench/contrib/files/browser/fileActions';
import { revertLocalChangesCommand, acceptLocalChangesCommand, CONFLICT_RESOLUTION_CONTEXT } from 'vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler'; import { revertLocalChangesCommand, acceptLocalChangesCommand, CONFLICT_RESOLUTION_CONTEXT } from 'vs/workbench/contrib/files/browser/editors/textFileSaveErrorHandler';
import { SyncActionDescriptor, MenuId, MenuRegistry, ILocalizedString } from 'vs/platform/actions/common/actions'; import { SyncActionDescriptor, MenuId, MenuRegistry, ILocalizedString } from 'vs/platform/actions/common/actions';
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions'; import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
...@@ -36,6 +36,7 @@ const category = { value: nls.localize('filesCategory', "File"), original: 'File ...@@ -36,6 +36,7 @@ const category = { value: nls.localize('filesCategory', "File"), original: 'File
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions); const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
registry.registerWorkbenchAction(SyncActionDescriptor.create(SaveAllAction, SaveAllAction.ID, SaveAllAction.LABEL, { primary: undefined, mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_S }, win: { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_S) } }), 'File: Save All', category.value); registry.registerWorkbenchAction(SyncActionDescriptor.create(SaveAllAction, SaveAllAction.ID, SaveAllAction.LABEL, { primary: undefined, mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KEY_S }, win: { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_S) } }), 'File: Save All', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.create(GlobalCompareResourcesAction, GlobalCompareResourcesAction.ID, GlobalCompareResourcesAction.LABEL), 'File: Compare Active File With...', category.value); registry.registerWorkbenchAction(SyncActionDescriptor.create(GlobalCompareResourcesAction, GlobalCompareResourcesAction.ID, GlobalCompareResourcesAction.LABEL), 'File: Compare Active File With...', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.create(ReopenResourcesAction, ReopenResourcesAction.ID, ReopenResourcesAction.LABEL), 'File: Reopen With...', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.create(FocusFilesExplorer, FocusFilesExplorer.ID, FocusFilesExplorer.LABEL), 'File: Focus on Files Explorer', category.value); registry.registerWorkbenchAction(SyncActionDescriptor.create(FocusFilesExplorer, FocusFilesExplorer.ID, FocusFilesExplorer.LABEL), 'File: Focus on Files Explorer', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.create(ShowActiveFileInExplorer, ShowActiveFileInExplorer.ID, ShowActiveFileInExplorer.LABEL), 'File: Reveal Active File in Side Bar', category.value); registry.registerWorkbenchAction(SyncActionDescriptor.create(ShowActiveFileInExplorer, ShowActiveFileInExplorer.ID, ShowActiveFileInExplorer.LABEL), 'File: Reveal Active File in Side Bar', category.value);
registry.registerWorkbenchAction(SyncActionDescriptor.create(CollapseExplorerView, CollapseExplorerView.ID, CollapseExplorerView.LABEL), 'File: Collapse Folders in Explorer', category.value); registry.registerWorkbenchAction(SyncActionDescriptor.create(CollapseExplorerView, CollapseExplorerView.ID, CollapseExplorerView.LABEL), 'File: Collapse Folders in Explorer', category.value);
......
...@@ -16,9 +16,9 @@ import { dispose, IDisposable } from 'vs/base/common/lifecycle'; ...@@ -16,9 +16,9 @@ import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { VIEWLET_ID, IExplorerService, IFilesConfiguration } from 'vs/workbench/contrib/files/common/files'; import { VIEWLET_ID, IExplorerService, IFilesConfiguration } from 'vs/workbench/contrib/files/common/files';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IFileService } from 'vs/platform/files/common/files'; import { IFileService } from 'vs/platform/files/common/files';
import { toResource, SideBySideEditor } from 'vs/workbench/common/editor'; import { toResource, SideBySideEditor, IEditorInput } from 'vs/workbench/common/editor';
import { ExplorerViewPaneContainer } from 'vs/workbench/contrib/files/browser/explorerViewlet'; import { ExplorerViewPaneContainer } from 'vs/workbench/contrib/files/browser/explorerViewlet';
import { IQuickInputService, ItemActivation } from 'vs/platform/quickinput/common/quickInput'; import { IQuickInputService, ItemActivation, IQuickPickItem } from 'vs/platform/quickinput/common/quickInput';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { ITextModel } from 'vs/editor/common/model'; import { ITextModel } from 'vs/editor/common/model';
...@@ -34,7 +34,7 @@ import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; ...@@ -34,7 +34,7 @@ import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { Schemas } from 'vs/base/common/network'; import { Schemas } from 'vs/base/common/network';
import { IDialogService, IConfirmationResult, getFileNamesMessage, IFileDialogService } from 'vs/platform/dialogs/common/dialogs'; import { IDialogService, IConfirmationResult, getFileNamesMessage, IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService, IOpenEditorOverrideHandler } from 'vs/workbench/services/editor/common/editorService';
import { Constants } from 'vs/base/common/uint'; import { Constants } from 'vs/base/common/uint';
import { CLOSE_EDITORS_AND_GROUP_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands'; import { CLOSE_EDITORS_AND_GROUP_COMMAND_ID } from 'vs/workbench/browser/parts/editor/editorCommands';
import { coalesce } from 'vs/base/common/arrays'; import { coalesce } from 'vs/base/common/arrays';
...@@ -47,6 +47,9 @@ import { IWorkingCopyService, IWorkingCopy } from 'vs/workbench/services/working ...@@ -47,6 +47,9 @@ import { IWorkingCopyService, IWorkingCopy } from 'vs/workbench/services/working
import { sequence, timeout } from 'vs/base/common/async'; import { sequence, timeout } from 'vs/base/common/async';
import { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService'; import { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService';
import { once } from 'vs/base/common/functional'; import { once } from 'vs/base/common/functional';
import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
export const NEW_FILE_COMMAND_ID = 'explorer.newFile'; export const NEW_FILE_COMMAND_ID = 'explorer.newFile';
export const NEW_FILE_LABEL = nls.localize('newFile', "New File"); export const NEW_FILE_LABEL = nls.localize('newFile', "New File");
...@@ -480,23 +483,27 @@ export class GlobalCompareResourcesAction extends Action { ...@@ -480,23 +483,27 @@ export class GlobalCompareResourcesAction extends Action {
if (activeResource) { if (activeResource) {
// Compare with next editor that opens // Compare with next editor that opens
const toDispose = this.editorService.overrideOpenEditor(editor => { const toDispose = this.editorService.overrideOpenEditor({
getEditorOverrides: (editor: IEditorInput, options: IEditorOptions | undefined, group: IEditorGroup | undefined) => {
// Only once! return [];
toDispose.dispose(); },
open: editor => {
// Only once!
toDispose.dispose();
// Open editor as diff
const resource = editor.resource;
if (resource) {
return {
override: this.editorService.openEditor({
leftResource: activeResource,
rightResource: resource
})
};
}
// Open editor as diff return undefined;
const resource = editor.resource;
if (resource) {
return {
override: this.editorService.openEditor({
leftResource: activeResource,
rightResource: resource
})
};
} }
return undefined;
}); });
once(this.quickInputService.onHide)((async () => { once(this.quickInputService.onHide)((async () => {
...@@ -512,6 +519,87 @@ export class GlobalCompareResourcesAction extends Action { ...@@ -512,6 +519,87 @@ export class GlobalCompareResourcesAction extends Action {
} }
} }
const builtinProviderDisplayName = nls.localize('builtinProviderDisplayName', "Built-in");
export class ReopenResourcesAction extends Action {
static readonly ID = 'workbench.files.action.reopenWithEditor';
static readonly LABEL = nls.localize('workbench.files.action.reopenWithEditor', "Reopen With...");
constructor(
id: string,
label: string,
@IQuickInputService private readonly quickInputService: IQuickInputService,
@IEditorService private readonly editorService: IEditorService,
) {
super(id, label);
}
async run(): Promise<void> {
const activeInput = this.editorService.activeEditor;
const activeEditorPane = this.editorService.activeEditorPane;
if (!activeEditorPane) {
return;
}
const options = activeEditorPane.options;
const group = activeEditorPane.group;
const activeResource = activeInput ? activeInput.resource : undefined;
if (!activeResource) {
return;
}
const overrides = this.editorService.getEditorOverrides(activeInput!, options, group);
const items: (IQuickPickItem & { handler?: IOpenEditorOverrideHandler })[] = overrides.map((override) => {
return {
handler: override[0],
id: override[1].id,
label: override[1].label,
description: override[1].active ? 'Currently Active' : undefined,
detail: override[1].detail
};
});
if (!items.length) {
return;
}
items.unshift({
id: 'default',
label: nls.localize('promptOpenWith.defaultEditor.displayName', "Text Editor"),
description: activeInput instanceof FileEditorInput ? 'Currently Active' : undefined,
detail: builtinProviderDisplayName
});
const picker = this.quickInputService.createQuickPick<(IQuickPickItem & { handler?: IOpenEditorOverrideHandler })>();
picker.items = items;
picker.placeholder = nls.localize('promptOpenWith.placeHolder', "Select editor to use for '{0}'...", resources.basename(activeResource));
const pickedItem = await new Promise<(IQuickPickItem & { handler?: IOpenEditorOverrideHandler }) | undefined>(resolve => {
picker.onDidAccept(() => {
resolve(picker.selectedItems.length === 1 ? picker.selectedItems[0] : undefined);
picker.dispose();
});
picker.show();
});
if (!pickedItem) {
return;
}
if (pickedItem.id === 'default') {
const fileEditorInput = this.editorService.createEditorInput({ resource: activeResource!, forceFile: true });
const textOptions = options ? { ...options, ignoreOverrides: true } : { ignoreOverrides: true };
await this.editorService.openEditor(fileEditorInput, textOptions, group);
return;
}
await pickedItem.handler!.open(activeInput!, options, group, pickedItem.id);
}
}
export class ToggleAutoSaveAction extends Action { export class ToggleAutoSaveAction extends Action {
static readonly ID = 'workbench.action.toggleAutoSave'; static readonly ID = 'workbench.action.toggleAutoSave';
static readonly LABEL = nls.localize('toggleAutoSave', "Toggle Auto Save"); static readonly LABEL = nls.localize('toggleAutoSave', "Toggle Auto Save");
......
...@@ -94,7 +94,26 @@ export class NotebookContribution implements IWorkbenchContribution { ...@@ -94,7 +94,26 @@ export class NotebookContribution implements IWorkbenchContribution {
@IInstantiationService private readonly instantiationService: IInstantiationService @IInstantiationService private readonly instantiationService: IInstantiationService
) { ) {
this.editorService.overrideOpenEditor((editor, options, group) => this.onEditorOpening(editor, options, group)); this.editorService.overrideOpenEditor({
getEditorOverrides: (editor: IEditorInput, options: IEditorOptions | undefined, group: IEditorGroup | undefined) => {
let resource = editor.resource;
if (!resource) {
return [];
}
const infos = notebookService.getContributedNotebookProviders(resource);
return infos.map(info => {
return {
label: info.displayName,
id: info.id,
active: editor instanceof NotebookEditorInput && editor.viewType === info.id,
detail: info.providerDisplayName
};
});
},
open: (editor, options, group, id) => this.onEditorOpening(editor, options, group, id)
});
this.editorService.onDidActiveEditorChange(() => { this.editorService.onDidActiveEditorChange(() => {
if (this.editorService.activeEditor && this.editorService.activeEditor! instanceof NotebookEditorInput) { if (this.editorService.activeEditor && this.editorService.activeEditor! instanceof NotebookEditorInput) {
...@@ -104,7 +123,7 @@ export class NotebookContribution implements IWorkbenchContribution { ...@@ -104,7 +123,7 @@ export class NotebookContribution implements IWorkbenchContribution {
}); });
} }
private onEditorOpening(originalInput: IEditorInput, options: IEditorOptions | ITextEditorOptions | undefined, group: IEditorGroup): IOpenEditorOverride | undefined { private onEditorOpening(originalInput: IEditorInput, options: IEditorOptions | ITextEditorOptions | undefined, group: IEditorGroup, id: string | undefined): IOpenEditorOverride | undefined {
let resource = originalInput.resource; let resource = originalInput.resource;
if (!resource) { if (!resource) {
return undefined; return undefined;
...@@ -112,15 +131,22 @@ export class NotebookContribution implements IWorkbenchContribution { ...@@ -112,15 +131,22 @@ export class NotebookContribution implements IWorkbenchContribution {
let info: NotebookProviderInfo | undefined; let info: NotebookProviderInfo | undefined;
const data = CellUri.parse(resource); const data = CellUri.parse(resource);
if (data && (info = getFirstNotebookInfo(this.notebookService, data.notebook))) { if (data) {
// cell-uri -> open (container) notebook const infos = this.notebookService.getContributedNotebookProviders(data.notebook);
const name = basename(data.notebook);
const input = this.instantiationService.createInstance(NotebookEditorInput, data.notebook, name, info.id); if (infos.length) {
this._resourceMapping.set(resource, input); const info = id === undefined ? infos[0] : (infos.find(info => info.id === id) || infos[0]);
return { override: this.editorService.openEditor(input, new NotebookEditorOptions({ ...options, forceReload: true, cellOptions: { resource, options } }), group) }; // cell-uri -> open (container) notebook
const name = basename(data.notebook);
const input = this.instantiationService.createInstance(NotebookEditorInput, data.notebook, name, info.id);
this._resourceMapping.set(resource, input);
return { override: this.editorService.openEditor(input, new NotebookEditorOptions({ ...options, forceReload: true, cellOptions: { resource, options } }), group) };
}
} }
info = getFirstNotebookInfo(this.notebookService, resource); const infos = this.notebookService.getContributedNotebookProviders(resource);
info = id === undefined ? infos[0] : infos.find(info => info.id === id);
if (!info) { if (!info) {
return undefined; return undefined;
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information. * Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { Disposable, IDisposable, DisposableStore } from 'vs/base/common/lifecycle'; import { Disposable, IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { URI } from 'vs/base/common/uri'; import { URI } from 'vs/base/common/uri';
...@@ -143,6 +144,7 @@ export class NotebookService extends Disposable implements INotebookService { ...@@ -143,6 +144,7 @@ export class NotebookService extends Disposable implements INotebookService {
id: notebookContribution.viewType, id: notebookContribution.viewType,
displayName: notebookContribution.displayName, displayName: notebookContribution.displayName,
selector: notebookContribution.selector || [], selector: notebookContribution.selector || [],
providerDisplayName: extension.description.isBuiltin ? nls.localize('builtinProviderDisplayName', "Built-in") : extension.description.displayName || extension.description.identifier.value,
})); }));
} }
} }
......
...@@ -17,15 +17,18 @@ export class NotebookProviderInfo { ...@@ -17,15 +17,18 @@ export class NotebookProviderInfo {
readonly id: string; readonly id: string;
readonly displayName: string; readonly displayName: string;
readonly selector: readonly NotebookSelector[]; readonly selector: readonly NotebookSelector[];
readonly providerDisplayName: string;
constructor(descriptor: { constructor(descriptor: {
readonly id: string; readonly id: string;
readonly displayName: string; readonly displayName: string;
readonly selector: readonly NotebookSelector[]; readonly selector: readonly NotebookSelector[];
readonly providerDisplayName: string;
}) { }) {
this.id = descriptor.id; this.id = descriptor.id;
this.displayName = descriptor.displayName; this.displayName = descriptor.displayName;
this.selector = descriptor.selector; this.selector = descriptor.selector;
this.providerDisplayName = descriptor.providerDisplayName;
} }
matches(resource: URI): boolean { matches(resource: URI): boolean {
......
...@@ -58,7 +58,9 @@ export class PreferencesContribution implements IWorkbenchContribution { ...@@ -58,7 +58,9 @@ export class PreferencesContribution implements IWorkbenchContribution {
// install editor opening listener unless user has disabled this // install editor opening listener unless user has disabled this
if (!!this.configurationService.getValue(USE_SPLIT_JSON_SETTING)) { if (!!this.configurationService.getValue(USE_SPLIT_JSON_SETTING)) {
this.editorOpeningListener = this.editorService.overrideOpenEditor((editor, options, group) => this.onEditorOpening(editor, options, group)); this.editorOpeningListener = this.editorService.overrideOpenEditor({
open: (editor, options, group) => this.onEditorOpening(editor, options, group)
});
} }
} }
......
...@@ -22,7 +22,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; ...@@ -22,7 +22,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { EditorDescriptor, Extensions as EditorExtensions, IEditorRegistry } from 'vs/workbench/browser/editor'; import { EditorDescriptor, Extensions as EditorExtensions, IEditorRegistry } from 'vs/workbench/browser/editor';
import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions'; import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions';
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions'; import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
import { ActiveEditorContext, Extensions as EditorInputExtensions, IEditorInputFactory, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor'; import { Extensions as EditorInputExtensions, IEditorInputFactory, IEditorInputFactoryRegistry, ActiveEditorContext } from 'vs/workbench/common/editor';
import * as SearchConstants from 'vs/workbench/contrib/search/common/constants'; import * as SearchConstants from 'vs/workbench/contrib/search/common/constants';
import * as SearchEditorConstants from 'vs/workbench/contrib/searchEditor/browser/constants'; import * as SearchEditorConstants from 'vs/workbench/contrib/searchEditor/browser/constants';
import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditor'; import { SearchEditor } from 'vs/workbench/contrib/searchEditor/browser/searchEditor';
...@@ -54,27 +54,29 @@ class SearchEditorContribution implements IWorkbenchContribution { ...@@ -54,27 +54,29 @@ class SearchEditorContribution implements IWorkbenchContribution {
@IContextKeyService protected readonly contextKeyService: IContextKeyService, @IContextKeyService protected readonly contextKeyService: IContextKeyService,
) { ) {
this.editorService.overrideOpenEditor((editor, options, group) => { this.editorService.overrideOpenEditor({
const resource = editor.resource; open: (editor, options, group) => {
if (!resource) { return undefined; } const resource = editor.resource;
if (!resource) { return undefined; }
if (!endsWith(resource.path, '.code-search')) { if (!endsWith(resource.path, '.code-search')) {
return undefined; return undefined;
} }
if (group.isOpened(editor)) { if (group.isOpened(editor) && editor instanceof SearchEditorInput) {
return undefined; return undefined;
} }
this.telemetryService.publicLog2('searchEditor/openSavedSearchEditor'); this.telemetryService.publicLog2('searchEditor/openSavedSearchEditor');
return { return {
override: (async () => { override: (async () => {
const { config } = await instantiationService.invokeFunction(parseSavedSearchEditor, resource); const { config } = await instantiationService.invokeFunction(parseSavedSearchEditor, resource);
const input = instantiationService.invokeFunction(getOrMakeSearchEditorInput, { backingUri: resource, config }); const input = instantiationService.invokeFunction(getOrMakeSearchEditorInput, { backingUri: resource, config });
return editorService.openEditor(input, { ...options, ignoreOverrides: true }, group); return editorService.openEditor(input, { ...options, ignoreOverrides: true }, group);
})() })()
}; };
}
}); });
} }
} }
......
...@@ -17,7 +17,7 @@ import { URI } from 'vs/base/common/uri'; ...@@ -17,7 +17,7 @@ import { URI } from 'vs/base/common/uri';
import { basename, isEqualOrParent, joinPath } from 'vs/base/common/resources'; import { basename, isEqualOrParent, joinPath } from 'vs/base/common/resources';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { IEditorGroupsService, IEditorGroup, GroupsOrder, IEditorReplacement, GroupChangeKind, preferredSideBySideGroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorGroupsService, IEditorGroup, GroupsOrder, IEditorReplacement, GroupChangeKind, preferredSideBySideGroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IResourceEditorInputType, SIDE_GROUP, IResourceEditorReplacement, IOpenEditorOverrideHandler, IEditorService, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE, ISaveEditorsOptions, ISaveAllEditorsOptions, IRevertAllEditorsOptions, IBaseSaveRevertAllEditorOptions } from 'vs/workbench/services/editor/common/editorService'; import { IResourceEditorInputType, SIDE_GROUP, IResourceEditorReplacement, IOpenEditorOverrideHandler, IEditorService, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE, ISaveEditorsOptions, ISaveAllEditorsOptions, IRevertAllEditorsOptions, IBaseSaveRevertAllEditorOptions, IOpenEditorOverrideEntry } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { Disposable, IDisposable, dispose, toDisposable, DisposableStore } from 'vs/base/common/lifecycle'; import { Disposable, IDisposable, dispose, toDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { coalesce, distinct, insert } from 'vs/base/common/arrays'; import { coalesce, distinct, insert } from 'vs/base/common/arrays';
...@@ -477,13 +477,23 @@ export class EditorService extends Disposable implements EditorServiceImpl { ...@@ -477,13 +477,23 @@ export class EditorService extends Disposable implements EditorServiceImpl {
return toDisposable(() => remove()); return toDisposable(() => remove());
} }
getEditorOverrides(editorInput: IEditorInput, options: IEditorOptions | undefined, group: IEditorGroup | undefined): [IOpenEditorOverrideHandler, IOpenEditorOverrideEntry][] {
const ret = [];
for (const handler of this.openEditorHandlers) {
const handlers = handler.getEditorOverrides ? handler.getEditorOverrides(editorInput, options, group).map(val => { return [handler, val] as [IOpenEditorOverrideHandler, IOpenEditorOverrideEntry]; }) : [];
ret.push(...handlers);
}
return ret;
}
private onGroupWillOpenEditor(group: IEditorGroup, event: IEditorOpeningEvent): void { private onGroupWillOpenEditor(group: IEditorGroup, event: IEditorOpeningEvent): void {
if (event.options && event.options.ignoreOverrides) { if (event.options && event.options.ignoreOverrides) {
return; return;
} }
for (const handler of this.openEditorHandlers) { for (const handler of this.openEditorHandlers) {
const result = handler(event.editor, event.options, group); const result = handler.open(event.editor, event.options, group);
const override = result?.override; const override = result?.override;
if (override) { if (override) {
event.prevent((() => override.then(editor => withNullAsUndefined(editor)))); event.prevent((() => override.then(editor => withNullAsUndefined(editor))));
...@@ -1110,6 +1120,10 @@ export class DelegatingEditorService implements IEditorService { ...@@ -1110,6 +1120,10 @@ export class DelegatingEditorService implements IEditorService {
@IEditorService private editorService: EditorService @IEditorService private editorService: EditorService
) { } ) { }
getEditorOverrides(editorInput: IEditorInput, options: IEditorOptions | undefined, group: IEditorGroup | undefined) {
return [];
}
openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, group?: OpenInEditorGroup): Promise<IEditorPane | undefined>; openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, group?: OpenInEditorGroup): Promise<IEditorPane | undefined>;
openEditor(editor: IResourceEditorInput | IUntitledTextResourceEditorInput, group?: OpenInEditorGroup): Promise<ITextEditorPane | undefined>; openEditor(editor: IResourceEditorInput | IUntitledTextResourceEditorInput, group?: OpenInEditorGroup): Promise<ITextEditorPane | undefined>;
openEditor(editor: IResourceDiffEditorInput, group?: OpenInEditorGroup): Promise<ITextDiffEditorPane | undefined>; openEditor(editor: IResourceDiffEditorInput, group?: OpenInEditorGroup): Promise<ITextDiffEditorPane | undefined>;
......
...@@ -26,8 +26,16 @@ export type ACTIVE_GROUP_TYPE = typeof ACTIVE_GROUP; ...@@ -26,8 +26,16 @@ export type ACTIVE_GROUP_TYPE = typeof ACTIVE_GROUP;
export const SIDE_GROUP = -2; export const SIDE_GROUP = -2;
export type SIDE_GROUP_TYPE = typeof SIDE_GROUP; export type SIDE_GROUP_TYPE = typeof SIDE_GROUP;
export interface IOpenEditorOverrideEntry {
id: string;
label: string;
active: boolean;
detail?: string;
}
export interface IOpenEditorOverrideHandler { export interface IOpenEditorOverrideHandler {
(editor: IEditorInput, options: IEditorOptions | ITextEditorOptions | undefined, group: IEditorGroup): IOpenEditorOverride | undefined; open(editor: IEditorInput, options: IEditorOptions | ITextEditorOptions | undefined, group: IEditorGroup, id?: string): IOpenEditorOverride | undefined;
getEditorOverrides?(editor: IEditorInput, options: IEditorOptions | undefined, group: IEditorGroup | undefined): IOpenEditorOverrideEntry[];
} }
export interface IOpenEditorOverride { export interface IOpenEditorOverride {
...@@ -201,6 +209,11 @@ export interface IEditorService { ...@@ -201,6 +209,11 @@ export interface IEditorService {
isOpen(editor: IResourceEditorInput): boolean; isOpen(editor: IResourceEditorInput): boolean;
isOpen(editor: IEditorInput): boolean; isOpen(editor: IEditorInput): boolean;
/**
* Get all available editor overrides for the editor input.
*/
getEditorOverrides(editorInput: IEditorInput, options: IEditorOptions | undefined, group: IEditorGroup | undefined): [IOpenEditorOverrideHandler, IOpenEditorOverrideEntry][];
/** /**
* Allows to override the opening of editors by installing a handler that will * Allows to override the opening of editors by installing a handler that will
* be called each time an editor is about to open allowing to override the * be called each time an editor is about to open allowing to override the
......
...@@ -963,14 +963,16 @@ suite('EditorService', () => { ...@@ -963,14 +963,16 @@ suite('EditorService', () => {
let overrideCalled = false; let overrideCalled = false;
const handler = service.overrideOpenEditor(editor => { const handler = service.overrideOpenEditor({
if (editor === input1) { open: editor => {
overrideCalled = true; if (editor === input1) {
overrideCalled = true;
return { override: service.openEditor(input2, { pinned: true }) }; return { override: service.openEditor(input2, { pinned: true }) };
} }
return undefined; return undefined;
}
}); });
await service.openEditor(input1, { pinned: true }); await service.openEditor(input1, { pinned: true });
......
...@@ -52,7 +52,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; ...@@ -52,7 +52,7 @@ import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations'; import { IDecorationsService, IResourceDecorationChangeEvent, IDecoration, IDecorationData, IDecorationsProvider } from 'vs/workbench/services/decorations/browser/decorations';
import { IDisposable, toDisposable, Disposable, DisposableStore } from 'vs/base/common/lifecycle'; import { IDisposable, toDisposable, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, IFindGroupScope, EditorGroupLayout, ICloseEditorOptions, GroupOrientation } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorGroupsService, IEditorGroup, GroupsOrder, GroupsArrangement, GroupDirection, IAddGroupOptions, IMergeGroupOptions, IMoveEditorOptions, ICopyEditorOptions, IEditorReplacement, IGroupChangeEvent, IFindGroupScope, EditorGroupLayout, ICloseEditorOptions, GroupOrientation } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService, IOpenEditorOverrideHandler, ISaveEditorsOptions, IRevertAllEditorsOptions, IResourceEditorInputType, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService'; import { IEditorService, IOpenEditorOverrideHandler, ISaveEditorsOptions, IRevertAllEditorsOptions, IResourceEditorInputType, SIDE_GROUP_TYPE, ACTIVE_GROUP_TYPE, IOpenEditorOverrideEntry } from 'vs/workbench/services/editor/common/editorService';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { IEditorRegistry, EditorDescriptor, Extensions } from 'vs/workbench/browser/editor'; import { IEditorRegistry, EditorDescriptor, Extensions } from 'vs/workbench/browser/editor';
import { EditorGroup } from 'vs/workbench/common/editor/editorGroup'; import { EditorGroup } from 'vs/workbench/common/editor/editorGroup';
...@@ -629,6 +629,7 @@ export class TestEditorService implements EditorServiceImpl { ...@@ -629,6 +629,7 @@ export class TestEditorService implements EditorServiceImpl {
constructor(private editorGroupService?: IEditorGroupsService) { } constructor(private editorGroupService?: IEditorGroupsService) { }
getEditors() { return []; } getEditors() { return []; }
getEditorOverrides(editorInput: IEditorInput, options: IEditorOptions | undefined, group: IEditorGroup | undefined): [IOpenEditorOverrideHandler, IOpenEditorOverrideEntry][] { return []; }
overrideOpenEditor(_handler: IOpenEditorOverrideHandler): IDisposable { return toDisposable(() => undefined); } overrideOpenEditor(_handler: IOpenEditorOverrideHandler): IDisposable { return toDisposable(() => undefined); }
openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined>; openEditor(editor: IEditorInput, options?: IEditorOptions | ITextEditorOptions, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined>;
openEditor(editor: IResourceEditorInput | IUntitledTextResourceEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextEditorPane | undefined>; openEditor(editor: IResourceEditorInput | IUntitledTextResourceEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextEditorPane | undefined>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册