| 42 | |
| 43 | |
| 44 | public class Archiver implements Tool { |
| 45 | Editor editor; |
| 46 | |
| 47 | // someday these will be settable |
| 48 | boolean useDate; |
| 49 | int digits = 3; |
| 50 | |
| 51 | NumberFormat numberFormat; |
| 52 | SimpleDateFormat dateFormat; |
| 53 | |
| 54 | |
| 55 | public String getMenuTitle() { |
| 56 | return tr("Archive Sketch"); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | public void init(Editor editor) { |
| 61 | this.editor = editor; |
| 62 | |
| 63 | numberFormat = NumberFormat.getInstance(); |
| 64 | numberFormat.setGroupingUsed(false); // no commas |
| 65 | numberFormat.setMinimumIntegerDigits(digits); |
| 66 | |
| 67 | dateFormat = new SimpleDateFormat("yyMMdd"); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | public void run() { |
| 72 | SketchController sketch = editor.getSketchController(); |
| 73 | |
| 74 | // first save the sketch so that things don't archive strangely |
| 75 | boolean success = false; |
| 76 | try { |
| 77 | success = sketch.save(); |
| 78 | } catch (Exception e) { |
| 79 | e.printStackTrace(); |
| 80 | } |
| 81 | if (!success) { |
| 82 | Base.showWarning(tr("Couldn't archive sketch"), |
| 83 | tr("Archiving the sketch has been canceled because\nthe sketch couldn't save properly."), null); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | File location = sketch.getSketch().getFolder(); |
| 88 | String name = location.getName(); |
| 89 | File parent = new File(location.getParent()); |
| 90 | |
| 91 | //System.out.println("loc " + location); |
| 92 | //System.out.println("par " + parent); |
| 93 | |
| 94 | File newbie = null; |
| 95 | String namely = null; |
| 96 | int index = 0; |
| 97 | do { |
| 98 | // only use the date if the sketch name isn't the default name |
| 99 | useDate = !name.startsWith("sketch_"); |
| 100 | |
| 101 | if (useDate) { |
nothing calls this directly
no outgoing calls
no test coverage detected