Skip to content

Edit tools in top level menu #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void Register(ref IServiceCollection collection)
collection.AddSingleton<IMenuItemRegistry, MenuItemRegistry>();

collection.AddSingleton<TransformMenuRegister>();
collection.AddSingleton<UndoRedoMenuRegister>();
collection.AddSingleton<CopyPasteMenuRegister>();
collection.AddSingleton<PaletteMenuRegister>();
collection.AddSingleton<ProjectMenuRegister>();
Expand Down
5 changes: 5 additions & 0 deletions Pixed.Application/Menu/CopyPasteMenuRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ public void Register()
_menuItemRegistry.Register(BaseMenuItem.Edit, "Cut", new AsyncCommand(_selectionManager.Cut), null, new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_cut_24_regular.svg"));
_menuItemRegistry.Register(BaseMenuItem.Edit, "Paste", new AsyncCommand(_selectionManager.Paste), null, new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_clipboard_paste_32_regular.svg"));
_menuItemRegistry.Register(BaseMenuItem.Edit, "Select All", _selectionManager.SelectAll, new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_copy_select_24_regular.svg"));

_menuItemRegistry.Register(BaseMenuItem.Base, "Copy", new AsyncCommand(_selectionManager.Copy), null, new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_copy_32_regular.svg"));
_menuItemRegistry.Register(BaseMenuItem.Base, "Cut", new AsyncCommand(_selectionManager.Cut), null, new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_cut_24_regular.svg"));
_menuItemRegistry.Register(BaseMenuItem.Base, "Paste", new AsyncCommand(_selectionManager.Paste), null, new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_clipboard_paste_32_regular.svg"));
_menuItemRegistry.Register(BaseMenuItem.Base, "Select All", _selectionManager.SelectAll, new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_copy_select_24_regular.svg"));
}
}
21 changes: 0 additions & 21 deletions Pixed.Application/Menu/MenuBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Pixed.Application.Utils;
using Pixed.Common;
using Pixed.Common.Menu;
using Pixed.Common.Models;
using Pixed.Common.Utils;
using Pixed.Core;
using Pixed.Core.Models;
Expand Down Expand Up @@ -157,26 +156,6 @@ private async Task<MenuItem> GetFileMenu()
private MenuItem GetEditMenu()
{
MenuItem editMenu = new("Edit");
MenuItem undoMenu = new("Undo")
{
Command = new ActionCommand(() =>
{
_applicationData.CurrentModel.Undo();
Subjects.ProjectModified.OnNext(_applicationData.CurrentModel);
}),
Icon = new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_arrow_undo_48_regular.svg")
};
MenuItem redoMenu = new("Redo")
{
Command = new ActionCommand(() =>
{
_applicationData.CurrentModel.Redo();
Subjects.ProjectModified.OnNext(_applicationData.CurrentModel);
}),
Icon = new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_arrow_redo_48_regular.svg")
};

editMenu.Items = [undoMenu, redoMenu];
AddToMenu(ref editMenu, GetEntries(BaseMenuItem.Edit));

return editMenu;
Expand Down
33 changes: 33 additions & 0 deletions Pixed.Application/Menu/UndoRedoMenuRegister.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Pixed.Common;
using Pixed.Common.Menu;
using Pixed.Common.Models;
using Pixed.Core;
using Pixed.Core.Models;

namespace Pixed.Application.Menu;
internal class UndoRedoMenuRegister(IMenuItemRegistry menuItemRegistry, ApplicationData applicationData)
{
private readonly IMenuItemRegistry _menuItemRegistry = menuItemRegistry;
private readonly ApplicationData _applicationData = applicationData;

public void Register()
{
_menuItemRegistry.Register(BaseMenuItem.Edit, "Undo", new ActionCommand(Undo), null, new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_arrow_undo_48_regular.svg"));
_menuItemRegistry.Register(BaseMenuItem.Edit, "Redo", new ActionCommand(Redo), null, new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_arrow_redo_48_regular.svg"));

_menuItemRegistry.Register(BaseMenuItem.Base, "Undo", new ActionCommand(Undo), null, new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_arrow_undo_48_regular.svg"));
_menuItemRegistry.Register(BaseMenuItem.Base, "Redo", new ActionCommand(Redo), null, new("avares://Pixed.Application/Resources/fluent-icons/ic_fluent_arrow_redo_48_regular.svg"));
}

private void Undo()
{
_applicationData.CurrentModel.Undo();
Subjects.ProjectModified.OnNext(_applicationData.CurrentModel);
}

private void Redo()
{
_applicationData.CurrentModel.Redo();
Subjects.ProjectModified.OnNext(_applicationData.CurrentModel);
}
}
3 changes: 3 additions & 0 deletions Pixed.Application/Pages/Main.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal partial class Main : EmptyPixedPage, IDisposable
private readonly ApplicationData _applicationData;
private readonly PixedProjectMethods _pixedProjectMethods;
private readonly TransformMenuRegister _transformToolsMenuRegister;
private readonly UndoRedoMenuRegister _undoRedoMenuRegister;
private readonly CopyPasteMenuRegister _copyPasteMenuRegister;
private readonly PaletteMenuRegister _paletteMenuRegister;
private readonly ProjectMenuRegister _projectMenuRegister;
Expand All @@ -47,6 +48,7 @@ public Main() : base()
_pixedProjectMethods = Get<PixedProjectMethods>();
_applicationData = Get<ApplicationData>();
_transformToolsMenuRegister = Get<TransformMenuRegister>();
_undoRedoMenuRegister = Get<UndoRedoMenuRegister>();
_copyPasteMenuRegister = Get<CopyPasteMenuRegister>();
_paletteMenuRegister = Get<PaletteMenuRegister>();
_projectMenuRegister = Get<ProjectMenuRegister>();
Expand Down Expand Up @@ -75,6 +77,7 @@ public override async void OnLoaded()
clipboard.Initialize(topLevel.Clipboard);
_viewMenuRegister.Register();
_transformToolsMenuRegister.Register();
_undoRedoMenuRegister.Register();
_copyPasteMenuRegister.Register();
_paletteMenuRegister.Register();
_toolsMenuRegister.Register();
Expand Down
Loading