' Gambas module file

Public Const DEFAULT_THEME As String = "gambas"

Property Theme As TextHighlighterTheme

Private $hTheme As New TextHighlighterTheme

Public Sub _init()
  
  Settings.Read($hTheme, "/Editor/Styles")
  
End

Public Sub InitEditor(hEditor As TextEditor, Optional (bDesaturate) As Boolean)
  
  Dim hTheme As TextHighlighterTheme
  
  If Application.DarkTheme And If Settings["/Editor/InvertTheme", True] Then
    hTheme = $hTheme.Copy()
    hTheme.Invert()
  Else
    hTheme = $hTheme
  Endif
  
  hEditor.Theme = hTheme
  hEditor.Background = hTheme["Background"].Color
  hEditor.Foreground = hTheme["Normal"].Color
  
  hEditor.Refresh
  
End

Public Sub GetColor(sStyle As String) As Integer

  Dim iColor As Integer
  
  Try iColor = $hTheme[sStyle].Color
  If Error Then
    iColor = Color.Pink
    Debug sStyle & "?"
  Endif
  
  If Application.DarkTheme And If Settings["/Editor/InvertTheme", True] Then
    iColor = Color.Invert(iColor, True)
  Endif
  
  Return iColor
  
End

Public Sub InitControl(hControl As Control)

  hControl.Background = GetColor("Background")
  hControl.Foreground = GetColor("Normal")
  
End

Private Function Theme_Read() As TextHighlighterTheme

  Return $hTheme

End

Private Sub Theme_Write(Value As TextHighlighterTheme)

  $hTheme = Value.Copy()
  Settings.Write($hTheme, "/Editor/Styles")
  
End

Public Sub GetTheme() As TextHighlighterTheme
  
  Dim hTheme As TextHighlighterTheme
  
  If Application.DarkTheme Then
    hTheme = $hTheme.Copy()
    hTheme.Invert()
    Return hTheme
  Else 
    Return $hTheme
  Endif
  
End
