mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Popups: cleanup
- fix popups font - fix hint update - cleaner API
This commit is contained in:
+4
-14
@@ -35,8 +35,6 @@ import com.intellij.psi.NavigatablePsiElement;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.ui.popup.HintUpdateSupply;
|
||||
import com.intellij.ui.speedSearch.ListWithFilter;
|
||||
import com.intellij.usages.UsageView;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -137,7 +135,6 @@ public class PsiElementListNavigator {
|
||||
return null;
|
||||
}
|
||||
List<NavigatablePsiElement> targetsList = Arrays.asList(targets);
|
||||
final JBList<NavigatablePsiElement>[] listR = new JBList[1];
|
||||
final IPopupChooserBuilder<NavigatablePsiElement> builder = JBPopupFactory.getInstance().createPopupChooserBuilder(targetsList);
|
||||
if (listRenderer instanceof PsiElementListCellRenderer) {
|
||||
((PsiElementListCellRenderer)listRenderer).installSpeedSearch(builder);
|
||||
@@ -148,14 +145,10 @@ public class PsiElementListNavigator {
|
||||
setMovable(true).
|
||||
setFont(EditorUtil.getEditorFont()).
|
||||
setRenderer(listRenderer).
|
||||
withHintUpdateSupply().
|
||||
setResizable(true).
|
||||
setItemsChosenCallback(selectedValues -> {
|
||||
consumer.consume(ArrayUtil.toObjectArray(selectedValues));
|
||||
}).
|
||||
setItemsChosenCallback(selectedValues -> consumer.consume(ArrayUtil.toObjectArray(selectedValues))).
|
||||
setCancelCallback(() -> {
|
||||
if (listR[0] != null) {
|
||||
HintUpdateSupply.hideHint(listR[0]);
|
||||
}
|
||||
if (listUpdaterTask != null) {
|
||||
listUpdaterTask.cancelTask();
|
||||
}
|
||||
@@ -171,11 +164,9 @@ public class PsiElementListNavigator {
|
||||
}
|
||||
|
||||
final JBPopup popup = popupChooserBuilder.createPopup();
|
||||
if (builder instanceof PopupChooserBuilder && ((PopupChooserBuilder)builder).getChooserComponent() instanceof ListWithFilter) {
|
||||
JBList<NavigatablePsiElement> list = (JBList)((ListWithFilter)((PopupChooserBuilder)builder).getChooserComponent()).getList();
|
||||
HintUpdateSupply.installSimpleHintUpdateSupply(list);
|
||||
if (builder instanceof PopupChooserBuilder) {
|
||||
JBList<NavigatablePsiElement> list = (JBList)((PopupChooserBuilder)builder).getChooserComponent();
|
||||
list.setTransferHandler(new TransferHandler(){
|
||||
@Nullable
|
||||
@Override
|
||||
protected Transferable createTransferable(JComponent c) {
|
||||
final Object[] selectedValues = list.getSelectedValues();
|
||||
@@ -191,7 +182,6 @@ public class PsiElementListNavigator {
|
||||
return COPY;
|
||||
}
|
||||
});
|
||||
listR[0] = list;
|
||||
}
|
||||
if (builder instanceof PopupChooserBuilder) {
|
||||
JScrollPane pane = ((PopupChooserBuilder)builder).getScrollPane();
|
||||
|
||||
@@ -42,9 +42,6 @@ import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.ui.popup.HintUpdateSupply;
|
||||
import com.intellij.ui.speedSearch.ListWithFilter;
|
||||
import com.intellij.usages.UsageView;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -127,7 +124,6 @@ public abstract class GotoTargetHandler implements CodeInsightActionHandler {
|
||||
Collections.addAll(allElements, targets);
|
||||
allElements.addAll(additionalActions);
|
||||
|
||||
final Ref<JBList<Object>> listR = new Ref<>();
|
||||
final IPopupChooserBuilder<Object> builder = JBPopupFactory.getInstance().createPopupChooserBuilder(allElements);
|
||||
final Ref<UsageView> usageView = new Ref<>();
|
||||
final JBPopup popup = builder.setNamerForFiltering(o -> {
|
||||
@@ -167,11 +163,9 @@ public abstract class GotoTargetHandler implements CodeInsightActionHandler {
|
||||
}
|
||||
}
|
||||
}).
|
||||
withHintUpdateSupply().
|
||||
setMovable(true).
|
||||
setCancelCallback(() -> {
|
||||
if (!listR.isNull()) {
|
||||
HintUpdateSupply.hideHint(listR.get());
|
||||
}
|
||||
final BackgroundUpdaterTask task = gotoData.listUpdaterTask;
|
||||
if (task != null) {
|
||||
task.cancelTask();
|
||||
@@ -186,12 +180,6 @@ public abstract class GotoTargetHandler implements CodeInsightActionHandler {
|
||||
setAdText(getAdText(gotoData.source, targets.length)).
|
||||
createPopup();
|
||||
|
||||
if (builder instanceof PopupChooserBuilder && ((PopupChooserBuilder)builder).getChooserComponent() instanceof ListWithFilter) {
|
||||
JBList<Object> list = (JBList)((ListWithFilter)((PopupChooserBuilder)builder).getChooserComponent()).getList();
|
||||
HintUpdateSupply.installSimpleHintUpdateSupply(list);
|
||||
listR.set(list);
|
||||
}
|
||||
|
||||
JScrollPane pane = builder instanceof PopupChooserBuilder ? ((PopupChooserBuilder)builder).getScrollPane() : null;
|
||||
if (pane != null) {
|
||||
pane.setBorder(null);
|
||||
|
||||
@@ -70,6 +70,10 @@ public class PopupChooserBuilder<T> implements IPopupChooserBuilder<T> {
|
||||
public interface PopupComponentAdapter<T> {
|
||||
JComponent getComponent();
|
||||
|
||||
default JComponent getChooserComponent() {
|
||||
return getComponent();
|
||||
}
|
||||
|
||||
default void setRenderer(ListCellRenderer renderer) {}
|
||||
|
||||
void setItemChosenCallback(Consumer<T> callback);
|
||||
@@ -109,10 +113,14 @@ public class PopupChooserBuilder<T> implements IPopupChooserBuilder<T> {
|
||||
default BooleanFunction<KeyEvent> getKeyEventHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
default void setFont(Font f) {
|
||||
getChooserComponent().setFont(f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PopupChooserBuilder setCancelOnClickOutside(boolean cancelOnClickOutside) {
|
||||
public PopupChooserBuilder<T> setCancelOnClickOutside(boolean cancelOnClickOutside) {
|
||||
myCancelOnClickOutside = cancelOnClickOutside;
|
||||
return this;
|
||||
}
|
||||
@@ -159,7 +167,7 @@ public class PopupChooserBuilder<T> implements IPopupChooserBuilder<T> {
|
||||
}
|
||||
|
||||
public JComponent getChooserComponent() {
|
||||
return myChooserComponent.getComponent();
|
||||
return myChooserComponent.getChooserComponent();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -235,7 +243,7 @@ public class PopupChooserBuilder<T> implements IPopupChooserBuilder<T> {
|
||||
|
||||
@Override
|
||||
public PopupChooserBuilder<T> setCancelCallback(Computable<Boolean> callback) {
|
||||
myCancelCallback = callback;
|
||||
addCancelCallback(callback);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -523,15 +531,24 @@ public class PopupChooserBuilder<T> implements IPopupChooserBuilder<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void addCancelCallback(Computable<Boolean> cbb) {
|
||||
Computable<Boolean> callback = myCancelCallback;
|
||||
myCancelCallback = () -> cbb.compute() && callback.compute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPopupChooserBuilder<T> withHintUpdateSupply() {
|
||||
HintUpdateSupply.installSimpleHintUpdateSupply(myChooserComponent.getComponent());
|
||||
HintUpdateSupply.installSimpleHintUpdateSupply(myChooserComponent.getChooserComponent());
|
||||
addCancelCallback(() -> {
|
||||
HintUpdateSupply.hideHint(myChooserComponent.getChooserComponent());
|
||||
return true;
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPopupChooserBuilder<T> setFont(Font f) {
|
||||
myChooserComponent.getComponent().setFont(f);
|
||||
myChooserComponent.setFont(f);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,11 @@ class PopupListAdapter<T> implements PopupChooserBuilder.PopupComponentAdapter<T
|
||||
return myListWithFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getChooserComponent() {
|
||||
return myListWithFilter.getList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRenderer(ListCellRenderer renderer) {
|
||||
myListWithFilter.getList().setCellRenderer(renderer);
|
||||
|
||||
Reference in New Issue
Block a user