Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<repository>
<id>netbeans</id>
<name>NetBeans</name>
<url>http://netbeans.apidesign.org/maven2/</url>
<url>https://netbeans.apidesign.org/maven2/</url>
</repository>
</repositories>
<dependencies>
Expand Down Expand Up @@ -152,6 +152,11 @@
<artifactId>org-openide-util-lookup</artifactId>
<version>RELEASE82</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-windows</artifactId>
<version>RELEASE82</version>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-modules</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import org.chrisle.netbeans.plugins.nbscratchfile.ui.FilterableFileTypeDialog;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.WindowManager;

/**
*
Expand All @@ -43,10 +43,14 @@
})
@Messages("CTL_CreateScratchFile=New Scratch File...")
public final class CreateScratchFile implements ActionListener {
private final FilterableFileTypeDialog _dialog = new FilterableFileTypeDialog(new JFrame(), false);
private FilterableFileTypeDialog dialog;

@Override
public void actionPerformed(ActionEvent e) {
_dialog.showDialog();
if (dialog == null) {
dialog = new FilterableFileTypeDialog(WindowManager.getDefault().getMainWindow(), false);
}

dialog.showDialog();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.awt.Color;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
Expand Down Expand Up @@ -125,13 +126,12 @@ public void keyReleased(KeyEvent e) {
super.addWindowFocusListener(new WindowFocusListener() {
@Override
public void windowGainedFocus(WindowEvent e) {
searchField.setFocusable(true);
searchField.requestFocusInWindow();
}

@Override
public void windowLostFocus(WindowEvent e) {
FilterableFileTypeDialog.this.setVisible(false);
searchField.setText("");
EventQueue.invokeLater(FilterableFileTypeDialog.this::closeIfFocusRemainsLost);
}
});

Expand All @@ -156,6 +156,15 @@ public void showDialog() {
super.setVisible(true);
}

private void closeIfFocusRemainsLost() {
KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();

if (isVisible() && !isFocused() && focusManager.getActiveWindow() != this) {
super.setVisible(false);
searchField.setText("");
}
}

private static boolean languagesFilter(LanguageType lang, String str) {
return lang.LanguageName().toLowerCase().contains(str.toLowerCase());
}
Expand Down
Loading