From 6dff9b87183a93430b020a835044aa0a8f8a5197 Mon Sep 17 00:00:00 2001 From: Creeper Lv Date: Sun, 18 Jan 2026 01:52:22 +1100 Subject: [PATCH] Editor now loads the first project in open folder. --- Progrart.Core/ProjectSystem/Builder.cs | 1 - Progrart/App.axaml.cs | 10 ++++- Progrart/Views/MainView.axaml | 11 ++++- Progrart/Views/MainView.axaml.cs | 59 ++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/Progrart.Core/ProjectSystem/Builder.cs b/Progrart.Core/ProjectSystem/Builder.cs index d67979c..97c5fbe 100644 --- a/Progrart.Core/ProjectSystem/Builder.cs +++ b/Progrart.Core/ProjectSystem/Builder.cs @@ -1,7 +1,6 @@ using Newtonsoft.Json; using Progrart.Core.JSExecution; using Progrart.Core.Storage; -using System.Diagnostics; namespace Progrart.Core.ProjectSystem { diff --git a/Progrart/App.axaml.cs b/Progrart/App.axaml.cs index 23e44e4..0e6ed25 100644 --- a/Progrart/App.axaml.cs +++ b/Progrart/App.axaml.cs @@ -8,6 +8,8 @@ using Progrart.Views; using Progrart.Icons; using Progrart.Pages; using Avalonia.Platform.Storage; +using System; +using Progrart.Core.ProjectSystem; namespace Progrart; @@ -15,6 +17,12 @@ public partial class App : Application { public static bool isDesktop = false; public static IStorageFolder? CurrentOpenFolder = null; + public static Project? LoadedProject = null; + internal static Action? ProjectLoadHandler = null; + public static void ProjectLoad() + { + ProjectLoadHandler?.Invoke(); + } public override void Initialize() { AvaloniaXamlLoader.Load(this); @@ -27,7 +35,7 @@ public partial class App : Application EditorProvider.Register("image", "Default Image Viewer", typeof(ImageViewPage)); EditorProvider.Register("progrart", "Default Progrart Editor", typeof(ProgrartEditorPage)); EditorProvider.Register("project", "Progrart Project Editor", typeof(ProjectEditor)); - EditorProvider.Register("console", "Console", typeof(Console)); + EditorProvider.Register("console", "Console", typeof(Pages.Console)); EditorProvider.BindFileType("cs", "text"); EditorProvider.BindFileType("c", "text"); EditorProvider.BindFileType("cpp", "text"); diff --git a/Progrart/Views/MainView.axaml b/Progrart/Views/MainView.axaml index 67c521a..e59f25c 100644 --- a/Progrart/Views/MainView.axaml +++ b/Progrart/Views/MainView.axaml @@ -133,7 +133,7 @@ All - @@ -207,6 +207,15 @@ + + + + + + + + + diff --git a/Progrart/Views/MainView.axaml.cs b/Progrart/Views/MainView.axaml.cs index 18b50bb..4c4c4a0 100644 --- a/Progrart/Views/MainView.axaml.cs +++ b/Progrart/Views/MainView.axaml.cs @@ -8,11 +8,13 @@ using Progrart.Controls; using Progrart.Core; using Progrart.Core.JSExecution; using Progrart.Core.ProjectSystem; +using Progrart.Core.Storage; using Progrart.Pages; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Threading; using System.Threading.Tasks; namespace Progrart.Views; @@ -106,6 +108,18 @@ public partial class MainView : UserControl var folder = folders[0]; App.CurrentOpenFolder = folder; FileContainer.Children.Add(new FileItem(folder)); + await foreach (var item in folder.GetItemsAsync()) + { + if (item.Name.ToLower().EndsWith(".progrart-project", StringComparison.OrdinalIgnoreCase)) + { + using var stream = await (item as IStorageFile)!.OpenReadAsync(); + using var reader = new StreamReader(stream); + var txt = await reader.ReadToEndAsync(); + App.LoadedProject = JsonConvert.DeserializeObject(txt); + App.ProjectLoad(); + break; + } + } } }; FileExplorerCloseButton.Click += (_, _) => @@ -117,6 +131,18 @@ public partial class MainView : UserControl { Execute(); }; + + ConfigBox.Items.Clear(); + App.ProjectLoadHandler = () => + { + ConfigBox.Items.Clear(); + if (App.LoadedProject is null) return; + foreach (var item in App.LoadedProject.Configurations) + { + ConfigBox.Items.Add(item.Name); + } + ConfigBox.SelectedIndex = 0; + }; } private void Execute() @@ -208,4 +234,37 @@ public partial class MainView : UserControl await stream_writer.WriteAsync(txt); await stream.FlushAsync(); } + + private void BuildButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + if (App.LoadedProject is not null) + { + Builder builder = new Builder(App.LoadedProject, new AvaloniaStorageProvider(App.CurrentOpenFolder)); + var config = App.LoadedProject.Configurations[ConfigBox.SelectedIndex]; + var name = config.Name; + if (config is null) return; + if (name is null) return; + int sum = 0; + int max = config.Items.Count; + ProgressGrid.IsVisible = true; + MainProgress.Value = sum; + MainProgress.Maximum= max; + builder.OnProgressUpdate = (a, b) => + { + Interlocked.Increment(ref sum); + Dispatcher.UIThread.Invoke(() => + { + MainProgress.Value = sum; + }); + }; + builder.OnCompleted= () => + { + Dispatcher.UIThread.Invoke(() => + { + ProgressGrid.IsVisible = false; + }); + }; + Task.Run(async () => await builder.Build(name, -1)); + } + } } \ No newline at end of file