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 Apr 17, 2020
1 parent f66ec91 commit 54ac061
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 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
56 changes: 29 additions & 27 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 @@ -39,12 +38,11 @@
import jadx.gui.ui.codearea.ClassCodeContentPanel;
import jadx.gui.ui.codearea.CodeArea;
import jadx.gui.ui.codearea.CodePanel;
import jadx.gui.utils.CacheObject;
import jadx.gui.utils.CodeUsageInfo;
import jadx.gui.utils.NLS;
import jadx.gui.utils.TextStandardActions;

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 @@ -57,23 +55,31 @@ 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;
initUI();
registerInitOnOpen();
loadWindowPos();
}

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 @@ -201,21 +207,14 @@ private boolean refreshDeobfMapFile(String renameText, RootNode root) {
dispose();
return false;
}
try {
writeDeobfMapFile(deobfMapPath, deobfMap);
} catch (IOException e) {
LOG.error("rename(): updateDeobfMap() failed");
dispose();
return false;
}
return true;
}

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 @@ -253,7 +252,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 @@ -266,7 +265,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 @@ -280,26 +278,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 @@ -325,8 +321,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 54ac061

Please sign in to comment.