<commit_before>package de.endrullis.idea.postfixtemplates.settings;

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.ui.GuiUtils;
import com.intellij.ui.ToolbarDecorator;
import de.endrullis.idea.postfixtemplates.language.CptFileType;
import de.endrullis.idea.postfixtemplates.language.CptLang;
import de.endrullis.idea.postfixtemplates.language.CptUtil;
import de.endrullis.idea.postfixtemplates.languages.SupportedLanguages;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.awt.*;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;

import static de.endrullis.idea.postfixtemplates.utils.CollectionUtils._List;

public class CptPluginSettingsForm implements CptPluginSettings.Holder, Disposable {
	/** This field holds the last state of the tree before saving the settings or null. */
	@Nullable
	private static Map<CptLang, List<CptVirtualFile>> lastTreeState;

	static Map<CptLang, List<CptVirtualFile>> getLastTreeState() {
		val state = lastTreeState;
		lastTreeState = null;
		return state;
	}

	private JPanel       mainPanel;
	private JPanel       templatesEditorPanel;
	private JRadioButton emptyLambdaRadioButton;
	private JRadioButton varLambdaRadioButton;
	private JPanel       treeContainer;
	private JEditorPane  templatesFileInfoLabel;
	private JCheckBox    automaticUpdatesCheckBox;

	@Nullable
	private Editor templatesEditor;

	@Nullable
	private CptManagementTree checkboxTree;


	public CptPluginSettingsForm() {
	}

	private void createTree() {
		checkboxTree = new CptManagementTree() {
			@Override
			protected void selectionChanged() {
				try {
					assert checkboxTree != null;
					val selectedFile = checkboxTree.getSelectedFile();

					if (selectedFile != null) {
						val file = selectedFile.getFile();
						final String fileName = selectedFile.getName().replace(".postfixTemplates", "");
						setEditorContent(file.exists() ? CptUtil.getContent(file) : "");

						val webTemplateFile = selectedFile.getWebTemplateFile();
						if (webTemplateFile != null) {
							String s = "<html>Web Template File \"" + fileName + "\"<table>";
							s += "<tr><td>Author:</td><td><a href=\"mailto:" + webTemplateFile.email + "\">" + webTemplateFile.author + "</a></td></tr>";
							s += "<tr><td>Website:</td><td><a href=\"" + webTemplateFile.website + "\">" + webTemplateFile.website + "</a></td></tr>";
							s += "<tr><tds>Description:</td><td>" + webTemplateFile.description + "</td></tr></table>";
							templatesFileInfoLabel.setText(s);
						} else {
							templatesFileInfoLabel.setText("<html>User Template File \"" + fileName + "\"");
						}
					}
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
			}
		};

		JPanel panel = new JPanel(new BorderLayout());
		panel.add(ToolbarDecorator.createDecorator(checkboxTree)
			.setAddActionUpdater(e -> checkboxTree.canAddFile())<commit_msg>added subject to mailto link<commit_after>package de.endrullis.idea.postfixtemplates.settings;

import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.ui.GuiUtils;
import com.intellij.ui.ToolbarDecorator;
import de.endrullis.idea.postfixtemplates.language.CptFileType;
import de.endrullis.idea.postfixtemplates.language.CptLang;
import de.endrullis.idea.postfixtemplates.language.CptUtil;
import de.endrullis.idea.postfixtemplates.languages.SupportedLanguages;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import java.awt.*;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;

import static de.endrullis.idea.postfixtemplates.utils.CollectionUtils._List;

public class CptPluginSettingsForm implements CptPluginSettings.Holder, Disposable {
	/** This field holds the last state of the tree before saving the settings or null. */
	@Nullable
	private static Map<CptLang, List<CptVirtualFile>> lastTreeState;

	static Map<CptLang, List<CptVirtualFile>> getLastTreeState() {
		val state = lastTreeState;
		lastTreeState = null;
		return state;
	}

	private JPanel       mainPanel;
	private JPanel       templatesEditorPanel;
	private JRadioButton emptyLambdaRadioButton;
	private JRadioButton varLambdaRadioButton;
	private JPanel       treeContainer;
	private JEditorPane  templatesFileInfoLabel;
	private JCheckBox    automaticUpdatesCheckBox;

	@Nullable
	private Editor templatesEditor;

	@Nullable
	private CptManagementTree checkboxTree;


	public CptPluginSettingsForm() {
	}

	private void createTree() {
		checkboxTree = new CptManagementTree() {
			@Override
			protected void selectionChanged() {
				try {
					assert checkboxTree != null;
					val selectedFile = checkboxTree.getSelectedFile();

					if (selectedFile != null) {
						val file = selectedFile.getFile();
						final String fileName = selectedFile.getName().replace(".postfixTemplates", "");
						setEditorContent(file.exists() ? CptUtil.getContent(file) : "");

						val webTemplateFile = selectedFile.getWebTemplateFile();
						if (webTemplateFile != null) {
							String subject = "";
							try {
								subject = URLEncoder.encode("[Custom Postfix Templates] " + fileName, "UTF-8").replaceAll("\\+", "%20");
							} catch (UnsupportedEncodingException e) {
								e.printStackTrace();
							}
							String s = "<html>Web Template File \"" + fileName + "\"<table>";
							s += "<tr><td>Author:</td><td><a href=\"mailto:" + webTemplateFile.email + "?subject=" + subject + "\">" + webTemplateFile.author + "</a></td></tr>";
							s += "<tr><td>Website:</td><td><a href=\"" + webTemplateFile.website + "\">" + webTemplateFile.website + "</a></td></tr>";
							s += "<tr><tds>Description:</td><td>" + webTemplateFile.description + "</td></tr></table>";
							templatesFileInfoLabel.setText(s);
						} else {
							templatesFileInfoLabel.setText("<html>User Template File \"" + fileName + "\"");
						}
					}
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
			}
		};

		JPanel panel = new JPanel(new BorderLayout());
		panel.add(ToolbarDecorator.createDecorator(checkboxTree)
			.setAddActionUpdater(e -> checkboxTree.canAddFile())
{'fraction_non_alphanumeric': 0.1244956772334294, 'fraction_numerical': 0.0004322766570605187, 'mean_word_length': 4.535087719298246, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3837473', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2084, 'n_words': 411}