mirror of
https://github.com/Microsoft/vscode
synced 2024-10-04 02:14:06 +00:00
Store conflicting defaults in storage service (#124366)
* Revert "Revert "Closes #122433""
This reverts commit 29c61570a5
.
* Get rid of ? to see if minifier is happy
* Bump ES build
This commit is contained in:
parent
fc0b6f5e5a
commit
045e5d2f56
|
@ -42,7 +42,7 @@
|
|||
"colors": "^1.4.0",
|
||||
"commander": "^7.0.0",
|
||||
"electron-osx-sign": "^0.4.16",
|
||||
"esbuild": "^0.8.30",
|
||||
"esbuild": "^0.12.1",
|
||||
"fs-extra": "^9.1.0",
|
||||
"got": "11.8.1",
|
||||
"iconv-lite-umd": "0.6.8",
|
||||
|
|
|
@ -992,10 +992,10 @@ entities@^1.1.1, entities@~1.1.1:
|
|||
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"
|
||||
integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==
|
||||
|
||||
esbuild@^0.8.30:
|
||||
version "0.8.30"
|
||||
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.30.tgz#3d057ff9ffe6d5d30bccb0afe8cc92a2e69622d3"
|
||||
integrity sha512-gCJQYUMO9QNrfpNOIiCnFoX41nWiPFCvURBQF+qWckyJ7gmw2xCShdKCXvS+RZcQ5krcxEOLIkzujqclePKhfw==
|
||||
esbuild@^0.12.1:
|
||||
version "0.12.1"
|
||||
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.12.1.tgz#f652d5b3b9432dbb42fc2c034ddd62360296e03d"
|
||||
integrity sha512-WfQ00MKm/Y4ysz1u9PCUAsV66k5lbrcEvS6aG9jhBIavpB94FBdaWeBkaZXxCZB4w+oqh+j4ozJFWnnFprOXbg==
|
||||
|
||||
eslint-scope@^5.0.0:
|
||||
version "5.0.0"
|
||||
|
|
|
@ -40,9 +40,13 @@ type ContributionPoints = Array<ContributionPoint>;
|
|||
export class EditorOverrideService extends Disposable implements IEditorOverrideService {
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
// Constants
|
||||
private static readonly configureDefaultID = 'promptOpenWith.configureDefault';
|
||||
private _contributionPoints: Map<string | glob.IRelativePattern, ContributionPoints> = new Map<string | glob.IRelativePattern, ContributionPoints>();
|
||||
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 cache: Set<string> | undefined;
|
||||
|
||||
constructor(
|
||||
|
@ -129,8 +133,8 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
|
|||
}
|
||||
const input = await this.doOverrideEditorInput(editor, options, group, selectedContribution);
|
||||
if (conflictingDefault && input) {
|
||||
// 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);
|
||||
// Show the conflicting default dialog
|
||||
await this.doHandleConflictingDefaults(selectedContribution.editorInfo.label, input.editor, input.options ?? options, group);
|
||||
}
|
||||
|
||||
// Add the group as we might've changed it with the quickpick
|
||||
|
@ -367,12 +371,23 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
|
|||
}
|
||||
|
||||
private async doHandleConflictingDefaults(editorName: string, currentEditor: IContributedEditorInput, options: IEditorOptions | undefined, group: IEditorGroup) {
|
||||
const makeCurrentEditorDefault = () => {
|
||||
const viewType = currentEditor.viewType;
|
||||
if (viewType) {
|
||||
this.updateUserAssociations(`*${extname(currentEditor.resource!)}`, viewType);
|
||||
}
|
||||
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);
|
||||
};
|
||||
|
||||
// If the user has already made a choice for this editor we don't want to ask them again
|
||||
if (storedChoices[globForResource] && 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.'),
|
||||
|
@ -400,12 +415,12 @@ export class EditorOverrideService extends Disposable implements IEditorOverride
|
|||
},
|
||||
{
|
||||
label: localize('editorOverride.keepDefault', 'Keep {0}', editorName),
|
||||
run: makeCurrentEditorDefault
|
||||
run: writeCurrentEditorsToStorage
|
||||
}
|
||||
]);
|
||||
// If the user pressed X we assume they want to keep the current editor as default
|
||||
const onCloseListener = handle.onDidClose(() => {
|
||||
makeCurrentEditorDefault();
|
||||
writeCurrentEditorsToStorage();
|
||||
onCloseListener.dispose();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue