same shortcut to enable/disable checkbox

This commit is contained in:
Konstantin Bulenkov
2012-02-14 16:47:26 +01:00
parent acf49c4d4f
commit ee7b952986
2 changed files with 22 additions and 3 deletions
@@ -122,11 +122,11 @@ public abstract class GotoActionBase extends AnAction {
return Pair.create("", 0);
}
protected static <T> void showNavigationPopup(AnActionEvent e, ChooseByNameModel model, final GotoActionCallback<T> callback) {
protected <T> void showNavigationPopup(AnActionEvent e, ChooseByNameModel model, final GotoActionCallback<T> callback) {
showNavigationPopup(e, model, callback, null, true);
}
protected static <T> void showNavigationPopup(AnActionEvent e,
protected <T> void showNavigationPopup(AnActionEvent e,
ChooseByNameModel model,
final GotoActionCallback<T> callback,
@Nullable final String findUsagesTitle,
@@ -138,6 +138,7 @@ public abstract class GotoActionBase extends AnAction {
LOG.assertTrue(startedAction != null);
Pair<String, Integer> start = getInitialText(useSelectionFromEditor ? e.getData(PlatformDataKeys.EDITOR) : null);
final ChooseByNamePopup popup = ChooseByNamePopup.createPopup(project, model, getPsiContext(e), start.first, mayRequestOpenInCurrentWindow, start.second);
popup.setCheckBoxShortcut(getShortcutSet());
popup.setFindUsagesTitle(findUsagesTitle);
final ChooseByNameFilter<T> filter = callback.createFilter(popup);
@@ -139,6 +139,7 @@ public abstract class ChooseByNameBase {
private boolean myClosedByShiftEnter = false;
protected final int myInitialIndex;
private String myFindUsagesTitle;
private ShortcutSet myCheckBoxShortcut;
public boolean checkDisposed() {
if (myDisposedFlag && myPostponedOkAction != null && !myPostponedOkAction.isProcessed()) {
@@ -363,7 +364,9 @@ public abstract class ChooseByNameBase {
myCheckBox.setSelected(myModel.loadInitialCheckBoxState());
if (checkBoxName == null) myCheckBox.setVisible(false);
if (checkBoxName == null) {
myCheckBox.setVisible(false);
}
addCard(myCheckBox, CHECK_BOX_CARD);
@@ -443,6 +446,17 @@ public abstract class ChooseByNameBase {
Font editorFont = new Font(scheme.getEditorFontName(), Font.PLAIN, scheme.getEditorFontSize());
myTextField.setFont(editorFont);
if (checkBoxName != null) {
if (myCheckBox != null) {
new AnAction("change goto check box", null ,null) {
@Override
public void actionPerformed(AnActionEvent e) {
myCheckBox.setSelected(!myCheckBox.isSelected());
}
}.registerCustomShortcutSet(myCheckBoxShortcut, myTextField);
}
}
if (isCloseByFocusLost()) {
myTextField.addFocusListener(new FocusAdapter() {
public void focusLost(final FocusEvent e) {
@@ -596,6 +610,10 @@ public abstract class ChooseByNameBase {
myCardContainer.add(wrapper, cardId);
}
public void setCheckBoxShortcut(ShortcutSet shortcutSet) {
myCheckBoxShortcut = shortcutSet;
}
private static Set<KeyStroke> getShortcuts(@NotNull String actionId) {
Set<KeyStroke> result = new HashSet<KeyStroke>();
Keymap keymap = KeymapManager.getInstance().getActiveKeymap();