Search in sources :

Example 1 with NameFilteringListModel

use of com.intellij.ui.speedSearch.NameFilteringListModel in project intellij-community by JetBrains.

the class NewRecentProjectPanel method createList.

@Override
protected JBList createList(AnAction[] recentProjectActions, Dimension size) {
    final JBList list = super.createList(recentProjectActions, size);
    list.setBackground(FlatWelcomeFrame.getProjectsBackground());
    list.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            Object selected = list.getSelectedValue();
            final ProjectGroup group;
            if (selected instanceof ProjectGroupActionGroup) {
                group = ((ProjectGroupActionGroup) selected).getGroup();
            } else {
                group = null;
            }
            int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_RIGHT) {
                if (group != null) {
                    if (!group.isExpanded()) {
                        group.setExpanded(true);
                        ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
                        int index = list.getSelectedIndex();
                        RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
                        list.setSelectedIndex(group.getProjects().isEmpty() ? index : index + 1);
                    }
                } else {
                    FlatWelcomeFrame frame = UIUtil.getParentOfType(FlatWelcomeFrame.class, list);
                    if (frame != null) {
                        FocusTraversalPolicy policy = frame.getFocusTraversalPolicy();
                        if (policy != null) {
                            Component next = policy.getComponentAfter(frame, list);
                            if (next != null) {
                                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                                    IdeFocusManager.getGlobalInstance().requestFocus(next, true);
                                });
                            }
                        }
                    }
                }
            } else if (keyCode == KeyEvent.VK_LEFT) {
                if (group != null && group.isExpanded()) {
                    group.setExpanded(false);
                    int index = list.getSelectedIndex();
                    ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
                    RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
                    list.setSelectedIndex(index);
                }
            }
        }
    });
    list.addMouseListener(new PopupHandler() {

        @Override
        public void invokePopup(Component comp, int x, int y) {
            final int index = list.locationToIndex(new Point(x, y));
            if (index != -1 && Arrays.binarySearch(list.getSelectedIndices(), index) < 0) {
                list.setSelectedIndex(index);
            }
            final ActionGroup group = (ActionGroup) ActionManager.getInstance().getAction("WelcomeScreenRecentProjectActionGroup");
            if (group != null) {
                ActionManager.getInstance().createActionPopupMenu(ActionPlaces.WELCOME_SCREEN, group).getComponent().show(comp, x, y);
            }
        }
    });
    return list;
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) NameFilteringListModel(com.intellij.ui.speedSearch.NameFilteringListModel) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) NameFilteringListModel(com.intellij.ui.speedSearch.NameFilteringListModel) JBList(com.intellij.ui.components.JBList)

Example 2 with NameFilteringListModel

use of com.intellij.ui.speedSearch.NameFilteringListModel in project intellij-community by JetBrains.

the class CodeInsightTestUtil method gotoImplementation.

@NotNull
@TestOnly
public static GotoTargetHandler.GotoData gotoImplementation(Editor editor, PsiFile file) {
    GotoTargetHandler.GotoData data = new GotoImplementationHandler().getSourceAndTargetElements(editor, file);
    if (data.listUpdaterTask != null) {
        JBList list = new JBList();
        CollectionListModel model = new CollectionListModel(new ArrayList());
        list.setModel(model);
        list.setModel(new NameFilteringListModel(list, Function.ID, Condition.FALSE, String::new));
        JBPopup popup = new ComponentPopupBuilderImpl(list, null).createPopup();
        data.listUpdaterTask.init((AbstractPopup) popup, list, new Ref<>());
        data.listUpdaterTask.queue();
        try {
            while (!data.listUpdaterTask.isFinished()) {
                UIUtil.dispatchAllInvocationEvents();
            }
        } finally {
            Disposer.dispose(popup);
        }
    }
    return data;
}
Also used : NameFilteringListModel(com.intellij.ui.speedSearch.NameFilteringListModel) GotoTargetHandler(com.intellij.codeInsight.navigation.GotoTargetHandler) GotoImplementationHandler(com.intellij.codeInsight.navigation.GotoImplementationHandler) ArrayList(java.util.ArrayList) JBList(com.intellij.ui.components.JBList) CollectionListModel(com.intellij.ui.CollectionListModel) JBPopup(com.intellij.openapi.ui.popup.JBPopup) ComponentPopupBuilderImpl(com.intellij.ui.popup.ComponentPopupBuilderImpl) TestOnly(org.jetbrains.annotations.TestOnly) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JBList (com.intellij.ui.components.JBList)2 NameFilteringListModel (com.intellij.ui.speedSearch.NameFilteringListModel)2 GotoImplementationHandler (com.intellij.codeInsight.navigation.GotoImplementationHandler)1 GotoTargetHandler (com.intellij.codeInsight.navigation.GotoTargetHandler)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 CollectionListModel (com.intellij.ui.CollectionListModel)1 PopupHandler (com.intellij.ui.PopupHandler)1 ComponentPopupBuilderImpl (com.intellij.ui.popup.ComponentPopupBuilderImpl)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 TestOnly (org.jetbrains.annotations.TestOnly)1