Skip to content

Commit 43d329d

Browse files
author
jantje
committed
creation of new config kind of works
Well it doesn't copy the config but it does not crash
1 parent 5dc84c3 commit 43d329d

File tree

2 files changed

+42
-60
lines changed

2 files changed

+42
-60
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,19 @@
11
package io.sloeber.core.listeners;
22

3-
/*** Message from jan baeyens
4-
* this listener makes sure that when you change from one configuration to another
5-
* the correct hardware libraries are attached to the project
6-
* for instance you can have a project with 2 configurations
7-
* one for teensy
8-
* one for arduino uno
9-
*
10-
*
11-
* when you use the spi library the library is a completely different library
12-
* this code takes care that you use the correct library when switching configuration
13-
*
14-
*/
15-
16-
import java.io.File;
17-
183
import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent;
194
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
5+
import org.eclipse.cdt.core.settings.model.ICDescriptionDelta;
206
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
217
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener;
228
import org.eclipse.core.resources.IProject;
23-
import org.eclipse.core.runtime.CoreException;
249
import org.eclipse.core.runtime.Status;
2510

2611
import io.sloeber.core.Activator;
2712
import io.sloeber.core.api.BoardDescription;
2813
import io.sloeber.core.api.SloeberProject;
2914
import io.sloeber.core.common.Common;
3015
import io.sloeber.core.common.Const;
31-
import io.sloeber.core.tools.Helpers;
32-
import io.sloeber.core.tools.Libraries;
3316

34-
@SuppressWarnings({ "unused" })
3517
public class ConfigurationChangeListener implements ICProjectDescriptionListener {
3618

3719
@Override
@@ -55,43 +37,27 @@ public void handleEvent(CProjectDescriptionEvent event) {
5537
"Ignoring configuration change during project creation " + activeProject.getName())); //$NON-NLS-1$
5638
return;
5739
}
40+
ICDescriptionDelta projectDelta = event.getProjectDelta();
41+
if (projectDelta != null) {
42+
int projectChangeFlags = projectDelta.getChangeFlags();
43+
int projectDeltaKind = projectDelta.getDeltaKind();
44+
}
45+
ICDescriptionDelta cfgDelta = event.getActiveCfgDelta();
46+
if (cfgDelta != null) {
47+
int cfgChangeFlags = cfgDelta.getChangeFlags();
48+
int cfgDeltaKind = cfgDelta.getDeltaKind();
49+
}
50+
ICDescriptionDelta defaultDelta = event.getDefaultSettingCfgDelta();
51+
if (defaultDelta != null) {
52+
int changeFlags = defaultDelta.getChangeFlags();
53+
int deltaKind = defaultDelta.getDeltaKind();
54+
}
55+
SloeberProject sloebberProject = SloeberProject.getSloeberProject(activeProject);
56+
5857
ICProjectDescription newProjDesc = event.getNewCProjectDescription();
5958
ICConfigurationDescription newConf = newProjDesc.getActiveConfiguration();
60-
IProject project = newConf.getProjectDescription().getProject();
61-
SloeberProject newSloebberProject = SloeberProject.getSloeberProject(project);
62-
BoardDescription newBoardDescriptor = newSloebberProject.getBoardDescription(newConf);
63-
64-
ICProjectDescription oldprojDesc = event.getOldCProjectDescription();
65-
ICConfigurationDescription oldConf = oldprojDesc.getActiveConfiguration();
66-
IProject oldProject = oldConf.getProjectDescription().getProject();
67-
SloeberProject oldSloebberProject = SloeberProject.getSloeberProject(oldProject);
68-
BoardDescription oldBoardDescriptor = oldSloebberProject.getBoardDescription(oldConf);
69-
70-
if (oldprojDesc.getName().equals(newProjDesc.getName())) {
71-
72-
File newBoardsFile = newBoardDescriptor.getReferencingBoardsFile();
73-
File oldBoardsFile = oldBoardDescriptor.getReferencingBoardsFile();
74-
String newBoardsName = newBoardDescriptor.getBoardName();
75-
String oldBoardsName = oldBoardDescriptor.getBoardName();
76-
// only if the boardsFile or variant Changed we need to reattach libraries and
77-
// cores
78-
if (newBoardsFile.equals(oldBoardsFile) && newBoardsName.equals(oldBoardsName)) {
79-
return;
80-
}
81-
82-
try {
83-
Helpers.setDirtyFlag(activeProject, newConf);
84-
Helpers.addArduinoCodeToProject(newBoardDescriptor, newConf);
85-
} catch (CoreException e) {
86-
// TODO Auto-generated catch block
87-
e.printStackTrace();
88-
}
89-
if (!newBoardsFile.equals(oldBoardsFile)) {
90-
Libraries.reAttachLibrariesToProject(newConf);
91-
}
92-
} else {
93-
// we are doing a swap between configs
94-
}
59+
BoardDescription newBoardDescriptor = sloebberProject.getBoardDescription(newConf);
60+
sloebberProject.setBoardDescription(newConf, newBoardDescriptor);
9561
}
9662

9763
}

io.sloeber.ui/src/io/sloeber/ui/project/properties/BoardSelectionPage.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,22 @@ private void doOK() {
394394
getValues();
395395
ICConfigurationDescription confdesc = getConfdesc();
396396
ICProjectDescription projDesc = confdesc.getProjectDescription();
397-
try {
397+
SloeberProject sProject = getSloeberProject();
398+
398399
for (Entry<String, BoardDescription> curEntry : myBoardDescs.entrySet()) {
399400
ICConfigurationDescription curConfDesc = projDesc.getConfigurationById(curEntry.getKey());
400-
getSloeberProject().setBoardDescription(curConfDesc, curEntry.getValue());
401+
BoardDescription boardDesc = curEntry.getValue();
402+
try {
403+
if ((curConfDesc != null) && (boardDesc != null)) {
404+
sProject.setBoardDescription(curConfDesc, boardDesc);
405+
} else {
406+
Activator.log(new Status(IStatus.ERROR, Activator.getId(), Messages.error_adding_arduino_code));
407+
}
408+
} catch (Exception e) {
409+
Activator.log(new Status(IStatus.ERROR, Activator.getId(), Messages.error_adding_arduino_code, e));
410+
}
411+
401412
}
402-
} catch (Exception e) {
403-
Activator.log(new Status(IStatus.ERROR, Activator.getId(), Messages.error_adding_arduino_code, e));
404-
}
405413
}
406414

407415
private SloeberProject getSloeberProject() {
@@ -489,7 +497,15 @@ public BoardDescription getBoardDescription() {
489497
} else {
490498
ICProjectDescription projDesc = getConfdesc().getProjectDescription();
491499
for (ICConfigurationDescription curConfDesc : projDesc.getConfigurations()) {
492-
myBoardDescs.put(curConfDesc.getId(), getSloeberProject().getBoardDescription(curConfDesc));
500+
BoardDescription boardDesc = getSloeberProject().getBoardDescription(curConfDesc);
501+
if (boardDesc == null) {
502+
// TOFIX new configuration is normally copy of but
503+
// I don't know what has been used to copy from
504+
// so make default for now
505+
boardDesc = new BoardDescription();
506+
}
507+
myBoardDescs.put(curConfDesc.getId(), boardDesc);
508+
493509
}
494510
myActiveBoardDesc = myBoardDescs.get(activeConfDesc.getId());
495511
if (myActiveBoardDesc == null) {

0 commit comments

Comments
 (0)