X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FLocalReaderFrame.java;h=bf94f26f8d7ceb1a197a7ab588e33fd4b1652fc9;hb=68e2c6d20049d713de1bd31b749450b2f60d8340;hp=bb77655b7734c48c05ecf6eb4458662bbcdeb1fd;hpb=5ce869b82f28c4d288b266d7dee03aa4898fff21;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java b/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java index bb77655..bf94f26 100644 --- a/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/LocalReaderFrame.java @@ -13,6 +13,7 @@ import java.awt.event.WindowEvent; import java.io.File; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -33,7 +34,7 @@ import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.Library; +import be.nikiroo.fanfix.LocalLibrary; import be.nikiroo.fanfix.bundles.Config; import be.nikiroo.fanfix.bundles.UiConfig; import be.nikiroo.fanfix.data.MetaData; @@ -70,7 +71,7 @@ class LocalReaderFrame extends JFrame { * * @param reader * the associated {@link LocalReader} to forward some commands - * and access its {@link Library} + * and access its {@link LocalLibrary} * @param type * the type of {@link Story} to load, or NULL for all types */ @@ -124,7 +125,7 @@ class LocalReaderFrame extends JFrame { final String typeF = type; outOfUi(pg, new Runnable() { public void run() { - Instance.getLibrary().refresh(pg); + Instance.getLibrary().refresh(false, pg); invalidate(); setJMenuBar(createMenu()); addBookPane(typeF, true); @@ -142,14 +143,15 @@ class LocalReaderFrame extends JFrame { * the selected type or author. * * @param value - * the author or the type + * the author or the type, or NULL to get all the + * authors-or-types * @param type * TRUE for type, FALSE for author */ private void addBookPane(String value, boolean type) { if (value == null) { if (type) { - for (String tt : Instance.getLibrary().getTypes()) { + for (String tt : Instance.getLibrary().getSources()) { if (tt != null) { addBookPane(tt, type); } @@ -188,6 +190,7 @@ class LocalReaderFrame extends JFrame { popup.add(createMenuItemOpenBook()); popup.addSeparator(); popup.add(createMenuItemExport()); + popup.add(createMenuItemMove()); popup.add(createMenuItemClearCache()); popup.add(createMenuItemRedownload()); popup.addSeparator(); @@ -217,7 +220,7 @@ class LocalReaderFrame extends JFrame { */ private void refreshBooks() { for (LocalReaderGroup group : booksByType.keySet()) { - List stories = Instance.getLibrary().getListByType( + List stories = Instance.getLibrary().getListBySource( booksByType.get(group)); group.refreshBooks(stories, words); } @@ -265,6 +268,7 @@ class LocalReaderFrame extends JFrame { file.add(createMenuItemOpenBook()); file.add(createMenuItemExport()); + file.add(createMenuItemMove()); file.addSeparator(); file.add(imprt); file.add(imprtF); @@ -308,7 +312,7 @@ class LocalReaderFrame extends JFrame { JMenu sources = new JMenu("Sources"); sources.setMnemonic(KeyEvent.VK_S); - List tt = Instance.getLibrary().getTypes(); + List tt = Instance.getLibrary().getSources(); tt.add(0, null); for (final String type : tt) { JMenuItem item = new JMenuItem(type == null ? "All" : type); @@ -527,6 +531,68 @@ class LocalReaderFrame extends JFrame { return refresh; } + /** + * Create the delete menu item. + * + * @return the item + */ + private JMenuItem createMenuItemMove() { + JMenu moveTo = new JMenu("Move to..."); + moveTo.setMnemonic(KeyEvent.VK_M); + + List types = new ArrayList(); + types.add(null); + types.addAll(Instance.getLibrary().getSources()); + + for (String type : types) { + JMenuItem item = new JMenuItem(type == null ? "New type..." : type); + + moveTo.add(item); + if (type == null) { + moveTo.addSeparator(); + } + + final String ftype = type; + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (selectedBook != null) { + String type = ftype; + if (type == null) { + Object rep = JOptionPane.showInputDialog( + LocalReaderFrame.this, "Move to:", + "Moving story", + JOptionPane.QUESTION_MESSAGE, null, null, + selectedBook.getMeta().getSource()); + if (rep == null) { + return; + } else { + type = rep.toString(); + } + } + + final String ftype = type; + outOfUi(null, new Runnable() { + public void run() { + reader.changeType(selectedBook.getMeta() + .getLuid(), ftype); + + selectedBook = null; + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + setJMenuBar(createMenu()); + } + }); + } + }); + } + } + }); + } + + return moveTo; + } + /** * Create the redownload (then delete original) menu item. * @@ -658,7 +724,7 @@ class LocalReaderFrame extends JFrame { } /** - * Import a {@link Story} into the main {@link Library}. + * Import a {@link Story} into the main {@link LocalLibrary}. *

* Should be called inside the UI thread. * @@ -698,7 +764,7 @@ class LocalReaderFrame extends JFrame { } /** - * Actually import the {@link Story} into the main {@link Library}. + * Actually import the {@link Story} into the main {@link LocalLibrary}. *

* Should be called inside the UI thread. *