Support sending selected episode data from Episodes panel to Rename panel via context menu (not just clipboard copy & paste)
This commit is contained in:
parent
4bd0ed265d
commit
ec501bc2ed
|
@ -36,6 +36,8 @@ import javax.swing.border.LineBorder;
|
|||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import net.filebot.CacheManager;
|
||||
import net.filebot.Settings;
|
||||
import net.filebot.cli.GroovyPad;
|
||||
|
@ -137,9 +139,16 @@ public class MainFrame extends JFrame {
|
|||
installAction(this.getRootPane(), getKeyStroke(VK_F1, 0), newAction("Help", evt -> {
|
||||
GettingStartedStage.start();
|
||||
}));
|
||||
|
||||
SwingEventBus.getInstance().register(this);
|
||||
}
|
||||
|
||||
protected void showPanel(PanelBuilder selectedBuilder) {
|
||||
@Subscribe
|
||||
public void selectPanel(PanelBuilder panel) {
|
||||
selectionList.setSelectedValue(panel, false);
|
||||
}
|
||||
|
||||
private void showPanel(PanelBuilder selectedBuilder) {
|
||||
JComponent contentPane = (JComponent) getContentPane();
|
||||
JComponent selectedPanel = null;
|
||||
|
||||
|
|
|
@ -19,6 +19,11 @@ public class AnalyzePanelBuilder implements PanelBuilder {
|
|||
return ResourceManager.getIcon("panel.analyze");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof AnalyzePanelBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
AnalyzePanel panel = new AnalyzePanel();
|
||||
|
|
|
@ -39,6 +39,7 @@ import net.filebot.ui.FileBotList;
|
|||
import net.filebot.ui.FileBotListExportHandler;
|
||||
import net.filebot.ui.LanguageComboBox;
|
||||
import net.filebot.ui.SelectDialog;
|
||||
import net.filebot.ui.rename.RenamePanelBuilder;
|
||||
import net.filebot.ui.transfer.ArrayTransferable;
|
||||
import net.filebot.ui.transfer.ClipboardHandler;
|
||||
import net.filebot.ui.transfer.CompositeTranserable;
|
||||
|
@ -47,6 +48,7 @@ import net.filebot.util.StringUtilities;
|
|||
import net.filebot.util.ui.LabelProvider;
|
||||
import net.filebot.util.ui.SelectButton;
|
||||
import net.filebot.util.ui.SimpleLabelProvider;
|
||||
import net.filebot.util.ui.SwingEventBus;
|
||||
import net.filebot.web.Episode;
|
||||
import net.filebot.web.EpisodeListProvider;
|
||||
import net.filebot.web.SearchResult;
|
||||
|
@ -251,6 +253,13 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
|
|||
|
||||
// popup menu
|
||||
JPopupMenu popup = new JPopupMenu("Episodes");
|
||||
popup.add(newAction("Import", ResourceManager.getIcon("database.go"), evt -> {
|
||||
// switch to Rename panel
|
||||
SwingEventBus.getInstance().post(new RenamePanelBuilder());
|
||||
|
||||
// load episode data
|
||||
invokeLater(200, () -> SwingEventBus.getInstance().post(EpisodeListExportHandler.export(this, false)));
|
||||
}));
|
||||
popup.add(newAction("Copy", ResourceManager.getIcon("rename.action.copy"), evt -> {
|
||||
getTransferHandler().getClipboardHandler().exportToClipboard(this, Toolkit.getDefaultToolkit().getSystemClipboard(), TransferHandler.COPY);
|
||||
}));
|
||||
|
@ -268,7 +277,7 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
|
|||
|
||||
@Override
|
||||
public Transferable createTransferable(JComponent c) {
|
||||
Transferable episodeArray = new ArrayTransferable<Episode>(list.getModel().toArray(new Episode[0]));
|
||||
Transferable episodeArray = export(list, true);
|
||||
Transferable textFile = super.createTransferable(c);
|
||||
|
||||
return new CompositeTranserable(episodeArray, textFile);
|
||||
|
@ -276,16 +285,20 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
|
|||
|
||||
@Override
|
||||
public void exportToClipboard(JComponent c, Clipboard clipboard, int action) throws IllegalStateException {
|
||||
ArrayTransferable<Episode> episodeData = export(list, false);
|
||||
Transferable stringSelection = new StringSelection(StringUtilities.join(episodeData.getArray(), System.lineSeparator()));
|
||||
|
||||
clipboard.setContents(new CompositeTranserable(episodeData, stringSelection), null);
|
||||
}
|
||||
|
||||
public static ArrayTransferable<Episode> export(FileBotList<?> list, boolean forceAll) {
|
||||
Episode[] selection = ((List<?>) list.getListComponent().getSelectedValuesList()).stream().map(Episode.class::cast).toArray(Episode[]::new);
|
||||
|
||||
if (selection.length == 0) {
|
||||
if (forceAll || selection.length == 0) {
|
||||
selection = list.getModel().stream().map(Episode.class::cast).toArray(Episode[]::new);
|
||||
}
|
||||
|
||||
Transferable episodeArray = new ArrayTransferable<Episode>(selection);
|
||||
Transferable stringSelection = new StringSelection(StringUtilities.join(selection, "\n"));
|
||||
|
||||
clipboard.setContents(new CompositeTranserable(episodeArray, stringSelection), null);
|
||||
return new ArrayTransferable<Episode>(selection);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
|
||||
package net.filebot.ui.episodelist;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.filebot.ResourceManager;
|
||||
import net.filebot.ui.PanelBuilder;
|
||||
|
||||
|
||||
public class EpisodeListPanelBuilder implements PanelBuilder {
|
||||
|
||||
@Override
|
||||
|
@ -16,12 +14,15 @@ public class EpisodeListPanelBuilder implements PanelBuilder {
|
|||
return "Episodes";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("panel.episodelist");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof EpisodeListPanelBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
|
||||
package net.filebot.ui.list;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.filebot.ResourceManager;
|
||||
import net.filebot.ui.PanelBuilder;
|
||||
|
||||
|
||||
public class ListPanelBuilder implements PanelBuilder {
|
||||
|
||||
@Override
|
||||
|
@ -16,12 +14,15 @@ public class ListPanelBuilder implements PanelBuilder {
|
|||
return "List";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("panel.list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof ListPanelBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
|
|
|
@ -43,7 +43,7 @@ class NamesListTransferablePolicy extends FileTransferablePolicy {
|
|||
|
||||
@Override
|
||||
public boolean accept(Transferable tr) throws Exception {
|
||||
return tr.isDataFlavorSupported(stringFlavor) || hasFileListFlavor(tr);
|
||||
return hasFileListFlavor(tr) || tr.isDataFlavorSupported(stringFlavor) || tr.isDataFlavorSupported(episodeArrayFlavor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -647,10 +647,12 @@ public class RenamePanel extends JComponent {
|
|||
|
||||
@Subscribe
|
||||
public void handle(Transferable transferable) throws Exception {
|
||||
TransferablePolicy handler = filesList.getTransferablePolicy();
|
||||
|
||||
if (handler != null && handler.accept(transferable)) {
|
||||
handler.handleTransferable(transferable, TransferAction.PUT);
|
||||
for (TransferablePolicy handler : new TransferablePolicy[] { filesList.getTransferablePolicy(), namesList.getTransferablePolicy() }) {
|
||||
System.out.println(handler.accept(transferable));
|
||||
if (handler != null && handler.accept(transferable)) {
|
||||
handler.handleTransferable(transferable, TransferAction.PUT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
|
||||
package net.filebot.ui.rename;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.filebot.ResourceManager;
|
||||
import net.filebot.ui.PanelBuilder;
|
||||
|
||||
|
||||
public class RenamePanelBuilder implements PanelBuilder {
|
||||
|
||||
@Override
|
||||
|
@ -16,12 +14,15 @@ public class RenamePanelBuilder implements PanelBuilder {
|
|||
return "Rename";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("panel.rename");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof RenamePanelBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
|
||||
package net.filebot.ui.sfv;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.filebot.ResourceManager;
|
||||
import net.filebot.ui.PanelBuilder;
|
||||
|
||||
|
||||
public class SfvPanelBuilder implements PanelBuilder {
|
||||
|
||||
@Override
|
||||
|
@ -16,12 +14,15 @@ public class SfvPanelBuilder implements PanelBuilder {
|
|||
return "SFV";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("panel.sfv");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof SfvPanelBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
|
||||
package net.filebot.ui.subtitle;
|
||||
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import net.filebot.ResourceManager;
|
||||
import net.filebot.ui.PanelBuilder;
|
||||
|
||||
|
||||
public class SubtitlePanelBuilder implements PanelBuilder {
|
||||
|
||||
@Override
|
||||
|
@ -16,12 +14,15 @@ public class SubtitlePanelBuilder implements PanelBuilder {
|
|||
return "Subtitles";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ResourceManager.getIcon("panel.subtitle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof SubtitlePanelBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent create() {
|
||||
|
|
|
@ -18,10 +18,14 @@ public class ArrayTransferable<T> implements Transferable {
|
|||
this.array = array;
|
||||
}
|
||||
|
||||
public T[] getArray() {
|
||||
return array.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||
if (isDataFlavorSupported(flavor)) {
|
||||
return array;
|
||||
return getArray();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -24,6 +24,21 @@ public class SwingEventBus extends AsyncEventBus {
|
|||
super(SwingUtilities::invokeLater, SwingEventBus::handleException);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Object object) {
|
||||
SwingUtilities.invokeLater(() -> super.register(object));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(Object object) {
|
||||
SwingUtilities.invokeLater(() -> super.unregister(object));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void post(Object object) {
|
||||
SwingUtilities.invokeLater(() -> super.post(object));
|
||||
}
|
||||
|
||||
protected static void handleException(Throwable throwable, SubscriberExceptionContext context) {
|
||||
debug.log(Level.WARNING, "Failed to handle event: " + context.getEvent(), throwable);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue