예제 #1
0
  /** Save all code in the current sketch. */
  public boolean save() throws IOException {
    if (mainFilename == null) {
      return saveAs();
    }

    if (isReadOnly()) {
      // if the files are read-only, need to first do a "save as".
      Base.showMessage(
          "File is read-only",
          "This file is marked \"read-only\", so you'll\n"
              + "need to re-save this file to another location.");
      // if the user cancels, give up on the save()
      if (!saveAs()) return false;
      return true;
    }

    BuildCode code = getCode();
    if (code != null) {
      if (hasMainWindow) {
        if (code.isModified()) {
          code.program = editor.getText();
          code.save();
        }
      }
    }
    BuildModel model = getModel();
    if (model != null) {
      if (model.isModified()) {
        model.save();
      }
    }
    return true;
  }
예제 #2
0
  /**
   * 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;
  }