com.intellij.codeInsight.lookup.LookupManager Java Examples
The following examples show how to use
com.intellij.codeInsight.lookup.LookupManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EscapeHandler.java From consulo with Apache License 2.0 | 6 votes |
@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); } }
Example #2
Source File: DocumentationManager.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public PsiElement getElementFromLookup(Editor editor, @Nullable PsiFile file) { Lookup activeLookup = LookupManager.getInstance(myProject).getActiveLookup(); if (activeLookup != null) { LookupElement item = activeLookup.getCurrentItem(); if (item != null) { int offset = editor.getCaretModel().getOffset(); if (offset > 0 && offset == editor.getDocument().getTextLength()) offset--; PsiReference ref = TargetElementUtil.findReference(editor, offset); PsiElement contextElement = file == null ? null : ObjectUtils.coalesce(file.findElementAt(offset), file); PsiElement targetElement = ref != null ? ref.getElement() : contextElement; if (targetElement != null) { PsiUtilCore.ensureValid(targetElement); } DocumentationProvider documentationProvider = getProviderFromElement(file); PsiManager psiManager = PsiManager.getInstance(myProject); PsiElement fromProvider = targetElement == null ? null : documentationProvider.getDocumentationElementForLookupItem(psiManager, item.getObject(), targetElement); return fromProvider != null ? fromProvider : CompletionUtil.getTargetElement(item); } } return null; }
Example #3
Source File: LookupDocumentSavingVetoer.java From consulo with Apache License 2.0 | 6 votes |
@Override public boolean maySaveDocument(@Nonnull Document document, boolean isSaveExplicit) { if (ApplicationManager.getApplication().isDisposed() || isSaveExplicit) { return true; } for (Project project : ProjectManager.getInstance().getOpenProjects()) { if (!project.isInitialized() || project.isDisposed()) { continue; } LookupEx lookup = LookupManager.getInstance(project).getActiveLookup(); if (lookup != null) { Editor editor = InjectedLanguageUtil.getTopLevelEditor(lookup.getEditor()); if (editor.getDocument() == document) { return false; } } } return true; }
Example #4
Source File: ShowQuickDocInfoAction.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Override public void actionPerformed(@Nonnull AnActionEvent e) { final Project project = e.getData(CommonDataKeys.PROJECT); final Editor editor = e.getData(CommonDataKeys.EDITOR); final PsiElement element = e.getData(CommonDataKeys.PSI_ELEMENT); if (project != null && editor != null) { FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_FEATURE); final LookupImpl lookup = (LookupImpl)LookupManager.getInstance(project).getActiveLookup(); if (lookup != null) { //dumpLookupElementWeights(lookup); FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_LOOKUP_FEATURE); } actionPerformedImpl(project, editor); } else if (project != null && element != null) { FeatureUsageTracker.getInstance().triggerFeatureUsed(CODEASSISTS_QUICKJAVADOC_CTRLN_FEATURE); CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { DocumentationManager.getInstance(project).showJavaDocInfo(element, null); } }, getCommandName(), null); } }
Example #5
Source File: ShowQuickDocInfoAction.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override protected CodeInsightActionHandler getHandler() { return new CodeInsightActionHandler() { @RequiredUIAccess @Override public void invoke(@Nonnull Project project, @Nonnull Editor editor, @Nonnull PsiFile file) { DocumentationManager.getInstance(project).showJavaDocInfo(editor, file, LookupManager.getActiveLookup(editor) == null); } @Override public boolean startInWriteAction() { return false; } }; }
Example #6
Source File: BaseCodeInsightAction.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Override public void update(AnActionEvent event) { Presentation presentation = event.getPresentation(); DataContext dataContext = event.getDataContext(); Project project = dataContext.getData(CommonDataKeys.PROJECT); if (project == null){ presentation.setEnabled(false); return; } final Lookup activeLookup = LookupManager.getInstance(project).getActiveLookup(); if (activeLookup != null){ presentation.setEnabled(isValidForLookup()); } else { super.update(event); } }
Example #7
Source File: CompletionAutoPopupHandler.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public Result checkAutoPopup(char charTyped, @Nonnull final Project project, @Nonnull final Editor editor, @Nonnull final PsiFile file) { LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (LOG.isDebugEnabled()) { LOG.debug("checkAutoPopup: character=" + charTyped + ";"); LOG.debug("phase=" + CompletionServiceImpl.getCompletionPhase()); LOG.debug("lookup=" + lookup); LOG.debug("currentCompletion=" + CompletionServiceImpl.getCompletionService().getCurrentCompletion()); } if (lookup != null) { if (editor.getSelectionModel().hasSelection()) { lookup.performGuardedChange(() -> EditorModificationUtil.deleteSelectedText(editor)); } return Result.STOP; } if (Character.isLetterOrDigit(charTyped) || charTyped == '_') { AutoPopupController.getInstance(project).scheduleAutoPopup(editor); return Result.STOP; } return Result.CONTINUE; }
Example #8
Source File: BackspaceHandler.java From consulo with Apache License 2.0 | 6 votes |
@Override public void doExecute(@Nonnull final Editor editor, Caret caret, final DataContext dataContext) { LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup == null) { myOriginalHandler.execute(editor, caret, dataContext); return; } int hideOffset = lookup.getLookupStart(); int originalStart = lookup.getLookupOriginalStart(); if (originalStart >= 0 && originalStart <= hideOffset) { hideOffset = originalStart - 1; } truncatePrefix(dataContext, lookup, myOriginalHandler, hideOffset, caret); }
Example #9
Source File: InplaceRefactoring.java From consulo with Apache License 2.0 | 6 votes |
private void restoreOldCaretPositionAndSelection(final int offset) { //move to old offset Runnable runnable = new Runnable() { @Override public void run() { myEditor.getCaretModel().moveToOffset(restoreCaretOffset(offset)); restoreSelection(); } }; final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myEditor); if (lookup != null && lookup.getLookupStart() <= (restoreCaretOffset(offset))) { lookup.setFocusDegree(LookupImpl.FocusDegree.UNFOCUSED); lookup.performGuardedChange(runnable); } else { runnable.run(); } }
Example #10
Source File: VariableInplaceRenameHandler.java From consulo with Apache License 2.0 | 6 votes |
@Override public void invoke(@Nonnull final Project project, final Editor editor, final PsiFile file, final DataContext dataContext) { PsiElement element = PsiElementRenameHandler.getElement(dataContext); if (element == null) { if (LookupManager.getActiveLookup(editor) != null) { final PsiElement elementUnderCaret = file.findElementAt(editor.getCaretModel().getOffset()); if (elementUnderCaret != null) { final PsiElement parent = elementUnderCaret.getParent(); if (parent instanceof PsiReference) { element = ((PsiReference)parent).resolve(); } else { element = PsiTreeUtil.getParentOfType(elementUnderCaret, PsiNamedElement.class); } } if (element == null) return; } else { return; } } editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); if (checkAvailable(element, editor, dataContext)) { doRename(element, editor, dataContext); } }
Example #11
Source File: PopupChoiceAction.java From StringManipulation with Apache License 2.0 | 6 votes |
@Override public void update(AnActionEvent e) { super.update(e); Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext()); if (editor == null) { e.getPresentation().setEnabled(false); return; } Project project = getEventProject(e); if (project != null) { InputEvent inputEvent = e.getInputEvent(); boolean onlyAltDown = false; if (inputEvent != null) { onlyAltDown = inputEvent.isAltDown() && !inputEvent.isShiftDown() && !inputEvent.isMetaDown() && !inputEvent.isControlDown(); } LookupEx activeLookup = LookupManager.getInstance(project).getActiveLookup(); boolean dialogOpen = isFromDialog(project); boolean popupCheck = activeLookup == null || (activeLookup != null && !onlyAltDown); boolean dialogCheck = !dialogOpen || (dialogOpen && !onlyAltDown); e.getPresentation().setEnabled((popupCheck && dialogCheck)); } }
Example #12
Source File: BuildCompletionAutoPopupHandler.java From intellij with Apache License 2.0 | 6 votes |
@Override public Result checkAutoPopup( char charTyped, final Project project, final Editor editor, final PsiFile file) { if (!(file instanceof BuildFile)) { return Result.CONTINUE; } if (LookupManager.getActiveLookup(editor) != null) { return Result.CONTINUE; } if (charTyped != '/' && charTyped != ':') { return Result.CONTINUE; } PsiElement psi = file.findElementAt(editor.getCaretModel().getOffset()); if (psi != null && psi.getParent() instanceof StringLiteral) { AutoPopupController.getInstance(project).scheduleAutoPopup(editor); return Result.STOP; } return Result.CONTINUE; }
Example #13
Source File: EscapeHandler.java From consulo with Apache License 2.0 | 6 votes |
@Override public void execute(Editor editor, DataContext dataContext) { final SelectionModel selectionModel = editor.getSelectionModel(); if (selectionModel.hasSelection()) { final TemplateState state = TemplateManagerImpl.getTemplateState(editor); if (state != null && editor.getUserData(InplaceRefactoring.INPLACE_RENAMER) != null) { final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup != null) { selectionModel.removeSelection(); lookup.hide(); return; } } } myOriginalHandler.execute(editor, dataContext); }
Example #14
Source File: EndHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public void doExecute(Editor editor, Caret caret, DataContext dataContext){ LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup == null || !lookup.isFocused()) { myOriginalHandler.execute(editor, caret, dataContext); return; } lookup.markSelectionTouched(); ScrollingUtil.moveEnd(lookup.getList()); lookup.refreshUi(false, true); }
Example #15
Source File: ChooseItemAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isEnabled(Editor editor, DataContext dataContext) { LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup == null) return false; if (!lookup.isAvailableToUser()) return false; if (focusedOnly && lookup.getFocusDegree() == LookupImpl.FocusDegree.UNFOCUSED) return false; if (finishingChar == Lookup.REPLACE_SELECT_CHAR) { return !lookup.getItems().isEmpty(); } return true; }
Example #16
Source File: ChooseItemAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public void execute(@Nonnull final Editor editor, final DataContext dataContext) { final LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup == null) { throw new AssertionError("The last lookup disposed at: " + LookupImpl.getLastLookupDisposeTrace() + "\n-----------------------\n"); } if ((finishingChar == Lookup.NORMAL_SELECT_CHAR || finishingChar == Lookup.REPLACE_SELECT_CHAR) && hasTemplatePrefix(lookup, finishingChar)) { lookup.hideLookup(true); ExpandLiveTemplateCustomAction.createExpandTemplateHandler(finishingChar).execute(editor, null, dataContext); return; } if (finishingChar == Lookup.NORMAL_SELECT_CHAR) { if (!lookup.isFocused()) { FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_CONTROL_ENTER); } } else if (finishingChar == Lookup.COMPLETE_STATEMENT_SELECT_CHAR) { FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_SMART_ENTER); } else if (finishingChar == Lookup.REPLACE_SELECT_CHAR) { FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_REPLACE); } else if (finishingChar == '.') { FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_FINISH_BY_CONTROL_DOT); } lookup.finishLookup(finishingChar); }
Example #17
Source File: HomeHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public void doExecute(Editor editor, Caret caret, DataContext dataContext){ LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup == null || !lookup.isFocused()) { myOriginalHandler.execute(editor, caret, dataContext); return; } lookup.markSelectionTouched(); ScrollingUtil.moveHome(lookup.getList()); }
Example #18
Source File: FlowRenameDialog.java From mule-intellij-plugins with Apache License 2.0 | 5 votes |
private void completeVariable(Editor editor) { String prefix = this.myNameSuggestionsField.getEnteredName(); PsiReference reference = this.myTag.getReference(); if(reference instanceof TagNameReference) { LookupElement[] lookupItems = TagNameReferenceCompletionProvider.getTagNameVariants(this.myTag, this.myTag.getNamespacePrefix()); editor.getCaretModel().moveToOffset(prefix.length()); editor.getSelectionModel().removeSelection(); LookupManager.getInstance(this.getProject()).showLookup(editor, lookupItems, prefix); } }
Example #19
Source File: ShowIntentionActionsHandler.java From consulo with Apache License 2.0 | 5 votes |
public void invoke(@Nonnull final Project project, @Nonnull Editor editor, @Nonnull PsiFile file, boolean showFeedbackOnEmptyMenu) { PsiDocumentManager.getInstance(project).commitAllDocuments(); if (editor instanceof EditorWindow) { editor = ((EditorWindow)editor).getDelegate(); file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file); } final LookupEx lookup = LookupManager.getActiveLookup(editor); if (lookup != null) { lookup.showElementActions(null); return; } final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project); letAutoImportComplete(editor, file, codeAnalyzer); ShowIntentionsPass.IntentionsInfo intentions = ShowIntentionsPass.getActionsToShow(editor, file, true); IntentionsUI.getInstance(project).hide(); if (HintManagerImpl.getInstanceImpl().performCurrentQuestionAction()) return; //intentions check isWritable before modification: if (!file.isWritable()) return; TemplateState state = TemplateManagerImpl.getTemplateState(editor); if (state != null && !state.isFinished()) { return; } editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); Editor finalEditor = editor; PsiFile finalFile = file; showIntentionHint(project, finalEditor, finalFile, intentions, showFeedbackOnEmptyMenu); }
Example #20
Source File: LangIndentSelectionAction.java From consulo with Apache License 2.0 | 5 votes |
@Override protected boolean isEnabled(Editor editor, DataContext dataContext) { if (!originalIsEnabled(editor, wantSelection())) return false; if (LookupManager.getActiveLookup(editor) != null) return false; PsiFile psiFile = dataContext.getData(CommonDataKeys.PSI_FILE); if (psiFile != null && NextPrevParameterAction.hasSutablePolicy(editor, psiFile)) return false; return true; }
Example #21
Source File: ConsoleHistoryController.java From consulo with Apache License 2.0 | 5 votes |
private boolean canMoveInEditor(final boolean next) { final Editor consoleEditor = myConsole.getCurrentEditor(); final Document document = consoleEditor.getDocument(); final CaretModel caretModel = consoleEditor.getCaretModel(); if (LookupManager.getActiveLookup(consoleEditor) != null) return false; if (next) { return document.getLineNumber(caretModel.getOffset()) == 0; } else { final int lineCount = document.getLineCount(); return (lineCount == 0 || document.getLineNumber(caretModel.getOffset()) == lineCount - 1) && StringUtil.isEmptyOrSpaces(document.getText().substring(caretModel.getOffset())); } }
Example #22
Source File: ConsoleExecuteAction.java From consulo with Apache License 2.0 | 5 votes |
@Override public final void update(@Nonnull AnActionEvent e) { EditorEx editor = myConsoleView.getConsoleEditor(); boolean enabled = !editor.isRendererMode() && isEnabled() && (myExecuteActionHandler.isEmptyCommandExecutionAllowed() || !StringUtil.isEmptyOrSpaces(editor.getDocument().getCharsSequence())); if (enabled) { Lookup lookup = LookupManager.getActiveLookup(editor); // we should check getCurrentItem() also - fast typing could produce outdated lookup, such lookup reports isCompletion() true enabled = lookup == null || !lookup.isCompletion() || lookup.getCurrentItem() == null || (lookup instanceof LookupImpl && ((LookupImpl)lookup).getFocusDegree() == LookupImpl.FocusDegree.UNFOCUSED); } e.getPresentation().setEnabled(enabled); }
Example #23
Source File: PopupPositionManager.java From consulo with Apache License 2.0 | 5 votes |
public static void positionPopupInBestPosition(final JBPopup hint, @Nullable final Editor editor, @Nullable DataContext dataContext, @Nonnull Position... relationToExistingPopup) { final LookupEx lookup = LookupManager.getActiveLookup(editor); if (lookup != null && lookup.getCurrentItem() != null && lookup.getComponent().isShowing()) { new PositionAdjuster(lookup.getComponent()).adjust(hint, relationToExistingPopup); lookup.addLookupListener(new LookupListener() { @Override public void lookupCanceled(@Nonnull LookupEvent event) { if (hint.isVisible()) { hint.cancel(); } } }); return; } final PositionAdjuster positionAdjuster = createPositionAdjuster(hint); if (positionAdjuster != null) { positionAdjuster.adjust(hint, relationToExistingPopup); return; } if (editor != null && editor.getComponent().isShowing() && editor instanceof EditorEx) { dataContext = ((EditorEx)editor).getDataContext(); } if (dataContext != null) { if (hint.canShow()) { hint.showInBestPositionFor(dataContext); } else { hint.setLocation(hint.getBestPositionFor(dataContext)); } } }
Example #24
Source File: DumpLookupElementWeights.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void update(@Nonnull final AnActionEvent e) { final Presentation presentation = e.getPresentation(); final Editor editor = e.getData(CommonDataKeys.EDITOR); presentation.setEnabled(editor != null && LookupManager.getActiveLookup(editor) != null); }
Example #25
Source File: UpDownHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public void update(AnActionEvent e) { final LookupEx lookup; if (myInput instanceof EditorTextField) { lookup = LookupManager.getActiveLookup(((EditorTextField)myInput).getEditor()); } else if (myInput instanceof EditorComponentImpl) { lookup = LookupManager.getActiveLookup(((EditorComponentImpl)myInput).getEditor()); } else { lookup = null; } e.getPresentation().setEnabled(lookup == null); }
Example #26
Source File: MemberInplaceRenameHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override protected boolean isAvailable(PsiElement element, Editor editor, PsiFile file) { final PsiElement nameSuggestionContext = file.findElementAt(editor.getCaretModel().getOffset()); if (element == null && LookupManager.getActiveLookup(editor) != null) { element = PsiTreeUtil.getParentOfType(nameSuggestionContext, PsiNamedElement.class); } final RefactoringSupportProvider supportProvider = element != null ? LanguageRefactoringSupport.INSTANCE.forLanguage(element.getLanguage()) : null; return editor.getSettings().isVariableInplaceRenameEnabled() && supportProvider != null && supportProvider.isMemberInplaceRenameAvailable(element, nameSuggestionContext); }
Example #27
Source File: DesktopPsiAwareTextEditorImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public Object getData(@Nonnull final Key<?> dataId) { if (PlatformDataKeys.DOMINANT_HINT_AREA_RECTANGLE == dataId) { final LookupImpl lookup = (LookupImpl)LookupManager.getInstance(myProject).getActiveLookup(); if (lookup != null && lookup.isVisible()) { return lookup.getBounds(); } } if (LangDataKeys.MODULE == dataId) { return ModuleUtilCore.findModuleForFile(myFile, myProject); } return super.getData(dataId); }
Example #28
Source File: Replacer.java From translator with MIT License | 5 votes |
@Override protected void action(String text, String translatedText) { if(editor != null && editor.getProject() != null){ LookupManager lookupManager = LookupManager.getInstance(editor.getProject()); ApplicationManager.getApplication().invokeLater(() -> lookupManager.showLookup(editor, getProposeList(translatedText))); } }
Example #29
Source File: LookupActionHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public void doExecute(@Nonnull Editor editor, Caret caret, DataContext dataContext) { LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); if (lookup == null || !lookup.isAvailableToUser()) { Project project = editor.getProject(); if (project != null && lookup != null) { LookupManager.getInstance(project).hideActiveLookup(); } myOriginalHandler.execute(editor, caret, dataContext); return; } lookup.markSelectionTouched(); executeInLookup(lookup, dataContext, caret); }
Example #30
Source File: SwaggerFixture.java From intellij-swagger with MIT License | 5 votes |
public void complete(@NotNull final String testFileNoExt, @NotNull final Format fileKind) { myCodeInsightFixture.configureByFile(fileKind.getFileNameWithExtension(testFileNoExt)); myCodeInsightFixture.complete(CompletionType.BASIC, 2); if (LookupManager.getActiveLookup(myCodeInsightFixture.getEditor()) != null) { myCodeInsightFixture.type('\n'); } }