/** * Handles 'Save As' for a build. * * <p>This basically just duplicates the current build to a new location, and then calls 'Save'. * (needs to take the current state of the open files and save them to the new folder.. but not * save over the old versions for the old sketch..) * * <p>Also removes the previously-generated .class and .jar files, because they can cause trouble. */ public boolean saveAs() throws IOException { // get new name for folder FileDialog fd = new FileDialog(new Frame(), "Save file as...", FileDialog.SAVE); // default to the folder that this file is in fd.setDirectory(folder.getCanonicalPath()); fd.setFile(mainFilename); fd.setVisible(true); String parentDir = fd.getDirectory(); String newName = fd.getFile(); // user cancelled selection if (newName == null) return false; File folder = new File(parentDir); // Find base name if (newName.toLowerCase().endsWith(".gcode")) newName = newName.substring(0, newName.length() - 6); if (newName.toLowerCase().endsWith(".ngc")) newName = newName.substring(0, newName.length() - 4); if (newName.toLowerCase().endsWith(".stl")) newName = newName.substring(0, newName.length() - 4); if (newName.toLowerCase().endsWith(".obj")) newName = newName.substring(0, newName.length() - 4); if (newName.toLowerCase().endsWith(".dae")) newName = newName.substring(0, newName.length() - 4); BuildCode code = getCode(); if (code != null) { // grab the contents of the current tab before saving // first get the contents of the editor text area if (hasMainWindow) { if (code.isModified()) { code.program = editor.getText(); } } File newFile = new File(folder, newName + ".gcode"); code.saveAs(newFile); } BuildModel model = getModel(); if (model != null) { File newFile = new File(folder, newName + ".stl"); model.saveAs(newFile); } this.name = newName; this.mainFilename = fd.getFile(); this.folder = folder; return true; }