Skip to content

Commit 2b91e27

Browse files
Merge pull request #289 from Power-Maverick/copilot/fix-compare-option-bug
Fix: Context menu options not appearing after linking/initialization until VS Code restart
2 parents 542e5d0 + 40c0e38 commit 2b91e27

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/helpers/templateHelper.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import fetch from "node-fetch";
55
import { copyFolderOrFile, createFolder, pathExists, readFileSync, writeFileSync } from "../utils/FileSystem";
66
import { Commands } from "../terminals/commands";
77
import { Console } from "../terminals/console";
8-
import { extensionName, tsTemplateType } from "../utils/Constants";
8+
import { extensionName, extensionPrefix, tsTemplateType } from "../utils/Constants";
99
import { Placeholders } from "../utils/Placeholders";
1010
import { ErrorMessages } from "../utils/ErrorMessages";
1111
import { pascalize } from "../utils/ExtensionMethods";
@@ -63,6 +63,9 @@ export class TemplateHelper {
6363
commands.push(Commands.LoadNpmPackages());
6464
Console.runCommand(commands);
6565

66+
// Update VS Code context to enable "Add Dataverse TS File" menu option
67+
await vscode.commands.executeCommand("setContext", `${extensionPrefix}.isTSProject`, true);
68+
6669
vscode.window.showInformationMessage(`${extensionName}: TypeScript project initialized.`);
6770
}
6871

@@ -141,6 +144,9 @@ export class TemplateHelper {
141144
commands.push(Commands.LoadNpmPackages());
142145
Console.runCommand(commands);
143146

147+
// Update VS Code context to enable "Add Dataverse JS File" menu option
148+
await vscode.commands.executeCommand("setContext", `${extensionPrefix}.isJSProject`, true);
149+
144150
vscode.window.showInformationMessage(`${extensionName}: JavaScript project initialized.`);
145151
}
146152

src/helpers/webResourceHelper.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { reduce } from "conditional-reduce";
33
import * as path from "path";
44
import * as vscode from "vscode";
5-
import { WebResourceType, wrDefinitionsStoreKey } from "../utils/Constants";
5+
import { extensionPrefix, WebResourceType, wrDefinitionsStoreKey } from "../utils/Constants";
66
import { ErrorMessages } from "../utils/ErrorMessages";
77
import { decodeFromBase64, encodeToBase64, extractGuid } from "../utils/ExtensionMethods";
88
import { copyFolderOrFile, createTempDirectory, getFileExtension, getFileName, getRelativeFilePath, getWorkspaceFolder, readFileAsBase64Sync, readFileSync, writeFileSync } from "../utils/FileSystem";
@@ -360,6 +360,7 @@ export class WebResourceHelper {
360360
}
361361
writeFileSync(linkerFile.fsPath, jsonToXML(linkerFileDataJson));
362362
vscode.commands.executeCommand("dvdt.explorer.webresources.loadWebResources");
363+
await this.updateLinkedResourcesContext();
363364
return resc;
364365
}
365366
}
@@ -379,6 +380,7 @@ export class WebResourceHelper {
379380
}
380381
writeFileSync(linkerFile.fsPath, jsonToXML(linkerFileDataJson));
381382
vscode.commands.executeCommand("dvdt.explorer.webresources.loadWebResources");
383+
await this.updateLinkedResourcesContext();
382384
return newResc;
383385
}
384386
}
@@ -405,6 +407,7 @@ export class WebResourceHelper {
405407
}
406408
writeFileSync(linkerFile.fsPath, jsonToXML(linkerFileDataJson));
407409
vscode.commands.executeCommand("dvdt.explorer.webresources.loadWebResources");
410+
await this.updateLinkedResourcesContext();
408411
}
409412
}
410413

@@ -577,15 +580,17 @@ export class WebResourceHelper {
577580
return { displayname: wrDisplayNameUR, name: `${prefix}_${wrNameUR}`, webresourcetype: wrType, content: wrContent, solutionid: solId, description: solName };
578581
}
579582
}
583+
}
580584

581-
//#endregion Private
582-
583-
// Ask for
584-
// Display Name
585-
// Name
586-
// Web Resource Type (infer it from file extension)
587-
// Content (get it from the file & convert it to base64)
585+
/**
586+
* Update the VS Code context for linked resources to enable/disable context menu items
587+
*/
588+
private async updateLinkedResourcesContext(): Promise<void> {
589+
const linkedFileNames = await this.getLinkedResourceStrings("@_localFileName");
590+
await vscode.commands.executeCommand("setContext", `${extensionPrefix}.linkedResources`, linkedFileNames);
588591
}
592+
593+
//#endregion Private
589594
}
590595

591596
/**

0 commit comments

Comments
 (0)