ability to switch off Zen Coding
authorEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Wed, 24 Feb 2010 13:39:34 +0000 (16:39 +0300)
committerEugene Kudelevsky <Eugene.Kudelevsky@jetbrains.com>
Wed, 24 Feb 2010 13:39:34 +0000 (16:39 +0300)
platform/platform-resources-en/src/messages/XmlBundle.properties
platform/platform-resources/src/META-INF/XmlPlugin.xml
xml/impl/src/com/intellij/codeInsight/template/XmlCustomLiveTemplate.java
xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettings.java [new file with mode: 0644]
xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettingsConfigurable.java [new file with mode: 0644]
xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettingsPanel.form [new file with mode: 0644]
xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettingsPanel.java [new file with mode: 0644]

index 45f8b0dc403abe7fae83c6daecd761457e88e1c1..9fe4c785ea5e44302f5676df26e426ab478129c3 100644 (file)
@@ -232,3 +232,5 @@ label.text.path.to.profiles.ini=Path to \"profiles.ini\":
 label.text.profile=&Profile:
 button.text.settings=Settings...
 display.name.firefox.settings=Firefox Settings
+zen.coding.settings=XML Zen Coding
+zen.coding.enable.label=Enable Zen Coding
index f05c4d4b8309530fe6fdbd9367e8bea4e128f584..3417e05b3a6456a4ee0859193088348ab498ebba 100644 (file)
 
     <applicationService serviceInterface="com.intellij.application.options.editor.XmlFoldingSettings"
                         serviceImplementation="com.intellij.application.options.editor.XmlFoldingSettings"/>
+
+    <applicationService serviceInterface="com.intellij.codeInsight.template.ZenCodingSettings"
+                          serviceImplementation="com.intellij.codeInsight.template.ZenCodingSettings"/>
+
     <exportable serviceInterface="com.intellij.application.options.editor.XmlFoldingSettings"/>
 
     <applicationService serviceInterface="com.intellij.application.options.XmlSettings"
     <basicWordSelectionFilter implementation="com.intellij.codeInsight.editorActions.XmlBasicWordSelectionFilter"/>
     <defaultLiveTemplatesProvider implementation="com.intellij.codeInsight.template.XmlDefaultLiveTemplatesProvider"/>
     <customLiveTemplate implementation="com.intellij.codeInsight.template.XmlCustomLiveTemplate"/>
+    <applicationConfigurable implementation="com.intellij.codeInsight.template.ZenCodingSettingsConfigurable"/>
     <productivityFeaturesProvider implementation="com.intellij.featureStatistics.XmlProductivityFeatureProvider"/>
 
     <idIndexer filetype="XML" implementationClass="com.intellij.psi.impl.cache.impl.idCache.XmlIdIndexer"/>
index ad278de1351f2a192a826d94d5db52f5878fd181..889cecd828ef5885099e6c88dd3f7b5b445a344f 100644 (file)
@@ -294,6 +294,10 @@ public class XmlCustomLiveTemplate implements CustomLiveTemplate {
   }
 
   public String computeTemplateKey(@NotNull CustomTemplateCallback callback) {
+    ZenCodingSettings settings = ZenCodingSettings.getInstance();
+    if (!settings.ENABLED) {
+      return null;
+    }
     PsiFile file = callback.getFile();
     if (file.getLanguage() instanceof XMLLanguage) {
       Editor editor = callback.getEditor();
diff --git a/xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettings.java b/xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettings.java
new file mode 100644 (file)
index 0000000..a344d18
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.codeInsight.template;
+
+import com.intellij.openapi.components.PersistentStateComponent;
+import com.intellij.openapi.components.ServiceManager;
+import com.intellij.openapi.components.State;
+import com.intellij.openapi.components.Storage;
+import com.intellij.util.xmlb.XmlSerializerUtil;
+
+/**
+ * @author Eugene.Kudelevsky
+ */
+@State(
+  name="DuplocatorSettings",
+  storages = {
+    @Storage(
+      id="DuplocatorSettings",
+      file="$APP_CONFIG$/other.xml"
+    )}
+)
+public class ZenCodingSettings implements PersistentStateComponent<ZenCodingSettings> {
+  public boolean ENABLED = true;
+
+  public static ZenCodingSettings getInstance() {
+    return ServiceManager.getService(ZenCodingSettings.class);
+  }
+
+  public ZenCodingSettings getState() {
+    return this;
+  }
+
+  public void loadState(ZenCodingSettings state) {
+    XmlSerializerUtil.copyBean(state, this);
+  }
+}
diff --git a/xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettingsConfigurable.java b/xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettingsConfigurable.java
new file mode 100644 (file)
index 0000000..b50e4bf
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.codeInsight.template;
+
+import com.intellij.openapi.options.ConfigurationException;
+import com.intellij.openapi.options.SearchableConfigurable;
+import com.intellij.xml.XmlBundle;
+import org.jetbrains.annotations.Nls;
+
+import javax.swing.*;
+
+/**
+ * @author Eugene.Kudelevsky
+ */
+public class ZenCodingSettingsConfigurable implements SearchableConfigurable {
+  private ZenCodingSettingsPanel myPanel;
+
+  public String getId() {
+    return getHelpTopic();
+  }
+
+  public Runnable enableSearch(String option) {
+    return null;
+  }
+
+  @Nls
+  public String getDisplayName() {
+    return XmlBundle.message("zen.coding.settings"); 
+  }
+
+  public Icon getIcon() {
+    return null;
+  }
+
+  public String getHelpTopic() {
+    return null;
+  }
+
+  public JComponent createComponent() {
+    if (myPanel == null) {
+      myPanel = new ZenCodingSettingsPanel();
+    }
+    return myPanel.getComponent();
+  }
+
+  public boolean isModified() {
+    return myPanel != null && myPanel.isModified();
+  }
+
+  public void apply() throws ConfigurationException {
+    if (myPanel != null) {
+      myPanel.apply();
+    }
+  }
+
+  public void reset() {
+    if (myPanel != null) {
+      myPanel.reset();
+    }
+  }
+
+  public void disposeUIResources() {
+    myPanel = null;
+  }
+}
diff --git a/xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettingsPanel.form b/xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettingsPanel.form
new file mode 100644 (file)
index 0000000..0cb05d3
--- /dev/null
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.codeInsight.template.ZenCodingSettingsPanel">
+  <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+    <margin top="0" left="0" bottom="0" right="0"/>
+    <constraints>
+      <xy x="20" y="20" width="500" height="400"/>
+    </constraints>
+    <properties/>
+    <border type="none"/>
+    <children>
+      <component id="3be87" class="javax.swing.JCheckBox" binding="myEnableZenCodingCheckBox">
+        <constraints>
+          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text resource-bundle="messages/XmlBundle" key="zen.coding.enable.label"/>
+        </properties>
+      </component>
+      <vspacer id="c2c50">
+        <constraints>
+          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
+        </constraints>
+      </vspacer>
+    </children>
+  </grid>
+</form>
diff --git a/xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettingsPanel.java b/xml/impl/src/com/intellij/codeInsight/template/ZenCodingSettingsPanel.java
new file mode 100644 (file)
index 0000000..5bbc95e
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2000-2010 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.codeInsight.template;
+
+import javax.swing.*;
+
+/**
+ * @author Eugene.Kudelevsky
+ */
+public class ZenCodingSettingsPanel {
+  private JPanel myPanel;
+  private JCheckBox myEnableZenCodingCheckBox;
+
+  public JPanel getComponent() {
+    return myPanel;
+  }
+
+  public boolean isModified() {
+    ZenCodingSettings settings = ZenCodingSettings.getInstance();
+    return settings.ENABLED != myEnableZenCodingCheckBox.isSelected();
+  }
+
+  public void apply() {
+    ZenCodingSettings settings = ZenCodingSettings.getInstance();
+    settings.ENABLED = myEnableZenCodingCheckBox.isSelected();
+  }
+
+  public void reset() {
+    ZenCodingSettings settings = ZenCodingSettings.getInstance();
+    myEnableZenCodingCheckBox.setSelected(settings.ENABLED);
+  }
+}