diff --git a/Installer/Package.wxs b/Installer/Package.wxs index d1b79f35..89d3fe2f 100644 --- a/Installer/Package.wxs +++ b/Installer/Package.wxs @@ -1,6 +1,6 @@  - + diff --git a/SkEditor/API/ApiVault.cs b/SkEditor/API/ApiVault.cs deleted file mode 100644 index 94bf8b62..00000000 --- a/SkEditor/API/ApiVault.cs +++ /dev/null @@ -1,25 +0,0 @@ -using SkEditor.Utilities.Files; -using System; - -namespace SkEditor.API; - -[Obsolete("Use SkEditorAPI interfaces instead")] -public static class ApiVault -{ - private static ISkEditorAPI instance; - - public static void Set(ISkEditorAPI api) - { - instance = api; - } - - public static ISkEditorAPI Get() - { - return instance; - } - - public static void RegisterFileAssociation(FileTypes.FileAssociation association) - { - FileTypes.RegisterExternalAssociation(association); - } -} \ No newline at end of file diff --git a/SkEditor/API/ISkEditorAPI.cs b/SkEditor/API/ISkEditorAPI.cs deleted file mode 100644 index 98b47009..00000000 --- a/SkEditor/API/ISkEditorAPI.cs +++ /dev/null @@ -1,68 +0,0 @@ -using Avalonia.Controls; -using AvaloniaEdit; -using FluentAvalonia.UI.Controls; -using SkEditor.Utilities; -using SkEditor.Utilities.Files; -using SkEditor.Views; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace SkEditor.API; - -public interface ISkEditorAPI -{ - public MainWindow GetMainWindow(); - - public string[] GetStartupFiles(); - - public Menu GetMenu(); - - public bool IsFileOpen(); - - public bool IsFile(TabViewItem tabItem); - - public TextEditor? GetTextEditor(); - - public OpenedFile? GetOpenedFile(); - - public TabView GetTabView(); - - public void OpenUrl(string url); - public void OpenFolder(string path); - - public void ShowMessage(string title, string message, Window window); - public void ShowMessage(string title, string message); - - public void ShowError(string message); - - public Task ShowMessageWithIcon(string title, string message, IconSource icon, string iconColor = "#ffffff", string primaryButtonContent = "ConfirmButton", string closeButtonContent = "CancelButton", bool primaryButton = true); - public Task ShowAdvancedMessage(string title, string message, string primaryButtonContent = "ConfirmButton", string closeButtonContent = "CancelButton", bool primaryButton = true); - - public AppConfig GetAppConfig(); - - public void Debug(string message); - - public void Log(string message, bool bottomBarInfo = false); - public void SendToBottomBar(object message); - - public void SaveData(); - - public List GetOpenedEditors(); - - #region Events - - public event EventHandler Closed; - public void OnClosed(); - - public event EventHandler FileCreated; - public void OnFileCreated(TextEditor textEditor); - - public event EventHandler FileClosing; - public bool OnFileClosing(TextEditor textEditor); - - public event EventHandler SettingsOpened; - public void OnSettingsOpened(); - - #endregion -} \ No newline at end of file diff --git a/SkEditor/API/Utilities/IWindows.cs b/SkEditor/API/Utilities/IWindows.cs index a8f34477..166418dc 100644 --- a/SkEditor/API/Utilities/IWindows.cs +++ b/SkEditor/API/Utilities/IWindows.cs @@ -33,12 +33,13 @@ public interface IWindows /// The dialog's icon. Can be null. /// The text of the cancel button. If null, no cancel button will be shown. /// The text of the primary button. Default is "Okay", cannot be null + /// Whether to try translate the title /// The result of the dialog. Task ShowDialog(string title, string message, object? icon = null, string? cancelButtonText = null, - string primaryButtonText = "Okay"); + string primaryButtonText = "Okay", bool translate = true); /// /// Show a message dialog to the user. diff --git a/SkEditor/App.axaml.cs b/SkEditor/App.axaml.cs index ab99871f..767ec967 100644 --- a/SkEditor/App.axaml.cs +++ b/SkEditor/App.axaml.cs @@ -82,7 +82,6 @@ public override async void OnFrameworkInitializationCompleted() try { SkEditorAPI.Core.SetStartupArguments(desktop.Args ?? []); - _ = new SkEditor(); MainWindow mainWindow = new(); desktop.MainWindow = mainWindow; diff --git a/SkEditor/Controls/Addons/AddonEntryControl.axaml.cs b/SkEditor/Controls/Addons/AddonEntryControl.axaml.cs index 9e2a3001..34967435 100644 --- a/SkEditor/Controls/Addons/AddonEntryControl.axaml.cs +++ b/SkEditor/Controls/Addons/AddonEntryControl.axaml.cs @@ -97,7 +97,7 @@ public void LoadVisuals(AddonMeta addonMeta) Symbol = Symbol.Warning, Foreground = new SolidColorBrush(addonMeta.HasCriticalErrors ? ErrorColor : WarningColor), FontSize = 36, - IsFilled = true + IconVariant = IconVariant.Filled }; Expander.Header = new TextBlock() { diff --git a/SkEditor/Controls/MainMenuControl.axaml b/SkEditor/Controls/MainMenuControl.axaml index 203a53bc..5f0bb07c 100644 --- a/SkEditor/Controls/MainMenuControl.axaml +++ b/SkEditor/Controls/MainMenuControl.axaml @@ -168,6 +168,11 @@ + + + + + diff --git a/SkEditor/Controls/MainMenuControl.axaml.cs b/SkEditor/Controls/MainMenuControl.axaml.cs index 7d9415fd..08f68a63 100644 --- a/SkEditor/Controls/MainMenuControl.axaml.cs +++ b/SkEditor/Controls/MainMenuControl.axaml.cs @@ -58,13 +58,15 @@ private void AssignCommands() MenuItemRefreshSyntax.Command = new RelayCommand(async () => await SyntaxLoader.RefreshSyntaxAsync()); - MenuItemSettings.Command = new RelayCommand(() => new SettingsWindow().ShowDialog(SkEditorAPI.Windows.GetMainWindow())); + MenuItemDocs.Command = new RelayCommand(AddDocsTab); MenuItemGenerateGui.Command = new RelayCommand(() => ShowDialogIfEditorIsOpen(new GuiGenerator())); MenuItemGenerateCommand.Command = new RelayCommand(() => ShowDialogIfEditorIsOpen(new CommandGenerator())); MenuItemRefactor.Command = new RelayCommand(() => ShowDialogIfEditorIsOpen(new RefactorWindow())); + MenuItemColorSelector.Command = new RelayCommand(() => new ColorSelectionWindow().ShowDialog(SkEditorAPI.Windows.GetMainWindow())); + MenuItemMarketplace.Command = new RelayCommand(() => new MarketplaceWindow().ShowDialog(SkEditorAPI.Windows.GetMainWindow())); - MenuItemDocs.Command = new RelayCommand(AddDocsTab); + MenuItemSettings.Command = new RelayCommand(() => new SettingsWindow().ShowDialog(SkEditorAPI.Windows.GetMainWindow())); } private static void ShowDialogIfEditorIsOpen(AppWindow window) diff --git a/SkEditor/Languages/English.xaml b/SkEditor/Languages/English.xaml index 5576fb79..ff93d261 100644 --- a/SkEditor/Languages/English.xaml +++ b/SkEditor/Languages/English.xaml @@ -15,6 +15,7 @@ Marketplace Rename Create + Color selector File @@ -58,6 +59,7 @@ GUI Command Refactor + Color selector Marketplace @@ -193,6 +195,9 @@ Convert spaces to tabs Renaming '{0}' into... + + Result in hex + Explorer diff --git a/SkEditor/Languages/Polish.xaml b/SkEditor/Languages/Polish.xaml index 99fa9b9e..2cd13046 100644 --- a/SkEditor/Languages/Polish.xaml +++ b/SkEditor/Languages/Polish.xaml @@ -15,6 +15,7 @@ Rynek Zmień nazwę Stwórz + Selektor kolorów Plik @@ -58,7 +59,8 @@ GUI Komenda Refaktoryzacja - + Selektor kolorów + Rynek Odśwież składnię @@ -192,6 +194,9 @@ Zamień taby na spacje Zamień spacje na taby Zmiana nazwy '{0}' na... + + + Rezultat w HEX diff --git a/SkEditor/SkEditor.cs b/SkEditor/SkEditor.cs deleted file mode 100644 index bc18f291..00000000 --- a/SkEditor/SkEditor.cs +++ /dev/null @@ -1,334 +0,0 @@ -using Avalonia; -using Avalonia.Controls; -using Avalonia.Controls.ApplicationLifetimes; -using Avalonia.Media; -using Avalonia.Media.Immutable; -using Avalonia.Threading; -using AvaloniaEdit; -using FluentAvalonia.UI.Controls; -using SkEditor.API; -using SkEditor.Utilities; -using SkEditor.Utilities.Files; -using SkEditor.Views; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Threading.Tasks; - -namespace SkEditor; - -public class SkEditor : ISkEditorAPI -{ - public SkEditor() - { -#pragma warning disable 0618 - ApiVault.Set(this); -#pragma warning restore 0618 - } - - /// Main window - public MainWindow GetMainWindow() - { - return SkEditorAPI.Windows.GetMainWindow(); - } - - /// Startup files - public string[] GetStartupFiles() - { - return SkEditorAPI.Core.GetStartupArguments(); - } - - - /// App's main menu - public Menu GetMenu() - { - return GetMainWindow().MainMenu.MainMenu; - } - - /// True if file is currently opened - public bool IsFileOpen() - { - return GetTextEditor() != null; - } - - /// True if provided TabItem is file - public bool IsFile(TabViewItem tabItem) - { - return tabItem.Content is TextEditor; - } - - - /// Current opened text editor if exists, otherwise null - public TextEditor GetTextEditor() - { - return GetMainWindow().TabControl.SelectedItem is TabViewItem tabItem && IsFile(tabItem) ? tabItem.Content as TextEditor : null; - } - - public OpenedFile? GetOpenedFile() - { - return SkEditorAPI.Files.GetOpenedFiles().FirstOrDefault(file => file.TabViewItem == GetMainWindow().TabControl.SelectedItem); - } - - /// App's tabcontrol - public TabView GetTabView() - { - return GetMainWindow().TabControl; - } - - public AppConfig GetAppConfig() => SkEditorAPI.Core.GetAppConfig(); - - /// - /// Opens provided URL in default browser - /// - public void OpenUrl(string url) - { - try - { - Process.Start(new ProcessStartInfo - { - FileName = url, - UseShellExecute = true - }); - } - catch - { - OpenUrl(url.Replace("&", "^&")); - } - } - - /// - /// Opens provided folder in file explorer - /// - public void OpenFolder(string path) - { - Process.Start(new ProcessStartInfo - { - FileName = path, - UseShellExecute = true, - Verb = "open" - }); - } - - - /// - /// Shows message box with provided message and title on provided window - /// - public async void ShowMessage(string title, string message, Window window) - { - await Dispatcher.UIThread.InvokeAsync(async () => - { - Application.Current.TryGetResource("MessageBoxBackground", out var background); - var dialog = new ContentDialog() - { - Title = title, - Content = message, - CloseButtonText = Translation.Get("CloseButton"), - Background = background as ImmutableSolidColorBrush - }; - await dialog.ShowAsync(window); - }); - } - /// - /// Shows message box with provided message and title - /// - public void ShowMessage(string title, string message) - { - ShowMessage(title, message, GetTopWindow()); - } - - /// - /// Shows error message box with provided message - /// - public async void ShowError(string message) - { - string error = Translation.Get("Error"); - await ShowMessageWithIcon(error, message, new SymbolIconSource() { Symbol = Symbol.ImportantFilled }, primaryButton: false, closeButtonContent: "Okay"); - } - - private bool isMessageOpened = false; - - /// - /// Shows info box with provided message, title and icon - /// - public async Task ShowMessageWithIcon(string title, string message, IconSource icon, string iconColor = "#ffffff", string primaryButtonContent = "ConfirmButton", string closeButtonContent = "CancelButton", bool primaryButton = true) - { - if (isMessageOpened) return ContentDialogResult.None; - - Application.Current.TryGetResource("MessageBoxBackground", out var background); - var dialog = new ContentDialog() - { - Title = title, - CloseButtonText = Translation.Get(closeButtonContent), - Background = background as ImmutableSolidColorBrush - }; - - if (primaryButton) dialog.PrimaryButtonText = Translation.Get(primaryButtonContent); - - dialog.Closed += (_, _) => isMessageOpened = false; - - if (icon is SymbolIconSource symbolIcon) symbolIcon.FontSize = 36; - - IconSourceElement iconElement = new() - { - IconSource = icon, - Width = 36, - Height = 36, - }; - - var grid = new Grid(); - grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); - grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); - - var textBlock = new TextBlock() - { - Text = message, - FontSize = 16, - Margin = new Thickness(10, 10, 0, 0), - TextWrapping = TextWrapping.Wrap, - MaxWidth = 400, - }; - - Grid.SetColumn(iconElement, 0); - Grid.SetColumn(textBlock, 1); - - grid.Children.Add(iconElement); - grid.Children.Add(textBlock); - - dialog.Content = grid; - - isMessageOpened = true; - return await dialog.ShowAsync(GetTopWindow()); - } - - /// - /// Shows advanced message box with provided message, title and buttons - /// - public async Task ShowAdvancedMessage(string title, string message, string primaryButtonContent = "ConfirmButton", string closeButtonContent = "CancelButton", bool primaryButton = true) - { - if (isMessageOpened) return ContentDialogResult.None; - - Application.Current.TryGetResource("MessageBoxBackground", out var background); - var dialog = new ContentDialog() - { - Title = title, - CloseButtonText = Translation.Get(closeButtonContent), - Background = background as ImmutableSolidColorBrush - }; - - if (primaryButton) dialog.PrimaryButtonText = Translation.Get(primaryButtonContent); - - dialog.Closed += (_, _) => isMessageOpened = false; - - var textBlock = new TextBlock() - { - Text = message, - FontSize = 16, - Margin = new Thickness(10, 10, 0, 0), - TextWrapping = TextWrapping.Wrap, - MaxWidth = 500, - LineSpacing = 2 - }; - - dialog.Content = textBlock; - - isMessageOpened = true; - return await dialog.ShowAsync(GetTopWindow()); - } - - public void Debug(string message) - { - ShowMessage("Debug", message, GetTopWindow()); - } - - private static Window GetTopWindow() - { - var windows = ((IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime).Windows; - var dialog = windows.FirstOrDefault(x => x.IsActive); - return dialog; - } - - public void Log(string message, bool bottomBarInfo = false) - { - Serilog.Log.Information(message); - if (bottomBarInfo) SendToBottomBar(message); - } - public void SendToBottomBar(object message) - { - GetMainWindow().BottomBar.UpdateLogs(message.ToString()); - } - - public void SaveData() - { - List tabs = GetTabView().TabItems - .OfType() - .Where(tab => tab.Content is TextEditor) - .ToList(); - - tabs.ForEach(tab => - { - string path = tab.Tag.ToString(); - if (string.IsNullOrEmpty(path)) - { - string tempPath = Path.Combine(Path.GetTempPath(), "SkEditor"); - Directory.CreateDirectory(tempPath); - string header = tab.Header.ToString().TrimEnd('*'); - path = Path.Combine(tempPath, header); - } - TextEditor editor = tab.Content as TextEditor; - string textToWrite = editor.Text; - using StreamWriter writer = new(path, false); - writer.Write(textToWrite); - }); - - GetAppConfig().Save(); - } - - public List GetOpenedEditors() - { - return GetTabView().TabItems - .OfType() - .Select(x => x.Content as TextEditor) - .Where(editor => editor != null) - .ToList(); - } - - - #region Events - - public event EventHandler Closed; - public void OnClosed() => Closed?.Invoke(this, EventArgs.Empty); - - public event EventHandler FileCreated; - public void OnFileCreated(TextEditor textEditor) => FileCreated?.Invoke(this, new TextEditorEventArgs(textEditor)); - - /// - /// Returns true if file can be closed - /// - /// False if file closing was cancelled - public event EventHandler FileClosing; - public bool OnFileClosing(TextEditor textEditor) - { - TextEditorCancelEventArgs args = new(textEditor); - FileClosing?.Invoke(this, args); - return !args.Cancel; - } - - public event EventHandler SettingsOpened; - public void OnSettingsOpened() => SettingsOpened?.Invoke(this, EventArgs.Empty); - - #endregion -} - - -public class TextEditorEventArgs(TextEditor textEditor) : EventArgs -{ - public TextEditor TextEditor { get; } = textEditor; -} - -public class TextEditorCancelEventArgs(TextEditor textEditor) : EventArgs -{ - public TextEditor TextEditor { get; } = textEditor; - public bool Cancel { get; set; } -} \ No newline at end of file diff --git a/SkEditor/SkEditor.csproj b/SkEditor/SkEditor.csproj index 13881b32..4b091fdb 100644 --- a/SkEditor/SkEditor.csproj +++ b/SkEditor/SkEditor.csproj @@ -8,10 +8,10 @@ app.manifest SkEditor.ico true - 2.8.0 - 2.8.0 - 2.8.0 - 2.8.0 + 2.8.1 + 2.8.1 + 2.8.1 + 2.8.1 false true @@ -43,25 +43,25 @@ - - - - - + + + + + - - + + - + - + - + @@ -123,6 +123,10 @@ MarketplaceWindow.axaml + + Code + ColorSelectionWindow.axaml + RefactorWindow.axaml @@ -168,6 +172,12 @@ + + + Designer + + + MSBuild:Compile diff --git a/SkEditor/Styles/CustomMenuItemStyle.axaml b/SkEditor/Styles/CustomMenuItemStyle.axaml index b949ff11..b12db8c0 100644 --- a/SkEditor/Styles/CustomMenuItemStyle.axaml +++ b/SkEditor/Styles/CustomMenuItemStyle.axaml @@ -73,7 +73,7 @@ diff --git a/SkEditor/Utilities/Completion/CompletionProvider.cs b/SkEditor/Utilities/Completion/CompletionProvider.cs index 7d21086e..0869cf10 100644 --- a/SkEditor/Utilities/Completion/CompletionProvider.cs +++ b/SkEditor/Utilities/Completion/CompletionProvider.cs @@ -1,5 +1,6 @@ using AvaloniaEdit; using System.Collections.Generic; +using System.Linq; using System.Text.RegularExpressions; namespace SkEditor.Utilities.Completion; @@ -24,19 +25,19 @@ public static IEnumerable GetCompletions(string word, TextEditor yield return completionItem; } - //string text = textEditor.Text; - //foreach (Match match in WordRegex().Matches(text).Cast()) - //{ - // string matchValue = match.Value; - // if (matchValue == word) continue; - // if (!matchValue.StartsWith(word)) continue; - // if (CompletionItems.Any(x => x.Name == matchValue)) continue; - // yield return new CompletionItem(matchValue, matchValue); - //} + string text = textEditor.Text; + foreach (Match match in VariableRegex().Matches(text).Cast().DistinctBy(x => x.Value)) + { + string matchValue = match.Value; + if (matchValue == word) continue; + if (!matchValue.StartsWith(word)) continue; + if (CompletionItems.Any(x => x.Name == matchValue)) continue; + yield return new CompletionItem(matchValue, matchValue); + } } - [GeneratedRegex(@"\w+")] - private static partial Regex WordRegex(); + [GeneratedRegex(@"{\w+}")] + private static partial Regex VariableRegex(); } public record CompletionItem(string Name, string Content); \ No newline at end of file diff --git a/SkEditor/Utilities/Docs/IDocumentationEntry.cs b/SkEditor/Utilities/Docs/IDocumentationEntry.cs index ce7a6c1c..1820b243 100644 --- a/SkEditor/Utilities/Docs/IDocumentationEntry.cs +++ b/SkEditor/Utilities/Docs/IDocumentationEntry.cs @@ -2,6 +2,7 @@ using Avalonia.Controls; using Avalonia.Media; using FluentAvalonia.UI.Controls; +using FluentIcons.Common; using System; using System.Collections.Generic; using System.Linq; @@ -59,7 +60,7 @@ static SymbolIconSource CreateIcon(Symbol symbol, string? colorKey = null) { return new SymbolIconSource { - IsFilled = true, + IconVariant = IconVariant.Filled, Symbol = symbol, Foreground = colorKey != null ? GetColor(colorKey) : null }; diff --git a/SkEditor/Utilities/Docs/Local/LocalProvider.cs b/SkEditor/Utilities/Docs/Local/LocalProvider.cs index 40d7ce10..eba91aa5 100644 --- a/SkEditor/Utilities/Docs/Local/LocalProvider.cs +++ b/SkEditor/Utilities/Docs/Local/LocalProvider.cs @@ -1,5 +1,6 @@ using Avalonia.Media; using FluentAvalonia.UI.Controls; +using FluentIcons.Common; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -142,7 +143,7 @@ public async Task DeleteAll() await SaveLocalDocs(); } - public IconSource Icon => new SymbolIconSource() { Symbol = Symbol.Folder, IsFilled = true }; + public IconSource Icon => new SymbolIconSource() { Symbol = Symbol.Folder, IconVariant = IconVariant.Filled }; public string? GetLink(IDocumentationEntry entry) { diff --git a/SkEditor/Utilities/Editor/EditorMargin.cs b/SkEditor/Utilities/Editor/EditorMargin.cs index d1ab5b0a..8ba62b95 100644 --- a/SkEditor/Utilities/Editor/EditorMargin.cs +++ b/SkEditor/Utilities/Editor/EditorMargin.cs @@ -127,7 +127,7 @@ protected override void OnPointerExited(PointerEventArgs e) HoveredIcon = null; } - protected override async void OnPointerPressed(PointerPressedEventArgs e) + protected override void OnPointerPressed(PointerPressedEventArgs e) { if (HoveredIcon == null) return; diff --git a/SkEditor/Utilities/Editor/TextEditorEventHandler.cs b/SkEditor/Utilities/Editor/TextEditorEventHandler.cs index ad05a809..fcafb3f6 100644 --- a/SkEditor/Utilities/Editor/TextEditorEventHandler.cs +++ b/SkEditor/Utilities/Editor/TextEditorEventHandler.cs @@ -173,7 +173,7 @@ public static void CheckForHex(TextEditor textEditor) foreach (Match match in matches.Cast()) { - string hex = match.Value[2..^1]; + string hex = match.Value.Contains("##") ? match.Value[2..^1] : match.Value[1..^1]; bool parsed = Color.TryParse(hex, out Color color); if (!parsed) continue; @@ -185,7 +185,7 @@ public static void CheckForHex(TextEditor textEditor) HighlightingSpan span = new() { - StartExpression = new Regex(@"<#" + hex + @">"), + StartExpression = new Regex(@"<[#]?" + hex + @">"), EndExpression = EmptyRegex(), SpanColor = new HighlightingColor() { Foreground = new SimpleHighlightingBrush(color) }, RuleSet = ruleSet, diff --git a/SkEditor/Utilities/InternalAPI/Classes/Windows.cs b/SkEditor/Utilities/InternalAPI/Classes/Windows.cs index 90e30a68..2f8cbad2 100644 --- a/SkEditor/Utilities/InternalAPI/Classes/Windows.cs +++ b/SkEditor/Utilities/InternalAPI/Classes/Windows.cs @@ -31,7 +31,7 @@ public async Task ShowDialog(string title, string message, object? icon = null, string? cancelButtonText = null, - string primaryButtonText = "Okay") + string primaryButtonText = "Okay", bool translate = true) { static string? TryGetTranslation(string? input) { @@ -45,7 +45,7 @@ public async Task ShowDialog(string title, Application.Current.TryGetResource("MessageBoxBackground", out var background); ContentDialog dialog = new() { - Title = TryGetTranslation(title), + Title = translate ? TryGetTranslation(title) : title, Background = background as ImmutableSolidColorBrush, PrimaryButtonText = TryGetTranslation(primaryButtonText), CloseButtonText = TryGetTranslation(cancelButtonText), @@ -77,6 +77,8 @@ public async Task ShowDialog(string title, IconSourceElement iconElement = new() { IconSource = source, + Height = 40, + Width = 40, }; var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*") }; diff --git a/SkEditor/Utilities/Parser/CodeParser.cs b/SkEditor/Utilities/Parser/CodeParser.cs index 6023e2a2..43a8a260 100644 --- a/SkEditor/Utilities/Parser/CodeParser.cs +++ b/SkEditor/Utilities/Parser/CodeParser.cs @@ -61,6 +61,7 @@ public void Parse() // Split the code into lines List lines = [.. Editor.Text.Split('\n')]; int lastSectionLine = -1; + RemoveComments(ref lines); // Parse sections for (var lineIndex = 0; lineIndex < lines.Count; lineIndex++) @@ -98,6 +99,34 @@ public void Parse() ParserPanel.ParseButton.Content = Translation.Get("CodeParserParsed"); } + private static void RemoveComments(ref List lines) + { + for (var i = 0; i < lines.Count; i++) + { + var line = lines[i]; + if (line.Contains("###")) + { + var index = line.IndexOf("###"); + lines[i] = line[..index]; + for (var j = i + 1; j < lines.Count; j++) + { + if (lines[j].Contains("###")) + { + var index2 = lines[j].IndexOf("###"); + lines[j] = lines[j][(index2 + 3)..]; + break; + } + lines[j] = ""; + } + } + else if (line.Contains('#')) + { + var index = line.IndexOf('#'); + lines[i] = line[..index]; + } + } + } + public void SetUnparsed() { IsParsed = false; diff --git a/SkEditor/Utilities/Tutorial.cs b/SkEditor/Utilities/Tutorial.cs index cbb30715..90461d62 100644 --- a/SkEditor/Utilities/Tutorial.cs +++ b/SkEditor/Utilities/Tutorial.cs @@ -32,6 +32,6 @@ public async static void ShowTutorial() private async static Task ShowTutorialMessage(string title, string message, PathIconSource iconSource) { - await SkEditorAPI.Windows.ShowDialog(title, message, iconSource); + await SkEditorAPI.Windows.ShowDialog(title, message, icon: iconSource, translate: false); } } diff --git a/SkEditor/Views/ColorSelectionWindow.axaml b/SkEditor/Views/ColorSelectionWindow.axaml new file mode 100644 index 00000000..4062f165 --- /dev/null +++ b/SkEditor/Views/ColorSelectionWindow.axaml @@ -0,0 +1,22 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/SkEditor/Views/ColorSelectionWindow.axaml.cs b/SkEditor/Views/ColorSelectionWindow.axaml.cs new file mode 100644 index 00000000..2be92496 --- /dev/null +++ b/SkEditor/Views/ColorSelectionWindow.axaml.cs @@ -0,0 +1,42 @@ +using Avalonia.Input; +using Avalonia.Media; +using CommunityToolkit.Mvvm.Input; +using FluentAvalonia.UI.Windowing; + +namespace SkEditor.Views; +public partial class ColorSelectionWindow : AppWindow +{ + public ColorSelectionWindow() + { + InitializeComponent(); + Focusable = true; + + AssignEvents(); + } + + private void AssignEvents() + { + KeyDown += (_, e) => + { + if (e.Key == Key.Escape) Close(); + }; + + ColorPicker.ColorChanged += (_, e) => + { + string hex = e.NewColor.ToHexString(false); + ResultTextBox.Text = hex; + }; + + ResultTextBox.KeyDown += (_, e) => + { + if (e.Key == Key.Enter && ResultTextBox.Text.Length == 7) + { + bool isValid = Color.TryParse(ResultTextBox.Text, out Color color); + if (!isValid) return; + ColorPicker.Color = color; + } + }; + + CopyButton.Command = new RelayCommand(async () => await Clipboard.SetTextAsync(ResultTextBox.Text)); + } +} diff --git a/SkEditor/Views/MainWindow.axaml.cs b/SkEditor/Views/MainWindow.axaml.cs index ea194366..5140dfb1 100644 --- a/SkEditor/Views/MainWindow.axaml.cs +++ b/SkEditor/Views/MainWindow.axaml.cs @@ -97,7 +97,6 @@ private async void OnClosing(object sender, WindowClosingEventArgs e) else { await SessionRestorer.SaveSession(); - SkEditorAPI.Logs.Debug("Session saved."); AlreadyClosed = true; Close(); } diff --git a/SkEditor/Views/Marketplace/Types/AddonItem.cs b/SkEditor/Views/Marketplace/Types/AddonItem.cs index 98fa77a6..56dd5a28 100644 --- a/SkEditor/Views/Marketplace/Types/AddonItem.cs +++ b/SkEditor/Views/Marketplace/Types/AddonItem.cs @@ -76,7 +76,7 @@ public override void Uninstall() throw new NotImplementedException(); } - public async void Manage() + public void Manage() { SkEditorAPI.Windows.ShowWindow(new SettingsWindow()); SettingsWindow.NavigateToPage(typeof(AddonsPage)); diff --git a/SkEditor/Views/Settings/SettingsWindow.axaml.cs b/SkEditor/Views/Settings/SettingsWindow.axaml.cs index 8fa809db..db3308ab 100644 --- a/SkEditor/Views/Settings/SettingsWindow.axaml.cs +++ b/SkEditor/Views/Settings/SettingsWindow.axaml.cs @@ -5,6 +5,7 @@ using FluentAvalonia.UI.Windowing; using SkEditor.API; using SkEditor.Utilities.Styling; +using SkEditor.Views.Settings; using System; namespace SkEditor.Views; @@ -27,14 +28,35 @@ public SettingsWindow() KeyDown += (_, e) => { - if (e.Key == Key.Escape) Close(); + if (e.Key != Key.Escape) return; + + if (FrameView.CanGoBack) + { + FrameView.GoBack(); + } + else + { + Close(); + } }; Closed += (s, e) => SkEditorAPI.Core.GetAppConfig().Save(); } public static void NavigateToPage(Type page) { - var navOpt = new FrameNavigationOptions() { TransitionInfoOverride = new EntranceNavigationTransitionInfo() }; + EntranceNavigationTransitionInfo transitionInfo = new(); + + var navOpt = new FrameNavigationOptions() { TransitionInfoOverride = transitionInfo, IsNavigationStackEnabled = true }; Instance.FrameView.NavigateToType(page, null, navOpt); + + if (page == typeof(HomePage)) + { + Instance.FrameView.BackStack.Clear(); + Instance.FrameView.ForwardStack.Clear(); + } + else if (Instance.FrameView.BackStack.Count == 0) + { + Instance.FrameView.BackStack.Add(new PageStackEntry(typeof(HomePage), null, transitionInfo)); + } } }