This commit is contained in:
Federico Fissore 2012-12-12 17:40:26 +01:00
parent cce70d269c
commit a5067567ed
3 changed files with 19 additions and 6 deletions

View File

@ -1182,8 +1182,13 @@ public class Base {
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER); Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
ActionListener listener = new ActionListener() { ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent event) {
activeEditor.getSketch().importLibrary(e.getActionCommand()); String jarPath = event.getActionCommand();
try {
activeEditor.getSketch().importLibrary(jarPath);
} catch (IOException e) {
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", jarPath), e);
}
} }
}; };
@ -1220,11 +1225,15 @@ public class Base {
// String packages[] = // String packages[] =
// Compiler.packageListFromClassPath(libraryClassPath); // Compiler.packageListFromClassPath(libraryClassPath);
libraries.add(subfolder); libraries.add(subfolder);
try {
String packages[] = String packages[] =
Compiler.headerListFromIncludePath(subfolder.getAbsolutePath()); Compiler.headerListFromIncludePath(subfolder.getAbsolutePath());
for (String pkg : packages) { for (String pkg : packages) {
importToLibraryTable.put(pkg, subfolder); importToLibraryTable.put(pkg, subfolder);
} }
} catch (IOException e) {
showWarning(_("Error"), I18n.format("Unable to list header files in {0}", subfolder), e);
}
JMenuItem item = new JMenuItem(libraryName); JMenuItem item = new JMenuItem(libraryName);
item.addActionListener(listener); item.addActionListener(listener);

View File

@ -1128,7 +1128,7 @@ public class Sketch {
* Add import statements to the current tab for all of packages inside * Add import statements to the current tab for all of packages inside
* the specified jar file. * the specified jar file.
*/ */
public void importLibrary(String jarPath) { public void importLibrary(String jarPath) throws IOException {
// make sure the user didn't hide the sketch folder // make sure the user didn't hide the sketch folder
ensureExistence(); ensureExistence();

View File

@ -644,14 +644,18 @@ public class Compiler implements MessageConsumer {
* not the header files in its sub-folders, as those should be included from * not the header files in its sub-folders, as those should be included from
* within the header files at the top-level). * within the header files at the top-level).
*/ */
static public String[] headerListFromIncludePath(String path) { static public String[] headerListFromIncludePath(String path) throws IOException {
FilenameFilter onlyHFiles = new FilenameFilter() { FilenameFilter onlyHFiles = new FilenameFilter() {
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
return name.endsWith(".h"); return name.endsWith(".h");
} }
}; };
return (new File(path)).list(onlyHFiles); String[] list = (new File(path)).list(onlyHFiles);
if (list == null) {
throw new IOException();
}
return list;
} }
static public ArrayList<File> findFilesInPath(String path, String extension, static public ArrayList<File> findFilesInPath(String path, String extension,