Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storing Libraries in subfolders #1986

Prev Previous commit
Next Next commit
Make the library (examples) menu nested
Previously, the library scanning code started supported subfolders
inside the libraries folders. Now, the import library and library
examples menus also reflect this nested structure.

In addition to the on-disk nesting, this also shows a top-level
structure (which was already added by the scanning code), dividing the
libraries into "Libraries for all boards", "Libraries for Arduino AVR
Boards" (or whatever core is being used) and "Libraries from your
sketchbook".
  • Loading branch information
matthijskooijman committed Oct 30, 2014
commit e7f6fba6ecf64e7aaf60054dd0bb6b020919022d
36 changes: 31 additions & 5 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -1312,14 +1312,31 @@ public void rebuildExamplesMenu(JMenu menu) {
if (libraries != null && !libraries.isEmpty()) {
if (found)
menu.addSeparator();
for (Library lib : getLibraries())
addSketchesSubmenu(menu, lib, false);
addLibraryExamples(menu, libraries);
}
} catch (IOException e) {
e.printStackTrace();
}
}

protected void addLibraryExamples(JMenu menu, LibraryList libs) throws IOException {
// Add any subdirectories first
for (LibraryList sub : libs.getSubs()) {
if (sub.isEmpty())
continue;

JMenu submenu = new JMenu(sub.getName());
addLibraryExamples(submenu, sub);
menu.add(submenu);
MenuScroller.setScrollerFor(submenu);
}

// Then add the libraries directly in this folder
for (Library lib : libs.getLibs()) {
addSketchesSubmenu(menu, lib, false);
}
}

public void updateLibraries() throws IOException {
// Calculate paths for libraries and examples
examplesFolder = getContentFile("examples");
Expand Down Expand Up @@ -1803,7 +1820,18 @@ public void actionPerformed(ActionEvent e) {
}

protected void addLibraries(JMenu menu, LibraryList libs) throws IOException {
for (Library lib : libs.getAll()) {
// Add any subdirectories first
for (LibraryList sub : libs.getSubs()) {
if (sub.isEmpty())
continue;

JMenu submenu = new JMenu(sub.getName());
addLibraries(submenu, sub);
menu.add(submenu);
MenuScroller.setScrollerFor(submenu);
}
// Then add the libraries directly in this folder
for (Library lib : libs.getLibs()) {
@SuppressWarnings("serial")
AbstractAction action = new AbstractAction(lib.getName()) {
public void actionPerformed(ActionEvent event) {
Expand All @@ -1821,8 +1849,6 @@ public void actionPerformed(ActionEvent event) {
JMenuItem item = new JMenuItem(action);
item.putClientProperty("library", lib);
menu.add(item);

// XXX: DAM: should recurse here so that library folders can be nested
}
}

Expand Down