Java Client: Clear site field with ESC key
This commit is contained in:
parent
997480cacb
commit
ff50cdd45d
@ -15,6 +15,7 @@ import com.lyndir.masterpassword.gui.util.*;
|
||||
import com.lyndir.masterpassword.gui.util.Platform;
|
||||
import com.lyndir.masterpassword.model.*;
|
||||
import com.lyndir.masterpassword.model.impl.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
@ -27,6 +28,7 @@ import java.util.*;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -264,6 +266,21 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
|
||||
}
|
||||
|
||||
|
||||
private final class SimpleAction extends AbstractAction {
|
||||
|
||||
private final Consumer<ActionEvent> action;
|
||||
|
||||
private SimpleAction(Consumer<ActionEvent> action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
action.accept(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final class NoUserPanel extends JPanel {
|
||||
|
||||
private NoUserPanel() {
|
||||
@ -481,6 +498,9 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
|
||||
private final JButton deleteButton = Components.button( Res.icons().delete(), event -> deleteSite(),
|
||||
"Delete the site from the user." );
|
||||
|
||||
private static final String USE_SITE_ACTION = "useSite";
|
||||
private static final String CLEAR_SITE_ACTION = "clearSite";
|
||||
|
||||
@Nonnull
|
||||
private final MPUser<?> user;
|
||||
private final JLabel resultLabel;
|
||||
@ -537,8 +557,6 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
|
||||
queryLabel.setText( strf( "%s's password for:", user.getFullName() ) );
|
||||
add( queryField = Components.textField( null, this::updateSites ) );
|
||||
queryField.putClientProperty( "JTextField.variant", "search" );
|
||||
queryField.addActionListener( this::useSite );
|
||||
queryField.getInputMap().put( copyLoginKeyStroke, JTextField.notifyAction );
|
||||
queryField.addKeyListener( this );
|
||||
queryField.requestFocusInWindow();
|
||||
add( Components.strut() );
|
||||
@ -546,10 +564,14 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener,
|
||||
add( Components.scrollPane( sitesList = Components.list(
|
||||
sitesModel = new CollectionListModel<MPQuery.Result<? extends MPSite<?>>>().selection( this::showSiteItem ),
|
||||
this::getSiteDescription ) ) );
|
||||
sitesList.registerKeyboardAction( this::useSite, KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ),
|
||||
JComponent.WHEN_FOCUSED );
|
||||
sitesList.registerKeyboardAction( this::useSite, KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK ),
|
||||
JComponent.WHEN_FOCUSED );
|
||||
|
||||
getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), USE_SITE_ACTION);
|
||||
getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(copyLoginKeyStroke, USE_SITE_ACTION);
|
||||
getActionMap().put(USE_SITE_ACTION, new SimpleAction(this::useSite));
|
||||
|
||||
getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CLEAR_SITE_ACTION);
|
||||
getActionMap().put(CLEAR_SITE_ACTION, new SimpleAction(e -> queryField.setText("")));
|
||||
|
||||
add( Components.strut() );
|
||||
|
||||
add( Components.label( strf(
|
||||
|
Loading…
Reference in New Issue
Block a user