From 68355718d6f31cbda86f3ae32007381a818c6796 Mon Sep 17 00:00:00 2001 From: Ali Azam Rana <85216275+alirana01@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:46:20 +0200 Subject: [PATCH] fix(menuconfig): add menuconfig option in ESP-IDF menu --- .../plugin.xml | 11 ++++ .../espressif/idf/sdk/config/ui/Messages.java | 2 + .../sdk/config/ui/OpenSdkConfigEditor.java | 63 +++++++++++++++++++ .../idf/sdk/config/ui/messages.properties | 2 + 4 files changed, 78 insertions(+) create mode 100644 bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/OpenSdkConfigEditor.java diff --git a/bundles/com.espressif.idf.sdk.config.ui/plugin.xml b/bundles/com.espressif.idf.sdk.config.ui/plugin.xml index 5a5322a7a..4ea7e54c7 100644 --- a/bundles/com.espressif.idf.sdk.config.ui/plugin.xml +++ b/bundles/com.espressif.idf.sdk.config.ui/plugin.xml @@ -39,6 +39,12 @@ + + + + diff --git a/bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/Messages.java b/bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/Messages.java index abeec55f3..f61856094 100644 --- a/bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/Messages.java +++ b/bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/Messages.java @@ -27,6 +27,8 @@ public class Messages extends NLS public static String SDKConfigurationEditor_SDKConfiguration; public static String SDKConfigurationEditor_StartingJSONConfigServer; public static String SDKConfigurationEditor_UnableFindKConfigFile; + public static String SDKConfigFileNotFound_ErrorMessage; + public static String SDKConfigurationFileNotFound_Title; static { // initialize resource bundle diff --git a/bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/OpenSdkConfigEditor.java b/bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/OpenSdkConfigEditor.java new file mode 100644 index 000000000..3cc59cca4 --- /dev/null +++ b/bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/OpenSdkConfigEditor.java @@ -0,0 +1,63 @@ +package com.espressif.idf.sdk.config.ui; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.ide.IDE; + +public class OpenSdkConfigEditor extends AbstractHandler +{ + + private static final String SDKCONFIG_FILE_NAME = "sdkconfig"; + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException + { + IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); + IProject project = getCurrentProject(); + try + { + IFile sdkConfigFile = project.getFile(SDKCONFIG_FILE_NAME); + if (sdkConfigFile.exists()) + { + IDE.openEditor(page, sdkConfigFile); + } + else + { + MessageDialog.openError(HandlerUtil.getActiveShell(event), Messages.SDKConfigurationFileNotFound_Title, + Messages.SDKConfigFileNotFound_ErrorMessage); + } + } + catch (CoreException e) + { + throw new ExecutionException("Error opening sdkconfig file", e); + } + + return null; + } + + /** + * Get the currently selected project in the workspace. + */ + private IProject getCurrentProject() + { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IProject[] projects = root.getProjects(); + for (IProject project : projects) + { + if (project.isOpen() && project.getFile(SDKCONFIG_FILE_NAME).exists()) + { + return project; + } + } + return null; + } +} \ No newline at end of file diff --git a/bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/messages.properties b/bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/messages.properties index dc2f386ba..ab73a7c97 100644 --- a/bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/messages.properties +++ b/bundles/com.espressif.idf.sdk.config.ui/src/com/espressif/idf/sdk/config/ui/messages.properties @@ -16,3 +16,5 @@ SDKConfigurationEditor_SaveChanges=Do you want to save the changes in the Design SDKConfigurationEditor_SDKConfiguration=SDK Configuration SDKConfigurationEditor_StartingJSONConfigServer=Starting JSON Configuration Server SDKConfigurationEditor_UnableFindKConfigFile=Unable to find kconfig_menus.json in the build config folder.\n +SDKConfigFileNotFound_ErrorMessage=No sdkconfig file found in the project. +SDKConfigurationFileNotFound_Title=sdkconfig missing \ No newline at end of file