-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for default workspace folder picker not working
- Loading branch information
David Garcia
committed
Jun 28, 2022
1 parent
7620920
commit 2594b74
Showing
3 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |