| 35 | |
| 36 | |
| 37 | public class Archiver implements Tool { |
| 38 | Base base; |
| 39 | Editor editor; |
| 40 | |
| 41 | // someday these will be settable |
| 42 | boolean useDate; |
| 43 | int digits = 3; |
| 44 | |
| 45 | NumberFormat numberFormat; |
| 46 | SimpleDateFormat dateFormat; |
| 47 | |
| 48 | |
| 49 | public String getMenuTitle() { |
| 50 | return Language.text("menu.tools.archive_sketch"); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | public void init(Base base) { |
| 55 | this.base = base; |
| 56 | |
| 57 | numberFormat = NumberFormat.getInstance(); |
| 58 | numberFormat.setGroupingUsed(false); // no commas |
| 59 | numberFormat.setMinimumIntegerDigits(digits); |
| 60 | |
| 61 | dateFormat = new SimpleDateFormat("yyMMdd"); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | public void run() { |
| 66 | editor = base.getActiveEditor(); |
| 67 | Sketch sketch = editor.getSketch(); |
| 68 | |
| 69 | if (sketch.isModified()) { |
| 70 | Messages.showWarning("Save", "Please save the sketch before archiving."); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | File location = sketch.getFolder(); |
| 75 | String name = location.getName(); |
| 76 | File parent = new File(location.getParent()); |
| 77 | |
| 78 | File newbie = null; |
| 79 | String namely = null; |
| 80 | int index = 0; |
| 81 | do { |
| 82 | // only use the date if the sketch name isn't the default name |
| 83 | useDate = !name.startsWith("sketch_"); |
| 84 | |
| 85 | if (useDate) { |
| 86 | String purty = dateFormat.format(new Date()); |
| 87 | String stamp = purty + ((char) ('a' + index)); |
| 88 | namely = name + "-" + stamp; |
| 89 | newbie = new File(parent, namely + ".zip"); |
| 90 | |
| 91 | } else { |
| 92 | String diggie = numberFormat.format(index + 1); |
| 93 | namely = name + "-" + diggie; |
| 94 | newbie = new File(parent, namely + ".zip"); |
nothing calls this directly
no outgoing calls
no test coverage detected