Skip to content

Remember last used local folder for server-side import/export #1510

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

Merged
merged 1 commit into from
Mar 12, 2025
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
7 changes: 5 additions & 2 deletions src/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
handleError,
isClassDeployed,
isClassOrRtn,
lastUsedLocalUri,
notIsfs,
notNull,
outputChannel,
Expand Down Expand Up @@ -649,7 +650,7 @@ export async function importLocalFilesToServerSideFolder(wsFolderUri: vscode.Uri
}
const api = new AtelierAPI(wsFolderUri);
// Get the default URI and remove the file anme
let defaultUri = vscode.workspace.workspaceFile;
let defaultUri = lastUsedLocalUri() ?? vscode.workspace.workspaceFile;
defaultUri = defaultUri.with({ path: defaultUri.path.split("/").slice(0, -1).join("/") });
// Prompt the user for files to import
let uris = await vscode.window.showOpenDialog({
Expand All @@ -674,6 +675,7 @@ export async function importLocalFilesToServerSideFolder(wsFolderUri: vscode.Uri
vscode.window.showErrorMessage("No classes or routines were selected.", "Dismiss");
return;
}
lastUsedLocalUri(uris[0]);
// Get the name and content of the files to import
const textDecoder = new TextDecoder();
const docs = await Promise.allSettled<{ name: string; content: string; uri: vscode.Uri }>(
Expand Down Expand Up @@ -777,7 +779,7 @@ export async function importXMLFiles(): Promise<any> {
if (defaultUri.scheme == FILESYSTEM_SCHEMA) {
// Need a default URI without the isfs scheme or the open dialog
// will show the server-side files instead of local ones
defaultUri = vscode.workspace.workspaceFile;
defaultUri = lastUsedLocalUri() ?? vscode.workspace.workspaceFile;
if (defaultUri.scheme != "file") {
vscode.window.showErrorMessage(
"'Import XML Files...' command is not supported for unsaved workspaces.",
Expand Down Expand Up @@ -809,6 +811,7 @@ export async function importXMLFiles(): Promise<any> {
vscode.window.showErrorMessage("No XML files were selected.", "Dismiss");
return;
}
lastUsedLocalUri(uris[0]);
// Read the XML files
const fileTimestamps: Map<string, string> = new Map();
const filesToList = await Promise.allSettled(
Expand Down
4 changes: 3 additions & 1 deletion src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getWsFolder,
handleError,
isClassOrRtn,
lastUsedLocalUri,
notNull,
outputChannel,
RateLimiter,
Expand Down Expand Up @@ -322,7 +323,7 @@ export async function exportDocumentsToXMLFile(): Promise<void> {
if (schemas.includes(defaultUri.scheme)) {
// Need a default URI without the isfs scheme or the save dialog
// will show the virtual files from the workspace folder
defaultUri = vscode.workspace.workspaceFile;
defaultUri = lastUsedLocalUri() ?? vscode.workspace.workspaceFile;
if (defaultUri.scheme != "file") {
vscode.window.showErrorMessage(
"'Export Documents to XML File...' command is not supported for unsaved workspaces.",
Expand Down Expand Up @@ -351,6 +352,7 @@ export async function exportDocumentsToXMLFile(): Promise<void> {
defaultUri,
});
if (uri) {
lastUsedLocalUri(uri);
// Get the XML content
const xmlContent = await api.actionXMLExport(documents).then((data) => data.result.content);
// Save the file
Expand Down
8 changes: 8 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,14 @@ export function queryToFuzzyLike(query: string): string {
return p;
}

let _lastUsedLocalUri: vscode.Uri;

/** Get or set the uri of last used local file for XML import/export or local file import from an `isfs(-readonly)` workspace folder */
export function lastUsedLocalUri(newValue?: vscode.Uri): vscode.Uri {
if (newValue) _lastUsedLocalUri = newValue;
return _lastUsedLocalUri;
}

class Semaphore {
/** Queue of tasks waiting to acquire the semaphore */
private _tasks: (() => void)[] = [];
Expand Down