Skip to content

Commit

Permalink
add open file button in project config editor
Browse files Browse the repository at this point in the history
  • Loading branch information
brianignacio5 committed Oct 8, 2024
1 parent 3d4e4e4 commit c0a76cf
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ To allow you to have multiple configurations for the same project, you can defin
+-----------------------------------+-------------------------------------------------------------------------------------------+
| **idf.customExtraVars** | Variables to be added to system environment variables |
+-----------------------------------+-------------------------------------------------------------------------------------------+
| **idf.adapterTargetName** | ESP-IDF Target Chip (Example: esp32) |
+-----------------------------------+-------------------------------------------------------------------------------------------+
| **idf.flashBaudRate** | Flash Baud rate |
+-----------------------------------+-------------------------------------------------------------------------------------------+
| **idf.monitorBaudRate** | Monitor Baud Rate (Empty by default to use SDKConfig CONFIG_ESP_CONSOLE_UART_BAUDRATE) |
Expand Down
22 changes: 22 additions & 0 deletions src/project-conf/projectConfPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ export class projectConfigurationPanel {
});
}
break;
case "openFilePath":
let selectedFile = await this.openFile();
if (selectedFile) {
this.panel.webview.postMessage({
command: "setFilePath",
confKey: message.confKey,
newPath: selectedFile,
sectionsKeys: message.sectionsKeys,
});
}
break;
default:
break;
}
Expand All @@ -137,6 +148,17 @@ export class projectConfigurationPanel {
}
}

private async openFile() {
const selectedFile = await window.showOpenDialog({
canSelectFolders: false,
canSelectFiles: true,
canSelectMany: false,
});
if (selectedFile && selectedFile.length > 0) {
return selectedFile[0].fsPath;
}
}

private clearSelectedProject(projectKeys: string[]) {
const selectedConfig = ESP.ProjectConfiguration.store.get<string>(
ESP.ProjectConfiguration.SELECTED_CONFIG
Expand Down
15 changes: 5 additions & 10 deletions src/views/project-conf/components/projectConfElem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ const openOcdDebugLevelOptions: { name: string; value: number }[] = [
{ name: "Verbose", value: 4 },
];
const idfTargets: { name: string; value: string }[] = [
{ name: "esp32", value: "esp32" },
{ name: "ESP32 S2", value: "esp32s2" },
{ name: "ESP32 S3", value: "esp32s3" },
{ name: "ESP32 C2", value: "esp32c2" },
{ name: "ESP32 C3", value: "esp32c3" },
{ name: "ESP32 C6", value: "esp32c6" },
{ name: "ESP32 H2", value: "esp32h2" },
];
function updateElement(sections: string[], newValue: any) {
store.updateConfigElement({ confKey: props.title, sections, newValue });
}
Expand All @@ -39,6 +29,10 @@ function openBuildDir(sections: string[]) {
store.openBuildPath({ confKey: props.title, sections });
}
function openFilePath(sections: string[]) {
store.openFilePath({ confKey: props.title, sections });
}
function addValueToArray(sections: string[], newValue: any) {
store.addValueToConfigElement({
confKey: props.title,
Expand Down Expand Up @@ -93,6 +87,7 @@ function removeValueFromArray(sections: string[], index: number) {
"
:sections="['build', 'sdkconfigFilePath']"
:updateMethod="updateElement"
:openMethod="openFilePath"
/>
</div>
<DictionaryElement
Expand Down
17 changes: 13 additions & 4 deletions src/views/project-conf/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* Project: ESP-IDF VSCode Extension
* File Created: Thursday, 31st August 2023 12:31:23 pm
* Copyright 2023 Espressif Systems (Shanghai) CO LTD
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -41,11 +41,20 @@ window.addEventListener("message", (event: MessageEvent) => {
});
}
break;
case "setFilePath":
if (msg.confKey) {
store.updateConfigElement({
confKey: msg.confKey,
sections: msg.sectionsKeys,
newValue: msg.newPath,
});
}
break;
case "initialLoad":
if (msg.confList) {
store.elements = msg.confList;
}
default:
break;
}
});
});
9 changes: 9 additions & 0 deletions src/views/project-conf/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export const useProjectConfStore = defineStore("project-config", () => {
});
}

function openFilePath(payload: { confKey: string; sections: string[] }) {
vscode.postMessage({
command: "openFilePath",
sectionsKeys: payload.sections,
confKey: payload.confKey,
});
}

function addNewConfigToList(confKey: string) {
let newConf = {
build: {
Expand Down Expand Up @@ -174,6 +182,7 @@ export const useProjectConfStore = defineStore("project-config", () => {
addNewConfigToList,
addValueToConfigElement,
openBuildPath,
openFilePath,
updateConfigElement,
removeValueFromConfigElement,
requestInitValues,
Expand Down

0 comments on commit c0a76cf

Please sign in to comment.