Skip to content

Commit

Permalink
Run indexJob before rename
Browse files Browse the repository at this point in the history
  • Loading branch information
bet4it committed May 15, 2020
1 parent 705ceca commit 6356e54
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
4 changes: 1 addition & 3 deletions jadx-gui/src/main/java/jadx/gui/ui/CommonSearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,17 +516,15 @@ public void done() {
}
}

protected void loadStartCommon() {
private void loadStartCommon() {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
progressPane.setIndeterminate(true);
progressPane.setVisible(true);
resultsTable.setEnabled(false);
warnLabel.setVisible(false);
}

private void loadFinishedCommon() {
setCursor(null);
resultsTable.setEnabled(true);
progressPane.setVisible(false);

TextSearchIndex textIndex = cache.getTextIndex();
Expand Down
48 changes: 29 additions & 19 deletions jadx-gui/src/main/java/jadx/gui/ui/RenameDialog.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jadx.gui.ui;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -42,7 +41,7 @@
import jadx.gui.ui.codearea.CodePanel;
import jadx.gui.utils.*;

public class RenameDialog extends JDialog {
public class RenameDialog extends CommonSearchDialog {
private static final long serialVersionUID = -3269715644416902410L;

private static final Logger LOG = LoggerFactory.getLogger(RenameDialog.class);
Expand All @@ -55,13 +54,16 @@ public class RenameDialog extends JDialog {

private CodeArea codeArea;

private JButton renameBtn;

public RenameDialog(CodeArea codeArea, JNode node) {
super(codeArea.getMainWindow());
mainWindow = codeArea.getMainWindow();
this.codeArea = codeArea;
this.node = node;
if (isDeobfuscationSettingsValid()) {
initUI();
registerInitOnOpen();
loadWindowPos();
} else {
LOG.error("Deobfuscation settings are invalid - please enable deobfuscation and disable force rewrite deobfuscation map");
Expand Down Expand Up @@ -95,14 +97,19 @@ private void showRenameDisabledErrorMessage(LangLocale langLocale, String messag
JOptionPane.ERROR_MESSAGE);
}

private void loadWindowPos() {
mainWindow.getSettings().loadWindowPos(this);
@Override
protected void openInit() {
prepare();
}

@Override
protected void loadStart() {
renameBtn.setEnabled(false);
}

@Override
public void dispose() {
mainWindow.getSettings().saveWindowPos(this);
super.dispose();
protected void loadFinished() {
renameBtn.setEnabled(true);
}

private Path getDeobfMapPath(RootNode root) {
Expand Down Expand Up @@ -239,7 +246,7 @@ private int refreshState(RootNode rootNode) {
RenameVisitor renameVisitor = new RenameVisitor();
renameVisitor.init(rootNode);

mainWindow.getCacheObject().getNodeCache().refresh(node);
cache.getNodeCache().refresh(node);

Set<JavaClass> updatedClasses = getUpdatedClasses();

Expand Down Expand Up @@ -277,7 +284,7 @@ private void refreshTabs(TabbedPane tabbedPane, Set<JavaClass> updatedClasses) {

private Set<JavaClass> getUpdatedClasses() {
Set<JavaClass> usageClasses = new HashSet<>();
CodeUsageInfo usageInfo = mainWindow.getCacheObject().getUsageInfo();
CodeUsageInfo usageInfo = cache.getUsageInfo();
if (usageInfo != null) {
usageInfo.getUsageList(node).forEach((node) -> {
JavaClass rootClass = node.getRootClass().getCls();
Expand All @@ -290,7 +297,6 @@ private Set<JavaClass> getUpdatedClasses() {
}

private void setRefreshTask(Set<JavaClass> refreshClasses) {
CacheObject cache = mainWindow.getCacheObject();
UnloadJob unloadJob = new UnloadJob(mainWindow.getWrapper(), mainWindow.getSettings().getThreadsCount(), refreshClasses);
RefreshJob refreshJob = new RefreshJob(mainWindow.getWrapper(), mainWindow.getSettings().getThreadsCount(), refreshClasses);
LOG.info("Waiting for old unloadJob and refreshJob");
Expand All @@ -304,26 +310,24 @@ private void setRefreshTask(Set<JavaClass> refreshClasses) {
LOG.info("Old unloadJob and refreshJob finished");
cache.setUnloadJob(unloadJob);
cache.setRefreshJob(refreshJob);
cache.setIndexJob(new IndexJob(mainWindow.getWrapper(), mainWindow.getCacheObject(), mainWindow.getSettings().getThreadsCount()));
cache.setIndexJob(new IndexJob(mainWindow.getWrapper(), cache, mainWindow.getSettings().getThreadsCount()));
mainWindow.runBackgroundUnloadRefreshAndIndexJobs();
}

private void initCommon() {
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
getRootPane().registerKeyboardAction(e -> dispose(), stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
}

@NotNull
private JPanel initButtonsPanel() {
protected JPanel initButtonsPanel() {
JButton cancelButton = new JButton(NLS.str("search_dialog.cancel"));
cancelButton.addActionListener(event -> dispose());
JButton renameBtn = new JButton(NLS.str("popup.rename"));
renameBtn = new JButton(NLS.str("popup.rename"));
renameBtn.addActionListener(event -> rename());
getRootPane().setDefaultButton(renameBtn);

progressPane = new ProgressPanel(mainWindow, false);

JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
buttonPane.add(progressPane);
buttonPane.add(Box.createRigidArea(new Dimension(5, 0)));
buttonPane.add(Box.createHorizontalGlue());
buttonPane.add(renameBtn);
Expand All @@ -349,8 +353,14 @@ private void initUI() {
renamePane.add(nodeLabel);
renamePane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

warnLabel = new JLabel();
warnLabel.setForeground(Color.RED);
warnLabel.setVisible(false);

JPanel textPane = new JPanel();
textPane.setLayout(new FlowLayout(FlowLayout.LEFT));
textPane.setLayout(new BoxLayout(textPane, BoxLayout.PAGE_AXIS));
textPane.add(warnLabel);
textPane.add(Box.createRigidArea(new Dimension(0, 5)));
textPane.add(renameField);
textPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

Expand Down
2 changes: 2 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/ui/SearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,13 @@ private JCheckBox makeOptionsCheckBox(String name, final SearchOptions opt) {

@Override
protected void loadFinished() {
resultsTable.setEnabled(true);
searchField.setEnabled(true);
}

@Override
protected void loadStart() {
resultsTable.setEnabled(false);
searchField.setEnabled(false);
}
}
3 changes: 2 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/UsageDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ protected void openInit() {

@Override
protected void loadFinished() {
resultsTable.setEnabled(true);
performSearch();
}

@Override
protected void loadStart() {
// no op
resultsTable.setEnabled(false);
}

@Override
Expand Down

0 comments on commit 6356e54

Please sign in to comment.