use of com.intellij.openapi.ui.popup.PopupStep in project intellij-community by JetBrains.
the class DetectionExcludesConfigurable method doAddAction.
private void doAddAction(AnActionButton button) {
final List<FrameworkType> types = new ArrayList<>();
for (FrameworkType type : FrameworkDetectorRegistry.getInstance().getFrameworkTypes()) {
if (!isExcluded(type)) {
types.add(type);
}
}
Collections.sort(types, (o1, o2) -> o1.getPresentableName().compareToIgnoreCase(o2.getPresentableName()));
types.add(0, null);
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<FrameworkType>("Framework to Exclude", types) {
@Override
public Icon getIconFor(FrameworkType value) {
return value != null ? value.getIcon() : null;
}
@NotNull
@Override
public String getTextFor(FrameworkType value) {
return value != null ? value.getPresentableName() : "All Frameworks...";
}
@Override
public boolean hasSubstep(FrameworkType selectedValue) {
return selectedValue != null;
}
@Override
public PopupStep onChosen(final FrameworkType frameworkType, boolean finalChoice) {
if (frameworkType == null) {
return doFinalStep(() -> chooseDirectoryAndAdd(null));
} else {
return addExcludedFramework(frameworkType);
}
}
});
final RelativePoint popupPoint = button.getPreferredPopupPoint();
if (popupPoint != null) {
popup.show(popupPoint);
} else {
popup.showInCenterOf(myMainPanel);
}
}
use of com.intellij.openapi.ui.popup.PopupStep in project intellij-community by JetBrains.
the class BaseRunConfigurationAction method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
final RunnerAndConfigurationSettings existing = context.findExisting();
if (existing == null) {
final List<ConfigurationFromContext> producers = getConfigurationsFromContext(context);
if (producers.isEmpty())
return;
if (producers.size() > 1) {
final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
Collections.sort(producers, ConfigurationFromContext.NAME_COMPARATOR);
final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<ConfigurationFromContext>(ExecutionBundle.message("configuration.action.chooser.title"), producers) {
@Override
@NotNull
public String getTextFor(final ConfigurationFromContext producer) {
return childActionName(producer.getConfigurationType(), producer.getConfiguration());
}
@Override
public Icon getIconFor(final ConfigurationFromContext producer) {
return producer.getConfigurationType().getIcon();
}
@Override
public PopupStep onChosen(final ConfigurationFromContext producer, final boolean finalChoice) {
perform(producer, context);
return FINAL_CHOICE;
}
});
final InputEvent event = e.getInputEvent();
if (event instanceof MouseEvent) {
popup.show(new RelativePoint((MouseEvent) event));
} else if (editor != null) {
popup.showInBestPositionFor(editor);
} else {
popup.showInBestPositionFor(dataContext);
}
} else {
perform(producers.get(0), context);
}
return;
}
perform(context);
}
use of com.intellij.openapi.ui.popup.PopupStep in project intellij-community by JetBrains.
the class TreePopupImpl method handleSelect.
private void handleSelect(boolean handleFinalChoices, MouseEvent e) {
final boolean pathIsAlreadySelected = myShowingChildPath != null && myShowingChildPath.equals(myWizardTree.getSelectionPath());
if (pathIsAlreadySelected)
return;
myPendingChildPath = null;
Object selected = myWizardTree.getLastSelectedPathComponent();
if (selected != null) {
final Object userObject = extractUserObject(selected);
if (getTreeStep().isSelectable(selected, userObject)) {
disposeChildren();
final boolean hasNextStep = myStep.hasSubstep(userObject);
if (!hasNextStep && !handleFinalChoices) {
myShowingChildPath = null;
return;
}
AtomicBoolean insideOnChosen = new AtomicBoolean(true);
ApplicationManager.getApplication().invokeLater(() -> {
if (insideOnChosen.get()) {
LOG.error("Showing dialogs from popup onChosen can result in focus issues. Please put the handler into BaseStep.doFinalStep or PopupStep.getFinalRunnable.");
}
}, ModalityState.any());
final PopupStep queriedStep;
try {
queriedStep = myStep.onChosen(userObject, handleFinalChoices);
} finally {
insideOnChosen.set(false);
}
if (queriedStep == PopupStep.FINAL_CHOICE || !hasNextStep) {
setFinalRunnable(myStep.getFinalRunnable());
setOk(true);
disposeAllParents(e);
} else {
myShowingChildPath = myWizardTree.getSelectionPath();
handleNextStep(queriedStep, myShowingChildPath);
myShowingChildPath = null;
}
}
}
}
use of com.intellij.openapi.ui.popup.PopupStep in project intellij-community by JetBrains.
the class ExpressionInputComponent method showHistory.
private void showHistory() {
List<XExpression> expressions = myExpressionEditor.getRecentExpressions();
if (!expressions.isEmpty()) {
ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep<XExpression>(null, expressions) {
@Override
public PopupStep onChosen(XExpression selectedValue, boolean finalChoice) {
myExpressionEditor.setExpression(selectedValue);
myExpressionEditor.requestFocusInEditor();
return FINAL_CHOICE;
}
}) {
@Override
protected ListCellRenderer getListElementRenderer() {
return new ColoredListCellRenderer<XExpression>() {
@Override
protected void customizeCellRenderer(@NotNull JList list, XExpression value, int index, boolean selected, boolean hasFocus) {
append(value.getExpression());
}
};
}
};
popup.getList().setFont(EditorUtil.getEditorFont());
popup.showUnderneathOf(myExpressionEditor.getEditorComponent());
}
}
use of com.intellij.openapi.ui.popup.PopupStep in project intellij-community by JetBrains.
the class XDebuggerUtilImpl method toggleAndReturnLineBreakpoint.
@NotNull
public static <P extends XBreakpointProperties> Promise<XLineBreakpoint> toggleAndReturnLineBreakpoint(@NotNull final Project project, @NotNull final XLineBreakpointType<P> type, @NotNull final XSourcePosition position, final boolean temporary, @Nullable final Editor editor, boolean canRemove) {
return new WriteAction<Promise<XLineBreakpoint>>() {
@Override
protected void run(@NotNull Result<Promise<XLineBreakpoint>> result) throws Throwable {
final VirtualFile file = position.getFile();
final int line = position.getLine();
final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
XLineBreakpoint<P> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line);
if (breakpoint != null) {
if (!temporary && canRemove) {
breakpointManager.removeBreakpoint(breakpoint);
}
} else {
List<? extends XLineBreakpointType<P>.XLineBreakpointVariant<P>> variants = type.computeVariants(project, position);
if (!variants.isEmpty() && editor != null) {
RelativePoint relativePoint = DebuggerUIUtil.getPositionForPopup(editor, line);
if (variants.size() > 1 && relativePoint != null) {
final AsyncPromise<XLineBreakpoint> res = new AsyncPromise<>();
class MySelectionListener implements ListSelectionListener {
RangeHighlighter myHighlighter = null;
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
updateHighlighter(((JList) e.getSource()).getSelectedValue());
}
}
public void initialSet(Object value) {
if (myHighlighter == null) {
updateHighlighter(value);
}
}
void updateHighlighter(Object value) {
clearHighlighter();
if (value instanceof XLineBreakpointType.XLineBreakpointVariant) {
TextRange range = ((XLineBreakpointType.XLineBreakpointVariant) value).getHighlightRange();
TextRange lineRange = DocumentUtil.getLineTextRange(editor.getDocument(), line);
if (range != null) {
range = range.intersection(lineRange);
} else {
range = lineRange;
}
if (range != null && !range.isEmpty()) {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
TextAttributes attributes = scheme.getAttributes(DebuggerColors.BREAKPOINT_ATTRIBUTES);
myHighlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), DebuggerColors.BREAKPOINT_HIGHLIGHTER_LAYER, attributes, HighlighterTargetArea.EXACT_RANGE);
}
}
}
private void clearHighlighter() {
if (myHighlighter != null) {
myHighlighter.dispose();
}
}
}
// calculate default item
int caretOffset = editor.getCaretModel().getOffset();
XLineBreakpointType<P>.XLineBreakpointVariant<P> defaultVariant = null;
for (XLineBreakpointType<P>.XLineBreakpointVariant<P> variant : variants) {
TextRange range = variant.getHighlightRange();
if (range != null && range.contains(caretOffset)) {
//noinspection ConstantConditions
if (defaultVariant == null || defaultVariant.getHighlightRange().getLength() > range.getLength()) {
defaultVariant = variant;
}
}
}
final int defaultIndex = defaultVariant != null ? variants.indexOf(defaultVariant) : 0;
final MySelectionListener selectionListener = new MySelectionListener();
ListPopupImpl popup = new ListPopupImpl(new BaseListPopupStep<XLineBreakpointType.XLineBreakpointVariant>("Set Breakpoint", variants) {
@NotNull
@Override
public String getTextFor(XLineBreakpointType.XLineBreakpointVariant value) {
return value.getText();
}
@Override
public Icon getIconFor(XLineBreakpointType.XLineBreakpointVariant value) {
return value.getIcon();
}
@Override
public void canceled() {
selectionListener.clearHighlighter();
}
@Override
public PopupStep onChosen(final XLineBreakpointType.XLineBreakpointVariant selectedValue, boolean finalChoice) {
selectionListener.clearHighlighter();
ApplicationManager.getApplication().runWriteAction(() -> {
P properties = (P) selectedValue.createProperties();
res.setResult(breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary));
});
return FINAL_CHOICE;
}
@Override
public int getDefaultOptionIndex() {
return defaultIndex;
}
}) {
@Override
protected void afterShow() {
super.afterShow();
selectionListener.initialSet(getList().getSelectedValue());
}
};
DebuggerUIUtil.registerExtraHandleShortcuts(popup, IdeActions.ACTION_TOGGLE_LINE_BREAKPOINT);
popup.setAdText(DebuggerUIUtil.getSelectionShortcutsAdText(IdeActions.ACTION_TOGGLE_LINE_BREAKPOINT));
popup.addListSelectionListener(selectionListener);
popup.show(relativePoint);
result.setResult(res);
return;
} else {
P properties = variants.get(0).createProperties();
result.setResult(Promise.resolve(breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary)));
return;
}
}
P properties = type.createBreakpointProperties(file, line);
result.setResult(Promise.resolve(breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary)));
return;
}
result.setResult(rejectedPromise());
}
}.execute().getResultObject();
}
Aggregations