use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class FinalListener method perform.
public void perform(final boolean generateFinal, final String modifier, final PsiVariable variable) {
final Document document = myEditor.getDocument();
LOG.assertTrue(variable != null);
final PsiModifierList modifierList = variable.getModifierList();
LOG.assertTrue(modifierList != null);
final int textOffset = modifierList.getTextOffset();
final Runnable runnable = () -> {
if (generateFinal) {
final PsiTypeElement typeElement = variable.getTypeElement();
final int typeOffset = typeElement != null ? typeElement.getTextOffset() : textOffset;
document.insertString(typeOffset, modifier + " ");
} else {
final int idx = modifierList.getText().indexOf(modifier);
document.deleteString(textOffset + idx, textOffset + idx + modifier.length() + 1);
}
};
final LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
if (lookup != null) {
lookup.performGuardedChange(runnable);
} else {
runnable.run();
}
PsiDocumentManager.getInstance(variable.getProject()).commitDocument(document);
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class JsonSchemaCrossReferencesTest method checkCompletion.
private void checkCompletion(String... strings) {
assertStringItems(strings);
LookupImpl lookup = getActiveLookup();
if (lookup != null)
lookup.hide();
JsonSchemaService.Impl.get(getProject()).reset();
doHighlighting();
complete();
assertStringItems(strings);
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class TreeInplaceEditor method eventDispatched.
@Override
public void eventDispatched(AWTEvent event) {
if (!isShown()) {
return;
}
MouseEvent mouseEvent = (MouseEvent) event;
if (mouseEvent.getClickCount() == 0 && !(event instanceof MouseWheelEvent)) {
return;
}
final int id = mouseEvent.getID();
if (id != MouseEvent.MOUSE_PRESSED && id != MouseEvent.MOUSE_RELEASED && id != MouseEvent.MOUSE_CLICKED && id != MouseEvent.MOUSE_WHEEL) {
return;
}
final Component sourceComponent = mouseEvent.getComponent();
final Point originalPoint = mouseEvent.getPoint();
final Editor editor = getEditor();
if (editor == null)
return;
Project project = editor.getProject();
LookupImpl activeLookup = project != null ? (LookupImpl) LookupManager.getInstance(project).getActiveLookup() : null;
if (activeLookup != null) {
final Point lookupPoint = SwingUtilities.convertPoint(sourceComponent, originalPoint, activeLookup.getComponent());
if (activeLookup.getComponent().getBounds().contains(lookupPoint)) {
//mouse click inside lookup
return;
} else {
//hide popup on mouse position changed
activeLookup.hide();
}
}
// do not cancel editing if we click in editor popup
final List<JBPopup> popups = JBPopupFactory.getInstance().getChildPopups(myInplaceEditorComponent);
for (JBPopup popup : popups) {
if (SwingUtilities.isDescendingFrom(sourceComponent, popup.getContent())) {
return;
}
}
final Point point = SwingUtilities.convertPoint(sourceComponent, originalPoint, myInplaceEditorComponent);
if (myInplaceEditorComponent.contains(point)) {
return;
}
final Component componentAtPoint = SwingUtilities.getDeepestComponentAt(sourceComponent, originalPoint.x, originalPoint.y);
for (Component comp = componentAtPoint; comp != null; comp = comp.getParent()) {
if (comp instanceof ComboPopup) {
if (id != MouseEvent.MOUSE_WHEEL) {
doPopupOKAction();
}
return;
}
}
if (id != MouseEvent.MOUSE_RELEASED) {
// do not cancel on release outside of the component
cancelEditing();
}
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class LightFixtureCompletionTestCase method selectItem.
protected void selectItem(@NotNull LookupElement item, final char completionChar) {
final LookupImpl lookup = getLookup();
lookup.setCurrentItem(item);
if (LookupEvent.isSpecialCompletionChar(completionChar)) {
lookup.finishLookup(completionChar);
} else {
type(completionChar);
}
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class CompletionTestCase method complete.
protected void complete(final int time) {
new CodeCompletionHandlerBase(myType).invokeCompletion(myProject, InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(myEditor, getFile()), time);
LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor);
myItems = lookup == null ? null : lookup.getItems().toArray(new LookupElement[lookup.getItems().size()]);
myPrefix = lookup == null ? "" : lookup.itemPattern(lookup.getItems().get(0));
}
Aggregations