<commit_before>package krasa.grepconsole.plugin;

import com.intellij.execution.configurations.RunConfigurationBase;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import krasa.grepconsole.action.HighlightManipulationAction;
import krasa.grepconsole.filter.support.SoundMode;
import krasa.grepconsole.gui.CompositeSettingsForm;
import krasa.grepconsole.gui.SettingsContext;
import krasa.grepconsole.model.Profile;
import krasa.grepconsole.model.Sound;
import krasa.grepconsole.plugin.runConfiguration.GrepConsoleData;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class MyConfigurable implements Configurable {

	private RunConfigurationBase runConfigurationBase;
	private long originalSelectedProfileId;
	@Nullable
	private ConsoleView console;
	protected CompositeSettingsForm form;
	private ServiceManager serviceManager = ServiceManager.getInstance();
	public GrepConsoleApplicationComponent applicationComponent = GrepConsoleApplicationComponent.getInstance();
	HighlightManipulationAction currentAction;
	private Project project;

	public MyConfigurable() {
		setDefaultProfileId();
	}

	public MyConfigurable(Project project) {
		setDefaultProfileId();
		this.project = project;
	}

	public MyConfigurable(Project project, @NotNull ConsoleView console) {
		this.console = console;
		originalSelectedProfileId = ServiceManager.getInstance().getSelectedProfileId(console);
		setDefaultProfileId();
		this.project = project;
	}

	public MyConfigurable(RunConfigurationBase runConfigurationBase) {
		this.runConfigurationBase = runConfigurationBase;
		originalSelectedProfileId = GrepConsoleData.getGrepConsoleData(runConfigurationBase).getSelectedProfileId();
		setDefaultProfileId();
		project = runConfigurationBase.getProject();
	}

	@Nls
	@Override
	public String getDisplayName() {
		return "Grep Console";
	}

	@Nullable
	public Icon getIcon() {
		return null;
	}

	@Override
	@Nullable
	@NonNls
	public String getHelpTopic() {
		return null;
	}

	@Override
	public JComponent createComponent() {
		if (form == null) {
			form = new CompositeSettingsForm(this, applicationComponent.getState(), originalSelectedProfileId);
		}
		return getRootComponent();
	}

	protected JPanel getRootComponent() {
		return form.getRootComponent();
	}

	protected void setDefaultProfileId() {
		if (originalSelectedProfileId == 0) {
			originalSelectedProfileId = applicationComponent.getState().getDefaultProfile().getId();
		}
	}

	@Override
	public boolean isModified() {
		return form != null && form.isSettingsModified(applicationComponent.getState());
	}

	@Override
	public void apply() throws ConfigurationException {
		apply(currentAction);
	}

	/**
	 * Run Configuration settings calls it all the time on change of models
	 */
	public void apply(@Nullable HighlightManipulationAction currentAction) {
		Profile selectedProfile = form.getSelectedProfile();
		if (selectedProfile != null) {
			PluginState formSettings = form.getSettings();
			applicationComponent.loadState(getClone(formSettings));


			long selectedProfileId = selectedProfile.getId();
			RunConfigurationBase runConfigurationBase = this.runConfigurationBase;
			if (runConfigurationBase == null && console != null) {
				runConfigurationBase = ServiceManager.getInstance().getRunConfigurationBase(console);
			}
			if (runConfigurationBase != null) {
				GrepConsoleData.getGrepConsoleData(runConfigurationBase).setSelectedProfileId(selectedProfileId);
			}
			if (selectedProfileId != originalSelectedProfileId) {
				Profile profile = applicationComponent.getState().getProfile(selectedProfileId);
				if (console != null) {
					serviceManager.profileChanged(console, profile);
				}
			}
			form.setOriginallySelectedProfileId(selectedProfileId);

			refreshServices(currentAction);
		}
	}

	protected PluginState getClone(PluginState formSettings) {
		return formSettings.clone();
	}

	protected void refreshServices(@Nullable HighlightManipulationAction currentAction) {
		serviceManager.resetSettings();
		applicationComponent.initFoldingCache();
		Sound.soundMode = SoundMode.DISABLED;
		if (currentAction != null) {
			currentAction.applySettings();
		}
		Sound.soundMode = SoundMode.ENABLED;
	}

	@Override
	public void reset() {
		if (form != null) {
			form.importFrom(applicationComponent.getState());
		}
	}

	@Override
	public void disposeUIResources() {
		form = null;
	}

	public void prepareForm(SettingsContext settingsContext) {
		form = new CompositeSettingsForm(this, applicationComponent.getState(), settingsContext, originalSelectedProfileId);
	}

	public void setCurrentAction(HighlightManipulationAction currentEditor) {
		this.currentAction = currentEditor;
	}

	public Project getProject() {
		return project;
	}

	public Profile getSelectedProfile() {
		if (form != null) {//TODO test it
			return form.getSelectedProfile();
		}
		return null;
	}
}
<commit_msg>TODO - fix of something<commit_after>package krasa.grepconsole.plugin;

import com.intellij.execution.configurations.RunConfigurationBase;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import krasa.grepconsole.action.HighlightManipulationAction;
import krasa.grepconsole.filter.support.SoundMode;
import krasa.grepconsole.gui.CompositeSettingsForm;
import krasa.grepconsole.gui.SettingsContext;
import krasa.grepconsole.model.Profile;
import krasa.grepconsole.model.Sound;
import krasa.grepconsole.plugin.runConfiguration.GrepConsoleData;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class MyConfigurable implements Configurable {

	private RunConfigurationBase runConfigurationBase;
	private long originalSelectedProfileId;
	@Nullable
	private ConsoleView console;
	protected CompositeSettingsForm form;
	private ServiceManager serviceManager = ServiceManager.getInstance();
	public GrepConsoleApplicationComponent applicationComponent = GrepConsoleApplicationComponent.getInstance();
	HighlightManipulationAction currentAction;
	private Project project;
	private Profile selectedProfile;

	public MyConfigurable() {
		setDefaultProfileId();
	}

	public MyConfigurable(Project project) {
		setDefaultProfileId();
		this.project = project;
	}

	public MyConfigurable(Project project, @NotNull ConsoleView console) {
		this.console = console;
		originalSelectedProfileId = ServiceManager.getInstance().getSelectedProfileId(console);
		setDefaultProfileId();
		this.project = project;
	}

	public MyConfigurable(RunConfigurationBase runConfigurationBase) {
		this.runConfigurationBase = runConfigurationBase;
		originalSelectedProfileId = GrepConsoleData.getGrepConsoleData(runConfigurationBase).getSelectedProfileId();
		setDefaultProfileId();
		project = runConfigurationBase.getProject();
	}

	@Nls
	@Override
	public String getDisplayName() {
		return "Grep Console";
	}

	@Nullable
	public Icon getIcon() {
		return null;
	}

	@Override
	@Nullable
	@NonNls
	public String getHelpTopic() {
		return null;
	}

	@Override
	public JComponent createComponent() {
		if (form == null) {
			form = new CompositeSettingsForm(this, applicationComponent.getState(), originalSelectedProfileId);
		}
		return getRootComponent();
	}

	protected JPanel getRootComponent() {
		return form.getRootComponent();
	}

	protected void setDefaultProfileId() {
		if (originalSelectedProfileId == 0) {
			originalSelectedProfileId = applicationComponent.getState().getDefaultProfile().getId();
		}
	}

	@Override
	public boolean isModified() {
		return form != null && form.isSettingsModified(applicationComponent.getState());
	}

	@Override
	public void apply() throws ConfigurationException {
		apply(currentAction);
	}

	/**
	 * Run Configuration settings calls it all the time on change of models
	 */
	public void apply(@Nullable HighlightManipulationAction currentAction) {
		Profile selectedProfile = form.getSelectedProfile();
		if (selectedProfile != null) {
			PluginState formSettings = form.getSettings();
			applicationComponent.loadState(getClone(formSettings));


			long selectedProfileId = selectedProfile.getId();
			RunConfigurationBase runConfigurationBase = this.runConfigurationBase;
			if (runConfigurationBase == null && console != null) {
				runConfigurationBase = ServiceManager.getInstance().getRunConfigurationBase(console);
			}
			if (runConfigurationBase != null) {
				GrepConsoleData.getGrepConsoleData(runConfigurationBase).setSelectedProfileId(selectedProfileId);
			}
			if (selectedProfileId != originalSelectedProfileId) {
				Profile profile = applicationComponent.getState().getProfile(selectedProfileId);
				if (console != null) {
					serviceManager.profileChanged(console, profile);
				}
			}
			form.setOriginallySelectedProfileId(selectedProfileId);

			refreshServices(currentAction);
		}
	}

	protected PluginState getClone(PluginState formSettings) {
		return formSettings.clone();
	}

	protected void refreshServices(@Nullable HighlightManipulationAction currentAction) {
		serviceManager.resetSettings();
		applicationComponent.initFoldingCache();
		Sound.soundMode = SoundMode.DISABLED;
		if (currentAction != null) {
			currentAction.applySettings();
		}
		Sound.soundMode = SoundMode.ENABLED;
	}

	@Override
	public void reset() {
		if (form != null) {
			form.importFrom(applicationComponent.getState());
		}
	}

	@Override
	public void disposeUIResources() {
		if (form != null) {
			selectedProfile = form.getSelectedProfile();
		}
		form = null;
	}

	public void prepareForm(SettingsContext settingsContext) {
		form = new CompositeSettingsForm(this, applicationComponent.getState(), settingsContext, originalSelectedProfileId);
	}

	public void setCurrentAction(HighlightManipulationAction currentEditor) {
		this.currentAction = currentEditor;
	}

	public Project getProject() {
		return project;
	}

	public Profile getSelectedProfile() {
		if (form != null) {
			selectedProfile = form.getSelectedProfile();
		}
		return selectedProfile;
	}
}

{'fraction_non_alphanumeric': 0.09163956380332887, 'fraction_numerical': 0.0001913143294432753, 'mean_word_length': 5.8512450851900395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1078682', 'n_tokens_mistral': 3092, 'n_tokens_neox': 2837, 'n_words': 586}