package com.intellij.codeInsight.template.impl;

import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupActionProvider;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementAction;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
import com.intellij.util.Consumer;
import com.intellij.util.PlatformIcons;

/**
 * @author peter
 */
public class LiveTemplateLookupActionProvider implements LookupActionProvider{
  @Override
  public void fillActions(LookupElement element, final Lookup lookup, Consumer<LookupElementAction> consumer) {
    if (element instanceof LiveTemplateLookupElement) {
      final TemplateImpl template = ((LiveTemplateLookupElement)element).getTemplate();

      consumer.consume(new LookupElementAction(PlatformIcons.EDIT, "Edit live template settings") {
        @Override
        public Result performLookupAction() {
          final Project project = lookup.getEditor().getProject();
          assert project != null;
          ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override
            public void run() {
              if (project.isDisposed()) return;

              final LiveTemplatesConfigurable configurable = new LiveTemplatesConfigurable();
              ShowSettingsUtil.getInstance().editConfigurable(project, configurable, new Runnable() {
                @Override
                public void run() {
                  configurable.getTemplateListPanel().editTemplate(template);
                }
              });
            }
          });
          return Result.HIDE_LOOKUP;
        }
      });
    }
  }
}

@@ -264,16 +264,52 @@
 Action;%0A
+import com.intellij.icons.AllIcons;%0A
 import c
@@ -637,16 +637,17 @@
 Provider
+ 
 %7B%0A  @Ove
@@ -1804,24 +1804,703 @@
  %7D%0A      %7D);
+%0A%0A      final TemplateImpl templateFromSettings = TemplateSettings.getInstance().getTemplate(template.getKey(), template.getGroupName());%0A      if (templateFromSettings != null) %7B%0A        consumer.consume(new LookupElementAction(AllIcons.Actions.Delete, String.format(%22Disable '%25s' template%22, template.getKey())) %7B%0A          @Override%0A          public Result performLookupAction() %7B%0A            ApplicationManager.getApplication().invokeLater(new Runnable() %7B%0A              @Override%0A              public void run() %7B%0A                templateFromSettings.setDeactivated(true);%0A              %7D%0A            %7D);%0A            return Result.HIDE_LOOKUP;%0A          %7D%0A        %7D);%0A      %7D
 %0A    %7D%0A  %7D%0A%7D

Add 'disable' action for live template lookup