From ad2b617aaa8c8b909dc536c1c1f9d51f5f722184 Mon Sep 17 00:00:00 2001 From: Seb Julliand Date: Fri, 23 Aug 2024 08:46:40 +0200 Subject: [PATCH] Add action to open location after download Signed-off-by: Seb Julliand --- src/locale/ids/de.json | 1 + src/locale/ids/en.json | 1 + src/locale/ids/fr.json | 3 ++- src/locale/ids/no.json | 1 + src/locale/ids/pl.json | 1 + src/views/ifsBrowser.ts | 18 ++++++++++-------- src/views/objectBrowser.ts | 19 ++++++++++--------- 7 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/locale/ids/de.json b/src/locale/ids/de.json index 5793e2ad5..66b409f1e 100644 --- a/src/locale/ids/de.json +++ b/src/locale/ids/de.json @@ -360,6 +360,7 @@ "objectBrowser.uploadAndReplaceMemberAsFile.infoMessage": "Quelle wurde hochgeladen.", "offline": "Offline", "online": "Online", + "open":"Open", "open.service.configuration": "Konfiguration öffnen", "overview": "Überblick", "overwrite": "Überschreiben", diff --git a/src/locale/ids/en.json b/src/locale/ids/en.json index 08ff07c8b..b0196009b 100644 --- a/src/locale/ids/en.json +++ b/src/locale/ids/en.json @@ -360,6 +360,7 @@ "objectBrowser.uploadAndReplaceMemberAsFile.infoMessage": "Member was uploaded.", "offline": "Offline", "online": "Online", + "open":"Open", "open.service.configuration": "Open configuration", "overview": "Overview", "overwrite": "Overwrite", diff --git a/src/locale/ids/fr.json b/src/locale/ids/fr.json index 634299e87..16d219e60 100644 --- a/src/locale/ids/fr.json +++ b/src/locale/ids/fr.json @@ -359,7 +359,8 @@ "objectBrowser.uploadAndReplaceMemberAsFile.errorMessage": "Erreur lors de l'upload du contenu du membre! {0}", "objectBrowser.uploadAndReplaceMemberAsFile.infoMessage": "Le membre a été uploadé.", "offline": "Hors ligne", - "online": "En ligne", + "online": "En ligne", + "open":"Ouvrir", "open.service.configuration": "Ouvrir la configuration", "overview": "Aperçu", "overwrite": "Écraser", diff --git a/src/locale/ids/no.json b/src/locale/ids/no.json index 3f8d73d0e..2561d9528 100644 --- a/src/locale/ids/no.json +++ b/src/locale/ids/no.json @@ -360,6 +360,7 @@ "objectBrowser.uploadAndReplaceMemberAsFile.infoMessage": "Fil ble sendt til member.", "offline": "Offline", "online": "Online", + "open":"Open", "open.service.configuration": "Åpne konfigurasjon", "overview": "Oversikt", "overwrite": "Erstatt", diff --git a/src/locale/ids/pl.json b/src/locale/ids/pl.json index 0556d8fdc..b398c192b 100644 --- a/src/locale/ids/pl.json +++ b/src/locale/ids/pl.json @@ -360,6 +360,7 @@ "objectBrowser.uploadAndReplaceMemberAsFile.infoMessage": "Podzbiór został wysłany.", "offline": "Nieaktywny", "online": "Online", + "open":"Open", "open.service.configuration": "Otwórz konfigurację", "overview": "Przeglądaj", "overwrite": "Nadpisz", diff --git a/src/views/ifsBrowser.ts b/src/views/ifsBrowser.ts index a1fa21561..0b18db503 100644 --- a/src/views/ifsBrowser.ts +++ b/src/views/ifsBrowser.ts @@ -805,7 +805,7 @@ export function initializeIFSBrowser(context: vscode.ExtensionContext) { vscode.window.showInformationMessage(t(`clearedList`)); quickPick.show(); } else { - quickPick.hide(); + quickPick.hide(); GlobalStorage.get().addPreviousFindTerm(findTerm); await doFindStreamfiles(findTerm, findPath); } @@ -825,24 +825,25 @@ export function initializeIFSBrowser(context: vscode.ExtensionContext) { if (ibmi) { const items = (nodes || [node]).filter(reduceIFSPath); const saveIntoDirectory = items.length > 1 || items[0].file.type === "directory"; - let downloadLocation: string | undefined; + let downloadLocationURI: vscode.Uri | undefined; if (saveIntoDirectory) { - downloadLocation = (await vscode.window.showOpenDialog({ + downloadLocationURI = (await vscode.window.showOpenDialog({ canSelectMany: false, canSelectFiles: false, canSelectFolders: true, defaultUri: vscode.Uri.file(ibmi.getLastDownloadLocation()) - }))?.[0]?.path; + }))?.[0]; } else { const remoteFilepath = path.join(ibmi.getLastDownloadLocation(), path.basename(node.path)); - downloadLocation = (await vscode.window.showSaveDialog({ + downloadLocationURI = (await vscode.window.showSaveDialog({ defaultUri: vscode.Uri.file(remoteFilepath), filters: { 'Streamfile': [extname(node.path).substring(1) || '*'] } - }))?.path; + })); } - if (downloadLocation) { + if (downloadLocationURI) { + const downloadLocation = downloadLocationURI.path; await ibmi.setLastDownloadLocation(saveIntoDirectory ? downloadLocation : dirname(downloadLocation)); const increment = 100 / items.length; window.withProgress({ title: t('ifsBrowser.downloadStreamfile.downloading'), location: vscode.ProgressLocation.Notification }, async (task) => { @@ -876,7 +877,8 @@ export function initializeIFSBrowser(context: vscode.ExtensionContext) { await ibmi.downloadFile(downloadLocation!, targetPath); } } - vscode.window.showInformationMessage(t(`ifsBrowser.downloadStreamfile.complete`)); + vscode.window.showInformationMessage(t(`ifsBrowser.downloadStreamfile.complete`), t("open")) + .then(open => open ? vscode.commands.executeCommand('revealFileInOS', saveIntoDirectory ? vscode.Uri.joinPath(downloadLocationURI, path.basename(items[0].path)) : downloadLocationURI) : undefined); } catch (e) { vscode.window.showErrorMessage(t(`ifsBrowser.downloadStreamfile.errorMessage`, e)); diff --git a/src/views/objectBrowser.ts b/src/views/objectBrowser.ts index cff7dd610..71c153d3a 100644 --- a/src/views/objectBrowser.ts +++ b/src/views/objectBrowser.ts @@ -823,23 +823,23 @@ export function initializeObjectBrowser(context: vscode.ExtensionContext) { } const saveIntoDirectory = members.length > 1; - let downloadLocation: string | undefined; + let downloadLocationURI: vscode.Uri | undefined; if (saveIntoDirectory) { - downloadLocation = (await vscode.window.showOpenDialog({ + downloadLocationURI = (await vscode.window.showOpenDialog({ canSelectMany: false, canSelectFiles: false, canSelectFolders: true, defaultUri: vscode.Uri.file(connection.getLastDownloadLocation()) - }))?.[0]?.path; + }))?.[0]; } else { - downloadLocation = (await vscode.window.showSaveDialog({ + downloadLocationURI = (await vscode.window.showSaveDialog({ defaultUri: vscode.Uri.file(path.join(connection.getLastDownloadLocation(), members[0].name)), filters: { 'Source member': [members[0].extension || '*'] } - }))?.path; + })); } - if (downloadLocation) { + if (downloadLocationURI) { //Remove double entries and map to { path, copy } object const toBeDownloaded = members .filter((member, index, list) => list.findIndex(m => m.library === member.library && m.file === member.file && m.name === member.name) === index) @@ -847,10 +847,10 @@ export function initializeObjectBrowser(context: vscode.ExtensionContext) { .map(member => ({ path: Tools.qualifyPath(member.library, member.file, member.name, member.asp), name: `${member.name}.${member.extension || "MBR"}`, copy: true })); if (!saveIntoDirectory) { - toBeDownloaded[0].name = basename(downloadLocation); - downloadLocation = dirname(downloadLocation); + toBeDownloaded[0].name = basename(downloadLocationURI.path); } + const downloadLocation = saveIntoDirectory ? downloadLocationURI.path : dirname(downloadLocationURI.path); await connection.setLastDownloadLocation(downloadLocation); //Ask what do to with existing files in the target directory @@ -896,7 +896,8 @@ export function initializeObjectBrowser(context: vscode.ExtensionContext) { task.report({ message: t('objectBrowser.downloadMemberContent.download.streamfiles'), increment: 33 }) await connection.downloadDirectory(downloadLocation!, directory); - vscode.window.showInformationMessage(t(`objectBrowser.downloadMemberContent.infoMessage`)); + vscode.window.showInformationMessage(t(`objectBrowser.downloadMemberContent.infoMessage`), t("open")) + .then(open => open ? vscode.commands.executeCommand('revealFileInOS', saveIntoDirectory ? vscode.Uri.joinPath(downloadLocationURI, toBeDownloaded[0].name) : downloadLocationURI) : undefined); }); } catch (e) { vscode.window.showErrorMessage(t(`objectBrowser.downloadMemberContent.errorMessage`, e));