From 8cf907e3b8d237c2a5aae0c376f125a98896c9b9 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 21 Dec 2014 18:52:49 +0100 Subject: [PATCH] replace text menu item (functioonality not implemented, yet) --- .../decompiler/flash/gui/MainFrameMenu.java | 13 +- .../flash/gui/MainFrameRibbonMenu.java | 11 ++ .../jpexs/decompiler/flash/gui/MainPanel.java | 39 +++++- .../flash/gui/NewVersionDialog.java | 2 +- .../decompiler/flash/gui/ReplaceDialog.java | 122 ++++++++++++++++++ .../decompiler/flash/gui/SearchDialog.java | 41 +++--- .../flash/gui/abc/MethodCodePanel.java | 2 +- .../flash/gui/action/ActionPanel.java | 2 +- .../flash/gui/graphics/replace16.png | Bin 0 -> 650 bytes .../flash/gui/graphics/replace32.png | Bin 0 -> 1436 bytes .../flash/gui/helpers/CheckResources.java | 2 + .../flash/gui/locales/MainFrame.properties | 2 + .../flash/gui/locales/MainFrame_hu.properties | 2 + .../flash/gui/locales/SearchDialog.properties | 2 + .../gui/locales/SearchDialog_hu.properties | 2 + 15 files changed, 218 insertions(+), 24 deletions(-) create mode 100644 src/com/jpexs/decompiler/flash/gui/ReplaceDialog.java create mode 100644 src/com/jpexs/decompiler/flash/gui/graphics/replace16.png create mode 100644 src/com/jpexs/decompiler/flash/gui/graphics/replace32.png diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index f576ba33f..9b0b600f3 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -155,9 +155,18 @@ public abstract class MainFrameMenu { mainFrame.getPanel().exportFla(swf); } - protected boolean search(boolean searhInText) { + protected boolean search(boolean searchInText) { if (swf != null) { - mainFrame.getPanel().searchInActionScriptOrText(searhInText); + mainFrame.getPanel().searchInActionScriptOrText(searchInText); + return true; + } + + return false; + } + + protected boolean replace() { + if (swf != null) { + mainFrame.getPanel().replaceText(); return true; } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java index 571fb1548..bb161d5c5 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java @@ -74,6 +74,7 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener private static final String ACTION_PARALLEL_SPEED_UP = "PARALLELSPEEDUP"; private static final String ACTION_INTERNAL_VIEWER_SWITCH = "INTERNALVIEWERSWITCH"; private static final String ACTION_SEARCH = "SEARCH"; + private static final String ACTION_REPLACE = "REPLACE"; private static final String ACTION_TIMELINE = "TIMELINE"; private static final String ACTION_AUTO_DEOBFUSCATE = "AUTODEOBFUSCATE"; private static final String ACTION_EXIT = "EXIT"; @@ -139,6 +140,7 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener private JCommandButton globalRenameCommandButton; private JCommandButton deobfuscationCommandButton; private JCommandButton searchCommandButton; + private JCommandButton replaceCommandButton; private JCommandToggleButton timeLineToggleButton; private CommandToggleButtonGroup timeLineToggleGroup; private JCommandButton gotoDocumentClassCommandButton; @@ -404,6 +406,10 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener searchCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.search")), View.getResizableIcon("search32")); assignListener(searchCommandButton, ACTION_SEARCH); + // todo: change icon + replaceCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.replace")), View.getResizableIcon("replace32")); + assignListener(replaceCommandButton, ACTION_REPLACE); + timeLineToggleButton = new JCommandToggleButton(fixCommandTitle(translate("menu.tools.timeline")), View.getResizableIcon("timeline32")); assignListener(timeLineToggleButton, ACTION_TIMELINE); @@ -423,6 +429,7 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener assignListener(loadCacheCommandButton, ACTION_LOAD_CACHE); toolsBand.addCommandButton(searchCommandButton, RibbonElementPriority.TOP); + toolsBand.addCommandButton(replaceCommandButton, RibbonElementPriority.TOP); toolsBand.addCommandButton(timeLineToggleButton, RibbonElementPriority.TOP); toolsBand.addCommandButton(gotoDocumentClassCommandButton, RibbonElementPriority.TOP); toolsBand.addCommandButton(proxyCommandButton, RibbonElementPriority.MEDIUM); @@ -630,6 +637,7 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener globalRenameCommandButton.setEnabled(swfLoaded); deobfuscationCommandButton.setEnabled(swfLoaded); searchCommandButton.setEnabled(swfLoaded); + replaceCommandButton.setEnabled(swfLoaded); timeLineToggleButton.setEnabled(swfLoaded); gotoDocumentClassCommandButton.setEnabled(hasAbc); @@ -759,6 +767,9 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener case ACTION_SEARCH: search(false); break; + case ACTION_REPLACE: + replace(); + break; case ACTION_TIMELINE: timeLineToggleGroup.setSelected(timeLineToggleButton, timeLineToggleGroup.getSelected() == timeLineToggleButton); if (timeLineToggleGroup.getSelected() == timeLineToggleButton) { diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index a41dc532e..b82dc45da 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -233,6 +233,8 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec private AbortRetryIgnoreHandler errorHandler = new GuiAbortRetryIgnoreHandler(); private CancellableWorker setSourceWorker; public TreeItem oldItem; + private SearchDialog searchDialog; + private SearchDialog replaceDialog; public static final String ACTION_SELECT_BKCOLOR = "SELECTCOLOR"; public static final String ACTION_REPLACE = "REPLACE"; @@ -858,7 +860,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec public boolean confirmExperimental() { return View.showConfirmDialog(null, translate("message.confirm.experimental"), translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION; } - private SearchDialog searchDialog; public List exportSelection(AbortRetryIgnoreHandler handler, String selFile, ExportDialog export) throws IOException { @@ -1102,12 +1103,12 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } - public void searchInActionScriptOrText(boolean searhInText) { + public void searchInActionScriptOrText(boolean searchInText) { if (searchDialog == null) { - searchDialog = new SearchDialog(getMainFrame().getWindow()); + searchDialog = new SearchDialog(getMainFrame().getWindow(), false); } - if (searhInText) { + if (searchInText) { searchDialog.searchInTextsRadioButton.setSelected(true); } else { searchDialog.searchInASRadioButton.setSelected(true); @@ -1163,6 +1164,36 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } + public void replaceText() { + if (replaceDialog == null) { + replaceDialog = new SearchDialog(getMainFrame().getWindow(), true); + } + + replaceDialog.setVisible(true); + if (replaceDialog.result) { + final String txt = replaceDialog.searchField.getText(); + if (!txt.isEmpty()) { + final SWF swf = getCurrentSwf(); + + new CancellableWorker() { + @Override + protected Void doInBackground() throws Exception { + boolean found = false; + if (searchText(txt, replaceDialog.ignoreCaseCheckBox.isSelected(), replaceDialog.regexpCheckBox.isSelected(), swf)) { + found = true; + } + + if (!found) { + View.showMessageDialog(null, translate("message.search.notfound").replace("%searchtext%", txt), translate("message.search.notfound.title"), JOptionPane.INFORMATION_MESSAGE); + } + + return null; + } + }.execute(); + } + } + } + private boolean searchText(String txt, boolean ignoreCase, boolean regexp, SWF swf) { if ((txt != null) && (!txt.isEmpty())) { SearchPanel textSearchPanel = previewPanel.getTextPanel().getSearchPanel(); diff --git a/src/com/jpexs/decompiler/flash/gui/NewVersionDialog.java b/src/com/jpexs/decompiler/flash/gui/NewVersionDialog.java index 39fbc7720..9e05a899d 100644 --- a/src/com/jpexs/decompiler/flash/gui/NewVersionDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/NewVersionDialog.java @@ -140,7 +140,7 @@ public class NewVersionDialog extends AppDialog implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - if (e.getActionCommand() == ACTION_OK) { + if (e.getActionCommand().equals(ACTION_OK)) { String url; if (latestVersion.updateLink != null) { url = latestVersion.updateLink; diff --git a/src/com/jpexs/decompiler/flash/gui/ReplaceDialog.java b/src/com/jpexs/decompiler/flash/gui/ReplaceDialog.java new file mode 100644 index 000000000..5809856f6 --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/ReplaceDialog.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui; + +import java.awt.Container; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Image; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JTextField; + +/** + * + * @author JPEXS + */ +public class ReplaceDialog extends AppDialog implements ActionListener { + + private static final String ACTION_OK = "OK"; + private static final String ACTION_CANCEL = "CANCEL"; + + public JTextField searchField = new MyTextField(); + public JCheckBox ignoreCaseCheckBox = new JCheckBox(translate("checkbox.ignorecase")); + //public JCheckBox regexpCheckBox = new JCheckBox(translate("checkbox.regexp")); + public boolean result = false; + + public ReplaceDialog(Window owner) { + super(owner); + setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); + ignoreCaseCheckBox.setSelected(true); + Container cnt = getContentPane(); + setSize(400, 150); + cnt.setLayout(new BoxLayout(cnt, BoxLayout.PAGE_AXIS)); + JPanel panButtons = new JPanel(new FlowLayout()); + JButton okButton = new JButton(translate("button.ok")); + okButton.setActionCommand(ACTION_OK); + okButton.addActionListener(this); + JButton cancelButton = new JButton(translate("button.cancel")); + cancelButton.setActionCommand(ACTION_CANCEL); + cancelButton.addActionListener(this); + panButtons.add(okButton); + panButtons.add(cancelButton); + JPanel panField = new JPanel(new FlowLayout()); + searchField.setPreferredSize(new Dimension(250, searchField.getPreferredSize().height)); + panField.add(new JLabel(translate("label.searchtext"))); + panField.add(searchField); + cnt.add(panField); + + JPanel checkPanel = new JPanel(new FlowLayout()); + checkPanel.add(ignoreCaseCheckBox); + //checkPanel.add(regexpCheckBox); + cnt.add(checkPanel); + + cnt.add(panButtons); + getRootPane().setDefaultButton(okButton); + View.centerScreen(this); + //View.setWindowIcon(this); + setIconImage(View.loadImage("search16")); + setTitle(translate("dialog.title")); + setModalityType(ModalityType.APPLICATION_MODAL); + pack(); + List images = new ArrayList<>(); + images.add(View.loadImage("search16")); + images.add(View.loadImage("search32")); + setIconImages(images); + } + + @Override + public void setVisible(boolean b) { + if (b) { + result = false; + searchField.requestFocusInWindow(); + } + super.setVisible(b); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals(ACTION_OK)) { + /*if (regexpCheckBox.isSelected()) { + try { + Pattern pat = Pattern.compile(searchField.getText()); + } catch (PatternSyntaxException ex) { + View.showMessageDialog(null, translate("error.invalidregexp"), translate("error"), JOptionPane.ERROR_MESSAGE); + return; + } + }*/ + result = true; + } else { + result = false; + } + setVisible(false); + } +} diff --git a/src/com/jpexs/decompiler/flash/gui/SearchDialog.java b/src/com/jpexs/decompiler/flash/gui/SearchDialog.java index 26e18142d..87e5fab59 100644 --- a/src/com/jpexs/decompiler/flash/gui/SearchDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/SearchDialog.java @@ -48,13 +48,14 @@ public class SearchDialog extends AppDialog implements ActionListener { private static final String ACTION_CANCEL = "CANCEL"; public JTextField searchField = new MyTextField(); + public JTextField replaceField = new MyTextField(); public JCheckBox ignoreCaseCheckBox = new JCheckBox(translate("checkbox.ignorecase")); public JCheckBox regexpCheckBox = new JCheckBox(translate("checkbox.regexp")); public JRadioButton searchInASRadioButton = new JRadioButton(translate("checkbox.searchAS")); public JRadioButton searchInTextsRadioButton = new JRadioButton(translate("checkbox.searchText")); public boolean result = false; - public SearchDialog(Window owner) { + public SearchDialog(Window owner, boolean replace) { super(owner); setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); ignoreCaseCheckBox.setSelected(true); @@ -75,34 +76,44 @@ public class SearchDialog extends AppDialog implements ActionListener { panField.add(new JLabel(translate("label.searchtext"))); panField.add(searchField); cnt.add(panField); + + if (replace) { + panField = new JPanel(new FlowLayout()); + replaceField.setPreferredSize(new Dimension(250, replaceField.getPreferredSize().height)); + panField.add(new JLabel(translate("label.replacementtext"))); + panField.add(replaceField); + cnt.add(panField); + } JPanel checkPanel = new JPanel(new FlowLayout()); checkPanel.add(ignoreCaseCheckBox); checkPanel.add(regexpCheckBox); cnt.add(checkPanel); - ButtonGroup group = new ButtonGroup(); - group.add(searchInASRadioButton); - group.add(searchInTextsRadioButton); + if (!replace) { + ButtonGroup group = new ButtonGroup(); + group.add(searchInASRadioButton); + group.add(searchInTextsRadioButton); - JPanel rbPanel = new JPanel(new FlowLayout()); - searchInASRadioButton.setSelected(true); - searchInTextsRadioButton.setSelected(false); - rbPanel.add(searchInASRadioButton); - rbPanel.add(searchInTextsRadioButton); - cnt.add(rbPanel); + JPanel rbPanel = new JPanel(new FlowLayout()); + searchInASRadioButton.setSelected(true); + searchInTextsRadioButton.setSelected(false); + rbPanel.add(searchInASRadioButton); + rbPanel.add(searchInTextsRadioButton); + cnt.add(rbPanel); + } cnt.add(panButtons); getRootPane().setDefaultButton(okButton); View.centerScreen(this); //View.setWindowIcon(this); - setIconImage(View.loadImage("search16")); - setTitle(translate("dialog.title")); + setIconImage(View.loadImage(replace ? "replace16" : "search16")); + setTitle(replace ? translate("dialog.title.replace") : translate("dialog.title")); setModalityType(ModalityType.APPLICATION_MODAL); pack(); List images = new ArrayList<>(); - images.add(View.loadImage("search16")); - images.add(View.loadImage("search32")); + images.add(View.loadImage(replace ? "replace16" : "search16")); + images.add(View.loadImage(replace ? "replace32" : "search32")); setIconImages(images); } @@ -117,7 +128,7 @@ public class SearchDialog extends AppDialog implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - if (e.getActionCommand() == ACTION_OK) { + if (e.getActionCommand().equals(ACTION_OK)) { if (regexpCheckBox.isSelected()) { try { Pattern pat = Pattern.compile(searchField.getText()); diff --git a/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java b/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java index d6ff0f702..4f7f5c503 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/MethodCodePanel.java @@ -140,7 +140,7 @@ public class MethodCodePanel extends JPanel implements ActionListener { break; case ACTION_HEX: case ACTION_HEX_ONLY: - if (e.getActionCommand() == ACTION_HEX) { + if (e.getActionCommand().equals(ACTION_HEX)) { hexOnlyButton.setSelected(false); } else { hexButton.setSelected(false); diff --git a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index fad374874..d582f1886 100644 --- a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -726,7 +726,7 @@ public class ActionPanel extends JPanel implements ActionListener, SearchListene break; case ACTION_HEX: case ACTION_HEX_ONLY: - if (e.getActionCommand() == ACTION_HEX) { + if (e.getActionCommand().equals(ACTION_HEX)) { hexOnlyButton.setSelected(false); } else { hexButton.setSelected(false); diff --git a/src/com/jpexs/decompiler/flash/gui/graphics/replace16.png b/src/com/jpexs/decompiler/flash/gui/graphics/replace16.png new file mode 100644 index 0000000000000000000000000000000000000000..d2a99e558617bddfd9f37ea91ab010031644f0f6 GIT binary patch literal 650 zcmV;50(Jd~P)F*CcfJGusp z=3q36Agn=%!JBwB@d1L~0wQ?uarK~=jRaIAzrYAVb~R`5h2TM=9=(Xh2%-T&7m4T) zvzyIkX4>lB*_oA?L#&ya?yl*o{=TX%HZ^tcR}h2+s0fS!N&yjl^thHV+Q>PF5W+{f zTvl!QFdwM(i1w9H6q%?a6L0WxZW%8w^gt4lFj9o%-v~6iz8$^LzMPiEIB}{QHhFH_ zWTTL?;AJgj90|+PDiW1aD~|&y$b>7C5X5cxb`@Xz00(!v7(ccdjX;@=ns?hN?109T ziQoiD;pzEabmt{r&DG&L0y)x+u0=^>V5Iqsgky^&fJ`$h5a`HUo0NH_E%9i^$F*la zu(%u=6i165t{&d98UaDT=>uIDxcL#)g#gFHE5fxH9?vWw>vSM! za}zv|(r^Z&M|4#pLx%=<8E%fb^?aW8Fr!S$^jsE$D2{S4+aimDK-pMPWM>=?&h4h8 z0lyoqah2 kTL0NaTEPE_|3`oU04S60euPb|*8l(j07*qoM6N<$f_IQ4)Bpeg literal 0 HcmV?d00001 diff --git a/src/com/jpexs/decompiler/flash/gui/graphics/replace32.png b/src/com/jpexs/decompiler/flash/gui/graphics/replace32.png new file mode 100644 index 0000000000000000000000000000000000000000..5bdfcb1a94c3c7646ef8a0031e3165bcdd39911f GIT binary patch literal 1436 zcmV;N1!MY&P)RTTdAKIgvY+L)%s zsA*B!D50rgWROHbS|}w*{u#1|QS|y%;#(vGiJ+t(7KP)BpnOmR6GHun8t{3T5A*lcjwNX2bEHbecy*M2G_IE z4z$){r=hN{ZmG;A>+9>yjc#I7Y`c6!<>b;@&i)C-QOiR*mk1#v$%*VYb;@KEZAJxv zD$%Y`(3ArTGOa0$vGBhrN>buHcc_rKWVH|rQL+5< zNts7iy6pR90E7imV3Yvl^zVM(gD-x`SWV8lHH3`|lhg-+jF2t{01|ow ziYd=%2r>4SE?~!!n=yN06fNBfZ~u@+#MN+%?zoyhD1iRHa^;xx{rZQJxNEF~RdeHr zgdLpeFjlCJc5T;64_gOAy1+&%ZkkT#E$w4t8mXMY%v(a}O?O(%(NK(wBfO@fi8QZi zE)a!mE>~?Bkz*hLrwD*!I-M)d@q~`g3#*YKC{4qN#W8=KvZ6e`#voJ3aHS82x7ssV z&KH6xCQyojY%tN5F`yCXkf%=N?6u4Cm@!g+;#`IR3aE}(;lV8mU%$19r}t4;udr{W zvCf>eS>dPkH0t-DGnL1vm_slIIS+QNXN5b23rYf%M_$4oPyf#0fAIRkvDkgAgL4K; zW+btv3269v0|OPXcKHjKOF-ceP)*O&Zux_TE>WaDlMXO#Tm&yK7=s7yNFbdrfv6xt z@vY$4`osi$)!c=7+s@$2=1wfCOZNhAsG**#~Gh&cSc!PdjAczot)uJML;flU;oDOXYr zf2{gtGMh8NP2?InWFgLv{Mv<<;5|R*2z1)`2*bLv5jD*D3!ND&Zpk-8N5Yb^ejiL3 zOPa=OS1TlWA-3->0qeC42wEGYB4N8;&nuQkP#DMWHAUj%(o36(40_HW%ar6L?&%?uYtWY)HKU_A zvS!ZzzI&v0jO`U`LZ@6AH=vblmKf;SwQE~#EI-kH(>0000