Skip to content

Commit 2bf9d47

Browse files
Merge branch 'master' into IEP-1649
2 parents 17da11c + ca94528 commit 2bf9d47

File tree

34 files changed

+2064
-348
lines changed

34 files changed

+2064
-348
lines changed

.codespellrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[codespell]
2+
skip = _build
3+
ignore-words-list = laf,OT,hart,EHEN,targetIn,dout,DOUT,oen,OEN,EMAC,emac,doubleClick,AfterAll
4+
write-changes = true

.github/workflows/pre-commit.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ jobs:
2222
- name: Install pre-commit
2323
run: pip install pre-commit
2424

25+
- name: Install codespell
26+
run: pip install codespell
27+
28+
- name: Run pre-commit checks
29+
run: |
30+
BASE_SHA=${{ github.event.pull_request.base.sha }}
31+
HEAD_SHA=${{ github.event.pull_request.head.sha }}
32+
CHANGED_FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA | grep -E '\.(py|c|h|md|rst|yml)$' || true)
33+
echo "Changed files:"
34+
echo "$CHANGED_FILES" | tr ' ' '\n'
35+
if [ -n "$CHANGED_FILES" ]; then
36+
pre-commit run --files $CHANGED_FILES -v
37+
else
38+
echo "No matching files changed."
39+
fi
40+
2541
- name: Validate commit messages
2642
run: |
2743
if [ "${{ github.event_name }}" = "pull_request" ]; then

.pre-commit-config.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@
99
rev: v1.2.1
1010
hooks:
1111
- id: conventional-precommit-linter
12-
stages: [commit-msg]
12+
stages: [commit-msg]
13+
14+
- repo: https://github.com/codespell-project/codespell
15+
rev: v2.4.1
16+
hooks:
17+
- id: codespell
18+
stages: [pre-commit]
19+
args: [--config=.codespellrc]
20+
files: ^.*\.(py|c|h|md|rst|yml)$

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ Fix: Window -> Preferences -> Plug-in Development -> API Baselines -> Missing AP
2929

3030
![image](https://github.com/espressif/idf-eclipse-plugin/assets/69584713/0a879d4f-99e2-4d5a-98ca-a745a6683752)
3131

32-
Fix: in "Project Explorer" -> com.espressif.idf.tests -> com.espressif.idf.ui.test -> META-INF -> doubleclick MANIFEST.MF -> Dependencies -> Add... -> Type "slf4j.api" -> Add&Save.
32+
Fix: in "Project Explorer" -> com.espressif.idf.tests -> com.espressif.idf.ui.test -> META-INF -> double-click MANIFEST.MF -> Dependencies -> Add... -> Type "slf4j.api" -> Add&Save.
3333

34-
* After importing project Eclipse might prompt a wizard to install `Maven Plugin Connectors` to resolve the idf-eclipse-plugins maven errors, make sure you install all of them. But, depending on the version(Eclipse / Extentions), an error may occur:
34+
* After importing project Eclipse might prompt a wizard to install `Maven Plugin Connectors` to resolve the idf-eclipse-plugins maven errors, make sure you install all of them. But, depending on the version(Eclipse / Extensions), an error may occur:
3535

3636
![image](https://github.com/espressif/idf-eclipse-plugin/assets/69584713/048196c9-8ac6-4f10-8095-596ab2ef05f2)
3737

38-
Fix: check the error and delete one of the extention (usually Tycho) - Help -> Install New Software -> Already Installed -> select "Tycho" -> Uninstall.
38+
Fix: check the error and delete one of the extension (usually Tycho) - Help -> Install New Software -> Already Installed -> select "Tycho" -> Uninstall.
3939

4040
* Run as -> SWTBot Test -> may lead to error:
4141

@@ -50,7 +50,7 @@ Fix: Uninstall SWTBot -> Install latest snapshot(04.04.2023): http://download.ec
5050
* Make changes locally on a specific local branch
5151
* Test with Maven Tycho using `$ mvn clean verify -Djarsigner.skip=true`
5252
* Submit a Pull Request(PR)
53-
* It is also recommended that you add or update a Functional Test if you are adding or updating a functionality in plugin. More details about adding SWTBot Funtional test can be found in the README.md in test folder in the repo.
53+
* It is also recommended that you add or update a Functional Test if you are adding or updating a functionality in plugin. More details about adding SWTBot Functional test can be found in the README.md in test folder in the repo.
5454

5555
## Coding Standards and guidelines
5656
* Code formatter https://github.com/espressif/idf-eclipse-plugin/blob/master/resources/espressif_eclipse_formatter.xml

bundles/com.espressif.idf.terminal.connector.serial/src/com/espressif/idf/terminal/connector/serial/controls/SerialSettingsPage.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,30 @@ public void createControl(Composite parent)
101101

102102
projectCombo = new Combo(comp, SWT.NONE);
103103
projectCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
104-
Optional<IProject> optProject = Optional.ofNullable(EclipseUtil.getSelectedIDFProjectInExplorer());
104+
105+
// Safely get selected IDF project with error handling
106+
IProject selectedProject = null;
107+
try {
108+
selectedProject = EclipseUtil.getSelectedIDFProjectInExplorer();
109+
} catch (NoSuchMethodError e) {
110+
// Fallback: try to get any selected project
111+
try {
112+
selectedProject = EclipseUtil.getSelectedProjectInExplorer();
113+
if (selectedProject != null) {
114+
try {
115+
if (!selectedProject.hasNature(IDFProjectNature.ID)) {
116+
selectedProject = null; // Not an IDF project
117+
}
118+
} catch (CoreException ce) {
119+
selectedProject = null;
120+
}
121+
}
122+
} catch (Exception ex) {
123+
// If all else fails, selectedProject remains null
124+
}
125+
}
126+
127+
Optional<IProject> optProject = Optional.ofNullable(selectedProject);
105128
optProject.ifPresent(project -> projectCombo.setText(project.getName()));
106129
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
107130
for (IProject project : projects)

bundles/com.espressif.idf.terminal.connector/src/com/espressif/idf/terminal/connector/controls/IDFConsoleWizardConfigurationPanel.java

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,34 @@
1313
package com.espressif.idf.terminal.connector.controls;
1414

1515
import java.util.Map;
16+
import java.util.Optional;
1617

17-
import org.eclipse.core.runtime.IAdaptable;
18+
import org.eclipse.core.resources.IProject;
19+
import org.eclipse.core.resources.ResourcesPlugin;
20+
import org.eclipse.core.runtime.CoreException;
1821
import org.eclipse.core.runtime.Platform;
1922
import org.eclipse.jface.dialogs.IDialogSettings;
20-
import org.eclipse.jface.viewers.ISelection;
21-
import org.eclipse.jface.viewers.IStructuredSelection;
22-
import org.eclipse.jface.viewers.StructuredSelection;
2323
import org.eclipse.swt.SWT;
2424
import org.eclipse.swt.layout.GridData;
2525
import org.eclipse.swt.layout.GridLayout;
26+
import org.eclipse.swt.widgets.Combo;
2627
import org.eclipse.swt.widgets.Composite;
2728
import org.eclipse.swt.widgets.Label;
2829
import org.eclipse.tm.terminal.view.core.interfaces.constants.ITerminalsConnectorConstants;
2930
import org.eclipse.tm.terminal.view.ui.interfaces.IConfigurationPanelContainer;
3031
import org.eclipse.tm.terminal.view.ui.panels.AbstractExtendedConfigurationPanel;
31-
import org.eclipse.ui.ISelectionService;
32-
import org.eclipse.ui.PlatformUI;
3332
import org.eclipse.ui.WorkbenchEncoding;
34-
import org.osgi.framework.Bundle;
33+
34+
import com.espressif.idf.core.IDFProjectNature;
35+
import com.espressif.idf.core.logging.Logger;
36+
import com.espressif.idf.ui.EclipseUtil;
3537

3638
/**
3739
* IDF console wizard configuration panel implementation.
3840
*/
3941
public class IDFConsoleWizardConfigurationPanel extends AbstractExtendedConfigurationPanel {
4042

41-
private Object resource;
43+
private Combo projectCombo;
4244

4345
/**
4446
* Constructor.
@@ -55,6 +57,7 @@ public void setupPanel(Composite parent) {
5557
panel.setLayout(new GridLayout());
5658
panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
5759

60+
createProjectCombo(panel);
5861
// Create the encoding selection combo
5962
createEncodingUI(panel, false);
6063

@@ -76,12 +79,40 @@ public void setupPanel(Composite parent) {
7679
layoutData.heightHint = 80;
7780
label.setLayoutData(layoutData);
7881

79-
Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
80-
if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) {
81-
resource = getSelectionResource();
82+
setControl(panel);
83+
}
84+
85+
private void createProjectCombo(Composite parent) {
86+
87+
Composite panel = new Composite(parent, SWT.NONE);
88+
GridLayout layout = new GridLayout(2, false);
89+
layout.marginHeight = 0;
90+
layout.marginWidth = 0;
91+
panel.setLayout(layout);
92+
panel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
93+
94+
Label projectLabel = new Label(panel, SWT.NONE);
95+
projectLabel
96+
.setText(Messages.IDFConsoleWizardConfigurationPanel_IDFConsoleWizardConfigurationPanel_ProjectLabel);
97+
98+
projectCombo = new Combo(panel, SWT.READ_ONLY);
99+
projectCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
100+
101+
for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
102+
try {
103+
if (project.hasNature(IDFProjectNature.ID)) {
104+
projectCombo.add(project.getName());
105+
}
106+
} catch (CoreException e) {
107+
Logger.log(e);
108+
}
82109
}
83110

84-
setControl(panel);
111+
Optional<IProject> optProject = Optional.ofNullable(EclipseUtil.getSelectedIDFProjectInExplorer());
112+
optProject.ifPresentOrElse(project -> projectCombo.setText(project.getName()), () -> {
113+
if (projectCombo.getItemCount() > 0)
114+
projectCombo.select(0);
115+
});
85116
}
86117

87118
@Override
@@ -96,19 +127,17 @@ public void setupData(Map<String, Object> data) {
96127

97128
@Override
98129
public void extractData(Map<String, Object> data) {
99-
// set the terminal connector id for local terminal
130+
100131
data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID,
101132
"com.espressif.idf.terminal.connector.espidfConnector"); //$NON-NLS-1$
102133

103-
// Store the encoding
104134
data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());
105135

106-
Bundle bundle = Platform.getBundle("org.eclipse.core.resources"); //$NON-NLS-1$
107-
if (bundle != null && bundle.getState() != Bundle.UNINSTALLED && bundle.getState() != Bundle.STOPPING) {
108-
// if we have a IResource selection use the location for working directory
109-
if (resource instanceof org.eclipse.core.resources.IResource) {
110-
String dir = ((org.eclipse.core.resources.IResource) resource).getProject().getLocation().toString();
111-
data.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, dir);
136+
if (projectCombo != null && !projectCombo.isDisposed() && !projectCombo.getText().isEmpty()) {
137+
IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(projectCombo.getText());
138+
if (p != null && p.exists() && p.getLocation() != null) {
139+
data.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, p.getLocation().toOSString());
140+
data.put(ITerminalsConnectorConstants.PROP_TITLE, p.getName());
112141
}
113142
}
114143
}
@@ -147,25 +176,4 @@ protected String getHostFromSettings() {
147176
public boolean isWithHostList() {
148177
return false;
149178
}
150-
151-
/**
152-
* Returns the IResource from the current selection
153-
*
154-
* @return the IResource, or <code>null</code>.
155-
*/
156-
private org.eclipse.core.resources.IResource getSelectionResource() {
157-
ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
158-
ISelection selection = selectionService != null ? selectionService.getSelection() : StructuredSelection.EMPTY;
159-
160-
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
161-
Object element = ((IStructuredSelection) selection).getFirstElement();
162-
if (element instanceof org.eclipse.core.resources.IResource) {
163-
return ((org.eclipse.core.resources.IResource) element);
164-
}
165-
if (element instanceof IAdaptable) {
166-
return ((IAdaptable) element).getAdapter(org.eclipse.core.resources.IResource.class);
167-
}
168-
}
169-
return null;
170-
}
171179
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.espressif.idf.terminal.connector.controls;
2+
3+
import org.eclipse.osgi.util.NLS;
4+
5+
public class Messages extends NLS {
6+
private static final String BUNDLE_NAME = Messages.class.getPackageName() + ".messages"; //$NON-NLS-1$
7+
static {
8+
// initialize resource bundle
9+
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
10+
}
11+
12+
private Messages() {
13+
}
14+
15+
public static String IDFConsoleWizardConfigurationPanel_MissingProjectErrorMsg;
16+
public static String IDFConsoleWizardConfigurationPanel_IDFConsoleWizardConfigurationPanel_ProjectLabel;
17+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
IDFConsoleWizardConfigurationPanel_MissingProjectErrorMsg=Please create and select an ESP-IDF Project first.
2+
IDFConsoleWizardConfigurationPanel_IDFConsoleWizardConfigurationPanel_ProjectLabel=Project name:

0 commit comments

Comments
 (0)