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

Method rebuildImportMenu

app/src/processing/app/Base.java:1100–1163  ·  view source on GitHub ↗
(JMenu importMenu)

Source from the content-addressed store, hash-verified

1098 }
1099
1100 public void rebuildImportMenu(JMenu importMenu) {
1101 if (importMenu == null)
1102 return;
1103 importMenu.removeAll();
1104
1105 JMenuItem menu = new JMenuItem(tr("Manage Libraries..."));
1106 // Ctrl+Shift+I on Windows and Linux, Command+Shift+I on macOS
1107 menu.setAccelerator(KeyStroke.getKeyStroke('I',
1108 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() |
1109 ActionEvent.SHIFT_MASK));
1110 menu.addActionListener(e -> openLibraryManager("", ""));
1111 importMenu.add(menu);
1112 importMenu.addSeparator();
1113
1114 JMenuItem addLibraryMenuItem = new JMenuItem(tr("Add .ZIP Library..."));
1115 addLibraryMenuItem.addActionListener(new ActionListener() {
1116 public void actionPerformed(ActionEvent e) {
1117 Base.this.handleAddLibrary();
1118 BaseNoGui.librariesIndexer.rescanLibraries();
1119 Base.this.onBoardOrPortChange();
1120 Base.this.rebuildImportMenu(Editor.importMenu);
1121 Base.this.rebuildExamplesMenu(Editor.examplesMenu);
1122 }
1123 });
1124 importMenu.add(addLibraryMenuItem);
1125 importMenu.addSeparator();
1126
1127 // Split between user supplied libraries and IDE libraries
1128 TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
1129
1130 if (targetPlatform != null) {
1131 LibraryList libs = getSortedLibraries();
1132 String lastLibType = null;
1133 for (UserLibrary lib : libs) {
1134 String libType = lib.getTypes().get(0);
1135 if (!libType.equals(lastLibType)) {
1136 if (lastLibType != null) {
1137 importMenu.addSeparator();
1138 }
1139 lastLibType = libType;
1140 JMenuItem platformItem = new JMenuItem(format(tr("{0} libraries"), tr(lastLibType)));
1141 platformItem.setEnabled(false);
1142 importMenu.add(platformItem);
1143 }
1144
1145 AbstractAction action = new AbstractAction(lib.getName()) {
1146 public void actionPerformed(ActionEvent event) {
1147 UserLibrary l = (UserLibrary) getValue("library");
1148 try {
1149 activeEditor.getSketchController().importLibrary(l);
1150 } catch (IOException e) {
1151 showWarning(tr("Error"), format("Unable to list header files in {0}", l.getSrcFolder()), e);
1152 }
1153 }
1154 };
1155 action.putValue("library", lib);
1156
1157 // Add new element at the bottom

Callers 3

actionPerformedMethod · 0.95
openLibraryManagerMethod · 0.95
buildSketchMenuMethod · 0.80

Calls 11

openLibraryManagerMethod · 0.95
getTargetPlatformMethod · 0.95
getSortedLibrariesMethod · 0.95
trMethod · 0.80
getMethod · 0.65
getNameMethod · 0.65
addMethod · 0.45
getTypesMethod · 0.45
equalsMethod · 0.45
formatMethod · 0.45
setEnabledMethod · 0.45

Tested by

no test coverage detected