Proper removing search results on SWF close

This commit is contained in:
Jindra Petřík
2021-02-23 22:50:48 +01:00
parent 43baf9d178
commit d6cf6a2c8b
9 changed files with 70 additions and 28 deletions

View File

@@ -176,4 +176,9 @@ public class ABCSearchResult implements Serializable, ScriptSearchResult {
return result;
}
@Override
public SWF getSWF() {
return scriptPack.getSwf();
}
}

View File

@@ -87,4 +87,9 @@ public class ActionSearchResult implements ScriptSearchResult {
public String toString() {
return path;
}
@Override
public SWF getSWF() {
return src.getSwf();
}
}

View File

@@ -4,6 +4,6 @@ package com.jpexs.decompiler.flash.search;
*
* @author JPEXS
*/
public interface ScriptSearchResult {
public interface ScriptSearchResult extends SearchResult {
}

View File

@@ -0,0 +1,11 @@
package com.jpexs.decompiler.flash.search;
import com.jpexs.decompiler.flash.SWF;
/**
*
* @author JPEXS
*/
public interface SearchResult {
public SWF getSWF();
}

View File

@@ -1195,10 +1195,7 @@ public abstract class MainFrameMenu implements MenuBuilder {
}
sr.setResults(Main.searchResultsStorage.getSearchResultsAt(mainFrame.getPanel().getAllSwfs(), fi));
sr.setVisible(true);
if (!Main.getMainFrame().getPanel().searchResultsDialogs.containsKey(swf)) {
Main.getMainFrame().getPanel().searchResultsDialogs.put(swf, new ArrayList<>());
}
Main.getMainFrame().getPanel().searchResultsDialogs.get(swf).add(sr);
Main.getMainFrame().getPanel().searchResultsDialogs.add(sr);
};
addMenuItem("/tools/" + (supportsMenuAction() ? "search" : "recentsearch") + "/" + i, searched, null, a, 0, null, true, null, false);
}

View File

@@ -189,10 +189,7 @@ public class MainFrameRibbonMenu extends MainFrameMenu {
}
sr.setResults(Main.searchResultsStorage.getSearchResultsAt(Main.getMainFrame().getPanel().getAllSwfs(), fi));
sr.setVisible(true);
if (!Main.getMainFrame().getPanel().searchResultsDialogs.containsKey(swf)) {
Main.getMainFrame().getPanel().searchResultsDialogs.put(swf, new ArrayList<>());
}
Main.getMainFrame().getPanel().searchResultsDialogs.get(swf).add(sr);
Main.getMainFrame().getPanel().searchResultsDialogs.add(sr);
});
j++;
historyButton.setHorizontalAlignment(SwingUtilities.LEFT);

View File

@@ -333,7 +333,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
public TreeItem oldItem;
public Map<SWF, List<SearchResultsDialog>> searchResultsDialogs = new HashMap<>();
public List<SearchResultsDialog> searchResultsDialogs = new ArrayList<>();
private static final Logger logger = Logger.getLogger(MainPanel.class.getName());
@@ -937,10 +937,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
List<SWFList> swfsLists = new ArrayList<>(swfs);
for (SWF swf : searchResultsDialogs.keySet()) {
for (SearchResultsDialog sr : searchResultsDialogs.get(swf)) {
sr.setVisible(false);
}
for (SearchResultsDialog sr : searchResultsDialogs) {
sr.setVisible(false);
}
searchResultsDialogs.clear();
@@ -976,12 +974,21 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
}
}
List<SWF> swfsToClose = new ArrayList<>();
swfsToClose.addAll(swfList);
for (SWF swf : swfList) {
if (searchResultsDialogs.containsKey(swf)) {
for (SearchResultsDialog sr : searchResultsDialogs.get(swf)) {
sr.setVisible(false);
}
searchResultsDialogs.remove(swf);
populateSwfs(swf, swfsToClose);
}
for (int i = 0; i < searchResultsDialogs.size(); i++) {
SearchResultsDialog sr = searchResultsDialogs.get(i);
for (SWF swf : swfsToClose) {
sr.removeSwf(swf);
}
if (sr.isEmpty()) {
sr.setVisible(false);
searchResultsDialogs.remove(i);
i--;
}
}
@@ -1935,13 +1942,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
SearchResultsDialog<ScriptSearchResult> sr = new SearchResultsDialog<>(getMainFrame().getWindow(), txt, ignoreCase, regexp, listeners);
sr.setResults(fResult);
sr.setVisible(true);
if (swfsUsed.size() == 1) {
SWF usedSwf = swfsUsed.iterator().next();
if (!searchResultsDialogs.containsKey(usedSwf)) {
searchResultsDialogs.put(usedSwf, new ArrayList<>());
}
searchResultsDialogs.get(usedSwf).add(sr);
}
searchResultsDialogs.add(sr);
if (!found) {
View.showMessageDialog(null, translate("message.search.notfound").replace("%searchtext%", txt), translate("message.search.notfound.title"), JOptionPane.INFORMATION_MESSAGE);
}

View File

@@ -16,7 +16,9 @@
*/
package com.jpexs.decompiler.flash.gui;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.search.SearchResult;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
@@ -27,6 +29,7 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Box;
import javax.swing.BoxLayout;
@@ -44,7 +47,7 @@ import javax.swing.SwingConstants;
* @author JPEXS
* @param <E> Element to search
*/
public class SearchResultsDialog<E> extends AppDialog {
public class SearchResultsDialog<E extends SearchResult> extends AppDialog {
private final JList<E> resultsList;
@@ -133,6 +136,20 @@ public class SearchResultsDialog<E> extends AppDialog {
}
}
public void removeSwf(SWF swf) {
List<E> newItems = new ArrayList<>();
for (int i = 0; i < model.getSize(); i++) {
if (model.getElementAt(i).getSWF() != swf) {
newItems.add(model.getElementAt(i));
}
}
setResults(newItems);
}
public boolean isEmpty() {
return model.isEmpty();
}
private void gotoButtonActionPerformed(ActionEvent evt) {
gotoElement();
}

View File

@@ -139,7 +139,16 @@ public class SearchResultsStorage {
@SuppressWarnings("unchecked")
public List<ScriptSearchResult> getSearchResultsAt(Set<SWF> allSwfs, int index) {
if (unpackedData.containsKey(index)) {
return unpackedData.get(index);
List<ScriptSearchResult> unpacked = unpackedData.get(index);
List<ScriptSearchResult> res = new ArrayList<>();
for (ScriptSearchResult sr : unpacked) {
if (allSwfs.contains(sr.getSWF())) {
res.add(sr);
}
}
return res;
}
List<ScriptSearchResult> result = new ArrayList<>();