From 946c825ee55c77764d0fac6674ba05c3fe886ff0 Mon Sep 17 00:00:00 2001 From: NotroDev Date: Thu, 25 Jul 2024 10:19:16 +0200 Subject: [PATCH 01/20] Fix NullReferenceException in change checker --- SkEditor/Utilities/Files/ChangeChecker.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SkEditor/Utilities/Files/ChangeChecker.cs b/SkEditor/Utilities/Files/ChangeChecker.cs index 1c0558a..61abe07 100644 --- a/SkEditor/Utilities/Files/ChangeChecker.cs +++ b/SkEditor/Utilities/Files/ChangeChecker.cs @@ -24,6 +24,7 @@ public static async void Check() try { OpenedFile file = SkEditorAPI.Files.GetCurrentOpenedFile(); + if (file == null) return; if (!file.IsEditor || string.IsNullOrWhiteSpace(file.Path)) return; string path = Uri.UnescapeDataString(file.Path); From 1e07ff287a97d511c7e23cdb99615165da9579c3 Mon Sep 17 00:00:00 2001 From: NotroDev Date: Thu, 25 Jul 2024 10:20:41 +0200 Subject: [PATCH 02/20] Remove unused AddChangeChecker --- SkEditor/Utilities/Files/FileHandler.cs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/SkEditor/Utilities/Files/FileHandler.cs b/SkEditor/Utilities/Files/FileHandler.cs index a63b929..7efdd13 100644 --- a/SkEditor/Utilities/Files/FileHandler.cs +++ b/SkEditor/Utilities/Files/FileHandler.cs @@ -127,21 +127,6 @@ public static void OpenFile(string path) SkEditorAPI.Files.OpenFile(path); } - private static void AddChangeChecker(string path, TabViewItem tabItem) - { - if (!SkEditorAPI.Core.GetAppConfig().CheckForChanges || tabItem.Content is not TextEditor) return; - - FileSystemWatcher watcher = new(Path.GetDirectoryName(path), Path.GetFileName(path)); - watcher.Changed += (sender, e) => ChangeChecker.HasChangedDictionary[path] = true; - (tabItem.Content as TextEditor).Unloaded += (sender, e) => - { - if (SkEditorAPI.Files.GetOpenedFiles().FirstOrDefault(openedFile => openedFile.TabViewItem == tabItem) is not OpenedFile openedFile) - { - watcher.Dispose(); - } - }; - } - public static void SwitchTab(int index) { if (index < SkEditorAPI.Files.GetOpenedTabs().Count) SkEditorAPI.Files.Select(index); From b499c52605f293015bcb28b7c694452a3f1758ae Mon Sep 17 00:00:00 2001 From: NotroDev Date: Thu, 25 Jul 2024 10:47:50 +0200 Subject: [PATCH 03/20] Fix the Save all shorcut --- SkEditor/Controls/MainMenuControl.axaml | 2 +- SkEditor/Controls/MainMenuControl.axaml.cs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/SkEditor/Controls/MainMenuControl.axaml b/SkEditor/Controls/MainMenuControl.axaml index 07b29b7..203a53b 100644 --- a/SkEditor/Controls/MainMenuControl.axaml +++ b/SkEditor/Controls/MainMenuControl.axaml @@ -38,7 +38,7 @@ - + diff --git a/SkEditor/Controls/MainMenuControl.axaml.cs b/SkEditor/Controls/MainMenuControl.axaml.cs index 2270df7..da78bdf 100644 --- a/SkEditor/Controls/MainMenuControl.axaml.cs +++ b/SkEditor/Controls/MainMenuControl.axaml.cs @@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.Input; using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Windowing; +using Serilog; using SkEditor.API; using SkEditor.Controls.Docs; using SkEditor.Utilities; @@ -24,6 +25,7 @@ public MainMenuControl() InitializeComponent(); AssignCommands(); + AddMissingHotkeys(); } private void AssignCommands() @@ -72,6 +74,23 @@ private static void ShowDialogIfEditorIsOpen(AppWindow window) window.ShowDialog(SkEditorAPI.Windows.GetMainWindow()); } + private void AddMissingHotkeys() + { + Loaded += (_, _) => + { + SkEditorAPI.Windows.GetMainWindow().KeyDown += (sender, e) => + { + if (e.PhysicalKey == PhysicalKey.S + && e.KeyModifiers == (KeyModifiers.Control | KeyModifiers.Alt) + && string.IsNullOrEmpty(e.KeySymbol)) + { + MenuItemSaveAll.Command.Execute(null); + e.Handled = true; + } + }; + }; + } + public static void AddDocsTab() { FluentIcons.Avalonia.Fluent.SymbolIconSource icon = new() From d43753a74b33f87f508495c9d1e4818f53dfacdf Mon Sep 17 00:00:00 2001 From: NotroDev Date: Thu, 25 Jul 2024 11:22:57 +0200 Subject: [PATCH 04/20] Add "highlight current line" option --- SkEditor/App.axaml | 4 ++++ SkEditor/Assets/Icons.axaml | 1 + SkEditor/Languages/English.xaml | 3 +++ SkEditor/Languages/Polish.xaml | 3 +++ SkEditor/Utilities/AppConfig.cs | 1 + SkEditor/Utilities/Files/FileBuilder.cs | 5 +++++ SkEditor/Utilities/Styling/Theme.cs | 2 ++ SkEditor/Utilities/Styling/ThemeEditor.cs | 9 +++++++-- .../Settings/Personalization/EditThemePage.axaml | 2 ++ .../Personalization/EditThemePage.axaml.cs | 2 ++ SkEditor/Views/Settings/PersonalizationPage.axaml | 10 +++++++++- .../Views/Settings/PersonalizationPage.axaml.cs | 14 +++++++++++++- 12 files changed, 52 insertions(+), 4 deletions(-) diff --git a/SkEditor/App.axaml b/SkEditor/App.axaml index f5909ae..066c5df 100644 --- a/SkEditor/App.axaml +++ b/SkEditor/App.axaml @@ -46,6 +46,10 @@ #26FFFFFF #161616 + + #05FFFFFF + #0DFFFFFF + 10 avares://SkEditor/Assets/JetBrainsMono#JetBrains Mono diff --git a/SkEditor/Assets/Icons.axaml b/SkEditor/Assets/Icons.axaml index 13df844..780012f 100644 --- a/SkEditor/Assets/Icons.axaml +++ b/SkEditor/Assets/Icons.axaml @@ -47,6 +47,7 @@ + diff --git a/SkEditor/Languages/English.xaml b/SkEditor/Languages/English.xaml index 417d832..5576fb7 100644 --- a/SkEditor/Languages/English.xaml +++ b/SkEditor/Languages/English.xaml @@ -305,6 +305,7 @@ Set how specific text is displayed with syntax highlightings. Font Current font: {0} + Highlight current line Theme @@ -415,6 +416,8 @@ Menu background Menu border Focused text box background + Current line background + Current line border Accent color diff --git a/SkEditor/Languages/Polish.xaml b/SkEditor/Languages/Polish.xaml index c42609c..99fa9b9 100644 --- a/SkEditor/Languages/Polish.xaml +++ b/SkEditor/Languages/Polish.xaml @@ -305,6 +305,7 @@ Ustaw sposób wyświetlania określonego tekstu z podświetlaniem składni. Czcionka Aktualnie: {0} + Podświetl bieżącą linię Motyw @@ -415,6 +416,8 @@ Tło menu Obramowanie menu Tło aktywnego pola tekstowego + Tło aktualnej linii + Obramowanie aktualnej linii Kolor wiodący diff --git a/SkEditor/Utilities/AppConfig.cs b/SkEditor/Utilities/AppConfig.cs index a15fe9f..04facd6 100644 --- a/SkEditor/Utilities/AppConfig.cs +++ b/SkEditor/Utilities/AppConfig.cs @@ -27,6 +27,7 @@ public partial class AppConfig : ObservableObject [ObservableProperty] private string _currentTheme = "Default.json"; [ObservableProperty] private Dictionary _fileSyntaxes = []; [ObservableProperty] private string _font = "Default"; + [ObservableProperty] private bool _highlightCurrentLine = true; [ObservableProperty] private bool _useSpacesInsteadOfTabs = false; [ObservableProperty] private int _tabSize = 4; [ObservableProperty] private bool _checkForUpdates = true; diff --git a/SkEditor/Utilities/Files/FileBuilder.cs b/SkEditor/Utilities/Files/FileBuilder.cs index 27d95a2..75a50a7 100644 --- a/SkEditor/Utilities/Files/FileBuilder.cs +++ b/SkEditor/Utilities/Files/FileBuilder.cs @@ -11,6 +11,7 @@ using SkEditor.API; using SkEditor.Utilities.Completion; using SkEditor.Utilities.Editor; +using SkEditor.Utilities.Styling; using SkEditor.Views; using SkEditor.Views.FileTypes; using System; @@ -241,6 +242,10 @@ private static TextEditor SetOptions(TextEditor editor) editor.Options.ConvertTabsToSpaces = SkEditorAPI.Core.GetAppConfig().UseSpacesInsteadOfTabs; editor.Options.IndentationSize = SkEditorAPI.Core.GetAppConfig().TabSize; + editor.TextArea.TextView.CurrentLineBackground = ThemeEditor.CurrentTheme.CurrentLineBackground; + editor.TextArea.TextView.CurrentLineBorder = new ImmutablePen(ThemeEditor.CurrentTheme.CurrentLineBorder, 2); + editor.Options.HighlightCurrentLine = SkEditorAPI.Core.GetAppConfig().HighlightCurrentLine; + return editor; } diff --git a/SkEditor/Utilities/Styling/Theme.cs b/SkEditor/Utilities/Styling/Theme.cs index f6a3279..944063d 100644 --- a/SkEditor/Utilities/Styling/Theme.cs +++ b/SkEditor/Utilities/Styling/Theme.cs @@ -24,6 +24,8 @@ public class Theme public ImmutableSolidColorBrush MenuBackground { get; set; } = new(Color.Parse("#ff151515")); public ImmutableSolidColorBrush MenuBorder { get; set; } = new(Color.Parse("#ff262626")); public ImmutableSolidColorBrush TextBoxFocusedBackground { get; set; } = new(Color.Parse("#ff191919")); + public ImmutableSolidColorBrush CurrentLineBackground { get; set; } = new(Color.Parse("#05FFFFFF")); + public ImmutableSolidColorBrush CurrentLineBorder { get; set; } = new(Color.Parse("#0DFFFFFF")); public ImmutableSolidColorBrush AccentColor { get; set; } = new(Colors.White); public string? CustomFont { get; set; } public bool UseMicaEffect { get; set; } = false; diff --git a/SkEditor/Utilities/Styling/ThemeEditor.cs b/SkEditor/Utilities/Styling/ThemeEditor.cs index 581c10e..8bba85e 100644 --- a/SkEditor/Utilities/Styling/ThemeEditor.cs +++ b/SkEditor/Utilities/Styling/ThemeEditor.cs @@ -39,10 +39,12 @@ public class ThemeEditor { "SelectedTabItemBorder", new string[] { "TabViewSelectedItemBorderBrush" } }, { "MenuBackground", new string[] { "MenuFlyoutPresenterBackground", "ComboBoxDropDownBackground", "FlyoutPresenterBackground" } }, { "MenuBorder", new string[] { "MenuFlyoutPresenterBorderBrush", "ComboBoxDropDownBorderBrush", "FlyoutBorderThemeBrush" } }, - { "TextBoxFocusedBackground", new string[] { "TextControlBackgroundFocused" } } + { "TextBoxFocusedBackground", new string[] { "TextControlBackgroundFocused" } }, + { "CurrentLineBackground", new string[] { "CurrentLineBackground" } }, + { "CurrentLineBorder", new string[] { "CurrentLineBorder" } }, }; - public static Dictionary DefaultColors { get; set; } = new(); + public static Dictionary DefaultColors { get; set; } = []; public static void LoadThemes() { @@ -216,6 +218,9 @@ private static void UpdateTextEditorColors() textEditor.Background = CurrentTheme.EditorBackgroundColor; textEditor.Foreground = CurrentTheme.EditorTextColor; textEditor.LineNumbersForeground = CurrentTheme.LineNumbersColor; + textEditor.TextArea.TextView.CurrentLineBackground = CurrentTheme.CurrentLineBackground; + textEditor.TextArea.TextView.CurrentLineBorder = new ImmutablePen(CurrentTheme.CurrentLineBorder, 2); + textEditor.TextArea.TextView.InvalidateVisual(); } } diff --git a/SkEditor/Views/Settings/Personalization/EditThemePage.axaml b/SkEditor/Views/Settings/Personalization/EditThemePage.axaml index b4ef2d4..bfc1555 100644 --- a/SkEditor/Views/Settings/Personalization/EditThemePage.axaml +++ b/SkEditor/Views/Settings/Personalization/EditThemePage.axaml @@ -23,6 +23,8 @@ + + diff --git a/SkEditor/Views/Settings/Personalization/EditThemePage.axaml.cs b/SkEditor/Views/Settings/Personalization/EditThemePage.axaml.cs index 66955f8..03441fa 100644 --- a/SkEditor/Views/Settings/Personalization/EditThemePage.axaml.cs +++ b/SkEditor/Views/Settings/Personalization/EditThemePage.axaml.cs @@ -34,6 +34,8 @@ private void SetUpColorPickers() SetUpColorPicker(MenuBackgroundExpander, "MenuBackground"); SetUpColorPicker(MenuBorderExpander, "MenuBorder"); SetUpColorPicker(TextBoxFocusedBackgroundExpander, "TextBoxFocusedBackground"); + SetUpColorPicker(CurrentLineBackgroundExpander, "CurrentLineBackground"); + SetUpColorPicker(CurrentLineBorderExpander, "CurrentLineBorder"); SetUpColorPicker(AccentColorExpander, "AccentColor"); } diff --git a/SkEditor/Views/Settings/PersonalizationPage.axaml b/SkEditor/Views/Settings/PersonalizationPage.axaml index 3ea58a3..c39ef38 100644 --- a/SkEditor/Views/Settings/PersonalizationPage.axaml +++ b/SkEditor/Views/Settings/PersonalizationPage.axaml @@ -4,7 +4,9 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ui="using:FluentAvalonia.UI.Controls" xmlns:controls="using:SkEditor.Controls" - mc:Ignorable="d" d:DesignWidth="800" + xmlns:utilities="clr-namespace:SkEditor.Utilities" + mc:Ignorable="d" d:DesignWidth="800" + x:DataType="utilities:AppConfig" x:Class="SkEditor.Views.Settings.PersonalizationPage"> @@ -24,6 +26,12 @@