Skip to content

Instantly share code, notes, and snippets.

@Natestah
Created June 23, 2024 16:22
Show Gist options
  • Save Natestah/aff8e57a8935d3fc1aea525ef756719f to your computer and use it in GitHub Desktop.
Save Natestah/aff8e57a8935d3fc1aea525ef756719f to your computer and use it in GitHub Desktop.
// Event with custom elements ( the status bar here has its own colors )
private void TextMateInstallationOnAppliedTheme(object sender, TextMate.TextMate.Installation e)
{
var panel = this.Find<StackPanel>("StatusBar");
if (panel == null)
{
return;
}
if (!e.ApplyBrushAction("statusBar.background", brush => panel.Background = brush))
{
panel.Background = Brushes.Purple;
}
if (!e.ApplyBrushAction("statusBar.foreground", brush => _statusTextBlock.Foreground = brush))
{
_statusTextBlock.Foreground = Brushes.White;
}
if (!e.ApplyBrushAction("sideBar.background", brush => _customMargin.BackGroundBrush = brush))
{
_customMargin.SetDefaultBackgroundBrush();
}
}
...
var registryTheme = _textMateRegistry.GetTheme();
GetOrCreateTransformer().SetTheme(registryTheme);
...
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime
{
MainWindow: Window window
})
{
_guiColorDictionary = registryTheme.GetGuiColorDictionary();
var themeName = theme.GetName();
// Applies to the application on a whole.. Some might want to opt out of this for their own setups.
if (applyWindowProperties)
{
if (themeName != null && themeName.ToLower().Contains("light"))
{
Application.Current.RequestedThemeVariant = ThemeVariant.Light;
}
else
{
Application.Current.RequestedThemeVariant = ThemeVariant.Dark;
}
ApplyBrushAction("editor.background",brush =>window.Background = brush);
ApplyBrushAction("editor.foreground",brush =>window.Foreground = brush);
}
ApplyBrushAction("editor.background",brush =>_editor.Background = brush);
ApplyBrushAction("editor.foreground",brush =>_editor.Foreground = brush);
if (_defaultSelectionBrush == null)
{
_defaultSelectionBrush = _editor.TextArea.SelectionBrush;
}
if (!ApplyBrushAction("editor.selectionBackground",
brush => _editor.TextArea.SelectionBrush = brush))
{
_editor.TextArea.SelectionBrush = _defaultSelectionBrush;
}
if (!ApplyBrushAction("editor.lineHighlightBackground",
brush =>
{
_editor.TextArea.TextView.CurrentLineBackground = brush;
_editor.TextArea.TextView.CurrentLineBorder = new Pen(brush); // Todo: VS Code didn't seem to have a border but it might be nice to have that option. For now just make it the same..
}))
{
_editor.TextArea.TextView.CurrentLineBackground = new SolidColorBrush(CurrentHighlightRendererDefaultBackground);
_editor.TextArea.TextView.CurrentLineBorder = new Pen(new SolidColorBrush(CurrentHighlightRendererDefaultBorder));
}
//Todo: looks like the margin doesn't have a active line highlight, would be a nice addition
if (!ApplyBrushAction("editorLineNumber.foreground",
brush => _editor.LineNumbersForeground = brush))
{
_editor.LineNumbersForeground = _editor.TextArea.Foreground;
}
AppliedTheme?.Invoke(this,this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment