1
1
package io .sloeber .core .listeners ;
2
2
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
-
18
3
import org .eclipse .cdt .core .settings .model .CProjectDescriptionEvent ;
19
4
import org .eclipse .cdt .core .settings .model .ICConfigurationDescription ;
5
+ import org .eclipse .cdt .core .settings .model .ICDescriptionDelta ;
20
6
import org .eclipse .cdt .core .settings .model .ICProjectDescription ;
21
7
import org .eclipse .cdt .core .settings .model .ICProjectDescriptionListener ;
22
8
import org .eclipse .core .resources .IProject ;
23
- import org .eclipse .core .runtime .CoreException ;
24
9
import org .eclipse .core .runtime .Status ;
25
10
26
11
import io .sloeber .core .Activator ;
27
12
import io .sloeber .core .api .BoardDescription ;
28
13
import io .sloeber .core .api .SloeberProject ;
29
14
import io .sloeber .core .common .Common ;
30
15
import io .sloeber .core .common .Const ;
31
- import io .sloeber .core .tools .Helpers ;
32
- import io .sloeber .core .tools .Libraries ;
33
16
34
- @ SuppressWarnings ({ "unused" })
35
17
public class ConfigurationChangeListener implements ICProjectDescriptionListener {
36
18
37
19
@ Override
@@ -55,43 +37,27 @@ public void handleEvent(CProjectDescriptionEvent event) {
55
37
"Ignoring configuration change during project creation " + activeProject .getName ())); //$NON-NLS-1$
56
38
return ;
57
39
}
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
+
58
57
ICProjectDescription newProjDesc = event .getNewCProjectDescription ();
59
58
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 );
95
61
}
96
62
97
63
}
0 commit comments