Skip to content

Commit

Permalink
explicitly set extension of file on save, which will trigger turtle f…
Browse files Browse the repository at this point in the history
…actory to save correctly.
  • Loading branch information
i-make-robots committed Feb 21, 2025
1 parent 8768012 commit 1a53d20
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettingsManager;
import com.marginallyclever.makelangelo.turtle.Turtle;
import com.marginallyclever.nodegraphcore.Node;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.filechooser.FileNameExtensionFilter;

/**
* Save a {@link Turtle} to a file.
*/
Expand All @@ -35,10 +38,21 @@ public void update() {
if(filenameValue==null || filenameValue.isEmpty()) return;

try {
var fc = TurtleFactory.getSaveFileChooser();
String withExtension = addExtension(filenameValue,((FileNameExtensionFilter)fc.getFileFilter()).getExtensions());
logger.debug("File selected by user: {}", withExtension);
PlotterSettings settings = PlotterSettingsManager.buildMakelangelo5();
TurtleFactory.save(turtle.getValue(),filenameValue,settings);
TurtleFactory.save(turtle.getValue(),withExtension,settings);
} catch (Exception e) {
logger.warn("Failed to save", e);
}
}

private String addExtension(String name, String [] extensions) {
for( String e : extensions ) {
if(FilenameUtils.getExtension(name).equalsIgnoreCase(e)) return name;
}

return name + "." + extensions[0];
}
}

0 comments on commit 1a53d20

Please # to comment.