Scan a folder recursively, and add any sketches found to the menu specified. Set the openReplaces parameter to true when opening the sketch should replace the sketch in the current window, or false when the sketch should open in a new window.
(JMenu menu, File folder,
final boolean replaceExisting)
| 1689 | * sketch should open in a new window. |
| 1690 | */ |
| 1691 | protected boolean addSketches(JMenu menu, File folder, |
| 1692 | final boolean replaceExisting) throws IOException { |
| 1693 | // skip .DS_Store files, etc (this shouldn't actually be necessary) |
| 1694 | if (!folder.isDirectory()) { |
| 1695 | return false; |
| 1696 | } |
| 1697 | |
| 1698 | if (folder.getName().equals("libraries")) { |
| 1699 | return false; // let's not go there |
| 1700 | } |
| 1701 | |
| 1702 | if (folder.getName().equals("sdk")) { |
| 1703 | // This could be Android's SDK folder. Let's double check: |
| 1704 | File suspectSDKPath = new File(folder.getParent(), folder.getName()); |
| 1705 | File expectedSDKPath = new File(sketchbookFolder, "android" + File.separator + "sdk"); |
| 1706 | if (expectedSDKPath.getAbsolutePath().equals(suspectSDKPath.getAbsolutePath())) { |
| 1707 | return false; // Most likely the SDK folder, skip it |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | String[] list = folder.list(); |
| 1712 | // If a bad folder or unreadable or whatever, this will come back null |
| 1713 | if (list == null) { |
| 1714 | return false; |
| 1715 | } |
| 1716 | |
| 1717 | // Alphabetize the list, since it's not always alpha order |
| 1718 | Arrays.sort(list, String.CASE_INSENSITIVE_ORDER); |
| 1719 | |
| 1720 | ActionListener listener = new ActionListener() { |
| 1721 | public void actionPerformed(ActionEvent e) { |
| 1722 | String path = e.getActionCommand(); |
| 1723 | if (new File(path).exists()) { |
| 1724 | boolean replace = replaceExisting; |
| 1725 | if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0) { |
| 1726 | replace = !replace; |
| 1727 | } |
| 1728 | // if (replace) { |
| 1729 | // handleOpenReplace(path); |
| 1730 | // } else { |
| 1731 | handleOpen(path); |
| 1732 | // } |
| 1733 | } else { |
| 1734 | Messages.showWarning("Sketch Disappeared", |
| 1735 | "The selected sketch no longer exists.\n" + |
| 1736 | "You may need to restart Processing to update\n" + |
| 1737 | "the sketchbook menu.", null); |
| 1738 | } |
| 1739 | } |
| 1740 | }; |
| 1741 | // offers no speed improvement |
| 1742 | //menu.addActionListener(listener); |
| 1743 | |
| 1744 | boolean found = false; |
| 1745 | |
| 1746 | // for (int i = 0; i < list.length; i++) { |
| 1747 | // if ((list[i].charAt(0) == '.') || |
| 1748 | // list[i].equals("CVS")) continue; |
no test coverage detected