public void apply() throws ConfigurationException {
    List<TemplateGroup> templateGroups = getTemplateGroups();
    for (TemplateGroup templateGroup : templateGroups) {
      Set<String> names = new HashSet<>();

      List<TemplateImpl> templates = templateGroup.getElements();
      for (TemplateImpl template : templates) {
        String key = template.getKey();
        if (StringUtil.isEmptyOrSpaces(key)) {
          throw new ConfigurationException(
            LangBundle.message("dialog.message.live.template.with.empty.abbreviation", templateGroup.getName()));
        }

        if (StringUtil.isEmptyOrSpaces(template.getString())) {
          throw new ConfigurationException(LangBundle.message("dialog.message.live.template.with.empty.text", key, templateGroup.getName()));
        }

        if (!names.add(key)) {
          throw new ConfigurationException(
            LangBundle.message("dialog.message.duplicate.live.templates.in.group", key, templateGroup.getName()));
        }
      }
    }

    for (TemplateGroup templateGroup : templateGroups) {
      for (TemplateImpl template : templateGroup.getElements()) {
        template.applyContext(getTemplateContext(template));
        template.applyOptions(getTemplateOptions(template));
      }
    }
    TemplateSettings templateSettings = TemplateSettings.getInstance();
    templateSettings.setTemplates(mutatorHelper.apply(templateGroups, (original, copied) -> {
      if (original.isModified()) {
        return;
      }

      List<TemplateImpl> originalElements = original.getElements();
      List<TemplateImpl> copiedElements = copied.getElements();
      if (!originalElements.equals(copiedElements)) {
        original.setModified(true);
      }
      else {
        LiveTemplateContextsSnapshot allContexts = LiveTemplateContextService.getInstance().getSnapshot();

        // TemplateImpl.equals doesn't compare context and  I (develar) don't want to risk and change this behavior, so, we compare it explicitly
        for (int i = 0; i < originalElements.size(); i++) {
          if (getDifference(allContexts, originalElements.get(i).getTemplateContext(), copiedElements.get(i).getTemplateContext()) != null) {
            original.setModified(true);
            break;
          }
        }
      }

    }));
    templateSettings.setDefaultShortcutChar(myExpandByDefaultPanel.getSelectedChar());
  }
public void apply()