fix(gui): don't ask to save blank project
This commit is contained in:
@@ -5,7 +5,6 @@ import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -133,6 +132,9 @@ public class JadxProject {
|
||||
}
|
||||
|
||||
public void setTreeExpansions(List<String> list) {
|
||||
if (list.equals(data.getTreeExpansionsV2())) {
|
||||
return;
|
||||
}
|
||||
data.setTreeExpansionsV2(list);
|
||||
changed();
|
||||
}
|
||||
@@ -141,19 +143,6 @@ public class JadxProject {
|
||||
return data.getTreeExpansionsV2();
|
||||
}
|
||||
|
||||
private boolean isParentOfExpansion(String[] parent, String[] child) {
|
||||
if (Arrays.equals(parent, child)) {
|
||||
return true;
|
||||
}
|
||||
for (int i = child.length - parent.length; i > 0; i--) {
|
||||
String[] arr = Arrays.copyOfRange(child, i, child.length);
|
||||
if (Arrays.equals(parent, arr)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public JadxCodeData getCodeData() {
|
||||
return data.getCodeData();
|
||||
}
|
||||
|
||||
@@ -694,45 +694,52 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
|
||||
private boolean ensureProjectIsSaved() {
|
||||
if (!project.isSaved() && !project.isInitial()) {
|
||||
// Check if we saved settings that indicate what to do
|
||||
if (project.isSaved() || project.isInitial()) {
|
||||
return true;
|
||||
}
|
||||
if (project.getFilePaths().isEmpty()) {
|
||||
// ignore blank project save
|
||||
return true;
|
||||
}
|
||||
// Check if we saved settings that indicate what to do
|
||||
if (settings.getSaveOption() == JadxSettings.SAVEOPTION.NEVER) {
|
||||
return true;
|
||||
}
|
||||
if (settings.getSaveOption() == JadxSettings.SAVEOPTION.ALWAYS) {
|
||||
saveProject();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (settings.getSaveOption() == JadxSettings.SAVEOPTION.NEVER) {
|
||||
return true;
|
||||
}
|
||||
JCheckBox remember = new JCheckBox(NLS.str("confirm.remember"));
|
||||
JLabel message = new JLabel(NLS.str("confirm.not_saved_message"));
|
||||
|
||||
if (settings.getSaveOption() == JadxSettings.SAVEOPTION.ALWAYS) {
|
||||
saveProject();
|
||||
return true;
|
||||
}
|
||||
JPanel inner = new JPanel(new BorderLayout());
|
||||
inner.add(remember, BorderLayout.SOUTH);
|
||||
inner.add(message, BorderLayout.NORTH);
|
||||
|
||||
JCheckBox remember = new JCheckBox(NLS.str("confirm.remember"));
|
||||
JLabel message = new JLabel(NLS.str("confirm.not_saved_message"));
|
||||
|
||||
JPanel inner = new JPanel(new BorderLayout());
|
||||
inner.add(remember, BorderLayout.SOUTH);
|
||||
inner.add(message, BorderLayout.NORTH);
|
||||
|
||||
int res = JOptionPane.showConfirmDialog(
|
||||
this,
|
||||
inner,
|
||||
NLS.str("confirm.not_saved_title"),
|
||||
JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
if (res == JOptionPane.CANCEL_OPTION) {
|
||||
return false;
|
||||
}
|
||||
if (res == JOptionPane.YES_OPTION) {
|
||||
int res = JOptionPane.showConfirmDialog(
|
||||
this,
|
||||
inner,
|
||||
NLS.str("confirm.not_saved_title"),
|
||||
JOptionPane.YES_NO_CANCEL_OPTION);
|
||||
switch (res) {
|
||||
case JOptionPane.YES_OPTION:
|
||||
if (remember.isSelected()) {
|
||||
settings.setSaveOption(JadxSettings.SAVEOPTION.ALWAYS);
|
||||
settings.sync();
|
||||
}
|
||||
saveProject();
|
||||
} else if (res == JOptionPane.NO_OPTION) {
|
||||
return true;
|
||||
|
||||
case JOptionPane.NO_OPTION:
|
||||
if (remember.isSelected()) {
|
||||
settings.setSaveOption(JadxSettings.SAVEOPTION.NEVER);
|
||||
settings.sync();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case JOptionPane.CANCEL_OPTION:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user