mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Live Templates: allow to disable template expanding by shortcut (IDEA-174833)
This commit is contained in:
+4
-3
@@ -66,15 +66,16 @@ abstract public class LiveTemplateLookupElement extends LookupElement {
|
||||
if (shortcut == TemplateSettings.DEFAULT_CHAR) {
|
||||
shortcut = TemplateSettings.getInstance().getDefaultShortcutChar();
|
||||
}
|
||||
if (shortcut != TemplateSettings.CUSTOM_CHAR) {
|
||||
presentation.setTypeText(" [" + KeyEvent.getKeyText(shortcut) + "] ");
|
||||
} else {
|
||||
if (shortcut == TemplateSettings.CUSTOM_CHAR) {
|
||||
String shortcutText =
|
||||
KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_EXPAND_LIVE_TEMPLATE_CUSTOM));
|
||||
if (StringUtil.isNotEmpty(shortcutText)) {
|
||||
presentation.setTypeText(" [" + shortcutText + "] ");
|
||||
}
|
||||
}
|
||||
else if (shortcut != TemplateSettings.NONE_CHAR) {
|
||||
presentation.setTypeText(" [" + KeyEvent.getKeyText(shortcut) + "] ");
|
||||
}
|
||||
}
|
||||
if (StringUtil.isNotEmpty(myDescription)) {
|
||||
presentation.setTailText(" (" + myDescription + ")", true);
|
||||
|
||||
+10
-3
@@ -80,6 +80,7 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
private static final String SPACE = CodeInsightBundle.message("template.shortcut.space");
|
||||
private static final String TAB = CodeInsightBundle.message("template.shortcut.tab");
|
||||
private static final String ENTER = CodeInsightBundle.message("template.shortcut.enter");
|
||||
private static final String NONE = CodeInsightBundle.message("template.shortcut.none");
|
||||
private final Map<TemplateOptionalProcessor, Boolean> myOptions;
|
||||
private final TemplateContext myContext;
|
||||
private JBPopup myContextPopup;
|
||||
@@ -241,7 +242,7 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
|
||||
gbConstraints.gridx = 1;
|
||||
gbConstraints.insets = JBUI.insetsLeft(4);
|
||||
myExpandByCombo = new ComboBox<>(new String[]{myDefaultShortcutItem, SPACE, TAB, ENTER});
|
||||
myExpandByCombo = new ComboBox<>(new String[]{myDefaultShortcutItem, SPACE, TAB, ENTER, NONE});
|
||||
myExpandByCombo.addItemListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(@NotNull ItemEvent e) {
|
||||
@@ -255,9 +256,12 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
else if(ENTER.equals(selectedItem)) {
|
||||
myTemplate.setShortcutChar(TemplateSettings.ENTER_CHAR);
|
||||
}
|
||||
else {
|
||||
else if (SPACE.equals(selectedItem)) {
|
||||
myTemplate.setShortcutChar(TemplateSettings.SPACE_CHAR);
|
||||
}
|
||||
else {
|
||||
myTemplate.setShortcutChar(TemplateSettings.NONE_CHAR);
|
||||
}
|
||||
}
|
||||
});
|
||||
expandWithLabel.setLabelFor(myExpandByCombo);
|
||||
@@ -503,9 +507,12 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
else if(myTemplate.getShortcutChar() == TemplateSettings.ENTER_CHAR) {
|
||||
myExpandByCombo.setSelectedItem(ENTER);
|
||||
}
|
||||
else {
|
||||
else if (myTemplate.getShortcutChar() == TemplateSettings.SPACE_CHAR) {
|
||||
myExpandByCombo.setSelectedItem(SPACE);
|
||||
}
|
||||
else {
|
||||
myExpandByCombo.setSelectedItem(TemplateSettings.NONE_CHAR);
|
||||
}
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
null, () -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
|
||||
@@ -69,11 +69,13 @@ public class TemplateSettings implements PersistentStateComponent<TemplateSettin
|
||||
public static final char ENTER_CHAR = '\n';
|
||||
public static final char DEFAULT_CHAR = 'D';
|
||||
public static final char CUSTOM_CHAR = 'C';
|
||||
public static final char NONE_CHAR = 'N';
|
||||
|
||||
@NonNls private static final String SPACE = "SPACE";
|
||||
@NonNls private static final String TAB = "TAB";
|
||||
@NonNls private static final String ENTER = "ENTER";
|
||||
@NonNls private static final String CUSTOM = "CUSTOM";
|
||||
@NonNls private static final String NONE = "NONE";
|
||||
|
||||
@NonNls private static final String NAME = "name";
|
||||
@NonNls private static final String VALUE = "value";
|
||||
@@ -115,6 +117,7 @@ public class TemplateSettings implements PersistentStateComponent<TemplateSettin
|
||||
return TAB.equals(shortcut) ? TAB_CHAR :
|
||||
ENTER.equals(shortcut) ? ENTER_CHAR :
|
||||
CUSTOM.equals(shortcut) ? CUSTOM_CHAR :
|
||||
NONE.equals(shortcut) ? NONE_CHAR :
|
||||
SPACE_CHAR;
|
||||
}
|
||||
|
||||
@@ -124,6 +127,7 @@ public class TemplateSettings implements PersistentStateComponent<TemplateSettin
|
||||
return shortcut == TAB_CHAR ? TAB :
|
||||
shortcut == ENTER_CHAR ? ENTER :
|
||||
shortcut == CUSTOM_CHAR ? CUSTOM :
|
||||
shortcut == NONE_CHAR ? NONE :
|
||||
SPACE;
|
||||
}
|
||||
}
|
||||
@@ -446,6 +450,9 @@ public class TemplateSettings implements PersistentStateComponent<TemplateSettin
|
||||
else if (SPACE.equals(shortcut)) {
|
||||
template.setShortcutChar(SPACE_CHAR);
|
||||
}
|
||||
else if (NONE.equals(shortcut)) {
|
||||
template.setShortcutChar(NONE_CHAR);
|
||||
}
|
||||
else {
|
||||
template.setShortcutChar(DEFAULT_CHAR);
|
||||
}
|
||||
@@ -621,6 +628,9 @@ public class TemplateSettings implements PersistentStateComponent<TemplateSettin
|
||||
else if (template.getShortcutChar() == SPACE_CHAR) {
|
||||
element.setAttribute(SHORTCUT, SPACE);
|
||||
}
|
||||
else if (template.getShortcutChar() == NONE_CHAR) {
|
||||
element.setAttribute(SHORTCUT, NONE);
|
||||
}
|
||||
if (template.getDescription() != null) {
|
||||
element.setAttribute(DESCRIPTION, template.getDescription());
|
||||
}
|
||||
|
||||
@@ -322,6 +322,7 @@ template.shortcut.enter=Enter
|
||||
template.shortcut.tab=Tab
|
||||
template.shortcut.space=Space
|
||||
template.shortcut.custom=Custom
|
||||
template.shortcut.none=None
|
||||
dialog.edit.live.template.title=Edit Live Template
|
||||
dialog.add.live.template.title=Add Live Template
|
||||
templates.no.defined=No templates defined in this context
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<templateSet group="surround">
|
||||
|
||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.surround.braces"
|
||||
name="B" toReformat="true" toShortenFQNames="true" value="{$SELECTION$}">
|
||||
name="B" toReformat="true" toShortenFQNames="true" value="{$SELECTION$}" shortcut="NONE">
|
||||
<context>
|
||||
<option name="JAVA_CODE" value="false" />
|
||||
<option name="JAVA_COMMENT" value="false" />
|
||||
@@ -18,7 +18,7 @@
|
||||
</template>
|
||||
|
||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.surround.parens"
|
||||
name="P" toReformat="false" toShortenFQNames="true" value="($SELECTION$)">
|
||||
name="P" toReformat="false" toShortenFQNames="true" value="($SELECTION$)" shortcut="NONE">
|
||||
<context>
|
||||
<option name="JAVA_CODE" value="false" />
|
||||
<option name="JAVA_COMMENT" value="false" />
|
||||
|
||||
Reference in New Issue
Block a user