Move purge to book context menu

This commit is contained in:
2020-02-08 21:31:02 +00:00
parent 5f34c57b23
commit 7e6a08d64b

View File

@@ -132,7 +132,6 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
JMenuItem bookNewChapter; JMenuItem bookNewChapter;
JMenuItem bookExportAudio; JMenuItem bookExportAudio;
JMenuItem bookPurgeBackups;
JMenu bookVisitACX; JMenu bookVisitACX;
JMenuItem bookVisitTitle; JMenuItem bookVisitTitle;
JMenuItem bookVisitAudition; JMenuItem bookVisitAudition;
@@ -296,17 +295,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
} }
}); });
bookPurgeBackups = new JMenuItem("Purge Backups");
bookPurgeBackups.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Debug.trace();
getBook().purgeBackups();
}
});
bookMenu.add(bookNewChapter); bookMenu.add(bookNewChapter);
bookMenu.add(bookExportAudio); bookMenu.add(bookExportAudio);
bookMenu.add(bookPurgeBackups);
bookVisitACX = new JMenu("Visit ACX"); bookVisitACX = new JMenu("Visit ACX");
bookMenu.add(bookVisitACX); bookMenu.add(bookVisitACX);
@@ -1847,18 +1837,16 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
Book book = (Book)node; Book book = (Book)node;
JPopupMenu menu = new JPopupMenu(); JPopupMenu menu = new JPopupMenu();
JMenuItem editData = new JMenuObject("Edit Data...", book, new ActionListener() { menu.add(new JMenuObject("Edit Data...", book, new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Debug.trace(); Debug.trace();
JMenuObject src = (JMenuObject)(e.getSource()); JMenuObject src = (JMenuObject)(e.getSource());
Book thisBook = (Book)(src.getObject()); Book thisBook = (Book)(src.getObject());
editBookInfo(thisBook); editBookInfo(thisBook);
} }
}); }));
menu.add(editData); menu.add(new JMenuObject("Reset all post gaps", book, new ActionListener() {
JMenuObject resetBookGaps = new JMenuObject("Reset all post gaps", book, new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Debug.trace(); Debug.trace();
JMenuObject src = (JMenuObject)(e.getSource()); JMenuObject src = (JMenuObject)(e.getSource());
@@ -1868,31 +1856,47 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
chap.resetPostGaps(); chap.resetPostGaps();
} }
} }
}); }));
menu.add(resetBookGaps); menu.add(new JMenuObject("Merge book...", book, new ActionListener() {
JMenuObject mergeBookMenu = new JMenuObject("Merge book...", book, new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Debug.trace(); Debug.trace();
JMenuObject src = (JMenuObject)(e.getSource()); JMenuObject src = (JMenuObject)(e.getSource());
Book thisBook = (Book)(src.getObject()); Book thisBook = (Book)(src.getObject());
mergeBook(thisBook); mergeBook(thisBook);
} }
}); }));
menu.add(mergeBookMenu);
menu.addSeparator(); menu.addSeparator();
JMenuObject closeBookMenu = new JMenuObject("Close book", book, new ActionListener() { menu.add(new JMenuObject("Scan for orphan files", book, new ActionListener() {
public void actionPerformed(ActionEvent e) {
Debug.trace();
JMenuObject src = (JMenuObject)(e.getSource());
Book thisBook = (Book)(src.getObject());
findOrphans(thisBook);
}
}));
menu.add(new JMenuObject("Purge backups", book, new ActionListener() {
public void actionPerformed(ActionEvent e) {
Debug.trace();
JMenuObject src = (JMenuObject)(e.getSource());
Book thisBook = (Book)(src.getObject());
thisBook.purgeBackups();
}
}));
menu.addSeparator();
menu.add(new JMenuObject("Close book", book, new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Debug.trace(); Debug.trace();
JMenuObject src = (JMenuObject)(e.getSource()); JMenuObject src = (JMenuObject)(e.getSource());
Book thisBook = (Book)(src.getObject()); Book thisBook = (Book)(src.getObject());
closeBook(thisBook); closeBook(thisBook);
} }
}); }));
menu.add(closeBookMenu);
menu.show(bookTree, e.getX(), e.getY()); menu.show(bookTree, e.getX(), e.getY());
} }
@@ -3609,13 +3613,14 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
return false; return false;
} }
public void gatherOrphans() { public void findOrphans(Book book) {
Chapter orphans = getChapterById("orphans"); Chapter orphans = getChapterById("orphans");
if (orphans == null) { if (orphans == null) {
orphans = new Chapter("orphans", "Orphan Files"); orphans = new Chapter("orphans", "Orphan Files");
bookTreeModel.insertNodeInto(orphans, getBook(), getBook().getChildCount()); orphans.setParentBook(book);
book.add(orphans);
} }
File bookRoot = new File(Options.get("path.storage"), getBook().getName()); File bookRoot = book.getLocation();
File[] files = new File(bookRoot, "files").listFiles(); File[] files = new File(bookRoot, "files").listFiles();
for (File f : files) { for (File f : files) {
String filename = f.getName(); String filename = f.getName();
@@ -3627,17 +3632,19 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
Debug.d("Testing orphanicity of", id); Debug.d("Testing orphanicity of", id);
if (!sentenceIdExists(id)) { if (!sentenceIdExists(id)) {
Sentence newSentence = new Sentence(id, id); Sentence newSentence = new Sentence(id, id);
newSentence.setParentBook(getBook()); newSentence.setParentBook(book);
bookTreeModel.insertNodeInto(newSentence, orphans, orphans.getChildCount()); orphans.add(newSentence);
} }
} }
} }
if (orphans.getChildCount() == 0) { if (orphans.getChildCount() == 0) {
try { book.remove(orphans);
bookTreeModel.removeNodeFromParent(orphans);
} catch (Exception ignored) {
}
} }
SwingUtilities.invokeLater(new Runnable() {
public void run() {
bookTreeModel.reload(book);
}
});
} }
public Chapter getChapterById(String id) { public Chapter getChapterById(String id) {