mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-26 20:54:22 +01:00
Find/Replace: display on top of the related Editor
If the editor is focused, acquire alwaysOnTop capabilities but drop them as soon as both the editor and the dialog are out of focus try to implement partial transparency As implemented in Notepad++, a partially transparent search/replace window could make it easier to interact with the editor (particularly in fullscreen contexts, when the "always on top" window could hide the search results). Unfortunately, Java can only apply the transparency to undecorated window, so it's a no-go. Java gurus, please come to the rescue :D Fix find/replace focus on Windows Probably this approach could be adopted by all OSes with a little care on the window lifecycle. [Find/Replace][Win] grab focus when just opened Solves https://github.com/arduino/Arduino/issues/6951#issuecomment-351995084 Use Windows method for all OS
This commit is contained in:
parent
edeb455f70
commit
b8a6e6d589
@ -43,6 +43,7 @@ import javax.swing.text.DefaultEditorKit;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.awt.GraphicsDevice.WindowTranslucency.*;
|
||||
import static processing.app.I18n.tr;
|
||||
|
||||
public class FindReplace extends javax.swing.JFrame {
|
||||
@ -58,6 +59,7 @@ public class FindReplace extends javax.swing.JFrame {
|
||||
public FindReplace(Editor editor, Map<String, Object> state) {
|
||||
this.editor = editor;
|
||||
|
||||
isTranslucencySupported();
|
||||
initComponents();
|
||||
|
||||
if (OSUtils.isMacOS()) {
|
||||
@ -70,16 +72,28 @@ public class FindReplace extends javax.swing.JFrame {
|
||||
}
|
||||
|
||||
Base.registerWindowCloseKeys(getRootPane(), e -> {
|
||||
setAutoRequestFocus(true);
|
||||
setVisible(false);
|
||||
Base.FIND_DIALOG_STATE = findDialogState();
|
||||
});
|
||||
|
||||
Base.setIcon(this);
|
||||
|
||||
editor.addWindowListener(new WindowAdapter() {
|
||||
public void windowActivated(WindowEvent e) {
|
||||
toFront();
|
||||
setAutoRequestFocus(false);
|
||||
}
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowActivated(WindowEvent e) {
|
||||
findField.requestFocusInWindow();
|
||||
findField.selectAll();
|
||||
return;
|
||||
}
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
@ -89,10 +103,20 @@ public class FindReplace extends javax.swing.JFrame {
|
||||
@Override
|
||||
public void setVisible(boolean b) {
|
||||
getRootPane().setDefaultButton(findButton);
|
||||
|
||||
// means we are restoring the window visibility
|
||||
setAutoRequestFocus(true);
|
||||
super.setVisible(b);
|
||||
}
|
||||
|
||||
private boolean useTranslucency;
|
||||
|
||||
private void isTranslucencySupported() {
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice gd = ge.getDefaultScreenDevice();
|
||||
//If translucent windows aren't supported, exit.
|
||||
useTranslucency = gd.isWindowTranslucencySupported(TRANSLUCENT);
|
||||
}
|
||||
|
||||
private Map<String, Object> findDialogState() {
|
||||
Map<String, Object> state = new HashMap<>();
|
||||
state.put(FIND_TEXT, findField.getText());
|
||||
|
Loading…
x
Reference in New Issue
Block a user