Skip to content

Commit c03deb4

Browse files
authored
Remember last used local folder for server-side import/export (#1510)
1 parent 0dceb03 commit c03deb4

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/commands/compile.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
handleError,
2626
isClassDeployed,
2727
isClassOrRtn,
28+
lastUsedLocalUri,
2829
notIsfs,
2930
notNull,
3031
outputChannel,
@@ -649,7 +650,7 @@ export async function importLocalFilesToServerSideFolder(wsFolderUri: vscode.Uri
649650
}
650651
const api = new AtelierAPI(wsFolderUri);
651652
// Get the default URI and remove the file anme
652-
let defaultUri = vscode.workspace.workspaceFile;
653+
let defaultUri = lastUsedLocalUri() ?? vscode.workspace.workspaceFile;
653654
defaultUri = defaultUri.with({ path: defaultUri.path.split("/").slice(0, -1).join("/") });
654655
// Prompt the user for files to import
655656
let uris = await vscode.window.showOpenDialog({
@@ -674,6 +675,7 @@ export async function importLocalFilesToServerSideFolder(wsFolderUri: vscode.Uri
674675
vscode.window.showErrorMessage("No classes or routines were selected.", "Dismiss");
675676
return;
676677
}
678+
lastUsedLocalUri(uris[0]);
677679
// Get the name and content of the files to import
678680
const textDecoder = new TextDecoder();
679681
const docs = await Promise.allSettled<{ name: string; content: string; uri: vscode.Uri }>(
@@ -777,7 +779,7 @@ export async function importXMLFiles(): Promise<any> {
777779
if (defaultUri.scheme == FILESYSTEM_SCHEMA) {
778780
// Need a default URI without the isfs scheme or the open dialog
779781
// will show the server-side files instead of local ones
780-
defaultUri = vscode.workspace.workspaceFile;
782+
defaultUri = lastUsedLocalUri() ?? vscode.workspace.workspaceFile;
781783
if (defaultUri.scheme != "file") {
782784
vscode.window.showErrorMessage(
783785
"'Import XML Files...' command is not supported for unsaved workspaces.",
@@ -809,6 +811,7 @@ export async function importXMLFiles(): Promise<any> {
809811
vscode.window.showErrorMessage("No XML files were selected.", "Dismiss");
810812
return;
811813
}
814+
lastUsedLocalUri(uris[0]);
812815
// Read the XML files
813816
const fileTimestamps: Map<string, string> = new Map();
814817
const filesToList = await Promise.allSettled(

src/commands/export.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
getWsFolder,
99
handleError,
1010
isClassOrRtn,
11+
lastUsedLocalUri,
1112
notNull,
1213
outputChannel,
1314
RateLimiter,
@@ -322,7 +323,7 @@ export async function exportDocumentsToXMLFile(): Promise<void> {
322323
if (schemas.includes(defaultUri.scheme)) {
323324
// Need a default URI without the isfs scheme or the save dialog
324325
// will show the virtual files from the workspace folder
325-
defaultUri = vscode.workspace.workspaceFile;
326+
defaultUri = lastUsedLocalUri() ?? vscode.workspace.workspaceFile;
326327
if (defaultUri.scheme != "file") {
327328
vscode.window.showErrorMessage(
328329
"'Export Documents to XML File...' command is not supported for unsaved workspaces.",
@@ -351,6 +352,7 @@ export async function exportDocumentsToXMLFile(): Promise<void> {
351352
defaultUri,
352353
});
353354
if (uri) {
355+
lastUsedLocalUri(uri);
354356
// Get the XML content
355357
const xmlContent = await api.actionXMLExport(documents).then((data) => data.result.content);
356358
// Save the file

src/utils/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,14 @@ export function queryToFuzzyLike(query: string): string {
943943
return p;
944944
}
945945

946+
let _lastUsedLocalUri: vscode.Uri;
947+
948+
/** Get or set the uri of last used local file for XML import/export or local file import from an `isfs(-readonly)` workspace folder */
949+
export function lastUsedLocalUri(newValue?: vscode.Uri): vscode.Uri {
950+
if (newValue) _lastUsedLocalUri = newValue;
951+
return _lastUsedLocalUri;
952+
}
953+
946954
class Semaphore {
947955
/** Queue of tasks waiting to acquire the semaphore */
948956
private _tasks: (() => void)[] = [];

0 commit comments

Comments
 (0)