IDEA-129351 Cannot restore deleted live template
authorVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Thu, 4 Sep 2014 17:32:38 +0000 (21:32 +0400)
committerVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Thu, 4 Sep 2014 17:33:56 +0000 (21:33 +0400)
platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateListPanel.java
platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java

index 9a7a724e2d5d21a8199d45794d97af7e573cb6f2..1c0b72a5a454cf8f501c59358b94b5a5c16aae9e 100644 (file)
@@ -19,6 +19,7 @@ package com.intellij.codeInsight.template.impl;
 import com.intellij.application.options.ExportSchemeAction;
 import com.intellij.application.options.SchemesToImportPopup;
 import com.intellij.codeInsight.CodeInsightBundle;
+import com.intellij.icons.AllIcons;
 import com.intellij.ide.DataManager;
 import com.intellij.ide.dnd.*;
 import com.intellij.ide.dnd.aware.DnDAwareTree;
@@ -690,6 +691,17 @@ public class TemplateListPanel extends JPanel implements Disposable {
         public void updateButton(AnActionEvent e) {
           e.getPresentation().setEnabled(getTemplate(getSingleSelectedIndex()) != null);
         }
+      }).addExtraAction(new AnActionButton("Restore deleted defaults", AllIcons.General.TodoDefault) {
+        @Override
+        public void actionPerformed(@NotNull AnActionEvent e) {
+          TemplateSettings.getInstance().reset();
+          reset();
+        }
+
+        @Override
+        public boolean isEnabled() {
+          return super.isEnabled() && !TemplateSettings.getInstance().getDeletedTemplates().isEmpty();
+        }
       });
     if (getSchemesManager().isExportAvailable()) {
       decorator.addExtraAction(new AnActionButton("Share...", PlatformIcons.EXPORT_ICON) {
index 38a78243c464993209a19fff5fa6ff21a2bbc294..cdefbe83a2520bbc226f82072f636a9b6586a9dd 100644 (file)
@@ -158,6 +158,10 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
       this.key = key;
     }
 
+    @Override
+    public String toString() {
+      return getKey()+"@" + getGroupName();
+    }
   }
 
   private TemplateKey myLastSelectedTemplate;
@@ -750,4 +754,9 @@ public class TemplateSettings implements PersistentStateComponent<Element>, Expo
   public List<TemplateKey> getDeletedTemplates() {
     return myDeletedTemplates;
   }
+
+  public void reset() {
+    myDeletedTemplates.clear();
+    loadDefaultLiveTemplates();
+  }
 }