未验证 提交 127f0ecf 编写于 作者: S Skylot

fix(gui): disable actions if files not loaded (#1644)

上级 cf7767e7
......@@ -132,6 +132,7 @@ import jadx.gui.update.JadxUpdate.IUpdateCallback;
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;
......@@ -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();
......@@ -488,6 +492,7 @@ public class MainWindow extends JFrame {
}
private void closeAll() {
notifyLoadListeners(false);
cancelBackgroundJobs();
clearTree();
resetCache();
......@@ -526,7 +531,10 @@ public class MainWindow extends JFrame {
backgroundExecutor.execute(NLS.str("progress.load"),
this::restoreOpenTabs,
status -> runInitialBackgroundJobs());
status -> {
runInitialBackgroundJobs();
notifyLoadListeners(true);
});
}
public void updateLiveReload(boolean state) {
......@@ -1210,6 +1218,22 @@ public class MainWindow extends JFrame {
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() {
......@@ -1499,6 +1523,17 @@ public class MainWindow extends JFrame {
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;
}
......
......@@ -3,6 +3,7 @@ package jadx.gui.ui.codearea;
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;
......@@ -18,7 +19,15 @@ public final class FindUsageAction extends JNodeAction {
@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);
}
}
......@@ -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);
}
......
package jadx.gui.utils;
public interface ILoadListener {
/**
* Update files/project loaded state
*
* @return true to remove listener
*/
boolean update(boolean loaded);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册