<commit_before>package nl.rubensten.texifyidea.run

import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.fileChooser.FileTypeDescriptor
import com.intellij.openapi.options.ConfigurationException
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.ui.*
import com.intellij.openapi.util.SystemInfo
import com.intellij.ui.RawCommandLineEditor
import com.intellij.ui.SeparatorComponent
import com.intellij.ui.TitledSeparator
import nl.rubensten.texifyidea.run.LatexCompiler.Format
import java.awt.event.ItemEvent
import javax.swing.JCheckBox
import javax.swing.JComponent
import javax.swing.JPanel

/**
 * @author <NAME>
 */
class LatexSettingsEditor(private var project: Project?) : SettingsEditor<LatexRunConfiguration>() {

    private lateinit var panel: JPanel
    private lateinit var compiler: LabeledComponent<ComboBox<LatexCompiler>>
    private lateinit var enableCompilerPath: JCheckBox
    private lateinit var compilerPath: TextFieldWithBrowseButton
    private lateinit var compilerArguments: LabeledComponent<RawCommandLineEditor>
    private lateinit var mainFile: LabeledComponent<ComponentWithBrowseButton<*>>

    // The following options may or may not exist.
    private var auxDir: JCheckBox? = null
    private var outDir: JCheckBox? = null
    private lateinit var outputFormat: LabeledComponent<ComboBox<Format>>
    private lateinit var bibliographyPanel: BibliographyPanel

    /** Whether to enable the sumatraPath text field. */
    private lateinit var enableSumatraPath: JCheckBox

    /** Allow users to specify a custom path to SumatraPDF.  */
    private lateinit var sumatraPath: TextFieldWithBrowseButton

    override fun resetEditorFrom(runConfiguration: LatexRunConfiguration) {
        // Reset the selected compiler.
        compiler.component.selectedItem = runConfiguration.compiler

        // Reset the custom compiler path
        compilerPath.text = runConfiguration.compilerPath
        enableCompilerPath.isSelected = runConfiguration.compilerPath != null

        // Reset the custom SumatraPDF path
        sumatraPath.text = runConfiguration.sumatraPath
        enableSumatraPath.isSelected = runConfiguration.sumatraPath != null

        // Reset compiler arguments
        val args = runConfiguration.compilerArguments
        compilerArguments.component.text = args ?: ""

        // Reset the main file to compile.
        val txtFile = mainFile.component as TextFieldWithBrowseButton
        val virtualFile = runConfiguration.mainFile
        val path = virtualFile?.path ?: ""
        txtFile.text = path

        // Reset seperate auxiliary files.
        if (auxDir != null) {
            auxDir!!.isSelected = runConfiguration.hasAuxiliaryDirectories()
        }

        // Reset seperate output files.
        if (outDir != null) {
            outDir!!.isSelected = runConfiguration.hasOutputDirectories()
        }

        // Reset output format.
        outputFormat.component.selectedItem = runConfiguration.outputFormat

        // Reset project.
        project = runConfiguration.project

        // Reset bibliography
        bibliographyPanel.configuration = runConfiguration.bibRunConfig<commit_msg>Add check for initialized sumatraPath property<commit_after>package nl.rubensten.texifyidea.run

import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.fileChooser.FileTypeDescriptor
import com.intellij.openapi.options.ConfigurationException
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.ui.*
import com.intellij.openapi.util.SystemInfo
import com.intellij.ui.RawCommandLineEditor
import com.intellij.ui.SeparatorComponent
import com.intellij.ui.TitledSeparator
import nl.rubensten.texifyidea.run.LatexCompiler.Format
import java.awt.event.ItemEvent
import javax.swing.JCheckBox
import javax.swing.JComponent
import javax.swing.JPanel

/**
 * @author <NAME>
 */
class LatexSettingsEditor(private var project: Project?) : SettingsEditor<LatexRunConfiguration>() {

    private lateinit var panel: JPanel
    private lateinit var compiler: LabeledComponent<ComboBox<LatexCompiler>>
    private lateinit var enableCompilerPath: JCheckBox
    private lateinit var compilerPath: TextFieldWithBrowseButton
    private lateinit var compilerArguments: LabeledComponent<RawCommandLineEditor>
    private lateinit var mainFile: LabeledComponent<ComponentWithBrowseButton<*>>

    // The following options may or may not exist.
    private var auxDir: JCheckBox? = null
    private var outDir: JCheckBox? = null
    private lateinit var outputFormat: LabeledComponent<ComboBox<Format>>
    private lateinit var bibliographyPanel: BibliographyPanel

    /** Whether to enable the sumatraPath text field. */
    private lateinit var enableSumatraPath: JCheckBox

    /** Allow users to specify a custom path to SumatraPDF.  */
    private lateinit var sumatraPath: TextFieldWithBrowseButton

    override fun resetEditorFrom(runConfiguration: LatexRunConfiguration) {
        // Reset the selected compiler.
        compiler.component.selectedItem = runConfiguration.compiler

        // Reset the custom compiler path
        compilerPath.text = runConfiguration.compilerPath
        enableCompilerPath.isSelected = runConfiguration.compilerPath != null

        if (::sumatraPath.isInitialized) {
            // Reset the custom SumatraPDF path
            sumatraPath.text = runConfiguration.sumatraPath
            enableSumatraPath.isSelected = runConfiguration.sumatraPath != null
        }

        // Reset compiler arguments
        val args = runConfiguration.compilerArguments
        compilerArguments.component.text = args ?: ""

        // Reset the main file to compile.
        val txtFile = mainFile.component as TextFieldWithBrowseButton
        val virtualFile = runConfiguration.mainFile
        val path = virtualFile?.path ?: ""
        txtFile.text = path

        // Reset seperate auxiliary files.
        if (auxDir != null) {
            auxDir!!.isSelected = runConfiguration.hasAuxiliaryDirectories()
        }

        // Reset seperate output files.
        if (outDir != null) {
            outDir!!.isSelected = runConfiguration.hasOutputDirectories()
        }

        // Reset output format.
        outputFormat.component.selectedItem = runConfiguration.outputFormat

        // Reset project.
        project = runConfiguration.project

        // Reset bibliography
        bibliographyPanel.configuration = runConfiguration.bibRunConfig
{'fraction_non_alphanumeric': 0.07028706717963895, 'fraction_numerical': 0.0, 'mean_word_length': 3.582372881355932, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5996539', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1714, 'n_words': 434}