Editor now loads the first project in open folder.

This commit is contained in:
Creeper Lv
2026-01-18 01:52:22 +11:00
parent 94f557d311
commit 6dff9b8718
4 changed files with 78 additions and 3 deletions

View File

@@ -1,7 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Progrart.Core.JSExecution; using Progrart.Core.JSExecution;
using Progrart.Core.Storage; using Progrart.Core.Storage;
using System.Diagnostics;
namespace Progrart.Core.ProjectSystem namespace Progrart.Core.ProjectSystem
{ {

View File

@@ -8,6 +8,8 @@ using Progrart.Views;
using Progrart.Icons; using Progrart.Icons;
using Progrart.Pages; using Progrart.Pages;
using Avalonia.Platform.Storage; using Avalonia.Platform.Storage;
using System;
using Progrart.Core.ProjectSystem;
namespace Progrart; namespace Progrart;
@@ -15,6 +17,12 @@ public partial class App : Application
{ {
public static bool isDesktop = false; public static bool isDesktop = false;
public static IStorageFolder? CurrentOpenFolder = null; 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() public override void Initialize()
{ {
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
@@ -27,7 +35,7 @@ public partial class App : Application
EditorProvider.Register("image", "Default Image Viewer", typeof(ImageViewPage)); EditorProvider.Register("image", "Default Image Viewer", typeof(ImageViewPage));
EditorProvider.Register("progrart", "Default Progrart Editor", typeof(ProgrartEditorPage)); EditorProvider.Register("progrart", "Default Progrart Editor", typeof(ProgrartEditorPage));
EditorProvider.Register("project", "Progrart Project Editor", typeof(ProjectEditor)); 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("cs", "text");
EditorProvider.BindFileType("c", "text"); EditorProvider.BindFileType("c", "text");
EditorProvider.BindFileType("cpp", "text"); EditorProvider.BindFileType("cpp", "text");

File diff suppressed because one or more lines are too long

View File

@@ -8,11 +8,13 @@ using Progrart.Controls;
using Progrart.Core; using Progrart.Core;
using Progrart.Core.JSExecution; using Progrart.Core.JSExecution;
using Progrart.Core.ProjectSystem; using Progrart.Core.ProjectSystem;
using Progrart.Core.Storage;
using Progrart.Pages; using Progrart.Pages;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Progrart.Views; namespace Progrart.Views;
@@ -106,6 +108,18 @@ public partial class MainView : UserControl
var folder = folders[0]; var folder = folders[0];
App.CurrentOpenFolder = folder; App.CurrentOpenFolder = folder;
FileContainer.Children.Add(new FileItem(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<Project>(txt);
App.ProjectLoad();
break;
}
}
} }
}; };
FileExplorerCloseButton.Click += (_, _) => FileExplorerCloseButton.Click += (_, _) =>
@@ -117,6 +131,18 @@ public partial class MainView : UserControl
{ {
Execute(); 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() private void Execute()
@@ -208,4 +234,37 @@ public partial class MainView : UserControl
await stream_writer.WriteAsync(txt); await stream_writer.WriteAsync(txt);
await stream.FlushAsync(); 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));
}
}
} }