Skip to content

Commit

Permalink
Merge pull request #1399 from halcyon-tech/feature/actionAutosaveFrom…
Browse files Browse the repository at this point in the history
…Editor

Handle editor saving in any case when running actions
  • Loading branch information
chrjorgensen committed Jun 28, 2023
2 parents bcfc66c + 8dee6f8 commit 3886f16
Showing 1 changed file with 23 additions and 35 deletions.
58 changes: 23 additions & 35 deletions src/instantiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ export async function loadAllofExtension(context: vscode.ExtensionContext) {
),
vscode.commands.registerCommand(`code-for-ibmi.openEditable`, async (path: string, line?: number, options?: QsysFsOptions) => {
console.log(path);
if(!options?.readonly && !path.startsWith('/')){
if (!options?.readonly && !path.startsWith('/')) {
const [library, name] = path.split('/');
const writable = await instance.getContent()?.checkObject({library, name, type: '*FILE'}, "*UPD");
if(!writable){
const writable = await instance.getContent()?.checkObject({ library, name, type: '*FILE' }, "*UPD");
if (!writable) {
options = options || {};
options.readonly = true;
}
Expand Down Expand Up @@ -227,54 +227,42 @@ export async function loadAllofExtension(context: vscode.ExtensionContext) {
CompileTools.clearDiagnostics();
}),
vscode.commands.registerCommand(`code-for-ibmi.runAction`, async (node) => {
if (node) {
const uri = node.resourceUri || node;

CompileTools.runAction(instance, uri);

} else {
const editor = vscode.window.activeTextEditor;
let willRun = false;

if (editor) {
const config = instance.getConfig()!;
const uri = editor.document.uri;
willRun = true;
if (config.autoSaveBeforeAction) {
await editor.document.save();
} else {
if (editor.document.isDirty) {
let result = await vscode.window.showWarningMessage(`The file must be saved to run Actions.`, `Save`, `Save automatically`, `Cancel`);

const editor = vscode.window.activeTextEditor;
const uri = (node?.resourceUri || node || editor?.document.uri) as vscode.Uri;
if (uri) {
const config = instance.getConfig();
if (config) {
let canRun = true;
if (editor && uri.path === editor.document.uri.path && editor.document.isDirty) {
if (config.autoSaveBeforeAction) {
await editor.document.save();
} else {
const result = await vscode.window.showWarningMessage(`The file must be saved to run Actions.`, `Save`, `Save automatically`, `Cancel`);
switch (result) {
case `Save`:
await editor.document.save();
willRun = true;
canRun = true;
break;
case `Save automatically`:
config.autoSaveBeforeAction = true;
await ConnectionConfiguration.update(config);
await editor.document.save();
willRun = true;
canRun = true;
break;
default:
willRun = false;
canRun = false;
break;
}
}
}

if (willRun) {
const scheme = uri.scheme;
switch (scheme) {
case `member`:
case `streamfile`:
case `file`:
CompileTools.runAction(instance, uri);
break;
}
if (canRun && [`member`, `streamfile`, `file`].includes(uri.scheme)) {
CompileTools.runAction(instance, uri);
}
}
else{
vscode.window.showErrorMessage('Please connect to an IBM i first');
}
}
}),

Expand Down Expand Up @@ -359,7 +347,7 @@ export async function loadAllofExtension(context: vscode.ExtensionContext) {
if (content) {
const path = (await content.isDirectory(ifsNode.path)) ? ifsNode.path : dirname(ifsNode.path);
const terminal = await Terminal.selectAndOpen(instance, Terminal.TerminalType.PASE);
terminal?.sendText(`cd ${path}`);
terminal?.sendText(`cd ${path}`);
}
}),

Expand Down

0 comments on commit 3886f16

Please sign in to comment.