Skip to content

Commit 8be2b7b

Browse files
committed
hope this solves #362
Added a job so the codde is not triggered directly from the event.
1 parent 88fd31d commit 8be2b7b

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

it.baeyens.arduino.core/src/it/baeyens/arduino/listeners/IndexerListener.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package it.baeyens.arduino.listeners;
22

33
/**
4-
* his index listener makes ity possible to detect missing libraries
4+
* this index listener makes it possible to detect missing libraries
55
* if configured to do so libraries are added automatically to the project
66
*/
77
import java.util.HashSet;
@@ -12,12 +12,17 @@
1212
import org.eclipse.cdt.core.index.IIndexerStateEvent;
1313
import org.eclipse.cdt.core.index.IIndexerStateListener;
1414
import org.eclipse.core.resources.IProject;
15+
import org.eclipse.core.runtime.IProgressMonitor;
16+
import org.eclipse.core.runtime.IStatus;
17+
import org.eclipse.core.runtime.Status;
18+
import org.eclipse.core.runtime.jobs.Job;
1519

1620
import it.baeyens.arduino.common.InstancePreferences;
1721
import it.baeyens.arduino.tools.Libraries;
1822

1923
public class IndexerListener implements IIndexChangeListener, IIndexerStateListener {
20-
Set<IProject> ChangedProjects = new HashSet<>();
24+
protected Set<IProject> ChangedProjects = new HashSet<>();
25+
Job installLibJob = null;
2126

2227
@Override
2328
public void indexChanged(IIndexChangeEvent event) {
@@ -30,11 +35,27 @@ public void indexChanged(IIndexerStateEvent event) {
3035

3136
if (event.indexerIsIdle()) {
3237
if (InstancePreferences.getAutomaticallyIncludeLibraries()) {
33-
for (IProject curProject : this.ChangedProjects) {
34-
Libraries.checkLibraries(curProject);
38+
if (this.installLibJob == null) {
39+
this.installLibJob = new Job("Adding Arduino libs...") { //$NON-NLS-1$
40+
41+
@Override
42+
protected IStatus run(IProgressMonitor monitor) {
43+
for (IProject curProject : IndexerListener.this.ChangedProjects) {
44+
Libraries.checkLibraries(curProject);
45+
}
46+
IndexerListener.this.ChangedProjects.clear();
47+
IndexerListener.this.installLibJob = null;
48+
return Status.OK_STATUS;
49+
}
50+
51+
};
52+
53+
this.installLibJob.setPriority(Job.DECORATE);
54+
this.installLibJob.schedule();
3555
}
56+
3657
}
37-
this.ChangedProjects.clear();
58+
3859
}
3960
}
4061

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/Libraries.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,21 +233,25 @@ public static void removeLibrariesFromProject(IProject project, Set<String> sele
233233
private static Set<String> getUnresolvedProjectIncludes(IProject iProject) {
234234
Set<String> ret = new TreeSet<>();
235235
ICProject tt = CoreModel.getDefault().create(iProject);
236+
IIndex index = null;
236237

237238
try {
238-
IIndex index = CCorePlugin.getIndexManager().getIndex(tt);
239+
index = CCorePlugin.getIndexManager().getIndex(tt);
239240
index.acquireReadLock();
241+
try {
240242

241-
IIndexFile allFiles[] = index.getFilesWithUnresolvedIncludes();
242-
for (IIndexFile curUnesolvedIncludeFile : allFiles) {
243-
IIndexInclude includes[] = curUnesolvedIncludeFile.getIncludes();
244-
for (IIndexInclude curinclude : includes) {
245-
if (curinclude.isActive() && !curinclude.isResolved()) {
246-
ret.add(new Path(curinclude.getName()).removeFileExtension().toString());
243+
IIndexFile allFiles[] = index.getFilesWithUnresolvedIncludes();
244+
for (IIndexFile curUnesolvedIncludeFile : allFiles) {
245+
IIndexInclude includes[] = curUnesolvedIncludeFile.getIncludes();
246+
for (IIndexInclude curinclude : includes) {
247+
if (curinclude.isActive() && !curinclude.isResolved()) {
248+
ret.add(new Path(curinclude.getName()).removeFileExtension().toString());
249+
}
247250
}
248251
}
252+
} finally {
253+
index.releaseReadLock();
249254
}
250-
index.releaseReadLock();
251255
} catch (CoreException e1) {
252256
// TODO Auto-generated catch block
253257
e1.printStackTrace();

it.baeyens.arduino.core/src/it/baeyens/arduino/ui/ExplorerLabelDecorator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ public String decorateText(String text, Object element) {
4646
// TODO Auto-generated method stub
4747
IProject proj = (IProject) element;
4848
try {
49-
if (proj.hasNature(Const.ArduinoNatureID)) {
50-
String boardName = Common.getBuildEnvironmentVariable(proj, Const.ENV_KEY_JANTJE_BOARD_NAME, "Board Error"); //$NON-NLS-1$
51-
String portName = Common.getBuildEnvironmentVariable(proj, Const.ENV_KEY_JANTJE_COM_PORT, "no port"); //$NON-NLS-1$
52-
return text + ' ' + boardName + ' ' + ':' + portName;
49+
if (proj.isOpen()) {
50+
if (proj.hasNature(Const.ArduinoNatureID)) {
51+
String boardName = Common.getBuildEnvironmentVariable(proj, Const.ENV_KEY_JANTJE_BOARD_NAME, "Board Error"); //$NON-NLS-1$
52+
String portName = Common.getBuildEnvironmentVariable(proj, Const.ENV_KEY_JANTJE_COM_PORT, "no port"); //$NON-NLS-1$
53+
return text + ' ' + boardName + ' ' + ':' + portName;
54+
}
5355
}
5456
} catch (CoreException e) {
5557
// TODO Auto-generated catch block

0 commit comments

Comments
 (0)