Skip to content

Refresh the available list of libraries whenever the Import Library menu is expanded #1783

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -950,15 +950,19 @@ protected void rebuildSketchbookMenu(JMenu menu) {
}


public void rebuildImportMenu(JMenu importMenu, final Editor editor) {
// NOTE(remoun): This method is called whenever the Sketch > Import Library
// menu is expanded, so make sure not to break that completely.
// Showing an error dialog and skipping invalid entries is fine.
public void rebuildImportMenu(final Editor editor) {
JMenu importMenu = Editor.importMenu;
importMenu.removeAll();

JMenuItem addLibraryMenuItem = new JMenuItem(_("Add Library..."));
addLibraryMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Base.this.handleAddLibrary(editor);
Base.this.onBoardOrPortChange();
Base.this.rebuildImportMenu(Editor.importMenu, editor);
Base.this.rebuildImportMenu(editor);
Base.this.rebuildExamplesMenu(Editor.examplesMenu);
}
});
Expand Down Expand Up @@ -1015,8 +1019,7 @@ public void onBoardOrPortChange() {
}
}


public void rebuildBoardsMenu(JMenu menu, final Editor editor) {
public void rebuildBoardsMenu(JMenu menu) {
//System.out.println("rebuilding boards menu");
menu.removeAll();
ButtonGroup group = new ButtonGroup();
Expand Down
12 changes: 10 additions & 2 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,15 @@ public void actionPerformed(ActionEvent e) {

if (importMenu == null) {
importMenu = new JMenu(_("Import Library..."));
base.rebuildImportMenu(importMenu, this);
importMenu.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
base.rebuildImportMenu(Editor.this);
}
}
});
// Rebuild the import menu here, so it's faster the first time it expands.
base.rebuildImportMenu(this);
}
sketchMenu.add(importMenu);

Expand Down Expand Up @@ -682,7 +690,7 @@ public void actionPerformed(ActionEvent e) {

if (boardsMenu == null) {
boardsMenu = new JMenu(_("Board"));
base.rebuildBoardsMenu(boardsMenu, this);
base.rebuildBoardsMenu(boardsMenu);
}
menu.add(boardsMenu);

Expand Down