Quick Fix choose Element

Hallo,
In this tutorial http://confluence.jetbrains.com/display/IntelliJIDEA/Quick+Fix it's shown how to fix an error by appending a new PSIElement to a VirtualFile. Therefore a filechooser is provided to select the file the new element should be appended. Instead of a file chooser I'm looking for an "PSIElementChooser", I thought about something like this:


PSIElementDesctiptor descripter = new PSIElementDesctiptor(MyTypes.MY_PSI_TYPE);
PSIElementChooser.choose(descriptor, project);


I thougt that must be a common use case, however I was not able to find anything, except the TreeClassChooserFactory that seems to work with compiled classes.
thanks for any help,
Sebastian

4 comments
Comment actions Permalink

This is not a common use case at all. Giving the user a choice of all PSI elements of a certain type would be unmanageable in any realistically sized project. You need to decide exactly what UI makes sense for choosing the element in your particular use case, and implement it yourself.

0
Comment actions Permalink

I see. For example a ChooseByName-Contributor registered via <gotoSymbolContributor/>-extension point offers exactly the UI I would need, including smart completion and a nice look. Instead of navigating to the selected symbol I would need the PSIElement. Does Idea offer a solution to use for a quick fix in a BaseIntentionAction?  

0
Comment actions Permalink

If you already have a goto symbol contibutor implemented and registered, you can use the ChooseByNamePanel class to embed the goto symbol UI in a dialog.

0
Comment actions Permalink

Thank you very much. The ChooseByNamePanel led me to the ChooseByNameFactory. I now used the following to retrieve the searched PsiElement:

  ChooseByNamePopupComponent chooseByNamePopupComponent = ChooseByNameFactory.getInstance(project).createChooseByNamePopupComponent(new GotoSymbolModel2(project));         chooseByNamePopupComponent.invoke(new ChooseByNamePopupComponent.Callback() {             @Override             public void elementChosen(Object element) {                // got it             }                      }, ModalityState.current(), false);

0

Please sign in to leave a comment.