Plugins management 2019: handle up/down in search field for navigate on result

GitOrigin-RevId: 50259672d80f1e955dd31387fd492541dd8337fb
This commit is contained in:
Alexander Lobas
2019-04-28 14:59:03 +03:00
committed by intellij-monorepo-bot
parent 85fa5fa5d5
commit f151b7c3a6
6 changed files with 68 additions and 7 deletions
@@ -411,7 +411,7 @@ public class PluginManagerConfigurableNewLayout
@Override
protected SearchResultPanel createSearchPanel(@NotNull Consumer<PluginsGroupComponent> selectionListener,
@NotNull PluginSearchTextField searchTextField) {
SearchPopupController trendingController = new SearchPopupController(searchTextField, false) {
SearchUpDownPopupController marketplaceController = new SearchUpDownPopupController(searchTextField) {
@NotNull
@Override
protected List<String> getAttributes() {
@@ -591,8 +591,11 @@ public class PluginManagerConfigurableNewLayout
}
};
MultiSelectionEventHandler eventHandler = new MultiSelectionEventHandler();
marketplaceController.setEventHandler(eventHandler);
PluginsGroupComponentWithProgress panel =
new PluginsGroupComponentWithProgress(new PluginListLayout(), new MultiSelectionEventHandler(), myNameListener,
new PluginsGroupComponentWithProgress(new PluginListLayout(), eventHandler, myNameListener,
PluginManagerConfigurableNewLayout.this.mySearchListener,
descriptor -> new NewListPluginComponent(myPluginModel, descriptor, true));
@@ -600,7 +603,7 @@ public class PluginManagerConfigurableNewLayout
PluginManagerConfigurableNew.registerCopyProvider(panel);
myMarketplaceSearchPanel =
new SearchResultPanel(trendingController, panel, 0, 0) {
new SearchResultPanel(marketplaceController, panel, 0, 0) {
@Override
protected void handleQuery(@NotNull String query, @NotNull PluginsGroup result) {
try {
@@ -843,7 +846,7 @@ public class PluginManagerConfigurableNewLayout
@Override
protected SearchResultPanel createSearchPanel(@NotNull Consumer<PluginsGroupComponent> selectionListener,
@NotNull PluginSearchTextField searchTextField) {
SearchPopupController installedController = new SearchPopupController(searchTextField, false) {
SearchUpDownPopupController installedController = new SearchUpDownPopupController(searchTextField) {
@NotNull
@Override
protected List<String> getAttributes() {
@@ -872,7 +875,10 @@ public class PluginManagerConfigurableNewLayout
}
};
PluginsGroupComponent panel = new PluginsGroupComponent(new PluginListLayout(), new MultiSelectionEventHandler(), myNameListener,
MultiSelectionEventHandler eventHandler = new MultiSelectionEventHandler();
installedController.setEventHandler(eventHandler);
PluginsGroupComponent panel = new PluginsGroupComponent(new PluginListLayout(), eventHandler, myNameListener,
PluginManagerConfigurableNewLayout.this.mySearchListener,
descriptor -> new NewListPluginComponent(myPluginModel, descriptor, false));
@@ -34,6 +34,8 @@ public abstract class CellPluginComponent extends JPanel {
public static final Color GRAY_COLOR = JBColor.namedColor("Label.infoForeground", new JBColor(Gray._120, Gray._135));
private static final Color HOVER_COLOR = JBColor.namedColor("Plugins.lightSelectionBackground", new JBColor(0xF5F9FF, 0x36393B));
public static boolean HANDLE_FOCUS_ON_SELECTION = true;
public final IdeaPluginDescriptor myPlugin;
protected LinkLabel myIconLabel;
@@ -127,7 +129,7 @@ public abstract class CellPluginComponent extends JPanel {
if (scrollAndFocus) {
scrollToVisible();
if (getParent() != null && type == EventHandler.SelectionType.SELECTION) {
if (getParent() != null && type == EventHandler.SelectionType.SELECTION && HANDLE_FOCUS_ON_SELECTION) {
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(this, true));
}
}
@@ -75,6 +75,9 @@ public abstract class EventHandler {
public void setSelectionListener(@Nullable Consumer<PluginsGroupComponent> listener) {
}
public void handleUpDown(@NotNull KeyEvent event) {
}
public enum SelectionType {
SELECTION, HOVER, NONE
}
@@ -196,6 +196,24 @@ public class MultiSelectionEventHandler extends EventHandler {
};
}
@Override
public void handleUpDown(@NotNull KeyEvent event) {
if (myComponents.isEmpty()) {
return;
}
try {
//noinspection AssignmentToStaticFieldFromInstanceMethod
CellPluginComponent.HANDLE_FOCUS_ON_SELECTION = false;
myKeyListener.keyPressed(event);
}
finally {
//noinspection AssignmentToStaticFieldFromInstanceMethod
CellPluginComponent.HANDLE_FOCUS_ON_SELECTION = true;
}
}
@Override
public void connect(@NotNull PluginsGroupComponent container) {
myContainer = container;
@@ -21,7 +21,7 @@ import java.util.List;
* @author Alexander Lobas
*/
public abstract class SearchPopupController {
private final PluginSearchTextField myTextField;
protected final PluginSearchTextField myTextField;
private final boolean myHandleSpace;
protected SearchPopup myPopup;
private final JBPopupListener mySearchPopupListener = new JBPopupAdapter() {
@@ -0,0 +1,32 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ide.plugins.newui;
import org.jetbrains.annotations.NotNull;
import java.awt.event.KeyEvent;
/**
* @author Alexander Lobas
*/
public abstract class SearchUpDownPopupController extends SearchPopupController {
private EventHandler myEventHandler;
public SearchUpDownPopupController(@NotNull PluginSearchTextField searchTextField) {
super(searchTextField, false);
}
public void setEventHandler(@NotNull EventHandler eventHandler) {
myEventHandler = eventHandler;
}
@Override
public boolean handleUpDown(@NotNull KeyEvent event) {
if (myPopup != null && myPopup.list != null) {
return super.handleUpDown(event);
}
if (!myTextField.getText().isEmpty() && myEventHandler != null) {
myEventHandler.handleUpDown(event);
}
return false;
}
}