diff --git a/.gitignore b/.gitignore index acc46eb..2f37e6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store node_modules .vscode-test/ src/scratch.js diff --git a/client/src/extension.ts b/client/src/extension.ts index dce8c90..38e0c21 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -140,7 +140,7 @@ export async function activate(ctx: vscode.ExtensionContext) { statusBarEnvItem.command = 'iiq-dev-accelerator.switchEnv'; ctx.subscriptions.push(statusBarEnvItem); - ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.importFileRoot', () => iiqCommands.importFileRoot())); + ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.importFileRoot', (uri?: vscode.Uri) => iiqCommands.importFileRoot(uri))); ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.runTask', () => iiqCommands.runTask())); ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.runTaskWithAttr', () => iiqCommands.runTaskWithAttr())); ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.runRule', () => iiqCommands.runRule())); @@ -157,7 +157,7 @@ export async function activate(ctx: vscode.ExtensionContext) { ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.compareLocalWithDeployed', () => iiqCommands.compareLocalWithDeployed())); ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.deployOpenFiles', () => iiqCommands.deployOpenFiles())); ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.showSysInfo', () => iiqCommands.showSysInfo())); - ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.refreshObject', () => iiqCommands.refreshObject())); + ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.refreshObject', (uri?: vscode.Uri) => iiqCommands.refreshObject(uri))); ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.importJava', () => iiqCommands.importJava())); ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.exportObjects', () => iiqCommands.exportObjects())); ctx.subscriptions.push(vscode.commands.registerCommand('iiq-dev-accelerator.switchMode', () => iiqCommands.switchMode())); diff --git a/client/src/iiq-commands.ts b/client/src/iiq-commands.ts index f11b446..6b1293c 100644 --- a/client/src/iiq-commands.ts +++ b/client/src/iiq-commands.ts @@ -881,7 +881,15 @@ export class IIQCommands { return [isSuccess, processFileErrors]; } - public async importFileRoot(): Promise<[boolean, {}]> { + public async importFileRoot(resourceUri?: vscode.Uri): Promise<[boolean, {}]> { + // If a URI was provided from right-click context, open that file first + if (resourceUri) { + const document = await vscode.workspace.openTextDocument(resourceUri); + await vscode.window.showTextDocument(document); + // Wait a moment for the context to update + await new Promise(resolve => setTimeout(resolve, 100)); + } + if(this.g_contextManager.getContextValue() == ContextValue.JavaFile){ this.importJava(); return; @@ -2119,9 +2127,19 @@ export class IIQCommands { return false; } - public async refreshObject(){ - if(!this.g_contextManager.getObjName()){ - vscode.window.showInformationMessage(`Couldn't determine the object name`); + public async refreshObject(resourceUri?: vscode.Uri){ + // If a URI was provided from right-click context, open that file first + if (resourceUri) { + const document = await vscode.workspace.openTextDocument(resourceUri); + await vscode.window.showTextDocument(document); + // Wait a moment for the context to update + await new Promise(resolve => setTimeout(resolve, 100)); + } + + if (!this.g_contextManager.getObjName()) { + vscode.window.showInformationMessage( + `Couldn't determine the object name` + ); return; } @@ -2131,30 +2149,59 @@ export class IIQCommands { var objName = this.g_contextManager.getObjName(); var xml = await this.searchObject(theClass, objId, objName); - if(!xml){ + if (!xml) { vscode.window.showInformationMessage("Empty object, exiting"); return; } - var showDiff = false; - const answer = await vscode.window.showQuickPick(["Yes", "No"], - {placeHolder: `Would you like to display it in a diff mode?`}); - if(answer === "Yes"){ - showDiff = true; - } + const alwaysShowDiffPrompt = vscode.workspace + .getConfiguration("iiq-dev-accelerator") + .get("refreshAlwaysShowDiffPrompt"); - const oldFileName = editor.document.fileName; - const newFile = tmp.fileSync({prefix: `${theClass}-${objName}`, postfix: '.xml'}); - const newFileName = newFile.name; - fs.writeFileSync(newFileName, xml); + const overwriteFile: boolean = vscode.workspace + .getConfiguration("iiq-dev-accelerator") + .get("refreshObjectOverwriteFile"); - if(showDiff){ - const title = "Old vs new " + theClass + ":'" + objName + "'"; - await vscode.commands.executeCommand("vscode.diff", vscode.Uri.file(oldFileName), vscode.Uri.file(newFileName), title); + let showDiff = false; + if (alwaysShowDiffPrompt || !overwriteFile) { + const answer = await vscode.window.showQuickPick(["Yes", "No"], { + placeHolder: `Would you like to display it in a diff mode?`, + }); + if (answer === "Yes") { + showDiff = true; + } } - else{ - let doc = await vscode.workspace.openTextDocument(newFileName); - await vscode.window.showTextDocument(doc); + + if (overwriteFile && !showDiff) { + // Overwrite the current file directly + const oldFileName = editor.document.fileName; + console.info(`Overwriting file ${oldFileName} with refreshed content`); + fs.writeFileSync(oldFileName, xml); + vscode.window.showInformationMessage( + `File ${path.basename(oldFileName)} has been refreshed` + ); + } else { + // Show diff between current file and refreshed content, or just show the temp file directly + const oldFileName = editor.document.fileName; + const newFile = tmp.fileSync({ + prefix: `${theClass}-${objName}`, + postfix: ".xml", + }); + const newFileName = newFile.name; + fs.writeFileSync(newFileName, xml); + + if (showDiff) { + const title = "Old vs new " + theClass + ":'" + objName + "'"; + await vscode.commands.executeCommand( + "vscode.diff", + vscode.Uri.file(oldFileName), + vscode.Uri.file(newFileName), + title + ); + } else { + let doc = await vscode.workspace.openTextDocument(newFileName); + await vscode.window.showTextDocument(doc); + } } } diff --git a/package.json b/package.json index 7b23af6..e963c83 100644 --- a/package.json +++ b/package.json @@ -195,6 +195,18 @@ "description": "Set to true if you want tomcat to be restarted automatically, otherwise you'll need to restart it manually for new certificates to take effects", "default": false, "scope": "application" + }, + "iiq-dev-accelerator.refreshObjectOverwriteFile": { + "type": "boolean", + "description": "When set to true, the refreshObject command will overwrite the current file instead of opening a temporary file", + "default": false, + "scope": "application" + }, + "iiq-dev-accelerator.refreshAlwaysShowDiffPrompt": { + "type": "boolean", + "description": "When set to true, the refreshObject command will always ask whether to show diff or overwrite, even if 'refreshObjectOverwriteFile' is set to true", + "default": false, + "scope": "application" } } }, @@ -357,6 +369,11 @@ "command": "iiq-dev-accelerator.evalBS", "when": "iiq.context == BeanShellSelection", "group": "iiq" + }, + { + "command": "iiq-dev-accelerator.refreshObject", + "when": "iiq.context == Rule || iiq.context == Task || iiq.context == ProjectXMLObject || iiq.context == TempXMLObject", + "group": "iiq" } ] }