From ee9c7478309762ddc21e21f946da0dcda04d7e59 Mon Sep 17 00:00:00 2001 From: sciencewhiz Date: Sat, 16 Nov 2024 19:04:34 -0800 Subject: [PATCH] Add option to importer to import XRP project --- .../resources/webviews/gradle2020import.html | 7 +++++++ .../src/webviews/gradle2020import.ts | 4 ++-- .../webviews/pages/gradle2020importpage.ts | 8 ++++++-- .../pages/gradle2020importpagetypes.ts | 1 + .../src/webviews/pages/sharedpages.ts | 19 +++++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/vscode-wpilib/resources/webviews/gradle2020import.html b/vscode-wpilib/resources/webviews/gradle2020import.html index 6e4d6bf8..138c4c9b 100644 --- a/vscode-wpilib/resources/webviews/gradle2020import.html +++ b/vscode-wpilib/resources/webviews/gradle2020import.html @@ -64,6 +64,13 @@

Welcome to WPILib 2020-2024 Project Importer

Check this if the project being imported is a romi project. This is not autodetected, and must be selected manually.
+
+ Import XRP Project + +
+ Check this if the project being imported is an XRP project. This is not autodetected, and must be selected manually. +
+
diff --git a/vscode-wpilib/src/webviews/gradle2020import.ts b/vscode-wpilib/src/webviews/gradle2020import.ts index 016c56ee..0217b4ee 100644 --- a/vscode-wpilib/src/webviews/gradle2020import.ts +++ b/vscode-wpilib/src/webviews/gradle2020import.ts @@ -245,11 +245,11 @@ export class Gradle2020Import extends WebViewBase { let success = false; if (cpp) { - const gradlePath = path.join(gradleBasePath, data.romi ? 'cppromi' : 'cpp'); + const gradlePath = path.join(gradleBasePath, data.romi ? 'cppromi' : data.xrp ? 'cppxrp': 'cpp'); success = await generateCopyCpp(path.join(resourceRoot, 'cpp'), path.join(oldProjectPath, 'src'), undefined, gradlePath, toFolder, true, []); } else { - const gradlePath = path.join(gradleBasePath, data.romi ? 'javaromi' : 'java'); + const gradlePath = path.join(gradleBasePath, data.romi ? 'javaromi' : data.xrp ? 'javaxrp' : 'java'); success = await generateCopyJava(path.join(resourceRoot, 'java'), path.join(oldProjectPath, 'src'), undefined, gradlePath, toFolder, javaRobotPackage, '', true, []); } diff --git a/vscode-wpilib/src/webviews/pages/gradle2020importpage.ts b/vscode-wpilib/src/webviews/pages/gradle2020importpage.ts index 986af95b..45cb0966 100644 --- a/vscode-wpilib/src/webviews/pages/gradle2020importpage.ts +++ b/vscode-wpilib/src/webviews/pages/gradle2020importpage.ts @@ -1,7 +1,7 @@ 'use strict'; import { IGradle2020IPCReceive, IGradle2020IPCSend } from './gradle2020importpagetypes'; -import { validateProject, validateTeamNumber, validateProjectFolder } from './sharedpages'; +import { validateProject, validateTeamNumber, validateProjectFolder, validateXrpRomi } from './sharedpages'; interface IVsCodeApi { postMessage(message: IGradle2020IPCReceive): void; @@ -25,7 +25,8 @@ function importProjectButtonClick() { const isValidTeam = validateTeamNumber(); const isValidProject = validateProject(); const isValidFolder = validateProjectFolder(); - if (!isValidTeam || !isValidProject || !isValidFolder) { + const isXrpRomiValid = validateXrpRomi(); + if (!isValidTeam || !isValidProject || !isValidFolder || !isXrpRomiValid) { return; } @@ -34,6 +35,7 @@ function importProjectButtonClick() { data: { desktop: (document.getElementById('desktopCB') as HTMLInputElement).checked, romi: (document.getElementById('romiCB') as HTMLInputElement).checked, + xrp: (document.getElementById('xrpCB') as HTMLInputElement).checked, fromProps: (document.getElementById('gradle2020Input') as HTMLInputElement).value, newFolder: (document.getElementById('newFolderCB') as HTMLInputElement).checked, projectName: (document.getElementById('projectName') as HTMLInputElement).value, @@ -78,6 +80,8 @@ window.addEventListener('load', (_: Event) => { document.getElementById('teamNumber')!.oninput = validateTeamNumber; document.getElementById('importProject')!.onclick = importProjectButtonClick; document.getElementById('projectFolder')!.oninput = validateProjectFolder; + document.getElementById('romiCB')!.onchange = validateXrpRomi; + document.getElementById('xrpCB')!.onchange = validateXrpRomi; vscode.postMessage({ type: 'loaded' }); }); diff --git a/vscode-wpilib/src/webviews/pages/gradle2020importpagetypes.ts b/vscode-wpilib/src/webviews/pages/gradle2020importpagetypes.ts index ade3bf99..dc23f72c 100644 --- a/vscode-wpilib/src/webviews/pages/gradle2020importpagetypes.ts +++ b/vscode-wpilib/src/webviews/pages/gradle2020importpagetypes.ts @@ -3,6 +3,7 @@ export interface IGradle2020IPCData { desktop: boolean; romi: boolean; + xrp: boolean; fromProps: string; toFolder: string; projectName: string; diff --git a/vscode-wpilib/src/webviews/pages/sharedpages.ts b/vscode-wpilib/src/webviews/pages/sharedpages.ts index 74d35559..7ad4304b 100644 --- a/vscode-wpilib/src/webviews/pages/sharedpages.ts +++ b/vscode-wpilib/src/webviews/pages/sharedpages.ts @@ -44,6 +44,25 @@ export function validateProjectFolder(): boolean { } } +export function validateXrpRomi(): boolean { + const romiCB = document.getElementById('romiCB') as HTMLInputElement; + const romiCBValue = romiCB.checked; + const xrpCB = document.getElementById('xrpCB') as HTMLInputElement; + const xrpCBValue = xrpCB.checked; + + const romiDiv = document.getElementById('romidiv') as HTMLDivElement; + const xrpDiv = document.getElementById('xrpdiv') as HTMLDivElement; + if (romiCBValue === true && xrpCBValue === true) { + romiDiv.classList.add('error'); + xrpDiv.classList.add('error'); + return false; + } else { + romiDiv.classList.remove('error'); + xrpDiv.classList.remove('error'); + return true; + } +} + export function validateTeamNumber(): boolean { const elem = document.getElementById('teamNumber') as HTMLInputElement; const s = elem.value;