Skip to content

Commit

Permalink
fix: providing selected project in explorer instead of first open pro…
Browse files Browse the repository at this point in the history
…ject (#1096)
  • Loading branch information
sigmaaa authored Dec 13, 2024
1 parent b4631fb commit 0e2151b
Showing 1 changed file with 4 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
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;

import com.espressif.idf.ui.EclipseUtil;

public class OpenSdkConfigEditor extends AbstractHandler
{

Expand All @@ -22,7 +22,7 @@ public class OpenSdkConfigEditor extends AbstractHandler
public Object execute(ExecutionEvent event) throws ExecutionException
{
IWorkbenchPage page = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
IProject project = getCurrentProject();
IProject project = EclipseUtil.getSelectedProjectInExplorer();
try
{
IFile sdkConfigFile = project.getFile(SDKCONFIG_FILE_NAME);
Expand All @@ -43,21 +43,4 @@ public Object execute(ExecutionEvent event) throws ExecutionException

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;
}
}
}

0 comments on commit 0e2151b

Please sign in to comment.