mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
TemplateContext.isEnabled should take into account "Other" setting; use isEnabled instead of isExplicitlyEnabled everywhere to avoid hiding enabled contexts (IDEA-157128)
This commit is contained in:
@@ -547,13 +547,13 @@ class Outer {
|
||||
|
||||
assert template.templateContext.getOwnValue(stmtContext)
|
||||
assert !template.templateContext.getOwnValue(stmtContext.baseContextType)
|
||||
template.templateContext.putValue(stmtContext, false)
|
||||
template.templateContext.putValue(stmtContext.baseContextType, true)
|
||||
template.templateContext.setEnabled(stmtContext, false)
|
||||
template.templateContext.setEnabled(stmtContext.baseContextType, true)
|
||||
try {
|
||||
assert !(template in manager.findMatchingTemplates(myFixture.file, editor, Lookup.REPLACE_SELECT_CHAR, TemplateSettings.instance)?.keySet())
|
||||
} finally {
|
||||
template.templateContext.putValue(stmtContext, true)
|
||||
template.templateContext.putValue(stmtContext.baseContextType, false)
|
||||
template.templateContext.setEnabled(stmtContext, true)
|
||||
template.templateContext.setEnabled(stmtContext.baseContextType, false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -576,7 +576,7 @@ class Outer {
|
||||
copy.writeTemplateContext(write)
|
||||
assert write.children.size() == 2 : JDOMUtil.writeElement(write)
|
||||
|
||||
copy.putValue(TemplateContextType.EP_NAME.findExtension(JavaCommentContextType), false)
|
||||
copy.setEnabled(TemplateContextType.EP_NAME.findExtension(JavaCommentContextType), false)
|
||||
|
||||
write = new Element("context")
|
||||
copy.writeTemplateContext(write)
|
||||
@@ -589,13 +589,34 @@ class Outer {
|
||||
|
||||
def defContext = new TemplateContext()
|
||||
def commentContext = TemplateContextType.EP_NAME.findExtension(JavaCommentContextType)
|
||||
defContext.putValue(commentContext, true)
|
||||
defContext.setEnabled(commentContext, true)
|
||||
|
||||
context.setDefaultContext(defContext)
|
||||
assert context.isEnabled(commentContext)
|
||||
assert !context.isEnabled(TemplateContextType.EP_NAME.findExtension(JavaCodeContextType.Generic))
|
||||
}
|
||||
|
||||
public void "test adding new context to Other"() {
|
||||
def defElement = JDOMUtil.loadDocument('''\
|
||||
<context>
|
||||
<option name="OTHER" value="true"/>
|
||||
</context>''').rootElement
|
||||
def context = new TemplateContext()
|
||||
context.readTemplateContext(defElement)
|
||||
|
||||
def javaContext = TemplateContextType.EP_NAME.findExtension(JavaCodeContextType.Generic)
|
||||
context.setEnabled(javaContext, true)
|
||||
|
||||
def saved = new Element('context')
|
||||
context.writeTemplateContext(saved)
|
||||
|
||||
context = new TemplateContext()
|
||||
context.readTemplateContext(saved)
|
||||
|
||||
assert context.isEnabled(javaContext)
|
||||
assert context.isEnabled(TemplateContextType.EP_NAME.findExtension(EverywhereContextType))
|
||||
}
|
||||
|
||||
private boolean isApplicable(String text, TemplateImpl inst) throws IOException {
|
||||
configureFromFileText("a.java", text);
|
||||
return TemplateManagerImpl.isApplicable(myFixture.getFile(), getEditor().getCaretModel().getOffset(), inst);
|
||||
|
||||
+6
-8
@@ -41,7 +41,6 @@ import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import com.intellij.util.ui.GridBag;
|
||||
@@ -150,7 +149,7 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
JPanel panel = new JPanel(new GridBagLayout());
|
||||
|
||||
GridBag gb = new GridBag().setDefaultInsets(4, 4, 4, 4).setDefaultWeightY(1).setDefaultFill(GridBagConstraints.BOTH);
|
||||
|
||||
|
||||
JPanel editorPanel = new JPanel(new BorderLayout(4, 4));
|
||||
editorPanel.setPreferredSize(JBUI.size(250, 100));
|
||||
editorPanel.setMinimumSize(editorPanel.getPreferredSize());
|
||||
@@ -260,11 +259,10 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
else {
|
||||
myTemplate.setShortcutChar(TemplateSettings.SPACE_CHAR);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
expandWithLabel.setLabelFor(myExpandByCombo);
|
||||
|
||||
|
||||
panel.add(myExpandByCombo, gbConstraints);
|
||||
gbConstraints.weightx = 1;
|
||||
gbConstraints.gridx = 2;
|
||||
@@ -287,7 +285,7 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
|
||||
gbConstraints.weighty = 1;
|
||||
gbConstraints.gridy++;
|
||||
panel.add(new JPanel(), gbConstraints);
|
||||
panel.add(new JPanel(), gbConstraints);
|
||||
|
||||
return panel;
|
||||
}
|
||||
@@ -295,7 +293,7 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
private List<TemplateContextType> getApplicableContexts() {
|
||||
ArrayList<TemplateContextType> result = new ArrayList<TemplateContextType>();
|
||||
for (TemplateContextType type : TemplateManagerImpl.getAllContextTypes()) {
|
||||
if (myContext.isExplicitlyEnabled(type)) {
|
||||
if (myContext.isEnabled(type)) {
|
||||
result.add(type);
|
||||
}
|
||||
}
|
||||
@@ -449,14 +447,14 @@ public class LiveTemplateSettingsEditor extends JPanel {
|
||||
parent.add(node);
|
||||
|
||||
if (children.isEmpty()) {
|
||||
node.setChecked(context.isExplicitlyEnabled(type));
|
||||
node.setChecked(context.isEnabled(type));
|
||||
}
|
||||
else {
|
||||
for (TemplateContextType child : children) {
|
||||
addContextNode(hierarchy, node, child, context);
|
||||
}
|
||||
final CheckedTreeNode other = new CheckedTreeNode(Pair.create(type, "Other"));
|
||||
other.setChecked(context.isExplicitlyEnabled(type));
|
||||
other.setChecked(context.isEnabled(type));
|
||||
node.add(other);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package com.intellij.codeInsight.template.impl;
|
||||
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.intellij.codeInsight.template.EverywhereContextType;
|
||||
import com.intellij.codeInsight.template.TemplateContextType;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -58,25 +57,12 @@ public class TemplateContext {
|
||||
Boolean storedValue = getOwnValue(contextType);
|
||||
if (storedValue == null) {
|
||||
TemplateContextType baseContextType = contextType.getBaseContextType();
|
||||
if (baseContextType != null && !(baseContextType instanceof EverywhereContextType)) {
|
||||
return isEnabled(baseContextType);
|
||||
}
|
||||
return false;
|
||||
return baseContextType != null && isEnabled(baseContextType);
|
||||
}
|
||||
return storedValue.booleanValue();
|
||||
}
|
||||
}
|
||||
|
||||
public void putValue(TemplateContextType context, boolean enabled) {
|
||||
synchronized (myContextStates) {
|
||||
myContextStates.put(context.getContextId(), enabled);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExplicitlyEnabled(TemplateContextType contextType) {
|
||||
return Boolean.TRUE.equals(getOwnValue(contextType));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Boolean getOwnValue(TemplateContextType contextType) {
|
||||
synchronized (myContextStates) {
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class TemplateEditorUtil {
|
||||
private static Document createDocument(CharSequence text, @Nullable TemplateContext context, Project project) {
|
||||
if (context != null) {
|
||||
for (TemplateContextType type : TemplateManagerImpl.getAllContextTypes()) {
|
||||
if (context.isExplicitlyEnabled(type)) {
|
||||
if (context.isEnabled(type)) {
|
||||
return type.createDocument(text, project);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user