Example usage for com.intellij.openapi.ui.popup ListPopupStep getDefaultOptionIndex

List of usage examples for com.intellij.openapi.ui.popup ListPopupStep getDefaultOptionIndex

Introduction

In this page you can find the example usage for com.intellij.openapi.ui.popup ListPopupStep getDefaultOptionIndex.

Prototype

int getDefaultOptionIndex();

Source Link

Document

Returns the index of the item to be initially selected in the list.

Usage

From source file:com.intellij.ui.popup.list.ListPopupImpl.java

License:Apache License

private boolean tryToAutoSelect(boolean handleFinalChoices) {
    ListPopupStep<Object> listStep = getListStep();
    boolean selected = false;
    if (listStep instanceof MultiSelectionListPopupStep<?>) {
        int[] indices = ((MultiSelectionListPopupStep) listStep).getDefaultOptionIndices();
        if (indices.length > 0) {
            ListScrollingUtil.ensureIndexIsVisible(myList, indices[0], 0);
            myList.setSelectedIndices(indices);
            selected = true;/*from  ww  w  .  java  2 s .c  o  m*/
        }
    } else {
        final int defaultIndex = listStep.getDefaultOptionIndex();
        if (defaultIndex >= 0 && defaultIndex < myList.getModel().getSize()) {
            ListScrollingUtil.selectItem(myList, defaultIndex);
            selected = true;
        }
    }

    if (!selected) {
        selectFirstSelectableItem();
    }

    if (listStep.isAutoSelectionEnabled()) {
        if (!isVisible() && getSelectableCount() == 1) {
            return _handleSelect(handleFinalChoices, null);
        } else if (isVisible() && hasSingleSelectableItemWithSubmenu()) {
            return _handleSelect(handleFinalChoices, null);
        }
    }

    return false;
}