From 57afd43ee39e06404c419b4bb558916f667579f3 Mon Sep 17 00:00:00 2001 From: Notro <77281214+NotroDev@users.noreply.github.com> Date: Sat, 25 May 2024 12:57:41 +0200 Subject: [PATCH] v2.5.0 (#58) * Fix session restoring crash * Fix syntax loading crash * fix: need to double close skeditor with session restore * update libs * fix: code parser yml crash and wrong section end * Add real-time code parsing experiment * fix: syntax crash * Added proper indentation pasting (#43) * Added proper indentation pasting (#16) * Added config option for paste indent + reworked bindings for settings * Change auto-indent paste option order in the settings * correct auto-indent option translation * Bump version to v2.5.0 * First push * supports for SkUnity as provider added basic search form added search validation for a provider added timeout system when sending the request to the provider first appearance of SkriptHub provider (will be next) * Added supports for SkriptHub * :sparkles: Added Connections page (and regrouped SkUnity key there) * Custom provider keys system * :sparkles: Added loading bar & warning when >= 100 results * :sparkles: Added examples endpoints * :sparkles: Added example and example fetching for some providers * :sparkles: Added 'Classe' type and fixed doc type parsing * :sparkles: Added a useful message for too many results/nothing found/etc... * :sparkles: Added auto complete box for addons * :sparkles: Added local docs provider (= download docs for offline use) * :zap: Enhanced usage of examples to give the whole object instead of just the ID * :sparkles: (Theoretically) Added SkriptMC docs provider * :sparkles: Moved publish's API keys to the new Connections settings page * :sparkles: Added event-values & expression changers (+ pattern generator for changers) * :bug: Fixed error when no examples were available * :zap: Enhanced connections page using sub-controls * :bug: Fixed empty changers showing blank buttons * :memo: Review changes * Add connection providers svg icon support, cleanup * :sparkles: Added local docs management window :sparkles: Added button to refresh providers :zap: Added FluentIcons to SkEditor & enhanced element's icons * :zap: A Lot of cleanup (Notro will be happy now XD) * :zap: Replaced ivon of doc management entry by a text * :zap: Replaced icon from Avalonia to FluentIcons * :bug: Fixed wrong size of the delete button * Fix experiments settings page title, change warning * Remove code unparsed info from the code parser * :sparkles: Added much better download buttons for doc elements * :sparkles: Added bunch-download for elements * :zap: Fixed doc provider type in the local doc manager * :sparkles: Added lang to the new documentation system * change selection color in documentation editors * :sparkles: Added colors to doc entry's icon + better addon badge color/link * Make loading addons a little bit faster * make loading addons a little bit faster * Move doc pattern syntax logic to its own class * cleanup * Refactor GetTypeIcon method * update libs --------- Co-authored-by: Sky Co-authored-by: Sky <50667548+ItsTheSky@users.noreply.github.com> --- Installer/Package.wxs | 2 +- SkEditor/API/AddonLoader.cs | 34 +- SkEditor/App.axaml | 1 + SkEditor/Assets/Brands/Pastebin.svg | 10 + SkEditor/Assets/Brands/SkriptHub.svg | 30 ++ SkEditor/Assets/Brands/SkriptMC.png | Bin 0 -> 1598 bytes SkEditor/Assets/Brands/skUnity.svg | 8 + SkEditor/Assets/Brands/skriptpl.svg | 1 + SkEditor/Assets/Icons.axaml | 1 + SkEditor/Assets/ThemeColors.axaml | 40 ++ .../Controls/ConnectionEntryControl.axaml | 27 + .../Controls/ConnectionEntryControl.axaml.cs | 57 +++ .../Controls/Docs/DocElementControl.axaml | 94 ++++ .../Controls/Docs/DocElementControl.axaml.cs | 465 ++++++++++++++++++ .../Controls/Docs/DocManagementEntry.axaml | 16 + .../Controls/Docs/DocManagementEntry.axaml.cs | 42 ++ .../Controls/Docs/DocumentationControl.axaml | 97 ++++ .../Docs/DocumentationControl.axaml.cs | 303 ++++++++++++ SkEditor/Controls/MainMenuControl.axaml | 2 +- SkEditor/Controls/MainMenuControl.axaml.cs | 17 + .../Sidebar/ParserSidebarPanel.axaml.cs | 18 +- SkEditor/Languages/Chinese.xaml | 1 - SkEditor/Languages/English.xaml | 76 ++- SkEditor/Languages/French.xaml | 2 - SkEditor/Languages/German.xaml | 1 - SkEditor/Languages/Hungarian.xaml | 1 - SkEditor/Languages/Korean.xaml | 1 - SkEditor/Languages/Magyar.xaml | 1 - SkEditor/Languages/Polish.xaml | 5 +- SkEditor/Languages/Russian.xaml | 1 - SkEditor/Languages/Spanish.xaml | 1 - SkEditor/SkEditor.csproj | 22 +- SkEditor/Utilities/AppConfig.cs | 51 +- SkEditor/Utilities/Docs/DocProvider.cs | 9 + SkEditor/Utilities/Docs/DocSyntaxColorizer.cs | 97 ++++ .../Utilities/Docs/HttpClientExtensions.cs | 23 + SkEditor/Utilities/Docs/IDocProvider.cs | 40 ++ .../Utilities/Docs/IDocumentationEntry.cs | 112 +++++ .../Utilities/Docs/IDocumentationExample.cs | 10 + .../Utilities/Docs/Local/LocalDocEntry.cs | 61 +++ .../Utilities/Docs/Local/LocalDocExample.cs | 20 + .../Utilities/Docs/Local/LocalProvider.cs | 147 ++++++ SkEditor/Utilities/Docs/SearchData.cs | 12 + .../Utilities/Docs/SkUnity/SkUnityDocEntry.cs | 53 ++ .../Docs/SkUnity/SkUnityDocExample.cs | 15 + .../Utilities/Docs/SkUnity/SkUnityProvider.cs | 216 ++++++++ .../Docs/SkriptHub/SkriptHubDocEntry.cs | 64 +++ .../Docs/SkriptHub/SkriptHubDocExample.cs | 15 + .../Docs/SkriptHub/SkriptHubProvider.cs | 191 +++++++ .../Docs/SkriptMC/SkriptMCDocEntry.cs | 54 ++ .../Docs/SkriptMC/SkriptMCDocExample.cs | 18 + .../Docs/SkriptMC/SkriptMCProvider.cs | 102 ++++ .../Editor/TextEditorEventHandler.cs | 45 +- SkEditor/Utilities/Files/FileBuilder.cs | 5 +- SkEditor/Utilities/Files/FileCloser.cs | 5 +- SkEditor/Utilities/Files/FileHandler.cs | 1 - SkEditor/Utilities/Files/SessionRestorer.cs | 7 +- SkEditor/Utilities/Parser/CodeParser.cs | 2 +- SkEditor/Utilities/Parser/CodeSection.cs | 44 +- SkEditor/Utilities/Projects/ProjectOpener.cs | 1 - SkEditor/Utilities/Syntax/FileSyntax.cs | 37 +- SkEditor/Utilities/Syntax/SyntaxLoader.cs | 32 +- SkEditor/ViewModels/DocumentationViewModel.cs | 12 + SkEditor/ViewModels/SettingsViewModel.cs | 1 + SkEditor/Views/LocalDocsManagerWindow.axaml | 47 ++ .../Views/LocalDocsManagerWindow.axaml.cs | 155 ++++++ SkEditor/Views/MainWindow.axaml.cs | 4 +- SkEditor/Views/PublishWindow.axaml | 9 +- SkEditor/Views/PublishWindow.axaml.cs | 6 +- SkEditor/Views/Settings/ConnectionsPage.axaml | 17 + .../Views/Settings/ConnectionsPage.axaml.cs | 37 ++ SkEditor/Views/Settings/ExperimentsPage.axaml | 6 +- .../Views/Settings/ExperimentsPage.axaml.cs | 1 + SkEditor/Views/Settings/GeneralPage.axaml | 21 +- SkEditor/Views/Settings/GeneralPage.axaml.cs | 9 +- SkEditor/Views/Settings/HomePage.axaml | 4 + SkEditor/Views/Settings/HomePage.axaml.cs | 1 + .../Personalization/FileSyntaxes.axaml.cs | 1 - 78 files changed, 3033 insertions(+), 164 deletions(-) create mode 100644 SkEditor/Assets/Brands/Pastebin.svg create mode 100644 SkEditor/Assets/Brands/SkriptHub.svg create mode 100644 SkEditor/Assets/Brands/SkriptMC.png create mode 100644 SkEditor/Assets/Brands/skUnity.svg create mode 100644 SkEditor/Assets/Brands/skriptpl.svg create mode 100644 SkEditor/Assets/ThemeColors.axaml create mode 100644 SkEditor/Controls/ConnectionEntryControl.axaml create mode 100644 SkEditor/Controls/ConnectionEntryControl.axaml.cs create mode 100644 SkEditor/Controls/Docs/DocElementControl.axaml create mode 100644 SkEditor/Controls/Docs/DocElementControl.axaml.cs create mode 100644 SkEditor/Controls/Docs/DocManagementEntry.axaml create mode 100644 SkEditor/Controls/Docs/DocManagementEntry.axaml.cs create mode 100644 SkEditor/Controls/Docs/DocumentationControl.axaml create mode 100644 SkEditor/Controls/Docs/DocumentationControl.axaml.cs create mode 100644 SkEditor/Utilities/Docs/DocProvider.cs create mode 100644 SkEditor/Utilities/Docs/DocSyntaxColorizer.cs create mode 100644 SkEditor/Utilities/Docs/HttpClientExtensions.cs create mode 100644 SkEditor/Utilities/Docs/IDocProvider.cs create mode 100644 SkEditor/Utilities/Docs/IDocumentationEntry.cs create mode 100644 SkEditor/Utilities/Docs/IDocumentationExample.cs create mode 100644 SkEditor/Utilities/Docs/Local/LocalDocEntry.cs create mode 100644 SkEditor/Utilities/Docs/Local/LocalDocExample.cs create mode 100644 SkEditor/Utilities/Docs/Local/LocalProvider.cs create mode 100644 SkEditor/Utilities/Docs/SearchData.cs create mode 100644 SkEditor/Utilities/Docs/SkUnity/SkUnityDocEntry.cs create mode 100644 SkEditor/Utilities/Docs/SkUnity/SkUnityDocExample.cs create mode 100644 SkEditor/Utilities/Docs/SkUnity/SkUnityProvider.cs create mode 100644 SkEditor/Utilities/Docs/SkriptHub/SkriptHubDocEntry.cs create mode 100644 SkEditor/Utilities/Docs/SkriptHub/SkriptHubDocExample.cs create mode 100644 SkEditor/Utilities/Docs/SkriptHub/SkriptHubProvider.cs create mode 100644 SkEditor/Utilities/Docs/SkriptMC/SkriptMCDocEntry.cs create mode 100644 SkEditor/Utilities/Docs/SkriptMC/SkriptMCDocExample.cs create mode 100644 SkEditor/Utilities/Docs/SkriptMC/SkriptMCProvider.cs create mode 100644 SkEditor/ViewModels/DocumentationViewModel.cs create mode 100644 SkEditor/Views/LocalDocsManagerWindow.axaml create mode 100644 SkEditor/Views/LocalDocsManagerWindow.axaml.cs create mode 100644 SkEditor/Views/Settings/ConnectionsPage.axaml create mode 100644 SkEditor/Views/Settings/ConnectionsPage.axaml.cs diff --git a/Installer/Package.wxs b/Installer/Package.wxs index 947a3934..3740ee5a 100644 --- a/Installer/Package.wxs +++ b/Installer/Package.wxs @@ -1,6 +1,6 @@  - + diff --git a/SkEditor/API/AddonLoader.cs b/SkEditor/API/AddonLoader.cs index 944a3291..59310981 100644 --- a/SkEditor/API/AddonLoader.cs +++ b/SkEditor/API/AddonLoader.cs @@ -1,12 +1,15 @@ +using Avalonia.Threading; using Serilog; using SkEditor.Utilities; using SkEditor.Views; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; +using System.Threading.Tasks; namespace SkEditor.API; public class AddonLoader @@ -87,19 +90,32 @@ private static void EnableAddons() { try { - AppDomain.CurrentDomain.GetAssemblies() + var addonTypes = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(s => s.GetTypes()) .Where(p => typeof(IAddon).IsAssignableFrom(p) && p.IsClass && !p.IsAbstract) - .Select(addonType => (IAddon)Activator.CreateInstance(addonType)) - .ToList() - .ForEach(addon => + .ToList(); + + var addons = new ConcurrentBag(); + + Parallel.ForEach(addonTypes, addonType => + { + try { - Addons.Add(addon); - addon.OnEnable(); - }); + var addon = (IAddon)Activator.CreateInstance(addonType); + addons.Add(addon); + Dispatcher.UIThread.InvokeAsync(() => addon.OnEnable()); + } + catch (Exception ex) + { + Log.Error(ex, $"Failed to initialize addon {addonType.Name}"); + } + }); + + Addons.AddRange(addons); - ApiVault.Get().GetAppConfig().AddonsToDelete.Clear(); - ApiVault.Get().GetAppConfig().AddonsToUpdate.Clear(); + var apiVault = ApiVault.Get(); + apiVault.GetAppConfig().AddonsToDelete.Clear(); + apiVault.GetAppConfig().AddonsToUpdate.Clear(); } catch (Exception ex) { diff --git a/SkEditor/App.axaml b/SkEditor/App.axaml index 28d08b4d..10fbcefb 100644 --- a/SkEditor/App.axaml +++ b/SkEditor/App.axaml @@ -11,6 +11,7 @@ + diff --git a/SkEditor/Assets/Brands/Pastebin.svg b/SkEditor/Assets/Brands/Pastebin.svg new file mode 100644 index 00000000..e6ed001c --- /dev/null +++ b/SkEditor/Assets/Brands/Pastebin.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/SkEditor/Assets/Brands/SkriptHub.svg b/SkEditor/Assets/Brands/SkriptHub.svg new file mode 100644 index 00000000..9d9dd26c --- /dev/null +++ b/SkEditor/Assets/Brands/SkriptHub.svg @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SkEditor/Assets/Brands/SkriptMC.png b/SkEditor/Assets/Brands/SkriptMC.png new file mode 100644 index 0000000000000000000000000000000000000000..3d15fd37232a4c73328fd9454fc7e696ec8353f0 GIT binary patch literal 1598 zcmV-E2EqA>P)d|TQQa*HxRA$n|!%}*`zb~;u8!TIW#x$OxD?Q19Jn< zM()f^z)Nfv1Ug#W1 z^Kwi?>N6su0TJDIJfpv zH{v|wNCNCu5nB~mGBbU-lYkp@p0S7iP^oiRWXYiIi+2u#EpE(t!sfie-(PKCv_`-c zZ+N~?8{~sYM70utRQKDJITC{3iRinw>|i7S>%O{@JRbvFY>W*OzG@kK_60dl*uz$s z*b_7&0NVbq*Rb*eXhec30-_WdSBm$D?juejAk9maJOB8C31ECEvP5Z{Mg&Y>&!&sw z80E(Zzy|U6|G|6UQB{yK0v=w~oXg|juZ)1r4NBg=cz1{Zg#WENzwhzeF)x8hBx5d( zPv|0t;z+>g7M(A$L}jh7dyFyUa`=`A=+y(%aNkx7Tr1X)veDG4OGD%upiYfuEsn1p zPMvO+0Gs1caE%1iXv59*?rsYpNrEHzTZCq6VQuAN36xOc5t|gaM-D$ z<(JSOGXXwgVp(L#Q8+2C!W1g)}dB4o%u6AA_OP{n6o>k5UP)Enj3TgwumGFQ+J@RTK3m1N$FAPB1XD zE*)xhE9Enm$im_K3M)x~%Q{}se<4}H>8>)mZ=+?1$&sJB<-2NWkYg&X6s3N$J~G;xQ>LSudw{=W-{C^-^<3?da&R^|64&eq&*DjF2q`!} z5#Miv+RP86>E{AN;Z&tP^zbn4{@=(W_wI3_$vQhCo%!VSHK#;*w@?r=Zp%(C7bMtW zeUMPJ-sO?`z9(w!ZsAV5$2et@OlO1gi>@iC7PmWP^zhP{XfxW-2O#>h_^&-2sKoLc zh%rYVjodB9TId<#K!6Z34<3Wo5FSnyoMCo#-7yp-J!6)vdq&{x)RS`i%{M>)>3bgV zj30aJee%2u^r<9$iEwF()-Y-k z>7ue#ruHqP)v`gR8Di3`xWi^+V`>u6rLlq6buAR$5cRxEJ>mrHACs;lzdOE5Cw5w0 z2*p-*Oy=?OA~HZoL&F8S{Y%(z$Ru|~mYftT$OzJyQC~f;fmNam^>fN+sY>^_E@!r&X!98~B zzTh!U4UQuLrVEV$koFsA-%5ZX3WA%Pio7&0SJ3NQ69I^bN6eZkyJw+9V6vpzZ0$~W z-4@p?w0Ayg5MekKLZtJx7OiLsdNB%Qb4Ib&7B2k&IoPwV8!S%D#4Ie~gppMd-3Qk^3YN@_@Io@J}HLAq> zL9Al;IGwWE;PcXy{{FxcYHo5)#|^gVL~J3e^{&&S%f$+x*XBmpy-k(X*&R37qZ7gK wx+W-In literal 0 HcmV?d00001 diff --git a/SkEditor/Assets/Brands/skUnity.svg b/SkEditor/Assets/Brands/skUnity.svg new file mode 100644 index 00000000..4ade28e2 --- /dev/null +++ b/SkEditor/Assets/Brands/skUnity.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/SkEditor/Assets/Brands/skriptpl.svg b/SkEditor/Assets/Brands/skriptpl.svg new file mode 100644 index 00000000..d7108872 --- /dev/null +++ b/SkEditor/Assets/Brands/skriptpl.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/SkEditor/Assets/Icons.axaml b/SkEditor/Assets/Icons.axaml index 3330b30a..13df8441 100644 --- a/SkEditor/Assets/Icons.axaml +++ b/SkEditor/Assets/Icons.axaml @@ -46,6 +46,7 @@ + diff --git a/SkEditor/Assets/ThemeColors.axaml b/SkEditor/Assets/ThemeColors.axaml new file mode 100644 index 00000000..da825303 --- /dev/null +++ b/SkEditor/Assets/ThemeColors.axaml @@ -0,0 +1,40 @@ + + + + #952923 + #C2362E + #F44336 + #D65A5A + #AA2A2A + #E91E63 + #9C27B0 + #673AB7 + #3F51B5 + #1A72BD + #AA1A72BD + #2196F3 + #AA2196F3 + #03A9F4 + #AA03A9F4 + #00BCD4 + #009688 + #2C582C + #3A783C + #4BA04F + #AA4BA04F + #6CCB5F + #8BC34A + #CDDC39 + #FFEB3B + #FFC107 + #FF9800 + #FF5722 + #FF4F00 + #795548 + #9E9E9E + #C0C0C0 + #607D8B + + \ No newline at end of file diff --git a/SkEditor/Controls/ConnectionEntryControl.axaml b/SkEditor/Controls/ConnectionEntryControl.axaml new file mode 100644 index 00000000..ef3c8dcd --- /dev/null +++ b/SkEditor/Controls/ConnectionEntryControl.axaml @@ -0,0 +1,27 @@ + + + + + + + + + + diff --git a/SkEditor/Controls/ConnectionEntryControl.axaml.cs b/SkEditor/Controls/ConnectionEntryControl.axaml.cs new file mode 100644 index 00000000..66470037 --- /dev/null +++ b/SkEditor/Controls/ConnectionEntryControl.axaml.cs @@ -0,0 +1,57 @@ +using Avalonia.Controls; +using Avalonia.Media.Imaging; +using Avalonia.Platform; +using Avalonia.Svg.Skia; +using FluentAvalonia.UI.Controls; +using SkEditor.API; +using System; +using System.Diagnostics; +using System.IO; + +namespace SkEditor.Controls; + +public partial class ConnectionEntryControl : UserControl +{ + + public ConnectionEntryControl(string name, string icon, string url, string key, + string? description = null) + { + InitializeComponent(); + + Expander.Header = name; + Expander.Description = description ?? ""; + + OpenDashboardButton.Click += (_, _) => + { + Process.Start(new ProcessStartInfo(url) + { + UseShellExecute = true + }); + }; + + ApiKeyTextBox.Text = ApiVault.Get().GetAppConfig().GetOptionValue(key); + ApiKeyTextBox.TextChanged += (_, _) => + { + ApiVault.Get().GetAppConfig().SetOptionValue(key, ApiKeyTextBox.Text); + }; + + Stream stream = AssetLoader.Open(new Uri("avares://SkEditor/Assets/Brands/" + icon)); + Expander.IconSource = new ImageIconSource() + { + Source = icon.EndsWith(".svg") ? LoadSvgIcon(stream) : LoadPngIcon(stream) + }; + } + + private static SvgImage LoadSvgIcon(Stream stream) + { + return new SvgImage + { + Source = SvgSource.LoadFromStream(stream) + }; + } + + private static Bitmap LoadPngIcon(Stream stream) + { + return new Bitmap(stream); + } +} \ No newline at end of file diff --git a/SkEditor/Controls/Docs/DocElementControl.axaml b/SkEditor/Controls/Docs/DocElementControl.axaml new file mode 100644 index 00000000..66339c36 --- /dev/null +++ b/SkEditor/Controls/Docs/DocElementControl.axaml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SkEditor/Views/LocalDocsManagerWindow.axaml.cs b/SkEditor/Views/LocalDocsManagerWindow.axaml.cs new file mode 100644 index 00000000..ceaa1872 --- /dev/null +++ b/SkEditor/Views/LocalDocsManagerWindow.axaml.cs @@ -0,0 +1,155 @@ +using Avalonia.Controls; +using Avalonia.Layout; +using CommunityToolkit.Mvvm.Input; +using FluentAvalonia.UI.Controls; +using FluentAvalonia.UI.Windowing; +using SkEditor.Controls.Docs; +using SkEditor.Utilities.Docs; +using SkEditor.Utilities.Docs.Local; +using System.Linq; + +namespace SkEditor.Views; + +public partial class LocalDocsManagerWindow : AppWindow +{ + public enum GroupBy + { + Provider, + Type, + Addon + } + + public LocalDocsManagerWindow() + { + InitializeComponent(); + + AssignCommands(); + LoadCategories(GroupBy.Provider); + } + + public void AssignCommands() + { + GroupByComboBox.SelectionChanged += (sender, args) => + { + var groupBy = (GroupBy)GroupByComboBox.SelectedIndex; + LoadCategories(groupBy); + }; + DeleteEverythingButton.Command = new RelayCommand(async () => + { + await LocalProvider.Get().DeleteAll(); + LoadCategories(GroupBy.Provider); + }); + } + + public void LoadCategories(GroupBy groupBy) + { + GroupByComboBox.SelectedIndex = (int)groupBy; + switch (groupBy) + { + case GroupBy.Provider: + LoadByProviders(); + break; + case GroupBy.Type: + LoadByTypes(); + break; + case GroupBy.Addon: + LoadByAddons(); + break; + } + } + + #region Loaders + + public async void LoadByProviders() + { + var elements = await LocalProvider.Get().GetElements(); + var providers = elements.Select(x => x.OriginalProvider).Distinct().ToList(); + var providerGroups = providers.Select(x => elements.FindAll(y => y.OriginalProvider == x)).ToList(); + + CategoriesPanel.Children.Clear(); + + foreach (var providerGroup in providerGroups) + { + var provider = providerGroup.First().OriginalProvider; + var expander = CreateExpander(provider.ToString(), + IDocProvider.Providers[provider].Icon, providerGroup.Count); + + foreach (var element in providerGroup) + { + var entry = new DocManagementEntry(element); + expander.Items.Add(entry); + } + + CategoriesPanel.Children.Add(expander); + } + } + + public async void LoadByTypes() + { + var elements = await LocalProvider.Get().GetElements(); + var types = elements.Select(x => x.DocType).Distinct().ToList(); + var typeGroups = types.Select(x => elements.FindAll(y => y.DocType == x)).ToList(); + + CategoriesPanel.Children.Clear(); + + foreach (var typeGroup in typeGroups) + { + var type = typeGroup.First().DocType; + var expander = CreateExpander(type.ToString(), + IDocumentationEntry.GetTypeIcon(type), typeGroup.Count); + + foreach (var element in typeGroup) + { + var entry = new DocManagementEntry(element); + expander.Items.Add(entry); + } + + CategoriesPanel.Children.Add(expander); + } + } + + public async void LoadByAddons() + { + var elements = await LocalProvider.Get().GetElements(); + var addons = elements.Select(x => x.Addon).Distinct().ToList(); + var addonGroups = addons.Select(x => elements.FindAll(y => y.Addon == x)).ToList(); + + CategoriesPanel.Children.Clear(); + + foreach (var addonGroup in addonGroups) + { + var addon = addonGroup.First().Addon; + var expander = CreateExpander(addon, + null, addonGroup.Count); + + foreach (var element in addonGroup) + { + var entry = new DocManagementEntry(element); + expander.Items.Add(entry); + } + + CategoriesPanel.Children.Add(expander); + } + } + + public SettingsExpander CreateExpander(string categoryName, IconSource? icon, int elementAmount) + { + return new SettingsExpander() + { + Header = new StackPanel() + { + Orientation = Orientation.Horizontal, + Spacing = 5, + Children = + { + new TextBlock { Text = categoryName }, + new InfoBadge { Value = elementAmount } + } + }, + IconSource = icon + }; + } + + + #endregion +} \ No newline at end of file diff --git a/SkEditor/Views/MainWindow.axaml.cs b/SkEditor/Views/MainWindow.axaml.cs index df535549..bbd2d488 100644 --- a/SkEditor/Views/MainWindow.axaml.cs +++ b/SkEditor/Views/MainWindow.axaml.cs @@ -80,8 +80,8 @@ private async void OnClosing(object sender, WindowClosingEventArgs e) ContentDialogResult result = await ApiVault.Get().ShowMessageWithIcon(Translation.Get("Attention"), Translation.Get("ClosingProgramWithUnsavedFiles"), new SymbolIconSource() { Symbol = Symbol.ImportantFilled }); if (result == ContentDialogResult.Primary) { - unsavedFiles.ForEach(item => item.Header = item.Header.ToString().TrimEnd('*')); - e.Cancel = false; + AlreadyClosed = true; + Close(); } } else diff --git a/SkEditor/Views/PublishWindow.axaml b/SkEditor/Views/PublishWindow.axaml index 7b9a2f0a..b4787f7e 100644 --- a/SkEditor/Views/PublishWindow.axaml +++ b/SkEditor/Views/PublishWindow.axaml @@ -15,8 +15,13 @@ - - + + diff --git a/SkEditor/Views/PublishWindow.axaml.cs b/SkEditor/Views/PublishWindow.axaml.cs index b355b4ba..081df4d7 100644 --- a/SkEditor/Views/PublishWindow.axaml.cs +++ b/SkEditor/Views/PublishWindow.axaml.cs @@ -23,8 +23,6 @@ private void InitializeUI() TitleBar.ExtendsContentIntoTitleBar = false; PublishButton.Command = new RelayCommand(Publish); - ApiKeyHint.Tapped += (sender, e) => OpenSiteWithApiKey(); - ApiKeyTextBox.TextChanged += (sender, e) => SaveApiKey(); CopyButton.Command = new RelayCommand(async () => await Clipboard.SetTextAsync(ResultTextBox.Text)); @@ -48,7 +46,7 @@ private void UpdateServiceInfo() { "Pastebin" => appConfig.PastebinApiKey, "code.skript.pl" => appConfig.CodeSkriptPlApiKey, - "skUnity Parser" => appConfig.SkunityApiKey, + "skUnity Parser" => appConfig.SkUnityAPIKey, _ => "", }; @@ -68,7 +66,7 @@ private void SaveApiKey() ApiVault.Get().GetAppConfig().CodeSkriptPlApiKey = ApiKeyTextBox.Text; break; case "skUnity Parser": - ApiVault.Get().GetAppConfig().SkunityApiKey = ApiKeyTextBox.Text; + ApiVault.Get().GetAppConfig().SkUnityAPIKey = ApiKeyTextBox.Text; break; } } diff --git a/SkEditor/Views/Settings/ConnectionsPage.axaml b/SkEditor/Views/Settings/ConnectionsPage.axaml new file mode 100644 index 00000000..8d223fba --- /dev/null +++ b/SkEditor/Views/Settings/ConnectionsPage.axaml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/SkEditor/Views/Settings/ConnectionsPage.axaml.cs b/SkEditor/Views/Settings/ConnectionsPage.axaml.cs new file mode 100644 index 00000000..a57582a2 --- /dev/null +++ b/SkEditor/Views/Settings/ConnectionsPage.axaml.cs @@ -0,0 +1,37 @@ +using Avalonia.Controls; +using CommunityToolkit.Mvvm.Input; +using SkEditor.Controls; + +namespace SkEditor.Views.Settings; + +public partial class ConnectionsPage : UserControl +{ + public ConnectionsPage() + { + InitializeComponent(); + + AssignCommands(); + } + + public void AssignCommands() + { + Title.BackButton.Command = new RelayCommand(() => SettingsWindow.NavigateToPage(typeof(HomePage))); + + SetupEntry("skUnity", "https://skunity.com/dashboard/skunity-api", "SkUnityAPIKey", + "Used as a documentation provider and a script host (via skUnity Parser)", "skUnity.svg"); + SetupEntry("SkriptHub", "https://skripthub.net/dashboard/api/", "SkriptHubAPIKey", + "Used as a documentation provider", "SkriptHub.svg"); + SetupEntry("SkriptMC", "https://skript-mc.fr/developer/", "SkriptMCAPIKey", + "Used as a documentation provider"); + SetupEntry("skript.pl", "https://code.skript.pl/api-key", "CodeSkriptPlApiKey", + "Used as a script host", "skriptpl.svg"); + SetupEntry("Pastebin", "https://pastebin.com/doc_api", "PastebinApiKey", + "Used as a script host", "Pastebin.svg"); + } + + public void SetupEntry(string name, string url, string key, string description, string? icon = null) + { + icon ??= name + ".png"; + ElementsPanel.Children.Add(new ConnectionEntryControl(name, icon, url, key, description)); + } +} \ No newline at end of file diff --git a/SkEditor/Views/Settings/ExperimentsPage.axaml b/SkEditor/Views/Settings/ExperimentsPage.axaml index 3bcc0c56..73aaacf9 100644 --- a/SkEditor/Views/Settings/ExperimentsPage.axaml +++ b/SkEditor/Views/Settings/ExperimentsPage.axaml @@ -9,11 +9,11 @@ x:Class="SkEditor.Views.Settings.ExperimentsPage"> - - + + - + diff --git a/SkEditor/Views/Settings/ExperimentsPage.axaml.cs b/SkEditor/Views/Settings/ExperimentsPage.axaml.cs index d8b1796a..047ee83f 100644 --- a/SkEditor/Views/Settings/ExperimentsPage.axaml.cs +++ b/SkEditor/Views/Settings/ExperimentsPage.axaml.cs @@ -15,6 +15,7 @@ public partial class ExperimentsPage : UserControl new Experiment("Projects", "Adds a sidebar for managing projects.", "EnableProjectsExperiment", "Folder"), new Experiment("Hex Preview", "Preview hex colors in the editor.", "EnableHexPreview", "ColorIcon"), new Experiment("Code Parser", "Parse code for informations. Doesn't contain error checking, see Analyzer addon instead. Requires Projects experiment.", "EnableCodeParser", "SearchIcon", Dependency: "EnableProjectsExperiment"), + new Experiment("Real-Time Code Parser", "Automatically parses your code with every change you make. Requires Code Parser experiment.", "EnableRealtimeCodeParser", "SearchIcon", Dependency: "EnableCodeParser"), new Experiment("Folding", "Folding code blocks. Requires Code Parser experiment.", "EnableFolding", "FoldingIcon", Dependency: "EnableCodeParser"), //new Experiment("Better pairing", "Experimental better version of auto pairing.", "EnableBetterPairing", "AutoPairingIcon"), new Experiment("Session restoring", "Automatically saves your files and reopens it next time you start the app.", "EnableSessionRestoring", "SessionRestoringIcon") diff --git a/SkEditor/Views/Settings/GeneralPage.axaml b/SkEditor/Views/Settings/GeneralPage.axaml index 382133fd..a1634e29 100644 --- a/SkEditor/Views/Settings/GeneralPage.axaml +++ b/SkEditor/Views/Settings/GeneralPage.axaml @@ -4,8 +4,9 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ui="using:FluentAvalonia.UI.Controls" xmlns:controls="using:SkEditor.Controls" - xmlns:vm="using:SkEditor.ViewModels" - 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.GeneralPage"> @@ -29,8 +30,8 @@ - - + + 1 @@ -56,6 +57,16 @@ + + + + + + + + + @@ -70,7 +81,7 @@ + Description="{DynamicResource SettingsGeneralRpcDescription}"> diff --git a/SkEditor/Views/Settings/GeneralPage.axaml.cs b/SkEditor/Views/Settings/GeneralPage.axaml.cs index 678b9bc2..90597815 100644 --- a/SkEditor/Views/Settings/GeneralPage.axaml.cs +++ b/SkEditor/Views/Settings/GeneralPage.axaml.cs @@ -5,7 +5,6 @@ using FluentAvalonia.UI.Controls; using SkEditor.API; using SkEditor.Utilities; -using SkEditor.ViewModels; using System.Collections.Generic; using System.IO; using System.Linq; @@ -17,7 +16,7 @@ public GeneralPage() { InitializeComponent(); - DataContext = new SettingsViewModel(); + DataContext = ApiVault.Get().GetAppConfig(); AssignCommands(); LoadLanguages(); @@ -70,11 +69,7 @@ private void AssignCommands() Title.BackButton.Command = new RelayCommand(() => SettingsWindow.NavigateToPage(typeof(HomePage))); RpcToggleSwitch.Command = new RelayCommand(ToggleRpc); WrappingToggleSwitch.Command = new RelayCommand(ToggleWrapping); - AutoIndentToggleSwitch.Command = new RelayCommand(() => ToggleSetting("IsAutoIndentEnabled")); - AutoPairingToggleSwitch.Command = new RelayCommand(() => ToggleSetting("IsAutoPairingEnabled")); - AutoSaveToggleSwitch.Command = new RelayCommand(() => ToggleSetting("IsAutoSaveEnabled")); - CheckForUpdatesToggleSwitch.Command = new RelayCommand(() => ToggleSetting("CheckForUpdates")); - CheckForChangesToggleSwitch.Command = new RelayCommand(() => ToggleSetting("CheckForChanges")); + IndentationAmountComboBox.SelectionChanged += (s, e) => { var appConfig = ApiVault.Get().GetAppConfig(); diff --git a/SkEditor/Views/Settings/HomePage.axaml b/SkEditor/Views/Settings/HomePage.axaml index ffb1ac0d..2e96359d 100644 --- a/SkEditor/Views/Settings/HomePage.axaml +++ b/SkEditor/Views/Settings/HomePage.axaml @@ -23,6 +23,10 @@ + + SettingsWindow.NavigateToPage(typeof(ExperimentsPage))); AboutItem.Command = new RelayCommand(() => SettingsWindow.NavigateToPage(typeof(AboutPage))); AddonsItem.Command = new RelayCommand(() => SettingsWindow.NavigateToPage(typeof(AddonsPage))); + ConnectionsItem.Command = new RelayCommand(() => SettingsWindow.NavigateToPage(typeof(ConnectionsPage))); } } diff --git a/SkEditor/Views/Settings/Personalization/FileSyntaxes.axaml.cs b/SkEditor/Views/Settings/Personalization/FileSyntaxes.axaml.cs index f92a9198..cef5ae89 100644 --- a/SkEditor/Views/Settings/Personalization/FileSyntaxes.axaml.cs +++ b/SkEditor/Views/Settings/Personalization/FileSyntaxes.axaml.cs @@ -2,7 +2,6 @@ using AvaloniaEdit; using CommunityToolkit.Mvvm.Input; using FluentAvalonia.UI.Controls; -using Microsoft.CodeAnalysis; using SkEditor.API; using SkEditor.Utilities.Syntax; using System.Collections.Generic;