feat(gui): allow to minimize/maximize search windows (#1298)

This commit is contained in:
Skylot
2021-12-04 12:20:19 +03:00
parent 947b621733
commit 6e8baef9b2
4 changed files with 28 additions and 17 deletions
@@ -23,7 +23,7 @@ import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
@@ -59,7 +59,7 @@ import jadx.gui.utils.NLS;
import jadx.gui.utils.UiUtils;
import jadx.gui.utils.search.TextSearchIndex;
public abstract class CommonSearchDialog extends JDialog {
public abstract class CommonSearchDialog extends JFrame {
private static final long serialVersionUID = 8939332306115370276L;
private static final Logger LOG = LoggerFactory.getLogger(CommonSearchDialog.class);
@@ -70,6 +70,7 @@ public abstract class CommonSearchDialog extends JDialog {
protected final transient CacheObject cache;
protected final transient MainWindow mainWindow;
protected final transient Font codeFont;
protected final transient String windowTitle;
protected ResultsModel resultsModel;
protected ResultsTable resultsTable;
@@ -77,16 +78,18 @@ public abstract class CommonSearchDialog extends JDialog {
protected JLabel warnLabel;
protected ProgressPanel progressPane;
protected String highlightText;
private String highlightText;
protected boolean highlightTextCaseInsensitive = false;
protected boolean highlightTextUseRegex = false;
public CommonSearchDialog(MainWindow mainWindow) {
super(mainWindow);
public CommonSearchDialog(MainWindow mainWindow, String title) {
this.mainWindow = mainWindow;
this.tabbedPane = mainWindow.getTabbedPane();
this.cache = mainWindow.getCacheObject();
this.codeFont = mainWindow.getSettings().getFont();
this.windowTitle = title;
UiUtils.setWindowIcons(this);
updateTitle();
}
protected abstract void openInit();
@@ -101,6 +104,19 @@ public abstract class CommonSearchDialog extends JDialog {
}
}
private void updateTitle() {
if (highlightText == null || highlightText.trim().isEmpty()) {
setTitle(windowTitle);
} else {
setTitle(windowTitle + ": " + highlightText);
}
}
public void setHighlightText(String highlightText) {
this.highlightText = highlightText;
updateTitle();
}
public void prepare() {
if (cache.getIndexService().isComplete()) {
loadFinishedCommon();
@@ -96,7 +96,7 @@ public class SearchDialog extends CommonSearchDialog {
private transient String initSearchText = null;
private SearchDialog(MainWindow mainWindow, SearchPreset preset, Set<SearchOptions> additionalOptions) {
super(mainWindow);
super(mainWindow, NLS.str("menu.text_search"));
this.searchPreset = preset;
this.options = buildOptions(preset);
this.options.addAll(additionalOptions);
@@ -251,11 +251,8 @@ public class SearchDialog extends CommonSearchDialog {
}
}
});
setTitle(NLS.str("menu.text_search"));
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setModalityType(ModalityType.MODELESS);
}
private class SearchEventEmitter {
@@ -326,7 +323,7 @@ public class SearchDialog extends CommonSearchDialog {
private void processSearchResults(java.util.List<JNode> results) {
LOG.debug("search result size: {}", results.size());
String text = searchField.getText();
highlightText = text;
setHighlightText(text);
highlightTextCaseInsensitive = options.contains(SearchOptions.IGNORE_CASE);
highlightTextUseRegex = options.contains(SearchOptions.USE_REGEX);
@@ -35,7 +35,7 @@ public class UsageDialog extends CommonSearchDialog {
private transient List<CodeNode> usageList;
public UsageDialog(MainWindow mainWindow, JNode node) {
super(mainWindow);
super(mainWindow, NLS.str("usage_dialog.title"));
this.node = node;
initUI();
@@ -114,7 +114,7 @@ public class UsageDialog extends CommonSearchDialog {
Collections.sort(usageList);
resultsModel.addAll(usageList);
// TODO: highlight only needed node usage
highlightText = null;
setHighlightText(null);
super.performSearch();
}
@@ -138,11 +138,9 @@ public class UsageDialog extends CommonSearchDialog {
contentPane.add(resultsPanel, BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.PAGE_END);
setTitle(NLS.str("usage_dialog.title"));
pack();
setSize(800, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setModalityType(ModalityType.MODELESS);
}
}
@@ -19,9 +19,9 @@ import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.RootPaneContainer;
import javax.swing.SwingUtilities;
import org.intellij.lang.annotations.MagicConstant;
@@ -253,9 +253,9 @@ public class UiUtils {
return CTRL_BNT_KEY;
}
public static void addEscapeShortCutToDispose(JDialog dialog) {
public static <T extends Window & RootPaneContainer> void addEscapeShortCutToDispose(T window) {
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
dialog.getRootPane().registerKeyboardAction(e -> dialog.dispose(), stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
window.getRootPane().registerKeyboardAction(e -> window.dispose(), stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
}
/**