diff --git a/src/org/jdownloader/gui/views/downloads/action/MergeToPackageAction.java b/src/org/jdownloader/gui/views/downloads/action/MergeToPackageAction.java index 09a8da5c0b..2d64010378 100644 --- a/src/org/jdownloader/gui/views/downloads/action/MergeToPackageAction.java +++ b/src/org/jdownloader/gui/views/downloads/action/MergeToPackageAction.java @@ -1,10 +1,9 @@ package org.jdownloader.gui.views.downloads.action; import java.awt.event.ActionEvent; -import java.util.HashSet; +import java.util.ArrayList; import java.util.List; -import org.appwork.utils.Regex; import org.appwork.utils.StringUtils; import org.appwork.utils.event.queue.QueueAction; import org.appwork.utils.swing.dialog.Dialog; @@ -23,6 +22,7 @@ import org.jdownloader.gui.views.linkgrabber.contextmenu.NewPackageDialog; import org.jdownloader.translate._JDT; import jd.controlling.downloadcontroller.DownloadController; +import jd.controlling.packagecontroller.AbstractNode; import jd.plugins.DownloadLink; import jd.plugins.FilePackage; @@ -119,24 +119,9 @@ public class MergeToPackageAction extends CustomizableTableContextAppAction commentDups = new HashSet(); - for (PackageView pv : sel.getPackageViews()) { - final String comment = pv.getPackage().getComment(); - if (StringUtils.isNotEmpty(comment)) { - final String[] commentLines = Regex.getLines(comment); - for (final String commentLine : commentLines) { - if (StringUtils.isNotEmpty(commentLine) && commentDups.add(commentLine)) { - if (sb.length() > 0) { - sb.append("\r\n"); - } - sb.append(commentLine); - } - } - } - } - if (sb.length() > 0) { - newPackage.setComment(sb.toString()); + final String mergedComment = mergePackageComments(sel.getPackageViews()); + if (!StringUtils.isEmpty(mergedComment)) { + newPackage.setComment(mergedComment); } switch (getLocation()) { case AFTER_SELECTION: @@ -170,22 +155,10 @@ public class MergeToPackageAction extends CustomizableTableContextAppAction> packages) { - final StringBuilder sb = new StringBuilder(); - final HashSet commentDups = new HashSet(); + final List filepackages = new ArrayList(); for (PackageView pv : packages) { - final String comment = pv.getPackage().getComment(); - if (StringUtils.isNotEmpty(comment)) { - final String[] commentLines = Regex.getLines(comment); - for (final String commentLine : commentLines) { - if (StringUtils.isNotEmpty(commentLine) && commentDups.add(commentLine)) { - if (sb.length() > 0) { - sb.append("\r\n"); - } - sb.append(commentLine); - } - } - } + filepackages.add(pv.getPackage()); } - return sb.toString(); + return org.jdownloader.gui.views.linkgrabber.contextmenu.MergeToPackageAction.mergePackageComments(filepackages); } } diff --git a/src/org/jdownloader/gui/views/downloads/contextmenumanager/MenuManagerDownloadTableContext.java b/src/org/jdownloader/gui/views/downloads/contextmenumanager/MenuManagerDownloadTableContext.java index 4a969b3d25..28f48116dc 100644 --- a/src/org/jdownloader/gui/views/downloads/contextmenumanager/MenuManagerDownloadTableContext.java +++ b/src/org/jdownloader/gui/views/downloads/contextmenumanager/MenuManagerDownloadTableContext.java @@ -1,8 +1,5 @@ package org.jdownloader.gui.views.downloads.contextmenumanager; -import jd.plugins.DownloadLink; -import jd.plugins.FilePackage; - import org.appwork.utils.os.CrossSystem; import org.appwork.utils.swing.EDTRunner; import org.jdownloader.controlling.contextmenu.ActionData; @@ -56,12 +53,16 @@ import org.jdownloader.gui.views.downloads.context.submenu.PriorityMenuContainer import org.jdownloader.gui.views.downloads.context.submenu.SettingsMenuContainer; import org.jdownloader.gui.views.downloads.table.DownloadsTable; import org.jdownloader.gui.views.downloads.table.DownloadsTableModel; +import org.jdownloader.gui.views.linkgrabber.actions.MergeSameNamedPackagesAction; import org.jdownloader.gui.views.linkgrabber.bottombar.IncludedSelectionSetup; import org.jdownloader.gui.views.linkgrabber.contextmenu.AddContainerContextMenuAction; import org.jdownloader.gui.views.linkgrabber.contextmenu.AddLinksContextMenuAction; import org.jdownloader.gui.views.linkgrabber.contextmenu.SortAction; import org.jdownloader.settings.GraphicalUserInterfaceSettings.DeleteFileOptions; +import jd.plugins.DownloadLink; +import jd.plugins.FilePackage; + public class MenuManagerDownloadTableContext extends ContextMenuManager { private static final MenuManagerDownloadTableContext INSTANCE = new MenuManagerDownloadTableContext(); @@ -91,7 +92,6 @@ public class MenuManagerDownloadTableContext extends ContextMenuManager> dupes = new HashMap>(); - final List pckages; - final boolean isLinkgrabber; - if (MainTabbedPane.getInstance().isDownloadView()) { - pckages = DownloadController.getInstance().getPackages(); - isLinkgrabber = false; - } else if (MainTabbedPane.getInstance().isLinkgrabberView()) { - final LinkCollector lc = LinkCollector.getInstance(); - pckages = lc.getPackages(); - isLinkgrabber = true; - } else { - return; - } final boolean caseInsensitive = isMatchPackageNamesCaseInsensitive(); - boolean foundDupes = false; final SelectionInfo sel = getSelection(); /* If user has selected a package, only collect duplicates of name of selected package. */ Map selectedPackagesMap = null; @@ -109,8 +94,30 @@ public class MergeSameNamedPackagesAction extends CustomizableTableContextAppAct } selectedPackagesMap.put(compareName, crawledpackage); } + if (selectedPackagesMap.isEmpty()) { + /* Do nothing */ + return; + } } - for (Object pckage : pckages) { + final Map> dupes = new HashMap>(); + final List packages = new ArrayList(); + final boolean isLinkgrabber; + if (MainTabbedPane.getInstance().isDownloadView()) { + isLinkgrabber = false; + for (final FilePackage item : DownloadController.getInstance().getPackages()) { + packages.add(item); + } + } else if (MainTabbedPane.getInstance().isLinkgrabberView()) { + isLinkgrabber = true; + for (final CrawledPackage item : LinkCollector.getInstance().getPackages()) { + packages.add(item); + } + } else { + /* This should never happen */ + return; + } + boolean foundDupes = false; + for (final AbstractNode pckage : packages) { String packagename; if (isLinkgrabber) { packagename = ((CrawledPackage) pckage).getName(); @@ -124,12 +131,12 @@ public class MergeSameNamedPackagesAction extends CustomizableTableContextAppAct /* Only search dupes for selected package(s) */ continue; } - List thisdupeslist = dupes.get(packagename); + List thisdupeslist = dupes.get(packagename); if (thisdupeslist != null) { /* We got at least two packages with the same name */ foundDupes = true; } else { - thisdupeslist = new ArrayList(); + thisdupeslist = new ArrayList(); dupes.put(packagename, thisdupeslist); } thisdupeslist.add(pckage); @@ -143,30 +150,40 @@ public class MergeSameNamedPackagesAction extends CustomizableTableContextAppAct @Override protected Void run() throws RuntimeException { /* Merge dupes */ - final Iterator>> dupes_iterator = dupes.entrySet().iterator(); + final Iterator>> dupes_iterator = dupes.entrySet().iterator(); while (dupes_iterator.hasNext()) { - final Entry> entry = dupes_iterator.next(); + final Entry> entry = dupes_iterator.next(); // final String packagename = entry.getKey(); - final List thisdupes = entry.getValue(); + final List thisdupes = entry.getValue(); if (thisdupes.size() == 1) { /* We need at least two packages to be able to merge them. */ continue; } /* Merge comments of all packages so we don't lose any information. */ if (isLinkgrabber) { - final List linkgrabberdupes = new ArrayList(); - for (final Object thisdupe : thisdupes) { - linkgrabberdupes.add((CrawledPackage) thisdupe); + final List casteddupes = new ArrayList(); + for (final AbstractNode thisdupe : thisdupes) { + casteddupes.add((CrawledPackage) thisdupe); } - final String mergedComments = MergeToPackageAction.mergeCrawledPackageListComments(linkgrabberdupes); + final String mergedComments = MergeToPackageAction.mergePackageComments(thisdupes); /* Pick package to merge the others into */ final CrawledPackage target = (CrawledPackage) thisdupes.remove(0); if (!StringUtils.isEmpty(mergedComments)) { target.setComment(mergedComments); } - LinkCollector.getInstance().merge(target, linkgrabberdupes, MergePosition.BOTTOM); + LinkCollector.getInstance().merge(target, casteddupes, MergePosition.BOTTOM); } else { - // TODO + final List casteddupes = new ArrayList(); + for (final AbstractNode thisdupe : thisdupes) { + casteddupes.add((FilePackage) thisdupe); + } + final String mergedComments = MergeToPackageAction.mergePackageComments(thisdupes); + /* Pick package to merge the others into */ + final FilePackage target = (FilePackage) thisdupes.remove(0); + if (!StringUtils.isEmpty(mergedComments)) { + target.setComment(mergedComments); + } + DownloadController.getInstance().merge(target, casteddupes, MergePosition.BOTTOM); } } return null; diff --git a/src/org/jdownloader/gui/views/linkgrabber/contextmenu/MenuManagerLinkgrabberTableContext.java b/src/org/jdownloader/gui/views/linkgrabber/contextmenu/MenuManagerLinkgrabberTableContext.java index f4fc684bdd..5944e76772 100644 --- a/src/org/jdownloader/gui/views/linkgrabber/contextmenu/MenuManagerLinkgrabberTableContext.java +++ b/src/org/jdownloader/gui/views/linkgrabber/contextmenu/MenuManagerLinkgrabberTableContext.java @@ -2,7 +2,6 @@ package org.jdownloader.gui.views.linkgrabber.contextmenu; import javax.swing.KeyStroke; -import org.appwork.utils.DebugMode; import org.appwork.utils.os.CrossSystem; import org.jdownloader.controlling.contextmenu.ActionData; import org.jdownloader.controlling.contextmenu.ContextMenuManager; @@ -94,6 +93,7 @@ public class MenuManagerLinkgrabberTableContext extends ContextMenuManager implements ActionContext { /** @@ -157,19 +159,24 @@ public class MergeToPackageAction extends CustomizableTableContextAppAction> packages) { - final List crawledpackagelist = new ArrayList(); + final List crawledpackagelist = new ArrayList(); for (PackageView pv : packages) { crawledpackagelist.add(pv.getPackage()); } - return mergeCrawledPackageListComments(crawledpackagelist); + return mergePackageComments(crawledpackagelist); } /** Merges comments of given packages into one string. */ - public static String mergeCrawledPackageListComments(final List packages) { + public static String mergePackageComments(final List packages) { final StringBuilder sb = new StringBuilder(); final HashSet commentDups = new HashSet(); - for (final CrawledPackage cp : packages) { - final String comment = cp.getComment(); + for (final AbstractNode cp : packages) { + final String comment; + if (cp instanceof CrawledPackage) { + comment = ((CrawledPackage) cp).getComment(); + } else { + comment = ((FilePackage) cp).getComment(); + } if (StringUtils.isNotEmpty(comment)) { final String[] commentLines = Regex.getLines(comment); for (final String commentLine : commentLines) {