Skip to content

Commit

Permalink
Revert "Closes microsoft#122433"
Browse files Browse the repository at this point in the history
This reverts commit 134d9b1.
  • Loading branch information
mjbvz committed May 20, 2021
1 parent 34180ac commit 29c6157
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions src/vs/workbench/services/editor/browser/editorOverrideService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ type ContributionPoints = Array<ContributionPoint>;
export class EditorOverrideService extends Disposable implements IEditorOverrideService {
readonly _serviceBrand: undefined;

// Constants
private static readonly configureDefaultID = 'promptOpenWith.configureDefault';
private static readonly overrideCacheStorageID = 'editorOverrideService.cache';
private static readonly conflictingDefaultsStorageID = 'editorOverrideService.conflictingDefaults';

// Data Stores
private _contributionPoints: Map<string | glob.IRelativePattern, ContributionPoints> = new Map<string | glob.IRelativePattern, ContributionPoints>();
private static readonly overrideCacheStorageID = 'editorOverrideService.cache';
private cache: Set<string> | undefined;

constructor(
Expand Down Expand Up @@ -133,8 +129,8 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
}
const input = await this.doOverrideEditorInput(editor, options, group, selectedContribution);
if (conflictingDefault && input) {
// Show the conflicting default dialog
await this.doHandleConflictingDefaults(selectedContribution.editorInfo.label, input.editor, input.options ?? options, group);
// Wait one second to give the user ample time to see the current editor then ask them to configure a default
this.doHandleConflictingDefaults(selectedContribution.editorInfo.label, input.editor, input.options ?? options, group);
}

// Add the group as we might've changed it with the quickpick
Expand Down Expand Up @@ -371,24 +367,13 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
}

private async doHandleConflictingDefaults(editorName: string, currentEditor: IContributedEditorInput, options: IEditorOptions | undefined, group: IEditorGroup) {
type StoredChoice = {
[key: string]: string[];
};
const contributionPoints = this.findMatchingContributions(currentEditor.resource!);
const storedChoices: StoredChoice = JSON.parse(this.storageService.get(EditorOverrideService.conflictingDefaultsStorageID, StorageScope.GLOBAL, '{}'));
const globForResource = `*${extname(currentEditor.resource!)}`;
// Writes to the storage service that a choice has been made for the currently installed editors
const writeCurrentEditorsToStorage = () => {
storedChoices[globForResource] = [];
contributionPoints.forEach(contrib => storedChoices[globForResource].push(contrib.editorInfo.id));
this.storageService.store(EditorOverrideService.conflictingDefaultsStorageID, JSON.stringify(storedChoices), StorageScope.GLOBAL, StorageTarget.MACHINE);
const makeCurrentEditorDefault = () => {
const viewType = currentEditor.viewType;
if (viewType) {
this.updateUserAssociations(`*${extname(currentEditor.resource!)}`, viewType);
}
};

// If the user has already made a choice for this editor we don't want to ask them again
if (storedChoices[globForResource]?.find(editorID => editorID === currentEditor.viewType)) {
return;
}

const handle = this.notificationService.prompt(Severity.Warning,
localize('editorOverride.conflictingDefaults', 'There are multiple default editors available for the resource.'),
[{
Expand All @@ -415,12 +400,12 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
},
{
label: localize('editorOverride.keepDefault', 'Keep {0}', editorName),
run: writeCurrentEditorsToStorage
run: makeCurrentEditorDefault
}
]);
// If the user pressed X we assume they want to keep the current editor as default
const onCloseListener = handle.onDidClose(() => {
writeCurrentEditorsToStorage();
makeCurrentEditorDefault();
onCloseListener.dispose();
});
}
Expand Down

0 comments on commit 29c6157

Please sign in to comment.