Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules
.vscode-test/
src/scratch.js
Expand Down
4 changes: 2 additions & 2 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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()));
Expand Down
89 changes: 68 additions & 21 deletions client/src/iiq-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand Down Expand Up @@ -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"
}
]
}
Expand Down