diff --git a/src/webview/newProjectPanel.mts b/src/webview/newProjectPanel.mts index 80e7c2ad..7e4540a4 100644 --- a/src/webview/newProjectPanel.mts +++ b/src/webview/newProjectPanel.mts @@ -61,7 +61,7 @@ import { } from "../utils/examplesUtil.mjs"; export const NINJA_AUTO_INSTALL_DISABLED = false; - // process.platform === "linux" && process.arch === "arm64"; +// process.platform === "linux" && process.arch === "arm64"; export const picotoolVersion = "2.0.0"; export const openOCDVersion = "0.12.0+dev"; @@ -165,10 +165,7 @@ enum Debugger { swd = "SWD (Pi host)", } -async function enumToBoard( - e: BoardType, - sdkPath: string -): Promise { +async function enumToBoard(e: BoardType, sdkPath: string): Promise { const quickPickItems: string[] = []; let board; switch (e) { @@ -1501,11 +1498,24 @@ export class NewProjectPanel {
` @@ -1885,14 +1895,18 @@ export class NewProjectPanel { options: ExecOptions ): Promise { return new Promise(resolve => { - const generatorProcess = exec(command, options, (error, stdout, stderr) => { - this._logger.debug(stdout); - this._logger.info(stderr); - if (error) { - this._logger.error(`Generator Process error: ${error.message}`); - resolve(null); // indicate error + const generatorProcess = exec( + command, + options, + (error, stdout, stderr) => { + this._logger.debug(stdout); + this._logger.info(stderr); + if (error) { + this._logger.error(`Generator Process error: ${error.message}`); + resolve(null); // indicate error + } } - }); + ); generatorProcess.on("exit", code => { // Resolve with exit code or -1 if code is undefined @@ -1940,18 +1954,37 @@ export class NewProjectPanel { : "" }${isWindows ? ";" : ":"}${customEnv[isWindows ? "Path" : "PATH"]}`; + // convert the selected board type to a vaild option + // for the project generator + let boardTypeFromEnum = ""; + if ("boardType" in options) { + try { + boardTypeFromEnum = await enumToBoard( + options.boardType === BoardType.default + ? BoardType.pico + : options.boardType, + options.toolchainAndSDK.sdkPath + ); + } catch (error) { + await window.showErrorMessage( + "Unknown board type: " + options.boardType + ); + return; + } + } + const basicNewProjectOptions: string[] = "consoleOptions" in options ? [ - await enumToBoard(options.boardType, options.toolchainAndSDK.sdkPath), + boardTypeFromEnum, ...options.consoleOptions.map(option => enumToParam(option)), !options.consoleOptions.includes(ConsoleOption.consoleOverUART) ? "-nouart" : "", ] : "boardType" in options && options.boardType !== BoardType.default - ? [await enumToBoard(options.boardType, options.toolchainAndSDK.sdkPath)] - : []; + ? [boardTypeFromEnum] + : []; if (!("boardType" in options) && this._isProjectImport) { try { const cmakel = await readFile( @@ -1971,11 +2004,7 @@ export class NewProjectPanel { } catch { /* ignore */ } - } else if ( - ("boardType" in options) && - isExampleBased && - "name" in options - ) { + } else if ("boardType" in options && isExampleBased && "name" in options) { if (options.boardType === BoardType.default) { if (options.name.includes("picow") || options.name.includes("pico_w")) { basicNewProjectOptions.push(`-board pico_w`); diff --git a/web/main.js b/web/main.js index 0e4a8d1a..5ed13a7a 100644 --- a/web/main.js +++ b/web/main.js @@ -450,12 +450,26 @@ var isPicoWireless = false; var selectedIndex = getIndexByValue(toolchainSelector, result.toolchainVersion); if (result.riscvToolchainVersion === "NONE") { - document.getElementById("sel-pico2").hidden = true; - if (document.getElementById('sel-board-type').selectedIndex > 1) { - document.getElementById('sel-board-type').selectedIndex = 0; + document.getElementById("sel-pico2").disabled = true; + const boardTypeSelector = document.getElementById('sel-board-type'); + + if (boardTypeSelector && boardTypeSelector.value.includes("pico2")) { + // first element could be hidden + //document.getElementById('sel-board-type').selectedIndex = 0; + + // select first not hidden option + for (let i = 0; i < boardTypeSelector.options.length; i++) { + const option = boardTypeSelector.options[i]; + + // Check if the option is not hidden + if (option.style.display !== 'none' && option.hidden === false) { + boardTypeSelector.selectedIndex = i; + break; + } + } } } else { - document.getElementById("sel-pico2").hidden = false; + document.getElementById("sel-pico2").disabled = false; } var riscv = document.getElementById("sel-riscv").checked; @@ -569,8 +583,9 @@ var isPicoWireless = false; document.getElementById('btn-create').addEventListener('click', submitBtnClick); const selectBoardTypeElement = document.getElementById('sel-board-type'); if (selectBoardTypeElement) { - selectBoardTypeElement.addEventListener('change', function () { + selectBoardTypeElement.addEventListener('change', function (event) { try { + // TODO: fix not very future proof for different model naming const isPicoWireless = selectBoardTypeElement.value.endsWith('w'); if (!isPicoWireless) { diff --git a/web/nav.js b/web/nav.js index 77c95cd7..f3301221 100644 --- a/web/nav.js +++ b/web/nav.js @@ -108,6 +108,7 @@ window.toggleCreateFromExampleMode = function (forceOn, forceOff) { const examplesList = document.getElementById('examples-list'); const projectNameGrid = document.getElementById('project-name-grid'); const projectNameDropdownButton = document.getElementById('project-name-dropdown-button'); + const defaultBoardTypeOption = document.getElementById('sel-default'); if (isExampleMode && (forceOn === undefined || !forceOn) && (forceOff === undefined || forceOff)) { if (createFromExampleBtn) { @@ -121,6 +122,29 @@ window.toggleCreateFromExampleMode = function (forceOn, forceOff) { //projectNameInput.required = true; } + if (defaultBoardTypeOption) { + defaultBoardTypeOption.hidden = true; + defaultBoardTypeOption.disabled = true; + + // if selected switch selection to first not hidden option + if (defaultBoardTypeOption.selected) { + const boardTypeSelector = document.getElementById('sel-board-type'); + + if (boardTypeSelector) { + // select first not hidden option + for (let i = 0; i < boardTypeSelector.options.length; i++) { + const option = boardTypeSelector.options[i]; + + // Check if the option is not hidden + if (option.style.display !== 'none' && option.hidden === false) { + boardTypeSelector.selectedIndex = i; + break; + } + } + } + } + } + if (projectNameInput) { // old datalist approach: projectNameInput.setAttribute('list', undefined); // remove keyup event listener from projectNameInput if it exists @@ -154,6 +178,12 @@ window.toggleCreateFromExampleMode = function (forceOn, forceOff) { //projectNameInput.setAttribute('list', "examples-list"); projectNameInput.setAttribute('placeholder', 'Select an example'); + if (defaultBoardTypeOption) { + defaultBoardTypeOption.hidden = false; + defaultBoardTypeOption.disabled = false; + defaultBoardTypeOption.selected = true; + } + window.removeExampleItems = window.removeExampleItems || function () { if (examplesList !== null) { // clear ul @@ -303,6 +333,24 @@ window.onload = function () { createFromExampleBtn.classList.add('hidden'); } toggleCreateFromExampleMode(true); + } else { + // hide if not force from example + const defaultBoardTypeOption = document.getElementById('sel-default'); + if (defaultBoardTypeOption) { + defaultBoardTypeOption.hidden = true; + defaultBoardTypeOption.disabled = true; + } + } + + // TODO: maybe can remove if sel-pico2 disable is moved into state restore + const sdkSelector = document.getElementById('sel-pico-sdk'); + if (sdkSelector) { + if (parseInt(sdkSelector.value.split(".")[0]) < 2) { + const selPico2 = document.getElementById('sel-pico2'); + if (selPico2) { + selPico2.disabled = true; + } + } } const burgerMenu = document.getElementById("burger-menu"); diff --git a/web/state.js b/web/state.js index 34ad04c4..af7ee03f 100644 --- a/web/state.js +++ b/web/state.js @@ -29,6 +29,7 @@ class State { cppCodeGen; cppRttiCodeGen; cppExceptionsCodeGen; + selRiscv; debuggerSelection; // special ui only state @@ -47,14 +48,18 @@ function restoreState(state) { /*if (state.projectLocation) { document.getElementById('inp-project-location').value = state.projectLocation; }*/ + // TODO: currently must be restorted before board type because otherwise + // the change of board type would trigger the change listener sending version bundle message + // this would undisable the pico2 board type and it does not get disabled again in the loading + // So maybe restore the board type disable state after restoring the state to avaoid these conflicts + if (state.selectedSDK) { + document.getElementById('sel-pico-sdk').value = state.selectedSDK; + } if (state.boardType) { document.getElementById('sel-board-type').value = state.boardType; // trigger change event to update the ui based on the selected board document.getElementById('sel-board-type').dispatchEvent(new Event('change')); } - if (state.selectedSDK) { - document.getElementById('sel-pico-sdk').value = state.selectedSDK; - } if (state.selectedToolchain) { document.getElementById('sel-toolchain').value = state.selectedToolchain; } @@ -381,6 +386,9 @@ function setupStateSystem(vscode) { case "cpp-exceptions-code-gen-cblist": state.cppExceptionsCodeGen = checkbox.checked; break; + case "sel-riscv": + state.selRiscv = checkbox.checked; + break; } vscode.setState(state);