Search in sources :

Example 1 with ChooseTargetItem

use of com.facebook.buck.intellij.ideabuck.actions.choosetargets.ChooseTargetItem 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");
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) Project(com.intellij.openapi.project.Project) ChooseTargetModel(com.facebook.buck.intellij.ideabuck.actions.choosetargets.ChooseTargetModel) KeyAdapter(java.awt.event.KeyAdapter) ChooseByNamePopup(com.intellij.ide.util.gotoByName.ChooseByNamePopup) BuckSettingsProvider(com.facebook.buck.intellij.ideabuck.config.BuckSettingsProvider) ChooseTargetItem(com.facebook.buck.intellij.ideabuck.actions.choosetargets.ChooseTargetItem)

Aggregations

ChooseTargetItem (com.facebook.buck.intellij.ideabuck.actions.choosetargets.ChooseTargetItem)1 ChooseTargetModel (com.facebook.buck.intellij.ideabuck.actions.choosetargets.ChooseTargetModel)1 BuckSettingsProvider (com.facebook.buck.intellij.ideabuck.config.BuckSettingsProvider)1 ChooseByNamePopup (com.intellij.ide.util.gotoByName.ChooseByNamePopup)1 Project (com.intellij.openapi.project.Project)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1