()
| 510 | } |
| 511 | |
| 512 | @AstroImageJ(reason = "Add save listener", modified = true) |
| 513 | void save() { |
| 514 | if (path==null) { |
| 515 | saveAs(); |
| 516 | return; |
| 517 | } |
| 518 | File f = new File(path); |
| 519 | if (f.exists() && !f.canWrite()) { |
| 520 | IJ.showMessage("Editor", "Unable to save because file is write-protected. \n \n" + path); |
| 521 | return; |
| 522 | } |
| 523 | String text = ta.getText(); |
| 524 | char[] chars = new char[text.length()]; |
| 525 | text.getChars(0, text.length(), chars, 0); |
| 526 | try { |
| 527 | BufferedReader br = new BufferedReader(new CharArrayReader(chars)); |
| 528 | BufferedWriter bw = new BufferedWriter(new FileWriter(path)); |
| 529 | while (true) { |
| 530 | String s = br.readLine(); |
| 531 | if (s==null) break; |
| 532 | bw.write(s, 0, s.length()); |
| 533 | bw.newLine(); |
| 534 | } |
| 535 | bw.close(); |
| 536 | IJ.showStatus(text.length()+" chars saved to " + path); |
| 537 | changes = false; |
| 538 | |
| 539 | saveListeners.forEach(Runnable::run); |
| 540 | } catch |
| 541 | (IOException e) {} |
| 542 | } |
| 543 | |
| 544 | void compileAndRun() { |
| 545 | if (path==null) |
no test coverage detected