<commit_before>package isabelle.eclipse.ui.preferences

import org.eclipse.core.runtime.preferences.{DefaultScope, IEclipsePreferences}
import org.eclipse.jface.resource.StringConverter
import org.eclipse.swt.SWT
import org.eclipse.swt.graphics.RGB

import isabelle.eclipse.ui.internal.IsabelleUIPlugin
import isabelle.eclipse.ui.preferences.IsabelleSyntaxClasses._


/** Initialises preferences for syntax colours (and styles).
  * The syntax styles are defined in {@link IsabelleSyntaxClasses}.
  *
  * @author <NAME>
  */
object ColorPreferenceInitializer {

  private def defaultPrefs: IEclipsePreferences = 
    DefaultScope.INSTANCE.getNode(IsabelleUIPlugin.plugin.pluginId)

  def initializeDefaultPreferences() {
    setDefaultsForSyntaxClasses(defaultPrefs)
  }
  
  private def setDefaultsForSyntaxClass(
    syntaxClass: IsabelleSyntaxClass,
    foreground: Option[RGB] = None,
    background: Option[RGB] = None,
    bold: Boolean = false,
    italic: Boolean = false,
    strikethrough: Boolean = false,
    underline: Boolean = false,
    underlineStyle: Option[Int] = None)(implicit prefs: IEclipsePreferences) =
    {
      lazy val WHITE = new RGB(255, 255, 255)
      lazy val BLACK = new RGB(0, 0, 0)
      val defaultForegroundColour = StringConverter.asString(foreground getOrElse BLACK)
      prefs.put(syntaxClass.foregroundColorKey, defaultForegroundColour)
      prefs.putBoolean(syntaxClass.foregroundColorEnabledKey, foreground.isDefined)
      val defaultBackgroundColour = StringConverter.asString(background getOrElse WHITE)
      prefs.put(syntaxClass.backgroundColorKey, defaultBackgroundColour)
      prefs.putBoolean(syntaxClass.backgroundColorEnabledKey, background.isDefined)
      prefs.putBoolean(syntaxClass.boldKey, bold)
      prefs.putBoolean(syntaxClass.italicKey, italic)
      prefs.putBoolean(syntaxClass.strikethroughKey, strikethrough)
      prefs.putBoolean(syntaxClass.underlineKey, underline)
      underlineStyle foreach (style => prefs.putInt(syntaxClass.underlineStyleKey, style))
    }

  private def setDefaultsForSyntaxClasses(implicit prefs: IEclipsePreferences) {
    
    val black = rgb(0, 0, 0)
    val red = rgb(255, 0, 0)
    val green = rgb(0, 128, 0)
    val blue = rgb(0, 0, 255)
    val chocolate = rgb(210, 105, 30)
    val darkRed = rgb(139, 0, 0)
    val keyword1 = rgb(0, 102, 153)
    val keyword2 = rgb(0, 153, 102)<commit_msg>using more Eclipse-like colour scheme for Isabelle<commit_after>package isabelle.eclipse.ui.preferences

import org.eclipse.core.runtime.preferences.{DefaultScope, IEclipsePreferences}
import org.eclipse.jface.resource.StringConverter
import org.eclipse.swt.SWT
import org.eclipse.swt.graphics.RGB

import isabelle.eclipse.ui.internal.IsabelleUIPlugin
import isabelle.eclipse.ui.preferences.IsabelleSyntaxClasses._


/** Initialises preferences for syntax colours (and styles).
  * The syntax styles are defined in {@link IsabelleSyntaxClasses}.
  *
  * @author <NAME>
  */
object ColorPreferenceInitializer {

  private def defaultPrefs: IEclipsePreferences = 
    DefaultScope.INSTANCE.getNode(IsabelleUIPlugin.plugin.pluginId)

  def initializeDefaultPreferences() {
    putSyntaxColoringPreferences(defaultPrefs)
  }
  
  private def setDefaultsForSyntaxClass(
    syntaxClass: IsabelleSyntaxClass,
    foreground: Option[RGB] = None,
    background: Option[RGB] = None,
    bold: Boolean = false,
    italic: Boolean = false,
    strikethrough: Boolean = false,
    underline: Boolean = false,
    underlineStyle: Option[Int] = None)(implicit prefs: IEclipsePreferences) =
    {
      lazy val WHITE = new RGB(255, 255, 255)
      lazy val BLACK = new RGB(0, 0, 0)
      val defaultForegroundColour = StringConverter.asString(foreground getOrElse BLACK)
      prefs.put(syntaxClass.foregroundColorKey, defaultForegroundColour)
      prefs.putBoolean(syntaxClass.foregroundColorEnabledKey, foreground.isDefined)
      val defaultBackgroundColour = StringConverter.asString(background getOrElse WHITE)
      prefs.put(syntaxClass.backgroundColorKey, defaultBackgroundColour)
      prefs.putBoolean(syntaxClass.backgroundColorEnabledKey, background.isDefined)
      prefs.putBoolean(syntaxClass.boldKey, bold)
      prefs.putBoolean(syntaxClass.italicKey, italic)
      prefs.putBoolean(syntaxClass.strikethroughKey, strikethrough)
      prefs.putBoolean(syntaxClass.underlineKey, underline)
      underlineStyle foreach (style => prefs.putInt(syntaxClass.underlineStyleKey, style))
    }

  def putSyntaxColoringPreferences(implicit prefs: IEclipsePreferences) {
    
    val black = rgb(0, 0, 0)
    val red = rgb(255, 0, 0)
    val green = rgb(0, 128, 0)
    val blue = rgb(0, 0, 255)
    val chocolate = rgb(210, 105, 30)
    val darkRed = rgb(139, 0, 0)
    val keyword1 = rgb(127, 0, 85)
    val comment = rgb(63, 127, 95)
    val quoted = rgb(240, 240, 240)
    
    setDefaultsForSyntaxClass(COMMENT, comment)
    setDefaultsForSyntaxClass(VERBATIM, rgb(63, 95, 191))//, quoted)
    setDefaultsForSyntaxClass(STRING, black, quoted)
    setDefaultsForSyntaxClass(KEYWORD, keyword1, bold = true)
    setDefaultsForSyntaxClass(KEYWORD2, keyword1, bold = true)
    setDefaultsForSyntaxClass(OPERATOR, black, bold = true)
    setDefaultsForSyntaxClass(LITERAL, keyword1)
    setDefaultsForSyntaxClass(DELIMITER, black)
    setDefaultsForSyntaxClass(TYPE, rgb(160, 32, 240))
    setDefaultsForSyntaxClass(FREE, blue)
    setDefaultsForSyntaxClass(SKOLEM, chocolate)
    setDefaultsForSyntaxClass(BOUND, green)
    setDefaultsForSyntaxClass(VAR, rgb(0, 0, 155))
    setDefaultsForSyntaxClass(INNER_STRING, chocolate)
    setDefaultsForSyntaxClass(INNER_COMMENT, darkRed)
    setDefaultsForSyntaxClass(DYN_FACT, rgb(123, 164, 40))
    setDefaultsForSyntaxClass(ANTIQ, rgb(63, 63, 191))
    setDefaultsForSyntaxClass(ML_KEYWORD, keyword1, bold = true)
    setDefaultsForSyntaxClass(ML_NUMERAL, blue)
    setDefaultsForSyntaxClass(ML_STRING, blue)
    setDefaultsForSyntaxClass(ML_COMMENT, comment)
    
    setDefaultsForSyntaxClass(CMD, keyword1, bold = true)
    setDefaultsForSyntaxClass(CMD_SCRIPT, keyword1)
    setDefaultsForSyntaxClass(CMD_GOAL, keyword1, bold = true)

    setDefaultsForSyntaxClass(ACTIVE, underline = true, underlineStyle = Some(SWT.UNDERLINE_LINK))
    setDefaultsForSyntaxClass(DIALOG_SELECTED,
      underline = true, underlineStyle = Some(SWT.UNDERLINE_DOUBLE))
  }
  
  def putSyntaxColoringPreferencesJEdit(implicit prefs: IEclipsePreferences) {
    
    val black = rgb(0, 0, 0)
    val red = rgb(255, 0, 0)
    val green = rgb(0, 128, 0)
    val blue = rgb(0, 0, 255)
    val chocolate = rgb(210, 105, 30)
    val darkRed = rgb(139, 0, 0)
    val keyword1 = rgb(0, 102, 153)
    val keyword2 = rgb(0, 153, 102)
{'fraction_non_alphanumeric': 0.09042395493625853, 'fraction_numerical': 0.03187073821523866, 'mean_word_length': 4.548519736842105, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '380783', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2074, 'n_words': 455}