use of com.facebook.buck.intellij.ideabuck.actions.choosetargets.ChooseTargetModel in project buck by facebook.
the class ChooseTargetAction method gotoActionPerformed.
@Override
protected void gotoActionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) {
return;
}
final ChooseTargetModel model = new ChooseTargetModel(project);
GotoActionCallback<String> callback = new GotoActionCallback<String>() {
@Override
public void elementChosen(ChooseByNamePopup chooseByNamePopup, Object element) {
if (element == null) {
return;
}
BuckSettingsProvider buckSettingsProvider = BuckSettingsProvider.getInstance();
if (buckSettingsProvider == null || buckSettingsProvider.getState() == null) {
return;
}
ChooseTargetItem item = (ChooseTargetItem) element;
// if the target selected isn't an alias, then it has to have :
if (item.getName().contains("//") && !item.getName().contains(":")) {
return;
}
if (buckSettingsProvider.getState().lastAlias != null) {
buckSettingsProvider.getState().lastAlias.put(project.getBasePath(), item.getBuildTarget());
}
BuckToolWindowFactory.updateBuckToolWindowTitle(project);
}
};
showNavigationPopup(e, model, callback, "Choose Build Target", true, false);
// Add navigation listener for auto complete
final ChooseByNamePopup chooseByNamePopup = project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
chooseByNamePopup.getTextField().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (KeyEvent.VK_RIGHT == e.getKeyCode()) {
ChooseTargetItem obj = (ChooseTargetItem) chooseByNamePopup.getChosenElement();
if (obj != null) {
chooseByNamePopup.getTextField().setText(obj.getName());
chooseByNamePopup.getTextField().repaint();
}
} else {
super.keyPressed(e);
}
String adText = chooseByNamePopup.getAdText();
if (adText != null) {
chooseByNamePopup.setAdText(adText + " and " + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 2)) + " to use autocomplete");
}
}
});
}
Aggregations