Commit f6d47529 authored by Skylot's avatar Skylot

gui: add key shortcuts for menu actions.

parent bd4d4f49
...@@ -16,6 +16,7 @@ import javax.swing.BoxLayout; ...@@ -16,6 +16,7 @@ import javax.swing.BoxLayout;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JList; import javax.swing.JList;
...@@ -23,6 +24,7 @@ import javax.swing.JPanel; ...@@ -23,6 +24,7 @@ import javax.swing.JPanel;
import javax.swing.JProgressBar; import javax.swing.JProgressBar;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.ListCellRenderer; import javax.swing.ListCellRenderer;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.SwingWorker; import javax.swing.SwingWorker;
...@@ -61,14 +63,14 @@ public class SearchDialog extends JDialog { ...@@ -61,14 +63,14 @@ public class SearchDialog extends JDialog {
private static final Logger LOG = LoggerFactory.getLogger(SearchDialog.class); private static final Logger LOG = LoggerFactory.getLogger(SearchDialog.class);
private static final int MAX_RESULTS_COUNT = 500; private static final int MAX_RESULTS_COUNT = 500;
private enum SearchOptions { enum SearchOptions {
CLASS, CLASS,
METHOD, METHOD,
FIELD, FIELD,
CODE CODE
} }
private static final Set<SearchOptions> OPTIONS = EnumSet.allOf(SearchOptions.class); private Set<SearchOptions> options = EnumSet.allOf(SearchOptions.class);
private final TabbedPane tabbedPane; private final TabbedPane tabbedPane;
private final JadxWrapper wrapper; private final JadxWrapper wrapper;
...@@ -79,11 +81,12 @@ public class SearchDialog extends JDialog { ...@@ -79,11 +81,12 @@ public class SearchDialog extends JDialog {
private JList resultsList; private JList resultsList;
private JProgressBar busyBar; private JProgressBar busyBar;
public SearchDialog(MainWindow mainWindow, TabbedPane tabbedPane, JadxWrapper wrapper) { public SearchDialog(MainWindow mainWindow, Set<SearchOptions> options) {
super(mainWindow); super(mainWindow);
this.tabbedPane = tabbedPane; this.tabbedPane = mainWindow.getTabbedPane();
this.wrapper = wrapper; this.wrapper = mainWindow.getWrapper();
this.cache = mainWindow.getCacheObject(); this.cache = mainWindow.getCacheObject();
this.options = options;
initUI(); initUI();
addWindowListener(new WindowAdapter() { addWindowListener(new WindowAdapter() {
...@@ -93,6 +96,7 @@ public class SearchDialog extends JDialog { ...@@ -93,6 +96,7 @@ public class SearchDialog extends JDialog {
@Override @Override
public void run() { public void run() {
prepare(); prepare();
searchField.requestFocus();
} }
}); });
} }
...@@ -126,23 +130,23 @@ public class SearchDialog extends JDialog { ...@@ -126,23 +130,23 @@ public class SearchDialog extends JDialog {
private synchronized void performSearch() { private synchronized void performSearch() {
resultsModel.removeAllElements(); resultsModel.removeAllElements();
String text = searchField.getText(); String text = searchField.getText();
if (text == null || text.isEmpty() || OPTIONS.isEmpty()) { if (text == null || text.isEmpty() || options.isEmpty()) {
return; return;
} }
TextSearchIndex index = cache.getTextIndex(); TextSearchIndex index = cache.getTextIndex();
if (index == null) { if (index == null) {
return; return;
} }
if (OPTIONS.contains(SearchOptions.CLASS)) { if (options.contains(SearchOptions.CLASS)) {
resultsModel.addAll(index.searchClsName(text)); resultsModel.addAll(index.searchClsName(text));
} }
if (OPTIONS.contains(SearchOptions.METHOD)) { if (options.contains(SearchOptions.METHOD)) {
resultsModel.addAll(index.searchMthName(text)); resultsModel.addAll(index.searchMthName(text));
} }
if (OPTIONS.contains(SearchOptions.FIELD)) { if (options.contains(SearchOptions.FIELD)) {
resultsModel.addAll(index.searchFldName(text)); resultsModel.addAll(index.searchFldName(text));
} }
if (OPTIONS.contains(SearchOptions.CODE)) { if (options.contains(SearchOptions.CODE)) {
resultsModel.addAll(index.searchCode(text)); resultsModel.addAll(index.searchCode(text));
} }
LOG.info("Search returned {} results", resultsModel.size()); LOG.info("Search returned {} results", resultsModel.size());
...@@ -321,7 +325,7 @@ public class SearchDialog extends JDialog { ...@@ -321,7 +325,7 @@ public class SearchDialog extends JDialog {
buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPane.add(cancelButton); buttonPane.add(cancelButton);
final Container contentPane = getContentPane(); Container contentPane = getContentPane();
contentPane.add(searchPane, BorderLayout.PAGE_START); contentPane.add(searchPane, BorderLayout.PAGE_START);
contentPane.add(listPane, BorderLayout.CENTER); contentPane.add(listPane, BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.PAGE_END); contentPane.add(buttonPane, BorderLayout.PAGE_END);
...@@ -339,7 +343,15 @@ public class SearchDialog extends JDialog { ...@@ -339,7 +343,15 @@ public class SearchDialog extends JDialog {
} }
}); });
setTitle(NLS.str("menu.search")); KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
getRootPane().registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
}, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
setTitle(NLS.str("menu.text_search"));
pack(); pack();
setSize(700, 500); setSize(700, 500);
setLocationRelativeTo(null); setLocationRelativeTo(null);
...@@ -350,13 +362,13 @@ public class SearchDialog extends JDialog { ...@@ -350,13 +362,13 @@ public class SearchDialog extends JDialog {
private JCheckBox makeOptionsCheckBox(String name, final SearchOptions opt) { private JCheckBox makeOptionsCheckBox(String name, final SearchOptions opt) {
final JCheckBox chBox = new JCheckBox(name); final JCheckBox chBox = new JCheckBox(name);
chBox.setAlignmentX(LEFT_ALIGNMENT); chBox.setAlignmentX(LEFT_ALIGNMENT);
chBox.setSelected(OPTIONS.contains(opt)); chBox.setSelected(options.contains(opt));
chBox.addItemListener(new ItemListener() { chBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
if (chBox.isSelected()) { if (chBox.isSelected()) {
OPTIONS.add(opt); options.add(opt);
} else { } else {
OPTIONS.remove(opt); options.remove(opt);
} }
performSearch(); performSearch();
} }
......
...@@ -6,8 +6,8 @@ menu.preferences=Preferences ...@@ -6,8 +6,8 @@ menu.preferences=Preferences
menu.sync=Sync with editor menu.sync=Sync with editor
menu.flatten=Show flatten packages menu.flatten=Show flatten packages
menu.navigation=Navigation menu.navigation=Navigation
menu.search=Search ... menu.text_search=Text search
menu.find_in_file=Find in ... menu.class_search=Class search
menu.tools=Tools menu.tools=Tools
menu.log=Log Viewer menu.log=Log Viewer
menu.help=Help menu.help=Help
...@@ -15,7 +15,6 @@ menu.about=About ...@@ -15,7 +15,6 @@ menu.about=About
menu.update_label=New version %s available! menu.update_label=New version %s available!
file.open=Open file file.open=Open file
file.save=Save file
file.save_all=Save all file.save_all=Save all
file.save_all_msg=Select directory for save decompiled sources file.save_all_msg=Select directory for save decompiled sources
file.select=Select file.select=Select
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment