Avalonia.TextMate - Review Updates

-Remove apply window updates bool.
-Remove duplicated CurrentHighlightRenderer Background/border settings, this is replaced with a new call for but doesn't answer the review note fully.
This commit is contained in:
Natestah 2024-07-04 06:54:02 -07:00
Родитель 600f2a2368
Коммит c765a9262d
5 изменённых файлов: 67 добавлений и 66 удалений

Просмотреть файл

@ -3,6 +3,9 @@ using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Controls.Platform; using Avalonia.Controls.Platform;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using System; using System;
using System.ComponentModel;
using Avalonia.Styling;
using AvaloniaEdit.Demo.ViewModels;
namespace AvaloniaEdit.Demo namespace AvaloniaEdit.Demo
{ {
@ -17,13 +20,12 @@ namespace AvaloniaEdit.Demo
{ {
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime) if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{ {
var window = new MainWindow(); var window = new MainWindow();
desktopLifetime.MainWindow = window; desktopLifetime.MainWindow = window;
//PlatformManager.CreateEmbeddableWindow().Crea if (window.DataContext is MainWindowViewModel mainWindowViewModel)
{
mainWindowViewModel.PropertyChanged +=MainWindowViewModelOnPropertyChanged;
}
} }
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewLifetime) else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewLifetime)
{ {
@ -40,5 +42,16 @@ namespace AvaloniaEdit.Demo
base.OnFrameworkInitializationCompleted(); base.OnFrameworkInitializationCompleted();
} }
private void MainWindowViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (DataContext is not MainWindowViewModel mainWindowViewModel) return;
if (e.PropertyName == nameof(MainWindowViewModel.SelectedTheme))
{
RequestedThemeVariant = mainWindowViewModel.SelectedTheme.ThemeName.ToString().Contains("light")
? ThemeVariant.Light
: ThemeVariant.Dark;
}
}
} }
} }

Просмотреть файл

@ -154,6 +154,11 @@ namespace AvaloniaEdit.Demo
{ {
_customMargin.SetDefaultBackgroundBrush(); _customMargin.SetDefaultBackgroundBrush();
} }
//Applying the Editor background to the whole window for demo sake.
e.ApplyBrushAction("editor.background",brush => Background = brush);
e.ApplyBrushAction("editor.foreground",brush => Foreground = brush);
} }
private void Caret_PositionChanged(object sender, EventArgs e) private void Caret_PositionChanged(object sender, EventArgs e)

Просмотреть файл

@ -82,7 +82,7 @@ namespace AvaloniaEdit.TextMate
return true; return true;
} }
public void SetTheme(IRawTheme theme, bool applyWindowProperties = true) public void SetTheme(IRawTheme theme)
{ {
_textMateRegistry.SetTheme(theme); _textMateRegistry.SetTheme(theme);
@ -93,70 +93,42 @@ namespace AvaloniaEdit.TextMate
_editorModel?.InvalidateViewPortLines(); _editorModel?.InvalidateViewPortLines();
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime _guiColorDictionary = registryTheme.GetGuiColorDictionary();
{
MainWindow: Window window ApplyBrushAction("editor.background",brush =>_editor.Background = brush);
}) ApplyBrushAction("editor.foreground",brush =>_editor.Foreground = brush);
if (_defaultSelectionBrush == null)
{ {
_guiColorDictionary = registryTheme.GetGuiColorDictionary(); _defaultSelectionBrush = _editor.TextArea.SelectionBrush;
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.Foreground;
}
AppliedTheme?.Invoke(this,this);
} }
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.SetDefaultHighlightLineColors();
}
//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.Foreground;
}
AppliedTheme?.Invoke(this,this);
} }
//These come out of CurrentHighlightRenderer sealed class.
public static readonly Color CurrentHighlightRendererDefaultBackground = Color.FromArgb(22, 20, 220, 224);
public static readonly Color CurrentHighlightRendererDefaultBorder = Color.FromArgb(52, 0, 255, 110);
public void Dispose() public void Dispose()
{ {

Просмотреть файл

@ -37,6 +37,12 @@ namespace AvaloniaEdit.Rendering
#region Properties #region Properties
public void SetDefaultColors()
{
BorderPen = new ImmutablePen(new ImmutableSolidColorBrush(DefaultBorder), 1);
BackgroundBrush = new ImmutableSolidColorBrush(DefaultBackground);
}
public int Line { public int Line {
get { return _line; } get { return _line; }
set { set {

Просмотреть файл

@ -2099,5 +2099,10 @@ namespace AvaloniaEdit.Rendering
} }
Size IScrollable.Viewport => _scrollViewport; Size IScrollable.Viewport => _scrollViewport;
public void SetDefaultHighlightLineColors()
{
_currentLineHighlightRenderer?.SetDefaultColors();
}
} }
} }