From 444499ed099bb923665f4248eee20cf976c3a12a Mon Sep 17 00:00:00 2001 From: MikiraSora Date: Sat, 28 Sep 2024 12:19:57 +0800 Subject: [PATCH] add ApplySuggestEditorLayoutCommand --- OngekiFumenEditor/AppBootstrapper.cs | 3 +-- ...plySuggestEditorLayoutCommandDefinition.cs | 26 +++++++++++++++++++ .../ApplySuggestEditorLayoutCommandHandler.cs | 20 ++++++++++++++ .../EditorLayout/EditorLayoutManager.cs | 17 +++++++++++- .../EditorLayout/IEditorLayoutManager.cs | 2 +- .../Kernel/EditorLayout/MenuDefinitions.cs | 20 ++++++++++++++ 6 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 OngekiFumenEditor/Kernel/EditorLayout/Commands/ApplySuggestEditorLayout/ApplySuggestEditorLayoutCommandDefinition.cs create mode 100644 OngekiFumenEditor/Kernel/EditorLayout/Commands/ApplySuggestEditorLayout/ApplySuggestEditorLayoutCommandHandler.cs create mode 100644 OngekiFumenEditor/Kernel/EditorLayout/MenuDefinitions.cs diff --git a/OngekiFumenEditor/AppBootstrapper.cs b/OngekiFumenEditor/AppBootstrapper.cs index 2e05ea65..db8892b1 100644 --- a/OngekiFumenEditor/AppBootstrapper.cs +++ b/OngekiFumenEditor/AppBootstrapper.cs @@ -236,8 +236,7 @@ public async void ShowStartupGUI() { if (MessageBox.Show(Resources.ShouldLoadSuggestLayout, Resources.Suggest, MessageBoxButton.YesNo) == MessageBoxResult.Yes) { - using var stream = ResourceUtils.OpenReadFromLocalAssemblyResourcesFolder("suggestLayout.bin"); - var result = await IoC.Get().LoadLayout(stream); + var result = await IoC.Get().ApplyDefaultSuggestEditorLayout(); if (!result) MessageBox.Show(Resources.LoadLayoutFailed); } diff --git a/OngekiFumenEditor/Kernel/EditorLayout/Commands/ApplySuggestEditorLayout/ApplySuggestEditorLayoutCommandDefinition.cs b/OngekiFumenEditor/Kernel/EditorLayout/Commands/ApplySuggestEditorLayout/ApplySuggestEditorLayoutCommandDefinition.cs new file mode 100644 index 00000000..27403c1d --- /dev/null +++ b/OngekiFumenEditor/Kernel/EditorLayout/Commands/ApplySuggestEditorLayout/ApplySuggestEditorLayoutCommandDefinition.cs @@ -0,0 +1,26 @@ +using Gemini.Framework.Commands; +using OngekiFumenEditor.Properties; + +namespace OngekiFumenEditor.Kernel.EditorLayout.Commands.About +{ + [CommandDefinition] + public class ApplySuggestEditorLayoutCommandDefinition : CommandDefinition + { + public const string CommandName = "EditorLayout.ApplySuggestEditorLayout"; + + public override string Name + { + get { return CommandName; } + } + + public override string Text + { + get { return "使用推荐的布局"; } + } + + public override string ToolTip + { + get { return Text; } + } + } +} \ No newline at end of file diff --git a/OngekiFumenEditor/Kernel/EditorLayout/Commands/ApplySuggestEditorLayout/ApplySuggestEditorLayoutCommandHandler.cs b/OngekiFumenEditor/Kernel/EditorLayout/Commands/ApplySuggestEditorLayout/ApplySuggestEditorLayoutCommandHandler.cs new file mode 100644 index 00000000..665c7cc4 --- /dev/null +++ b/OngekiFumenEditor/Kernel/EditorLayout/Commands/ApplySuggestEditorLayout/ApplySuggestEditorLayoutCommandHandler.cs @@ -0,0 +1,20 @@ +using Caliburn.Micro; +using Gemini.Framework.Commands; +using Gemini.Framework.Threading; +using OngekiFumenEditor.Kernel.EditorLayout; +using OngekiFumenEditor.Kernel.EditorLayout.Commands.About; +using OngekiFumenEditor.Modules.FumenVisualEditor.Kernel; +using OngekiFumenEditor.UI.Dialogs; +using System.Threading.Tasks; + +namespace OngekiFumenEditor.Kernel.MiscMenu.Commands.About +{ + [CommandHandler] + public class ApplySuggestEditorLayoutCommandHandler : CommandHandlerBase + { + public override async Task Run(Command command) + { + await IoC.Get().ApplyDefaultSuggestEditorLayout(); + } + } +} \ No newline at end of file diff --git a/OngekiFumenEditor/Kernel/EditorLayout/EditorLayoutManager.cs b/OngekiFumenEditor/Kernel/EditorLayout/EditorLayoutManager.cs index 87766476..46b8b062 100644 --- a/OngekiFumenEditor/Kernel/EditorLayout/EditorLayoutManager.cs +++ b/OngekiFumenEditor/Kernel/EditorLayout/EditorLayoutManager.cs @@ -1,4 +1,5 @@ using Caliburn.Micro; +using Gemini.Framework; using Gemini.Framework.Services; using Gemini.Modules.Shell.Services; using Gemini.Modules.Shell.ViewModels; @@ -53,7 +54,15 @@ public async Task LoadLayout(Stream intputLayoutDataStream) if (!TryGetDependices(out var shell, out var shellView)) return false; - return layoutItemStatePersister.LoadState(shell, shellView, tempFilePath); + var r = layoutItemStatePersister.LoadState(shell, shellView, tempFilePath); + if (!r) + + return false; + + if (shell.Documents.FirstOrDefault() is IDocument document) + await shell.OpenDocumentAsync(document); + + return true; } catch (Exception e) { @@ -84,5 +93,11 @@ public async Task SaveLayout(Stream outputLayoutDataStream) return false; } } + + public Task ApplyDefaultSuggestEditorLayout() + { + using var stream = ResourceUtils.OpenReadFromLocalAssemblyResourcesFolder("suggestLayout.bin"); + return IoC.Get().LoadLayout(stream); + } } } diff --git a/OngekiFumenEditor/Kernel/EditorLayout/IEditorLayoutManager.cs b/OngekiFumenEditor/Kernel/EditorLayout/IEditorLayoutManager.cs index 885a17a2..4b2c010c 100644 --- a/OngekiFumenEditor/Kernel/EditorLayout/IEditorLayoutManager.cs +++ b/OngekiFumenEditor/Kernel/EditorLayout/IEditorLayoutManager.cs @@ -12,6 +12,6 @@ public interface IEditorLayoutManager Task SaveLayout(Stream outputLayoutDataStream); Task LoadLayout(Stream intputLayoutDataStream); - //Task CheckAndNotifyUserUseSuggestLayout(); + Task ApplyDefaultSuggestEditorLayout(); } } diff --git a/OngekiFumenEditor/Kernel/EditorLayout/MenuDefinitions.cs b/OngekiFumenEditor/Kernel/EditorLayout/MenuDefinitions.cs new file mode 100644 index 00000000..fc7f433a --- /dev/null +++ b/OngekiFumenEditor/Kernel/EditorLayout/MenuDefinitions.cs @@ -0,0 +1,20 @@ +using Gemini.Framework.Menus; +using OngekiFumenEditor.Kernel.EditorLayout.Commands.About; +using OngekiFumenEditor.Kernel.MiscMenu.Commands.About; +using OngekiFumenEditor.Kernel.MiscMenu.Commands.CallFullGC; +using OngekiFumenEditor.Kernel.MiscMenu.Commands.OpenUrlCommon; +using OngekiFumenEditor.Properties; +using System.ComponentModel.Composition; + +namespace OngekiFumenEditor.Kernel.EditorLayout +{ + public static class MenuDefinitions + { + [Export] + public static MenuItemGroupDefinition EditorLayoutMenuGroup = new MenuItemGroupDefinition(Gemini.Modules.MainMenu.MenuDefinitions.WindowMenu, 999); + + [Export] + public static MenuItemDefinition ApplySuggestEditorLayoutMenuItem = new CommandMenuItemDefinition( + EditorLayoutMenuGroup, 0); + } +} \ No newline at end of file