Skip to content

Commit

Permalink
feat(gui): option for search results count per page (#1652)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Sep 5, 2022
1 parent 258987b commit 1195582
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 60 deletions.
4 changes: 0 additions & 4 deletions jadx-gui/src/main/java/jadx/gui/search/SearchTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
Expand Down Expand Up @@ -35,7 +34,6 @@ public class SearchTask extends CancelableBackgroundTask {
private final TaskProgress taskProgress = new TaskProgress();

private final AtomicInteger resultsCount = new AtomicInteger(0);
private final AtomicBoolean complete = new AtomicBoolean(false);
private int resultsLimit;
private Future<TaskStatus> future;

Expand All @@ -60,7 +58,6 @@ public synchronized void fetchResults() {
throw new IllegalStateException("Previous task not yet finished");
}
resetCancel();
complete.set(false);
resultsCount.set(0);
taskProgress.updateTotal(jobs.stream().mapToInt(s -> s.getProvider().total()).sum());
future = backgroundExecutor.execute(this);
Expand All @@ -74,7 +71,6 @@ public synchronized boolean addResult(JNode resultNode) {
this.resultsListener.accept(resultNode);
if (resultsLimit != 0 && resultsCount.incrementAndGet() >= resultsLimit) {
cancel();
complete.set(false);
return true;
}
return false;
Expand Down
9 changes: 9 additions & 0 deletions jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class JadxSettings extends JadxCLIArgs {
private boolean codeAreaLineWrap = false;
private int srhResourceSkipSize = 1000;
private String srhResourceFileExt = ".xml|.html|.js|.json|.txt";
private int searchResultsPerPage = 50;
private boolean useAutoSearch = true;
private boolean keepCommonDialogOpen = false;
private boolean smaliAreaShowBytecode = false;
Expand Down Expand Up @@ -541,6 +542,14 @@ public void setSrhResourceFileExt(String all) {
srhResourceFileExt = all.trim();
}

public int getSearchResultsPerPage() {
return searchResultsPerPage;
}

public void setSearchResultsPerPage(int searchResultsPerPage) {
this.searchResultsPerPage = searchResultsPerPage;
}

public boolean isUseAutoSearch() {
return useAutoSearch;
}
Expand Down
62 changes: 18 additions & 44 deletions jadx-gui/src/main/java/jadx/gui/settings/JadxSettingsWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -676,48 +672,26 @@ private SettingsGroup makeOtherGroup() {
}

private SettingsGroup makeSearchResGroup() {
SettingsGroup group = new SettingsGroup(NLS.str("preferences.search_res_title"));
int prevSize = settings.getSrhResourceSkipSize();
String prevExts = settings.getSrhResourceFileExt();
SpinnerNumberModel sizeLimitModel = new SpinnerNumberModel(prevSize,
0, Integer.MAX_VALUE, 1);
JSpinner spinner = new JSpinner(sizeLimitModel);
JTextField fileExtField = new JTextField();
group.addRow(NLS.str("preferences.res_skip_file"), spinner);
group.addRow(NLS.str("preferences.res_file_ext"), fileExtField);

spinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
int size = (Integer) spinner.getValue();
settings.setSrhResourceSkipSize(size);
}
});

fileExtField.getDocument().addDocumentListener(new DocumentListener() {
private void update() {
String ext = fileExtField.getText();
settings.setSrhResourceFileExt(ext);
}

@Override
public void insertUpdate(DocumentEvent e) {
update();
}
JSpinner resultsPerPage = new JSpinner(
new SpinnerNumberModel(settings.getSearchResultsPerPage(), 0, Integer.MAX_VALUE, 1));
resultsPerPage.addChangeListener(ev -> settings.setSearchResultsPerPage((Integer) resultsPerPage.getValue()));

@Override
public void removeUpdate(DocumentEvent e) {
update();
}
JSpinner sizeLimit = new JSpinner(
new SpinnerNumberModel(settings.getSrhResourceSkipSize(), 0, Integer.MAX_VALUE, 1));
sizeLimit.addChangeListener(ev -> settings.setSrhResourceSkipSize((Integer) sizeLimit.getValue()));

@Override
public void changedUpdate(DocumentEvent e) {
update();
}
});
fileExtField.setText(prevExts);

return group;
JTextField fileExtField = new JTextField();
fileExtField.getDocument().addDocumentListener(new DocumentUpdateListener((ev) -> {
String ext = fileExtField.getText();
settings.setSrhResourceFileExt(ext);
}));
fileExtField.setText(settings.getSrhResourceFileExt());

SettingsGroup searchGroup = new SettingsGroup(NLS.str("preferences.search_group_title"));
searchGroup.addRow(NLS.str("preferences.search_results_per_page"), resultsPerPage);
searchGroup.addRow(NLS.str("preferences.res_skip_file"), sizeLimit);
searchGroup.addRow(NLS.str("preferences.res_file_ext"), fileExtField);
return searchGroup;
}

private void needReload() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private void search(String text) {
updateTableHighlight();
prepareForSearch();
});
this.searchTask.setResultsLimit(50);
this.searchTask.setResultsLimit(mainWindow.getSettings().getSearchResultsPerPage());
this.searchTask.setProgressListener(this::updateProgress);
this.searchTask.fetchResults();
LOG.debug("Total search items count estimation: {}", this.searchTask.getTaskProgress().total());
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 @@ -194,7 +194,8 @@ preferences.rename=Umbenennen
preferences.rename_case=System unterscheidet zwischen Groß/Kleinschreibung
preferences.rename_valid=Ist eine gültige Kennung
preferences.rename_printable=Ist druckbar
preferences.search_res_title=Ressourcen durchsuchen
preferences.search_group_title=Ressourcen durchsuchen
#preferences.search_results_per_page=Results per page (0 - no limit)
preferences.res_file_ext=Dateierweiterungen (z.B. .xml|.html), * bedeutet alle
preferences.res_skip_file=Dateien überspringen (MB)

Expand Down
7 changes: 4 additions & 3 deletions jadx-gui/src/main/resources/i18n/Messages_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ preferences.rename=Rename identifiers
preferences.rename_case=To fix case sensitivity issues
preferences.rename_valid=To make them valid
preferences.rename_printable=To make printable
preferences.search_res_title=Search Resource
preferences.res_file_ext=File Extensions (e.g. .xml|.html), * means all
preferences.res_skip_file=Skip files exceed (MB)
preferences.search_group_title=Search
preferences.search_results_per_page=Results per page (0 - no limit)
preferences.res_file_ext=Resource files extensions ('xml|html', * for all)
preferences.res_skip_file=Skip resources files if larger (MB)
msg.open_file=Please open file
msg.saving_sources=Saving sources
Expand Down
7 changes: 4 additions & 3 deletions jadx-gui/src/main/resources/i18n/Messages_es_ES.properties
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ preferences.reset_title=Reestablecer preferencias
#preferences.rename_case=
#preferences.rename_valid=
#preferences.rename_printable=
#preferences.search_res_title=
#preferences.res_file_ext=
#preferences.res_skip_file=
#preferences.search_group_title=Search
#preferences.search_results_per_page=Results per page (0 - no limit)
#preferences.res_file_ext=Resource files extensions ('xml|html', * for all)
#preferences.res_skip_file=Skip resources files if larger (MB)

msg.open_file=Por favor, abra un archivo
msg.saving_sources=Guardando fuente
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 @@ -194,7 +194,8 @@ preferences.rename=이름 바꾸기
preferences.rename_case=시스템 대소문자 구분
preferences.rename_valid=유효한 식별자로 바꾸기
preferences.rename_printable=출력 가능하게 바꾸기
preferences.search_res_title=리소스 검색
preferences.search_group_title=리소스 검색
#preferences.search_results_per_page=Results per page (0 - no limit)
preferences.res_file_ext=파일 확장자 (예: .xml|.html) (* 은 전체를 의미)
preferences.res_skip_file=이 옵션보다 큰 파일 건너 뛰기 (MB)

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 @@ -194,7 +194,8 @@ preferences.rename=Renomear identificadores
preferences.rename_case=Corrigir problemas de capitalização (case sensitivity)
preferences.rename_valid=Deixá-las válidas
preferences.rename_printable=Deixá-las imprimíveis (printable)
preferences.search_res_title=Buscar recursos
preferences.search_group_title=Buscar recursos
#preferences.search_results_per_page=Results per page (0 - no limit)
preferences.res_file_ext=Extensões de arquivos (ex: .xml|.html), * significa todas
preferences.res_skip_file=Pular arquivos excedidos

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 @@ -194,7 +194,8 @@ preferences.rename=重命名标识符
preferences.rename_case=需要标识符能区分大小写
preferences.rename_valid=需要标识符能符合规范
preferences.rename_printable=需要标识符可正常显示
preferences.search_res_title=搜索资源
preferences.search_group_title=搜索资源
#preferences.search_results_per_page=Results per page (0 - no limit)
preferences.res_file_ext=文件扩展名 (e.g. .xml|.html),* 表示所有
preferences.res_skip_file=跳过文件大小(MB)

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 @@ -194,7 +194,8 @@ preferences.rename=重新命名識別碼
preferences.rename_case=以修復區分大小寫問題
preferences.rename_valid=以使其有效
preferences.rename_printable=以使其可列印
preferences.search_res_title=搜尋資源
preferences.search_group_title=搜尋資源
#preferences.search_results_per_page=Results per page (0 - no limit)
preferences.res_file_ext=副檔名 (e.g. .xml|.html), * 表示全部
preferences.res_skip_file=略過大於此值的檔案 (MB)

Expand Down

0 comments on commit 1195582

Please sign in to comment.