Second stage of open, occurs after having checked to see if the modifications (if any) to the previous sketch need to be saved.
(File sketchFile)
| 1764 | * modifications (if any) to the previous sketch need to be saved. |
| 1765 | */ |
| 1766 | protected boolean handleOpenInternal(File sketchFile) { |
| 1767 | // check to make sure that this .pde file is |
| 1768 | // in a folder of the same name |
| 1769 | String fileName = sketchFile.getName(); |
| 1770 | |
| 1771 | File file = Sketch.checkSketchFile(sketchFile); |
| 1772 | |
| 1773 | if (file == null) { |
| 1774 | if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) { |
| 1775 | |
| 1776 | Base.showWarning(tr("Bad file selected"), tr("Arduino can only open its own sketches\n" + |
| 1777 | "and other files ending in .ino or .pde"), null); |
| 1778 | return false; |
| 1779 | |
| 1780 | } else { |
| 1781 | String properParent = fileName.substring(0, fileName.length() - 4); |
| 1782 | |
| 1783 | Object[] options = {tr("OK"), tr("Cancel")}; |
| 1784 | String prompt = I18n.format(tr("The file \"{0}\" needs to be inside\n" + |
| 1785 | "a sketch folder named \"{1}\".\n" + |
| 1786 | "Create this folder, move the file, and continue?"), |
| 1787 | fileName, |
| 1788 | properParent); |
| 1789 | |
| 1790 | int result = JOptionPane.showOptionDialog(this, prompt, tr("Moving"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); |
| 1791 | |
| 1792 | if (result != JOptionPane.YES_OPTION) { |
| 1793 | return false; |
| 1794 | } |
| 1795 | |
| 1796 | // create properly named folder |
| 1797 | File properFolder = new File(sketchFile.getParent(), properParent); |
| 1798 | if (properFolder.exists()) { |
| 1799 | Base.showWarning(tr("Error"), I18n.format(tr("A folder named \"{0}\" already exists. " + |
| 1800 | "Can't open sketch."), properParent), null); |
| 1801 | return false; |
| 1802 | } |
| 1803 | if (!properFolder.mkdirs()) { |
| 1804 | //throw new IOException("Couldn't create sketch folder"); |
| 1805 | Base.showWarning(tr("Error"), tr("Could not create the sketch folder."), null); |
| 1806 | return false; |
| 1807 | } |
| 1808 | // copy the sketch inside |
| 1809 | File properPdeFile = new File(properFolder, sketchFile.getName()); |
| 1810 | try { |
| 1811 | Base.copyFile(sketchFile, properPdeFile); |
| 1812 | } catch (IOException e) { |
| 1813 | Base.showWarning(tr("Error"), tr("Could not copy to a proper location."), e); |
| 1814 | return false; |
| 1815 | } |
| 1816 | |
| 1817 | // remove the original file, so user doesn't get confused |
| 1818 | sketchFile.delete(); |
| 1819 | |
| 1820 | // update with the new path |
| 1821 | file = properPdeFile; |
| 1822 | |
| 1823 | } |
no test coverage detected