Skip to content

Commit afecb81

Browse files
author
Federico Fissore
committed
Removed "libraries" and "hardware" entries from File > Sketchbook. Fixes #3432
1 parent fef4e56 commit afecb81

File tree

2 files changed

+81
-44
lines changed

2 files changed

+81
-44
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Arduino is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package cc.arduino.view;
31+
32+
import javax.swing.*;
33+
import java.awt.*;
34+
35+
public class JMenuUtils {
36+
37+
public static JMenu findSubMenuWithLabel(JMenu menu, String text) {
38+
for (Component submenu : menu.getMenuComponents()) {
39+
if (submenu instanceof JMenu && text.equals(((JMenu) submenu).getText())) {
40+
return (JMenu) submenu;
41+
}
42+
}
43+
return null;
44+
}
45+
46+
}

app/src/processing/app/Base.java

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,32 +1122,26 @@ public void actionPerformed(ActionEvent e) {
11221122
menu.addSeparator();
11231123

11241124
// Add a list of all sketches and subfolders
1125-
try {
1126-
boolean sketches = addSketches(menu, BaseNoGui.getSketchbookFolder(), true);
1127-
if (sketches) menu.addSeparator();
1128-
} catch (IOException e) {
1129-
e.printStackTrace();
1130-
}
1125+
boolean sketches = addSketches(menu, BaseNoGui.getSketchbookFolder(), true);
1126+
if (sketches) menu.addSeparator();
11311127

11321128
// Add each of the subfolders of examples directly to the menu
1133-
try {
1134-
boolean found = addSketches(menu, BaseNoGui.getExamplesFolder(), true);
1135-
if (found) menu.addSeparator();
1136-
} catch (IOException e) {
1137-
e.printStackTrace();
1138-
}
1129+
boolean found = addSketches(menu, BaseNoGui.getExamplesFolder(), true);
1130+
if (found) menu.addSeparator();
11391131
}
11401132

11411133

11421134
protected void rebuildSketchbookMenu(JMenu menu) {
1143-
//System.out.println("rebuilding sketchbook menu");
1144-
//new Exception().printStackTrace();
1145-
try {
1146-
menu.removeAll();
1147-
addSketches(menu, BaseNoGui.getSketchbookFolder(), false);
1148-
//addSketches(menu, getSketchbookFolder());
1149-
} catch (IOException e) {
1150-
e.printStackTrace();
1135+
menu.removeAll();
1136+
addSketches(menu, BaseNoGui.getSketchbookFolder(), false);
1137+
1138+
JMenu librariesMenu = JMenuUtils.findSubMenuWithLabel(menu, "libraries");
1139+
if (librariesMenu != null) {
1140+
menu.remove(librariesMenu);
1141+
}
1142+
JMenu hardwareMenu = JMenuUtils.findSubMenuWithLabel(menu, "hardware");
1143+
if (hardwareMenu != null) {
1144+
menu.remove(hardwareMenu);
11511145
}
11521146
}
11531147

@@ -1234,30 +1228,28 @@ public void actionPerformed(ActionEvent event) {
12341228
}
12351229

12361230
public void rebuildExamplesMenu(JMenu menu) {
1237-
if (menu == null)
1231+
if (menu == null) {
12381232
return;
1239-
try {
1240-
menu.removeAll();
1233+
}
12411234

1242-
// Add examples from distribution "example" folder
1243-
boolean found = addSketches(menu, BaseNoGui.getExamplesFolder(), false);
1244-
if (found) menu.addSeparator();
1235+
menu.removeAll();
12451236

1246-
// Add examples from libraries
1247-
LibraryList ideLibs = getIDELibs();
1248-
ideLibs.sort();
1249-
for (UserLibrary lib : ideLibs)
1237+
// Add examples from distribution "example" folder
1238+
boolean found = addSketches(menu, BaseNoGui.getExamplesFolder(), false);
1239+
if (found) menu.addSeparator();
1240+
1241+
// Add examples from libraries
1242+
LibraryList ideLibs = getIDELibs();
1243+
ideLibs.sort();
1244+
for (UserLibrary lib : ideLibs)
1245+
addSketchesSubmenu(menu, lib, false);
1246+
1247+
LibraryList userLibs = getUserLibs();
1248+
if (userLibs.size() > 0) {
1249+
menu.addSeparator();
1250+
userLibs.sort();
1251+
for (UserLibrary lib : userLibs)
12501252
addSketchesSubmenu(menu, lib, false);
1251-
1252-
LibraryList userLibs = getUserLibs();
1253-
if (userLibs.size() > 0) {
1254-
menu.addSeparator();
1255-
userLibs.sort();
1256-
for (UserLibrary lib : userLibs)
1257-
addSketchesSubmenu(menu, lib, false);
1258-
}
1259-
} catch (IOException e) {
1260-
e.printStackTrace();
12611253
}
12621254
}
12631255

@@ -1588,7 +1580,7 @@ public void actionPerformed(ActionEvent actionevent) {
15881580
* should replace the sketch in the current window, or false when the
15891581
* sketch should open in a new window.
15901582
*/
1591-
protected boolean addSketches(JMenu menu, File folder, final boolean replaceExisting) throws IOException {
1583+
protected boolean addSketches(JMenu menu, File folder, final boolean replaceExisting) {
15921584
if (folder == null)
15931585
return false;
15941586

@@ -1624,14 +1616,13 @@ public int compare(File file, File file2) {
16241616
}
16251617

16261618
private boolean addSketchesSubmenu(JMenu menu, UserLibrary lib,
1627-
boolean replaceExisting)
1628-
throws IOException {
1619+
boolean replaceExisting) {
16291620
return addSketchesSubmenu(menu, lib.getName(), lib.getInstalledFolder(),
16301621
replaceExisting);
16311622
}
16321623

16331624
private boolean addSketchesSubmenu(JMenu menu, String name, File folder,
1634-
final boolean replaceExisting) throws IOException {
1625+
final boolean replaceExisting) {
16351626

16361627
ActionListener listener = new ActionListener() {
16371628
public void actionPerformed(ActionEvent e) {

0 commit comments

Comments
 (0)