protected GradleEditTaskDialog(@Nullable Project project) { super(project); setTitle("Select Gradle Task"); setModal(true); TextFieldWithAutoCompletionListProvider<String> provider = new TextFieldWithAutoCompletion.StringsCompletionProvider(null, null) { @NotNull @Override public Collection<String> getItems(String prefix, boolean cached, CompletionParameters parameters) { setItems(myAvailableTasks); return super.getItems(prefix, cached, parameters); } }; myTaskField = new TextFieldWithAutoCompletion<String>(project, provider, true, null); myTaskPanel.add(myTaskField); init(); }
@NotNull private static TextFieldWithAutoCompletionListProvider<String> getCompletionProvider(@NotNull final List<String> targetVariants) { return new StringsCompletionProvider(targetVariants, null) { @Override public int compare(String item1, String item2) { return Integer.valueOf(ContainerUtil.indexOf(targetVariants, item1)).compareTo(ContainerUtil.indexOf(targetVariants, item2)); } }; }
@Override public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) { PsiFile file = parameters.getOriginalFile(); Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); if (document != null) { DataContext dataContext = document.getUserData(CommitMessage.DATA_CONTEXT_KEY); if (dataContext != null) { result.stopHere(); if (parameters.getInvocationCount() > 0) { ChangeList[] lists = VcsDataKeys.CHANGE_LISTS.getData(dataContext); if (lists != null) { String prefix = TextFieldWithAutoCompletionListProvider.getCompletionPrefix(parameters); CompletionResultSet insensitive = result.caseInsensitive().withPrefixMatcher(new CamelHumpMatcher(prefix)); for (ChangeList list : lists) { for (Change change : list.getChanges()) { ContentRevision revision = change.getAfterRevision() == null ? change.getBeforeRevision() : change.getAfterRevision(); if (revision != null) { FilePath filePath = revision.getFile(); LookupElementBuilder element = LookupElementBuilder.create(filePath.getName()). withIcon(filePath.getFileType().getIcon()); insensitive.addElement(element); } } } } } } } }
@Override public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) { PsiFile file = parameters.getOriginalFile(); Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); if (document != null) { DataContext dataContext = document.getUserData(CommitMessage.DATA_CONTEXT_KEY); if (dataContext != null) { result.stopHere(); if (parameters.getInvocationCount() > 0) { ChangeList[] lists = VcsDataKeys.CHANGE_LISTS.getData(dataContext); if (lists != null) { String prefix = TextFieldWithAutoCompletionListProvider.getCompletionPrefix(parameters); CompletionResultSet insensitive = result.caseInsensitive().withPrefixMatcher(new CamelHumpMatcher(prefix)); for (ChangeList list : lists) { for (Change change : list.getChanges()) { ContentRevision revision = change.getAfterRevision() == null ? change.getBeforeRevision() : change.getAfterRevision(); if (revision != null) { FilePath filePath = revision.getFile(); LookupElementBuilder element = LookupElementBuilder.create(filePath.getName()). withIcon(filePath.getFileType().getIcon()); insensitive.addElement(element); } } } } } } } }
@RequiredReadAction @Override public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) { PsiFile file = parameters.getOriginalFile(); Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file); if (document != null) { DataContext dataContext = document.getUserData(CommitMessage.DATA_CONTEXT_KEY); if (dataContext != null) { result.stopHere(); if (parameters.getInvocationCount() > 0) { ChangeList[] lists = dataContext.getData(VcsDataKeys.CHANGE_LISTS); if (lists != null) { String prefix = TextFieldWithAutoCompletionListProvider.getCompletionPrefix(parameters); CompletionResultSet insensitive = result.caseInsensitive().withPrefixMatcher(new CamelHumpMatcher(prefix)); for (ChangeList list : lists) { for (Change change : list.getChanges()) { VirtualFile virtualFile = change.getVirtualFile(); if (virtualFile != null) { LookupElementBuilder element = LookupElementBuilder.create(virtualFile.getName()). withIcon(VirtualFilePresentation.getIcon(virtualFile)); insensitive.addElement(element); } } } } } } } }