Skip to content

Commit

Permalink
feat(gui): remember save preference decision (PR #2103)
Browse files Browse the repository at this point in the history
* First version

* Use dropdown

* Spotless

* Language strings and tests

* Comment out translated versions

* Remove more translations

---------

Co-authored-by: Emiel Matthys <[email protected]>
  • Loading branch information
EmielMatthys and Emiel Matthys authored Feb 15, 2024
1 parent 5fbabde commit 018ff98
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 24 deletions.
2 changes: 1 addition & 1 deletion jadx-gui/src/main/java/jadx/gui/settings/JadxProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void addToSearchHistory(String str) {

private void changed() {
JadxSettings settings = mainWindow.getSettings();
if (settings != null && settings.isAutoSaveProject()) {
if (settings != null && settings.getSaveOption() == JadxSettings.SAVEOPTION.ALWAYS) {
save();
} else {
saved = false;
Expand Down
25 changes: 16 additions & 9 deletions jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,22 @@ public class JadxSettings extends JadxCLIArgs {
private LangLocale langLocale = NLS.defaultLocale();
private boolean autoStartJobs = false;
private String excludedPackages = "";
private boolean autoSaveProject = true;
private SAVEOPTION saveOption = SAVEOPTION.ASK;

public enum SAVEOPTION {
ASK,
NEVER,
ALWAYS
}

public SAVEOPTION getSaveOption() {
return saveOption;
}

public void setSaveOption(SAVEOPTION saveOption) {
this.saveOption = saveOption;
}

private Map<ActionModel, Shortcut> shortcuts = new HashMap<>();

@JadxSettingsAdapter.GsonExclude
Expand Down Expand Up @@ -447,14 +462,6 @@ public void setAutoStartJobs(boolean autoStartJobs) {
this.autoStartJobs = autoStartJobs;
}

public boolean isAutoSaveProject() {
return autoSaveProject;
}

public void setAutoSaveProject(boolean autoSaveProject) {
this.autoSaveProject = autoSaveProject;
}

public ShortcutsWrapper getShortcuts() {
if (shortcutsWrapper == null) {
shortcutsWrapper = new ShortcutsWrapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,15 @@ private void enableComponentList(Collection<JComponent> connectedComponents, boo
}

private SettingsGroup makeProjectGroup() {
JCheckBox autoSave = new JCheckBox();
autoSave.setSelected(settings.isAutoSaveProject());
autoSave.addItemListener(e -> settings.setAutoSaveProject(e.getStateChange() == ItemEvent.SELECTED));
JComboBox<JadxSettings.SAVEOPTION> dropdown = new JComboBox<>(JadxSettings.SAVEOPTION.values());
dropdown.setSelectedItem(settings.getSaveOption());
dropdown.addActionListener(e -> {
settings.setSaveOption((JadxSettings.SAVEOPTION) dropdown.getSelectedItem());
needReload();
});

SettingsGroup group = new SettingsGroup(NLS.str("preferences.project"));
group.addRow(NLS.str("preferences.autoSave"), autoSave);
group.addRow(NLS.str("preferences.saveOption"), dropdown);

return group;
}
Expand Down
31 changes: 30 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 @@ -41,10 +41,12 @@
import javax.swing.Action;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
Expand Down Expand Up @@ -627,16 +629,43 @@ private void addTreeCustomNodes() {

private boolean ensureProjectIsSaved() {
if (!project.isSaved() && !project.isInitial()) {
// 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;
}

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,
NLS.str("confirm.not_saved_message"),
inner,
NLS.str("confirm.not_saved_title"),
JOptionPane.YES_NO_CANCEL_OPTION);
if (res == JOptionPane.CANCEL_OPTION) {
return false;
}
if (res == JOptionPane.YES_OPTION) {
if (remember.isSelected()) {
settings.setSaveOption(JadxSettings.SAVEOPTION.ALWAYS);
settings.sync();
}
saveProject();
} else if (res == JOptionPane.NO_OPTION) {
if (remember.isSelected()) {
settings.setSaveOption(JadxSettings.SAVEOPTION.NEVER);
settings.sync();
}
}
}
return true;
Expand Down
3 changes: 2 additions & 1 deletion jadx-gui/src/main/resources/i18n/Messages_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ preferences.fsCaseSensitive=Dateisystem unterscheidet zwischen Groß/Kleinschrei
preferences.skipResourcesDecode=Keine Ressourcen dekodieren
preferences.useKotlinMethodsForVarNames=Kotlin-Methoden für die Umbenennung von Variablen verwenden
preferences.commentsLevel=Level der Code Kommentierungen
preferences.autoSave=Autom. speichern
#preferences.saveOption=Auto-save settings
preferences.threads=Verarbeitungs-Thread-Anzahl
preferences.excludedPackages=Ausgeschlossene Pakete
preferences.excludedPackages.tooltip=Liste der durch Leerzeichen getrennten Paketnamen, die nicht dekompiliert oder indiziert werden (spart RAM)
Expand Down Expand Up @@ -320,6 +320,7 @@ confirm.save_as_title=Speichern unter bestätigen
confirm.save_as_message=%s existiert bereits.\nErsetzen?
confirm.not_saved_title=Projekt speichern
confirm.not_saved_message=Das aktuelle Projekt speichern, bevor Sie fortfahren?
#confirm.remember=Remember my decision

certificate.cert_type=Type
certificate.serialSigVer=Version
Expand Down
3 changes: 2 additions & 1 deletion jadx-gui/src/main/resources/i18n/Messages_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ preferences.fsCaseSensitive=File system is case-sensitive
preferences.skipResourcesDecode=Don't decode resources
preferences.useKotlinMethodsForVarNames=Use kotlin methods for variables rename
preferences.commentsLevel=Code comments level
preferences.autoSave=Auto save
preferences.saveOption=Auto-save settings
preferences.threads=Processing threads count
preferences.excludedPackages=Excluded packages
preferences.excludedPackages.tooltip=List of space separated package names that will not be decompiled or indexed (saves RAM)
Expand Down Expand Up @@ -320,6 +320,7 @@ confirm.save_as_title=Confirm Save as
confirm.save_as_message=%s already exists.\nDo you want to replace it?
confirm.not_saved_title=Save project
confirm.not_saved_message=Save the current project before proceeding?
confirm.remember=Remember my decision

certificate.cert_type=Type
certificate.serialSigVer=Version
Expand Down
3 changes: 2 additions & 1 deletion jadx-gui/src/main/resources/i18n/Messages_es_ES.properties
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ preferences.replaceConsts=Reemplazar constantes
preferences.skipResourcesDecode=No descodificar recursos
#preferences.useKotlinMethodsForVarNames=Use kotlin methods for variables rename
#preferences.commentsLevel=Code comments level
#preferences.autoSave=
#preferences.saveOption=Auto-save settings
preferences.threads=Número de hilos a procesar
#preferences.excludedPackages=
#preferences.excludedPackages.tooltip=
Expand Down Expand Up @@ -320,6 +320,7 @@ popup.rename=Nimeta ümber
#confirm.save_as_message=
#confirm.not_saved_title=
#confirm.not_saved_message=
#confirm.remember=

certificate.cert_type=Tipo
certificate.serialSigVer=Versión
Expand Down
3 changes: 2 additions & 1 deletion jadx-gui/src/main/resources/i18n/Messages_id_ID.properties
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ preferences.fsCaseSensitive=File sistem bersifat sensitif huruf besar-kecil
preferences.skipResourcesDecode=Jangan dekode sumber daya
preferences.useKotlinMethodsForVarNames=Gunakan metode Kotlin untuk mengganti nama variabel
preferences.commentsLevel=Tingkat komentar kode
preferences.autoSave=Simpan otomatis
#preferences.saveOption=Auto-save settings
preferences.threads=Jumlah utas pemrosesan
preferences.excludedPackages=Package yang dikecualikan
preferences.excludedPackages.tooltip=Daftar nama paket yang dipisahkan spasi yang tidak akan di deskompilasi atau diindeks (menghemat RAM)
Expand Down Expand Up @@ -320,6 +320,7 @@ confirm.save_as_title=Konfirmasi Simpan Sebagai
confirm.save_as_message=%s sudah ada.\nApakah Anda ingin menggantinya?
confirm.not_saved_title=Simpan proyek
confirm.not_saved_message=Simpan proyek saat ini sebelum melanjutkan?
#confirm.remember=Remember my decision

certificate.cert_type=Tipe
certificate.serialSigVer=Versi Tanda Tangan
Expand Down
3 changes: 2 additions & 1 deletion jadx-gui/src/main/resources/i18n/Messages_ko_KR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ preferences.fsCaseSensitive=파일 시스템 대소문자 구별
preferences.skipResourcesDecode=리소스 디코딩 하지 않기
preferences.useKotlinMethodsForVarNames=변수 이름 바꾸기에 kotlin 메서드 사용
preferences.commentsLevel=코드 주석 수준
preferences.autoSave=자동 저장
#preferences.saveOption=Auto-save settings
preferences.threads=처리 스레드 수
preferences.excludedPackages=제외할 패키지
preferences.excludedPackages.tooltip=RAM 절약을 위해 디컴파일되거나 인덱싱하지 않을 패키지 이름 목록 (공백으로 항목 구분)
Expand Down Expand Up @@ -320,6 +320,7 @@ confirm.save_as_title=다른 이름으로 저장 확인
confirm.save_as_message=%s이(가) 이미 있습니다.\n바꾸시겠습니까?
confirm.not_saved_title=프로젝트 저장
confirm.not_saved_message=계속하기 전에 현재 프로젝트를 저장 하시겠습니까?
#confirm.remember=Remember my decision

certificate.cert_type=유형
certificate.serialSigVer=버전
Expand Down
3 changes: 2 additions & 1 deletion jadx-gui/src/main/resources/i18n/Messages_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ preferences.fsCaseSensitive=Sistema de arquivo diferencia maiúsculas de minúsc
preferences.skipResourcesDecode=Não decodificar recursos
preferences.useKotlinMethodsForVarNames=Usar métodos do kotlin para renomear variáveis
preferences.commentsLevel=Nível de comentários do código
preferences.autoSave=Salvar automaticamente
#preferences.saveOption=Auto-save settings
preferences.threads=Número de threads no processo
preferences.excludedPackages=Pacotes ignorados
preferences.excludedPackages.tooltip=Lista espaço de pacotes que não vão ser descompilados ou indexados (economiza RAM)
Expand Down Expand Up @@ -320,6 +320,7 @@ confirm.save_as_title=Confirmar operação
confirm.save_as_message=%s Já existe.\nVocê deseja substituir?
confirm.not_saved_title=Salvar projeto
confirm.not_saved_message=Salvar projeto atual antes de continuar?
#confirm.remember=Remember my decision

certificate.cert_type=Tipo
certificate.serialSigVer=Versão
Expand Down
3 changes: 2 additions & 1 deletion jadx-gui/src/main/resources/i18n/Messages_ru_RU.properties
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ preferences.fsCaseSensitive=Учитывать регистр в файлово
preferences.skipResourcesDecode=Не декодировать ресурсы
preferences.useKotlinMethodsForVarNames=Kotlin методы как имена полей
preferences.commentsLevel=Уровень лога операций
preferences.autoSave=Автосохранение
#preferences.saveOption=Auto-save settings
preferences.threads=Количество используемых потоков
preferences.excludedPackages=Исключенные пакеты
preferences.excludedPackages.tooltip=Список пакетов, которые не будут декомпилироваться и индексироваться (экономит ОЗУ)
Expand Down Expand Up @@ -320,6 +320,7 @@ confirm.save_as_title=Подтверджение сохранения
confirm.save_as_message=%s уже существует.\nВы хотите его перезаписать?
confirm.not_saved_title=Сохранить проект
confirm.not_saved_message=Сохранить текущий проект перед выходом?
#confirm.remember=Remember my decision

certificate.cert_type=Type
certificate.serialSigVer=Version
Expand Down
3 changes: 2 additions & 1 deletion jadx-gui/src/main/resources/i18n/Messages_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ preferences.fsCaseSensitive=文件系统区分大小写
preferences.skipResourcesDecode=不反编译资源文件
preferences.useKotlinMethodsForVarNames=使用Kotlin方法来重命名变量
preferences.commentsLevel=代码注释等级
preferences.autoSave=自动保存
#preferences.saveOption=Auto-save settings
preferences.threads=并行线程数
preferences.excludedPackages=排除的包
preferences.excludedPackages.tooltip=排除于反编译或索引的以空格分隔的包名列表(节省 RAM)
Expand Down Expand Up @@ -320,6 +320,7 @@ confirm.save_as_title=确认另存为
confirm.save_as_message=%s 已存在。\n你想替换它吗?
confirm.not_saved_title=保存项目
confirm.not_saved_message=在继续之前保存当前项目?
#confirm.remember=Remember my decision

certificate.cert_type=类型
certificate.serialSigVer=版本
Expand Down
3 changes: 2 additions & 1 deletion jadx-gui/src/main/resources/i18n/Messages_zh_TW.properties
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ preferences.fsCaseSensitive=檔案系統區分大小寫
preferences.skipResourcesDecode=不要為資源解碼
preferences.useKotlinMethodsForVarNames=使用 Kotlin 方法來為變數重新命名
preferences.commentsLevel=程式碼註解層級
preferences.autoSave=自動儲存
#preferences.saveOption=Auto-save settings
preferences.threads=執行緒數
preferences.excludedPackages=被排除的套件
preferences.excludedPackages.tooltip=排除於索引或反編譯外的套件列表 (以空格分隔) (節省 RAM)
Expand Down Expand Up @@ -320,6 +320,7 @@ confirm.save_as_title=確認另存為
confirm.save_as_message=%s 已存在。\n您要覆寫它嗎?
confirm.not_saved_title=儲存專案
confirm.not_saved_message=在繼續進行前要先儲存目前專案嗎?
#confirm.remember=Remember my decision

certificate.cert_type=類型
certificate.serialSigVer=版本
Expand Down

0 comments on commit 018ff98

Please sign in to comment.