Prompt for a sketch to open, and open it in a new window. @throws Exception
()
| 817 | * @throws Exception |
| 818 | */ |
| 819 | public void handleOpenPrompt() throws Exception { |
| 820 | // get the frontmost window frame for placing file dialog |
| 821 | FileDialog fd = new FileDialog(activeEditor, tr("Open an Arduino sketch..."), FileDialog.LOAD); |
| 822 | File lastFolder = new File(PreferencesData.get("last.folder", BaseNoGui.getSketchbookFolder().getAbsolutePath())); |
| 823 | if (lastFolder.exists() && lastFolder.isFile()) { |
| 824 | lastFolder = lastFolder.getParentFile(); |
| 825 | } |
| 826 | fd.setDirectory(lastFolder.getAbsolutePath()); |
| 827 | |
| 828 | // Only show .pde files as eligible bachelors |
| 829 | fd.setFilenameFilter(new FilenameFilter() { |
| 830 | public boolean accept(File dir, String name) { |
| 831 | return name.toLowerCase().endsWith(".ino") |
| 832 | || name.toLowerCase().endsWith(".pde"); |
| 833 | } |
| 834 | }); |
| 835 | |
| 836 | fd.setVisible(true); |
| 837 | |
| 838 | String directory = fd.getDirectory(); |
| 839 | String filename = fd.getFile(); |
| 840 | |
| 841 | // User canceled selection |
| 842 | if (filename == null) return; |
| 843 | |
| 844 | File inputFile = new File(directory, filename); |
| 845 | |
| 846 | PreferencesData.set("last.folder", inputFile.getAbsolutePath()); |
| 847 | handleOpen(inputFile); |
| 848 | } |
| 849 | |
| 850 | |
| 851 | /** |
no test coverage detected