use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class LightCompletionTestCase method selectItem.
protected void selectItem(LookupElement item, char completionChar) {
final LookupImpl lookup = (LookupImpl) LookupManager.getInstance(getProject()).getActiveLookup();
lookup.setCurrentItem(item);
if (completionChar == 0 || completionChar == '\n' || completionChar == '\t') {
lookup.finishLookup(completionChar);
} else {
type(completionChar);
}
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class ListTemplatesHandler method showTemplatesLookup.
private static void showTemplatesLookup(final Project project, final Editor editor, final PsiFile file, @NotNull Map<TemplateImpl, String> matchingTemplates, @NotNull MultiMap<String, CustomLiveTemplateLookupElement> customTemplatesLookupElements) {
LookupImpl lookup = (LookupImpl) LookupManager.getInstance(project).createLookup(editor, LookupElement.EMPTY_ARRAY, "", new TemplatesArranger());
for (Map.Entry<TemplateImpl, String> entry : matchingTemplates.entrySet()) {
TemplateImpl template = entry.getKey();
lookup.addItem(createTemplateElement(template), new PlainPrefixMatcher(StringUtil.notNullize(entry.getValue())));
}
for (Map.Entry<String, Collection<CustomLiveTemplateLookupElement>> entry : customTemplatesLookupElements.entrySet()) {
for (CustomLiveTemplateLookupElement lookupElement : entry.getValue()) {
lookup.addItem(lookupElement, new PlainPrefixMatcher(entry.getKey()));
}
}
showLookup(lookup, file);
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class EscapeHandler method execute.
@Override
public void execute(Editor editor, DataContext dataContext) {
TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
if (templateState != null && !templateState.isFinished()) {
SelectionModel selectionModel = editor.getSelectionModel();
LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(editor);
// the idea behind lookup checking is that if there is a preselected value in lookup
// then user might want just to close lookup but not finish a template.
// E.g. user wants to move to the next template segment by Tab without completion invocation.
// If there is no selected value in completion that user definitely wants to finish template
boolean lookupIsEmpty = lookup == null || lookup.getCurrentItem() == null;
if (!selectionModel.hasSelection() && lookupIsEmpty) {
CommandProcessor.getInstance().setCurrentCommandName(CodeInsightBundle.message("finish.template.command"));
templateState.gotoEnd(true);
return;
}
}
if (myOriginalHandler.isEnabled(editor, dataContext)) {
myOriginalHandler.execute(editor, dataContext);
}
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class TemplateState method initListeners.
private void initListeners() {
if (isDisposed())
return;
myEditorDocumentListener = new DocumentAdapter() {
@Override
public void beforeDocumentChange(DocumentEvent e) {
myDocumentChanged = true;
}
};
myLookupListener = new LookupAdapter() {
@Override
public void itemSelected(LookupEvent event) {
if (isCaretOutsideCurrentSegment(null)) {
if (isCaretInsideNextVariable()) {
nextTab();
} else {
gotoEnd(true);
}
}
}
};
LookupManager.getInstance(myProject).addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (LookupManager.PROP_ACTIVE_LOOKUP.equals(evt.getPropertyName())) {
Lookup lookup = (Lookup) evt.getNewValue();
if (lookup != null) {
lookup.addLookupListener(myLookupListener);
}
}
}
}, this);
myCommandListener = new CommandAdapter() {
boolean started = false;
@Override
public void commandStarted(CommandEvent event) {
myDocumentChangesTerminateTemplate = isCaretOutsideCurrentSegment(event.getCommandName());
started = true;
}
@Override
public void beforeCommandFinished(CommandEvent event) {
if (started && !isDisposed()) {
Runnable runnable = () -> afterChangedUpdate();
final LookupImpl lookup = myEditor != null ? (LookupImpl) LookupManager.getActiveLookup(myEditor) : null;
if (lookup != null) {
lookup.performGuardedChange(runnable);
} else {
runnable.run();
}
}
}
};
myCaretListener = new CaretAdapter() {
@Override
public void caretAdded(CaretEvent e) {
if (isMultiCaretMode()) {
finishTemplateEditing();
}
}
@Override
public void caretRemoved(CaretEvent e) {
if (isMultiCaretMode()) {
finishTemplateEditing();
}
}
};
if (myEditor != null) {
myEditor.getCaretModel().addCaretListener(myCaretListener);
}
myDocument.addDocumentListener(myEditorDocumentListener, this);
CommandProcessor.getInstance().addCommandListener(myCommandListener, this);
}
use of com.intellij.codeInsight.lookup.impl.LookupImpl in project intellij-community by JetBrains.
the class TemplateState method dispose.
@Override
public synchronized void dispose() {
if (myLookupListener != null) {
final LookupImpl lookup = myEditor != null ? (LookupImpl) LookupManager.getActiveLookup(myEditor) : null;
if (lookup != null) {
lookup.removeLookupListener(myLookupListener);
}
myLookupListener = null;
}
myEditorDocumentListener = null;
myCommandListener = null;
myCaretListener = null;
myProcessor = null;
//Avoid the leak of the editor
releaseAll();
myDocument = null;
}
Aggregations