MCPcopy
hub / github.com/arduino/Arduino / rebuildExamplesMenu

Method rebuildExamplesMenu

app/src/processing/app/Base.java:1165–1333  ·  view source on GitHub ↗
(JMenu menu)

Source from the content-addressed store, hash-verified

1163 }
1164
1165 public void rebuildExamplesMenu(JMenu menu) {
1166 if (menu == null) {
1167 return;
1168 }
1169
1170 menu.removeAll();
1171
1172 // Add examples from distribution "example" folder
1173 JMenuItem label = new JMenuItem(tr("Built-in Examples"));
1174 label.setEnabled(false);
1175 menu.add(label);
1176 boolean found = addSketches(menu, BaseNoGui.getExamplesFolder());
1177 if (found) {
1178 menu.addSeparator();
1179 }
1180
1181 // Libraries can come from 4 locations: collect info about all four
1182 String boardId = null;
1183 String referencedPlatformName = null;
1184 String myArch = null;
1185 TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
1186 if (targetPlatform != null) {
1187 myArch = targetPlatform.getId();
1188 boardId = BaseNoGui.getTargetBoard().getName();
1189 String core = BaseNoGui.getBoardPreferences().get("build.core", "arduino");
1190 if (core.contains(":")) {
1191 String refcore = core.split(":")[0];
1192 TargetPlatform referencedPlatform = BaseNoGui.getTargetPlatform(refcore, myArch);
1193 if (referencedPlatform != null) {
1194 referencedPlatformName = referencedPlatform.getPreferences().get("name");
1195 }
1196 }
1197 }
1198
1199 // Divide the libraries into 7 lists, corresponding to the 4 locations
1200 // with the retired IDE libs further divided into their own list, and
1201 // any incompatible sketchbook libs further divided into their own list.
1202 // The 7th list of "other" libraries should always be empty, but serves
1203 // as a safety feature to prevent any library from vanishing.
1204 LibraryList allLibraries = BaseNoGui.librariesIndexer.getInstalledLibraries();
1205 LibraryList ideLibs = new LibraryList();
1206 LibraryList retiredIdeLibs = new LibraryList();
1207 LibraryList platformLibs = new LibraryList();
1208 LibraryList referencedPlatformLibs = new LibraryList();
1209 LibraryList sketchbookLibs = new LibraryList();
1210 LibraryList sketchbookIncompatibleLibs = new LibraryList();
1211 LibraryList otherLibs = new LibraryList();
1212 for (UserLibrary lib : allLibraries) {
1213 // Get the library's location - used for sorting into categories
1214 Location location = lib.getLocation();
1215 // Is this library compatible?
1216 List<String> arch = lib.getArchitectures();
1217 boolean compatible;
1218 if (myArch == null || arch == null || arch.contains("*")) {
1219 compatible = true;
1220 } else {
1221 compatible = arch.contains(myArch);
1222 }

Callers 3

actionPerformedMethod · 0.95
openLibraryManagerMethod · 0.95
buildFileMenuMethod · 0.80

Calls 15

addSketchesMethod · 0.95
getExamplesFolderMethod · 0.95
getTargetPlatformMethod · 0.95
getIdMethod · 0.95
getTargetBoardMethod · 0.95
getBoardPreferencesMethod · 0.95
getPreferencesMethod · 0.95
sortMethod · 0.95
addSketchesSubmenuMethod · 0.95
setScrollerForMethod · 0.95
trMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected