Move addChapter

This commit is contained in:
2020-02-08 22:24:33 +00:00
parent f0ae69d610
commit 577ff9c1eb
@@ -130,7 +130,6 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
JMenuItem fileExit; JMenuItem fileExit;
JMenuItem fileOpenArchive; JMenuItem fileOpenArchive;
JMenuItem bookNewChapter;
JMenuItem bookExportAudio; JMenuItem bookExportAudio;
JMenu bookVisitACX; JMenu bookVisitACX;
JMenuItem bookVisitTitle; JMenuItem bookVisitTitle;
@@ -276,14 +275,6 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
bookMenu = new JMenu("Book"); bookMenu = new JMenu("Book");
bookNewChapter = new JMenuItem("New Chapter");
bookNewChapter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Debug.trace();
addChapter();
}
});
bookExportAudio = new JMenuItem("Export Audio"); bookExportAudio = new JMenuItem("Export Audio");
bookExportAudio.addActionListener(new ActionListener() { bookExportAudio.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@@ -292,7 +283,6 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
} }
}); });
bookMenu.add(bookNewChapter);
bookMenu.add(bookExportAudio); bookMenu.add(bookExportAudio);
bookVisitACX = new JMenu("Visit ACX"); bookVisitACX = new JMenu("Visit ACX");
@@ -1812,6 +1802,17 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
Book book = (Book)node; Book book = (Book)node;
JPopupMenu menu = new JPopupMenu(); JPopupMenu menu = new JPopupMenu();
menu.add(new JMenuObject("Add chapter", book, new ActionListener() {
public void actionPerformed(ActionEvent e) {
Debug.trace();
JMenuObject src = (JMenuObject)(e.getSource());
Book thisBook = (Book)(src.getObject());
addChapter(thisBook);
}
}));
menu.addSeparator();
menu.add(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();
@@ -2190,9 +2191,15 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
} }
public void addChapter() { public void addChapter() {
if (getBook() != null) {
addChapter(getBook());
}
}
public void addChapter(Book book) {
Debug.trace(); Debug.trace();
Chapter last = getBook().getLastChapter(); Chapter last = book.getLastChapter();
String name = "Chapter " + (getBook().getChildCount() + 1); String name = "Chapter " + (book.getChildCount() + 1);
if (last != null) { if (last != null) {
String lastname = last.getName(); String lastname = last.getName();
Pattern p = Pattern.compile("^([^\\d]+)(\\d+)$"); Pattern p = Pattern.compile("^([^\\d]+)(\\d+)$");
@@ -2203,8 +2210,9 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
name = chapname + (chapnum + 1); name = chapname + (chapnum + 1);
} }
} }
Chapter c = getBook().addChapter(name); Chapter c = book.addChapter(name);
bookTreeModel.reload(c); bookTreeModel.reload(book);
bookTree.setSelectionPath(new TreePath(c.getPath()));
bookTree.scrollPathToVisible(new TreePath(c.getPath())); bookTree.scrollPathToVisible(new TreePath(c.getPath()));
} }