Search in sources :

Example 1 with TextWithMnemonic

use of com.intellij.openapi.util.text.TextWithMnemonic in project consulo by consulo.

the class CheckboxAction method createCustomComponent.

@Nonnull
@Override
public JComponent createCustomComponent(Presentation presentation, @Nonnull String place) {
    // this component cannot be stored right here because of action system architecture:
    // one action can be shown on multiple toolbars simultaneously
    TextWithMnemonic textWithMnemonic = TextWithMnemonic.parse(presentation.getTextValue().getValue());
    JCheckBox checkBox = new JCheckBox(textWithMnemonic.getText());
    checkBox.setOpaque(false);
    checkBox.setToolTipText(presentation.getDescription());
    checkBox.setMnemonic(textWithMnemonic.getMnemonic());
    checkBox.setDisplayedMnemonicIndex(textWithMnemonic.getMnemonicIndex());
    checkBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JCheckBox checkBox = (JCheckBox) e.getSource();
            ActionToolbar actionToolbar = UIUtil.getParentOfType(ActionToolbar.class, checkBox);
            DataContext dataContext = actionToolbar != null ? actionToolbar.getToolbarDataContext() : DataManager.getInstance().getDataContext(checkBox);
            CheckboxAction.this.actionPerformed(new AnActionEvent(null, dataContext, ActionPlaces.UNKNOWN, CheckboxAction.this.getTemplatePresentation(), ActionManager.getInstance(), 0));
        }
    });
    return checkBox;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) TextWithMnemonic(com.intellij.openapi.util.text.TextWithMnemonic) Nonnull(javax.annotation.Nonnull)

Example 2 with TextWithMnemonic

use of com.intellij.openapi.util.text.TextWithMnemonic in project consulo by consulo.

the class ActionMenuItem method updateTextAndMnemonic.

private void updateTextAndMnemonic(@Nullable LocalizeValue textValue) {
    // first initialization
    if (myTextValue == null) {
        return;
    }
    if (textValue != null) {
        myTextValue = textValue;
    }
    String value = myTextValue.getValue();
    TextWithMnemonic textWithMnemonic = TextWithMnemonic.parse(value);
    setText(textWithMnemonic.getText());
    setDisplayedMnemonicIndex(myEnableMnemonics ? textWithMnemonic.getMnemonicIndex() : -1);
    setMnemonic(myEnableMnemonics ? textWithMnemonic.getMnemonic() : 0);
}
Also used : TextWithMnemonic(com.intellij.openapi.util.text.TextWithMnemonic)

Example 3 with TextWithMnemonic

use of com.intellij.openapi.util.text.TextWithMnemonic in project consulo by consulo.

the class ActionButton method updateTextAndMnemonic.

protected void updateTextAndMnemonic(@Nonnull LocalizeValue localizeValue) {
    boolean disabledMnemonic = myPresentation.isDisabledMnemonic();
    if (disabledMnemonic) {
        myLastComputedText = localizeValue.getValue();
        setDisplayedMnemonicIndex(-1);
    } else {
        TextWithMnemonic textWithMnemonic = TextWithMnemonic.parse(localizeValue.getValue());
        myLastComputedText = textWithMnemonic.getText();
        setDisplayedMnemonicIndex(textWithMnemonic.getMnemonicIndex());
    }
}
Also used : TextWithMnemonic(com.intellij.openapi.util.text.TextWithMnemonic)

Example 4 with TextWithMnemonic

use of com.intellij.openapi.util.text.TextWithMnemonic in project consulo by consulo.

the class ActionMenu method updateTextAndMnemonic.

private void updateTextAndMnemonic(@Nullable LocalizeValue newTextValue, boolean disableMnemonic) {
    myPresentationMnemonicDisabled = disableMnemonic;
    // first initialization
    if (myTextValue == null) {
        return;
    }
    if (newTextValue != null) {
        myTextValue = newTextValue;
    }
    String value = myTextValue.getValue();
    TextWithMnemonic textWithMnemonic = TextWithMnemonic.parse(value);
    setText(textWithMnemonic.getText());
    setDisplayedMnemonicIndex(textWithMnemonic.getMnemonicIndex());
    myMnemonicUpdate = true;
    try {
        setMnemonic(textWithMnemonic.getMnemonic());
    } finally {
        myMnemonicUpdate = false;
    }
}
Also used : TextWithMnemonic(com.intellij.openapi.util.text.TextWithMnemonic)

Aggregations

TextWithMnemonic (com.intellij.openapi.util.text.TextWithMnemonic)4 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Nonnull (javax.annotation.Nonnull)1