Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action to open location after download of members/streamfiles #2224

Merged
merged 1 commit into from
Aug 23, 2024
Merged
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 src/locale/ids/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/locale/ids/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/locale/ids/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/locale/ids/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/locale/ids/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 10 additions & 8 deletions src/views/ifsBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) => {
Expand Down Expand Up @@ -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));
Expand Down
19 changes: 10 additions & 9 deletions src/views/objectBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,34 +823,34 @@ 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)
.sort((m1, m2) => m1.name.localeCompare(m2.name))
.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
Expand Down Expand Up @@ -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));
Expand Down