Skip to content

Commit

Permalink
fix for default workspace folder picker not working
Browse files Browse the repository at this point in the history
  • Loading branch information
David Garcia committed Jun 28, 2022
1 parent 7620920 commit 2594b74
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/pipelineHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ export async function convertPipeline(gitlabFileUri: theia.Uri | undefined): Pro
await theia.window.showTextDocument(outputFile);
theia.window.showInformationMessage("File conversion completed!");
} catch (error) {
theia.window.showErrorMessage('Error: ' + (error as Error).message); error.
console.error(error);
if (error instanceof OperationCanceledError) {
theia.window.showErrorMessage(error.message);
} else {
theia.window.showErrorMessage(`Error: ${(error as Error).message}`);
}
throw error;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/quickPickFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function quickPickJenkinsfileFileItem(fileUri: theia.Uri, rootFolde
});

if (!fileItem) {
throw new Error('No item was selected');
throw new OperationCanceledError('No item was selected');
}
return fileItem;
}
Expand Down
64 changes: 58 additions & 6 deletions src/quickPickWorkspaceFolder.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,68 @@
import * as theia from '@theia/plugin';
import { Disposable, QuickPick, window } from "@theia/plugin";
import { OperationCanceledError } from './Errors';

export interface Item extends theia.QuickPickItem {
actualFolder: theia.WorkspaceFolder;
}

export interface IPickMetadata {
title: string;
placeholder: string;
items: Item[];
}

export async function quickPickWorkspaceFolder(noWorkspacesMessage: string): Promise<theia.WorkspaceFolder> {
if (theia.workspace.workspaceFolders && theia.workspace.workspaceFolders.length === 1) {
return theia.workspace.workspaceFolders[0];
} else if (theia.workspace.workspaceFolders && theia.workspace.workspaceFolders.length > 1) {
const selected = await theia.window.showWorkspaceFolderPick();
if (!selected) {
throw new OperationCanceledError(noWorkspacesMessage);
const items: Item[] = [];
theia.workspace.workspaceFolders.forEach(wsFolder => {
items.push(<Item>{
label: wsFolder.name,
actualFolder: wsFolder
})
})
const fileItem: Item = await quickPickFileItem({
title: "Root folder",
placeholder: "Select a folder/project to work with:",
items: items
});

if (!fileItem) {
throw new OperationCanceledError('No item was selected');
}
return selected;
return fileItem.actualFolder;
} else {
throw new Error(noWorkspacesMessage);
throw new Error("Unexpected workspace status");
}
}

export async function quickPickFileItem(pickMetadata: IPickMetadata): Promise<Item> {
const disposables: Disposable[] = [];
const result: Item = await new Promise<Item>((resolve, reject) => {
const pickBox: QuickPick<Item> = window.createQuickPick<Item>();
pickBox.title = pickMetadata.title;
pickBox.placeholder = pickMetadata.placeholder;
pickBox.items = pickMetadata.items;
pickBox.ignoreFocusOut = true;

disposables.push(
pickBox.onDidAccept(() => {
if (!pickBox.selectedItems[0]) {
return;
}
return resolve(pickBox.selectedItems[0]);
}),
pickBox.onDidHide(() => {
return reject(new OperationCanceledError("No file selected"));
})
);
disposables.push(pickBox);
pickBox.show();
});
for (const d of disposables) {
d.dispose();
}
}
return result;
}

0 comments on commit 2594b74

Please sign in to comment.