Skip to content

Commit

Permalink
fix(menuconfig): add menuconfig option in ESP-IDF menu (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
alirana01 committed Sep 24, 2024
1 parent e574281 commit 0917e35
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bundles/com.espressif.idf.sdk.config.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
</reference>
</visibleWhen>
</command>
<command
commandId="com.espressif.idf.sdk.config.ui.command.menuConfig"
icon="icons/sdkconfig.png"
label="Menu Config"
style="push">
</command>
</menuContribution>
</extension>
<extension
Expand All @@ -48,6 +54,11 @@
id="com.espressif.idf.sdk.config.ui.command.setdefault"
name="%command.name">
</command>
<command
defaultHandler="com.espressif.idf.sdk.config.ui.OpenSdkConfigEditor"
id="com.espressif.idf.sdk.config.ui.command.menuConfig"
name="Open MenuConfig">
</command>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0917e35

Please sign in to comment.