@@ -1044,25 +1044,17 @@ protected void rebuildSketchbookMenu(JMenu menu) {
1044
1044
}
1045
1045
1046
1046
public LibraryList getIDELibs () {
1047
- LibraryList libs = new LibraryList ();
1048
1047
if (libraries == null )
1049
- return libs ;
1050
- for (Library lib : libraries ) {
1051
- if (!FileUtils .isSubDirectory (getSketchbookFolder (), lib .getRootFolder ()))
1052
- libs .add (lib );
1053
- }
1054
- return libs ;
1048
+ return new LibraryList ();
1049
+ LibraryList res = new LibraryList (libraries );
1050
+ res .removeAll (getUserLibs ());
1051
+ return res ;
1055
1052
}
1056
1053
1057
1054
public LibraryList getUserLibs () {
1058
- LibraryList libs = new LibraryList ();
1059
1055
if (libraries == null )
1060
- return libs ;
1061
- for (Library lib : libraries ) {
1062
- if (FileUtils .isSubDirectory (getSketchbookFolder (), lib .getRootFolder ()))
1063
- libs .add (lib );
1064
- }
1065
- return libs ;
1056
+ return new LibraryList ();
1057
+ return libraries .filterLibrariesInSubfolder (getSketchbookFolder ());
1066
1058
}
1067
1059
1068
1060
public void rebuildImportMenu (JMenu importMenu , final Editor editor ) {
@@ -1124,28 +1116,16 @@ public void rebuildExamplesMenu(JMenu menu) {
1124
1116
1125
1117
// Add examples from libraries
1126
1118
LibraryList ideLibs = getIDELibs ();
1127
- Collections .sort (ideLibs , Library .CASE_INSENSITIVE_ORDER );
1128
- for (Library lib : ideLibs ) {
1129
- File folder = lib .getRootFolder ();
1130
- String name = lib .getName ();
1131
- addSketchesSubmenu (menu , name , folder , false );
1132
- // Allows "fat" libraries to have examples in the root folder
1133
- if (folder .getName ().equals (Base .getTargetPlatform ().getName ()))
1134
- addSketchesSubmenu (menu , name , folder .getParentFile (), false );
1135
- }
1119
+ ideLibs .sort ();
1120
+ for (Library lib : ideLibs )
1121
+ addSketchesSubmenu (menu , lib , false );
1136
1122
1137
1123
LibraryList userLibs = getUserLibs ();
1138
1124
if (userLibs .size ()>0 ) {
1139
1125
menu .addSeparator ();
1140
- Collections .sort (userLibs , Library .CASE_INSENSITIVE_ORDER );
1141
- for (Library lib : userLibs ) {
1142
- File folder = lib .getRootFolder ();
1143
- String name = lib .getName ();
1144
- addSketchesSubmenu (menu , name , folder , false );
1145
- // Allows "fat" libraries to have examples in the root folder
1146
- if (folder .getName ().equals (Base .getTargetPlatform ().getName ()))
1147
- addSketchesSubmenu (menu , name , folder .getParentFile (), false );
1148
- }
1126
+ userLibs .sort ();
1127
+ for (Library lib : userLibs )
1128
+ addSketchesSubmenu (menu , lib , false );
1149
1129
}
1150
1130
} catch (IOException e ) {
1151
1131
e .printStackTrace ();
@@ -1155,7 +1135,7 @@ public void rebuildExamplesMenu(JMenu menu) {
1155
1135
public LibraryList scanLibraries (List <File > folders ) {
1156
1136
LibraryList res = new LibraryList ();
1157
1137
for (File folder : folders )
1158
- res .addAll (scanLibraries (folder ));
1138
+ res .addOrReplaceAll (scanLibraries (folder ));
1159
1139
return res ;
1160
1140
}
1161
1141
@@ -1178,8 +1158,7 @@ public LibraryList scanLibraries(File folder) {
1178
1158
continue ;
1179
1159
}
1180
1160
1181
- Library lib = Library .fromFolder (subfolder , Base .getTargetPlatform ().getName ());
1182
-
1161
+ Library lib = Library .create (subfolder );
1183
1162
// (also replace previously found libs with the same name)
1184
1163
if (lib != null )
1185
1164
res .addOrReplace (lib );
@@ -1206,18 +1185,20 @@ public void onBoardOrPortChange() {
1206
1185
// Libraries located in the latest folders on the list can override
1207
1186
// other libraries with the same name.
1208
1187
libraries = scanLibraries (librariesFolders );
1209
-
1188
+ String currentArch = Base .getTargetPlatform ().getName ();
1189
+ libraries = libraries .filterByArchitecture (currentArch );
1190
+
1210
1191
// Populate importToLibraryTable
1211
1192
importToLibraryTable = new HashMap <String , Library >();
1212
1193
for (Library lib : libraries ) {
1213
1194
try {
1214
- String headers [] = headerListFromIncludePath (lib .getRootFolder ());
1195
+ String headers [] = headerListFromIncludePath (lib .getSrcFolder ());
1215
1196
for (String header : headers ) {
1216
1197
importToLibraryTable .put (header , lib );
1217
1198
}
1218
1199
} catch (IOException e ) {
1219
1200
showWarning (_ ("Error" ), I18n
1220
- .format ("Unable to list header files in {0}" , lib .getRootFolder ()), e );
1201
+ .format ("Unable to list header files in {0}" , lib .getSrcFolder ()), e );
1221
1202
}
1222
1203
}
1223
1204
@@ -1495,6 +1476,13 @@ protected boolean addSketches(JMenu menu, File folder,
1495
1476
return ifound ; // actually ignored, but..
1496
1477
}
1497
1478
1479
+ private boolean addSketchesSubmenu (JMenu menu , Library lib ,
1480
+ boolean replaceExisting )
1481
+ throws IOException {
1482
+ return addSketchesSubmenu (menu , lib .getName (), lib .getFolder (),
1483
+ replaceExisting );
1484
+ }
1485
+
1498
1486
private boolean addSketchesSubmenu (JMenu menu , String name , File folder ,
1499
1487
final boolean replaceExisting ) throws IOException {
1500
1488
@@ -1564,26 +1552,25 @@ public void actionPerformed(ActionEvent e) {
1564
1552
protected void addLibraries (JMenu menu , LibraryList libs ) throws IOException {
1565
1553
1566
1554
LibraryList list = new LibraryList (libs );
1567
- Collections .sort (list , Library .CASE_INSENSITIVE_ORDER );
1568
-
1569
- ActionListener listener = new ActionListener () {
1570
- public void actionPerformed (ActionEvent event ) {
1571
- String jarPath = event .getActionCommand ();
1572
- try {
1573
- activeEditor .getSketch ().importLibrary (jarPath );
1574
- } catch (IOException e ) {
1575
- showWarning (_ ("Error" ), I18n .format ("Unable to list header files in {0}" , jarPath ), e );
1576
- }
1577
- }
1578
- };
1555
+ list .sort ();
1579
1556
1580
1557
for (Library lib : list ) {
1581
- File folder = lib .getRootFolder ();
1582
-
1558
+ @ SuppressWarnings ("serial" )
1559
+ AbstractAction action = new AbstractAction (lib .getName ()) {
1560
+ public void actionPerformed (ActionEvent event ) {
1561
+ Library l = (Library ) getValue ("library" );
1562
+ try {
1563
+ activeEditor .getSketch ().importLibrary (l );
1564
+ } catch (IOException e ) {
1565
+ showWarning (_ ("Error" ), I18n .format ("Unable to list header files in {0}" , l .getSrcFolder ()), e );
1566
+ }
1567
+ }
1568
+ };
1569
+ action .putValue ("library" , lib );
1570
+
1583
1571
// Add new element at the bottom
1584
- JMenuItem item = new JMenuItem (lib .getName ());
1585
- item .addActionListener (listener );
1586
- item .setActionCommand (folder .getAbsolutePath ());
1572
+ JMenuItem item = new JMenuItem (action );
1573
+ item .putClientProperty ("library" , lib );
1587
1574
menu .add (item );
1588
1575
1589
1576
// XXX: DAM: should recurse here so that library folders can be nested
0 commit comments