From 9a04c2805433e863333105a1c4ac4c0440c1768a Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Thu, 13 Sep 2018 22:37:28 -0400 Subject: [PATCH] Fix initialization of text consumers & action handlers on sites list. --- .../com/lyndir/masterpassword/gui/util/DocumentModel.java | 5 ++++- .../lyndir/masterpassword/gui/view/UserContentPanel.java | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/DocumentModel.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/DocumentModel.java index 78e99809..8a599657 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/DocumentModel.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/util/DocumentModel.java @@ -87,8 +87,11 @@ public class DocumentModel implements Selectable { @Override public DocumentModel selection(@Nullable final String selectedItem, @Nullable final Consumer selectionConsumer) { - selection( selectionConsumer ); setText( selectedItem ); + selection( selectionConsumer ); + + if (selectionConsumer != null) + selectionConsumer.accept( selectedItem ); return this; } diff --git a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java index c620dfb2..a1b896ed 100644 --- a/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java +++ b/platform-independent/java/gui/src/main/java/com/lyndir/masterpassword/gui/view/UserContentPanel.java @@ -542,6 +542,10 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener, add( Components.scrollPane( sitesList = Components.list( sitesModel = new CollectionListModel>>().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 ); add( Components.strut() ); add( Components.label( strf( @@ -1015,9 +1019,7 @@ public class UserContentPanel extends JPanel implements MasterPassword.Listener, if (siteItems.stream().noneMatch( MPQuery.Result::isExact )) siteItems.add( MPQuery.Result.allOf( new MPNewSite( user, query.getQuery() ), query.getQuery() ) ); - Res.ui( () -> { - sitesModel.set( siteItems ); - } ); + Res.ui( () -> sitesModel.set( siteItems ) ); } ); }