Skip to content

Commit

Permalink
Use contents of folder textbox as default folder for file dialog (wpi…
Browse files Browse the repository at this point in the history
  • Loading branch information
wpineth committed Mar 29, 2024
1 parent 7e6c044 commit 73ac0a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 13 additions & 1 deletion vscode-wpilib/src/webviews/pages/projectcreatorpage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,19 @@ function selectProjectBase() {

function selectProjectFolder() {
(document.activeElement as HTMLElement).blur();
vscode.postMessage({ type: 'newproject' });
vscode.postMessage({
type: 'newproject',
data: {
base: '',
desktop: false,
language,
newFolder: false,
projectName: '',
projectType,
teamNumber: '',
toFolder: (document.getElementById('projectFolder') as HTMLInputElement).value,
}
});
}

function generateProject() {
Expand Down
8 changes: 6 additions & 2 deletions vscode-wpilib/src/webviews/projectcreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { setDesktopEnabled } from '../shared/generator';
import { extensionContext, promptForProjectOpen } from '../utilities';
import { IProjectIPCData, IProjectIPCReceive, IProjectIPCSend, ProjectType } from './pages/projectcreatorpagetypes';
import { WebViewBase } from './webviewbase';
import { Uri } from '../vscodeshim';

export class ProjectCreator extends WebViewBase {
public static async Create(exampleTemplateApi: IExampleTemplateAPI, resourceRoot: string): Promise<ProjectCreator> {
Expand All @@ -31,7 +32,9 @@ export class ProjectCreator extends WebViewBase {
this.webview.webview.onDidReceiveMessage(async (data: IProjectIPCReceive) => {
switch (data.type) {
case 'newproject':
await this.handleNewProjectLoc();
if (data.data) {
await this.handleNewProjectLoc(data.data);
}
break;
case 'projecttype':
await this.handleProjectType();
Expand Down Expand Up @@ -130,12 +133,13 @@ export class ProjectCreator extends WebViewBase {
}
}

private async handleNewProjectLoc() {
private async handleNewProjectLoc(data: IProjectIPCData) {
const open: vscode.OpenDialogOptions = {
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
openLabel: i18n('ui', 'Select Folder'),
defaultUri: data.toFolder.length > 0 ? Uri.file(data.toFolder) : undefined
};
const result = await vscode.window.showOpenDialog(open);

Expand Down

0 comments on commit 73ac0a9

Please sign in to comment.