|
@@ -3,6 +3,7 @@ using System.Windows.Input;
|
|
|
using Avalonia.Controls;
|
|
|
using Avalonia.Markup.Xaml;
|
|
|
using PixiEditor.Helpers;
|
|
|
+using PixiEditor.Models.Commands.CommandContext;
|
|
|
|
|
|
namespace PixiEditor.Models.Commands.XAML;
|
|
|
|
|
@@ -15,6 +16,8 @@ internal class Command : MarkupExtension
|
|
|
public bool UseProvided { get; set; }
|
|
|
|
|
|
public bool GetPixiCommand { get; set; }
|
|
|
+
|
|
|
+ public string SourceInfoTag { get; set; }
|
|
|
|
|
|
public Command() { }
|
|
|
|
|
@@ -33,7 +36,7 @@ internal class Command : MarkupExtension
|
|
|
Description = attribute.Description,
|
|
|
DefaultShortcut = attribute.GetShortcut(),
|
|
|
Shortcut = attribute.GetShortcut()
|
|
|
- }, false);
|
|
|
+ }, null, false);
|
|
|
}
|
|
|
|
|
|
if (commandController is null)
|
|
@@ -42,13 +45,14 @@ internal class Command : MarkupExtension
|
|
|
}
|
|
|
|
|
|
Commands.Command command = commandController.Commands[Name];
|
|
|
- return GetPixiCommand ? command : GetICommand(command, UseProvided);
|
|
|
+ return GetPixiCommand ? command : GetICommand(command, new CommandBindingSourceInfo(SourceInfoTag), UseProvided);
|
|
|
}
|
|
|
|
|
|
- public static ICommand GetICommand(Commands.Command command, bool useProvidedParameter) => new ProvidedICommand()
|
|
|
+ public static ICommand GetICommand(Commands.Command command, ICommandExecutionSourceInfo? source, bool useProvidedParameter) => new ProvidedICommand()
|
|
|
{
|
|
|
Command = command,
|
|
|
UseProvidedParameter = useProvidedParameter,
|
|
|
+ Source = source
|
|
|
};
|
|
|
|
|
|
class ProvidedICommand : ICommand
|
|
@@ -90,18 +94,14 @@ internal class Command : MarkupExtension
|
|
|
|
|
|
public bool UseProvidedParameter { get; init; }
|
|
|
|
|
|
+ public ICommandExecutionSourceInfo Source { get; init; }
|
|
|
+
|
|
|
public bool CanExecute(object parameter) => UseProvidedParameter ? Command.Methods.CanExecute(parameter) : Command.CanExecute();
|
|
|
|
|
|
public void Execute(object parameter)
|
|
|
{
|
|
|
- if (UseProvidedParameter)
|
|
|
- {
|
|
|
- Command.Methods.Execute(parameter);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Command.Execute();
|
|
|
- }
|
|
|
+ var context = new CommandExecutionContext(parameter, Source);
|
|
|
+ Command.Execute(context, UseProvidedParameter);
|
|
|
}
|
|
|
}
|
|
|
}
|