Skip to content

Commit

Permalink
fix(gui): disable actions if files not loaded (#1644)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Aug 16, 2022
1 parent cf7767e commit 127f0ec
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 4 deletions.
37 changes: 36 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
import jadx.gui.update.data.Release;
import jadx.gui.utils.CacheObject;
import jadx.gui.utils.FontUtils;
import jadx.gui.utils.ILoadListener;
import jadx.gui.utils.Icons;
import jadx.gui.utils.LafManager;
import jadx.gui.utils.Link;
Expand Down Expand Up @@ -211,6 +212,9 @@ public class MainWindow extends JFrame {
private JDebuggerPanel debuggerPanel;
private JSplitPane verticalSplitter;

private List<ILoadListener> loadListeners = new ArrayList<>();
private boolean loaded;

public MainWindow(JadxSettings settings) {
this.settings = settings;
this.cacheObject = new CacheObject();
Expand Down Expand Up @@ -488,6 +492,7 @@ private void saveAll() {
}

private void closeAll() {
notifyLoadListeners(false);
cancelBackgroundJobs();
clearTree();
resetCache();
Expand Down Expand Up @@ -526,7 +531,10 @@ private void onOpen() {

backgroundExecutor.execute(NLS.str("progress.load"),
this::restoreOpenTabs,
status -> runInitialBackgroundJobs());
status -> {
runInitialBackgroundJobs();
notifyLoadListeners(true);
});
}

public void updateLiveReload(boolean state) {
Expand Down Expand Up @@ -1210,6 +1218,22 @@ public void actionPerformed(ActionEvent e) {
toolbar.add(updateLink);

mainPanel.add(toolbar, BorderLayout.NORTH);

addLoadListener(loaded -> {
textSearchAction.setEnabled(loaded);
clsSearchAction.setEnabled(loaded);
commentSearchAction.setEnabled(loaded);
backAction.setEnabled(loaded);
forwardAction.setEnabled(loaded);
syncAction.setEnabled(loaded);
saveAllAction.setEnabled(loaded);
exportAction.setEnabled(loaded);
saveProjectAsAction.setEnabled(loaded);
reload.setEnabled(loaded);
deobfAction.setEnabled(loaded);
quarkAction.setEnabled(loaded);
return false;
});
}

private void initUI() {
Expand Down Expand Up @@ -1499,6 +1523,17 @@ private void saveSplittersInfo() {
settings.setDebuggerVarTreeSplitterLoc(debuggerPanel.getRightSplitterLocation());
}

public void addLoadListener(ILoadListener loadListener) {
this.loadListeners.add(loadListener);
// set initial value
loadListener.update(loaded);
}

public void notifyLoadListeners(boolean loaded) {
this.loaded = loaded;
loadListeners.removeIf(listener -> listener.update(loaded));
}

public JadxWrapper getWrapper() {
return wrapper;
}
Expand Down
11 changes: 10 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/ui/codearea/FindUsageAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.awt.event.KeyEvent;

import jadx.gui.treemodel.JNode;
import jadx.gui.ui.MainWindow;
import jadx.gui.ui.dialog.UsageDialog;
import jadx.gui.utils.NLS;

Expand All @@ -18,7 +19,15 @@ public FindUsageAction(CodeArea codeArea) {

@Override
public void runAction(JNode node) {
UsageDialog usageDialog = new UsageDialog(getCodeArea().getMainWindow(), node);
MainWindow mw = getCodeArea().getMainWindow();
UsageDialog usageDialog = new UsageDialog(mw, node);
mw.addLoadListener(loaded -> {
if (!loaded) {
usageDialog.dispose();
return true;
}
return false;
});
usageDialog.setVisible(true);
}
}
15 changes: 13 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/ui/dialog/SearchDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,28 @@ public class SearchDialog extends CommonSearchDialog {

public static void search(MainWindow window, SearchPreset preset) {
SearchDialog searchDialog = new SearchDialog(window, preset, Collections.emptySet());
searchDialog.setVisible(true);
show(searchDialog, window);
}

public static void searchInActiveTab(MainWindow window, SearchPreset preset) {
SearchDialog searchDialog = new SearchDialog(window, preset, EnumSet.of(SearchOptions.ACTIVE_TAB));
searchDialog.setVisible(true);
show(searchDialog, window);
}

public static void searchText(MainWindow window, String text) {
SearchDialog searchDialog = new SearchDialog(window, SearchPreset.TEXT, Collections.emptySet());
searchDialog.initSearchText = text;
show(searchDialog, window);
}

private static void show(SearchDialog searchDialog, MainWindow mw) {
mw.addLoadListener(loaded -> {
if (!loaded) {
searchDialog.dispose();
return true;
}
return false;
});
searchDialog.setVisible(true);
}

Expand Down
11 changes: 11 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/utils/ILoadListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package jadx.gui.utils;

public interface ILoadListener {

/**
* Update files/project loaded state
*
* @return true to remove listener
*/
boolean update(boolean loaded);
}

0 comments on commit 127f0ec

Please sign in to comment.