CommandLibraryExtension.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using PixiEditor.Extensions.CommonApi.Commands;
  2. using PixiEditor.Extensions.Sdk;
  3. namespace Sample8_CommandLibrary;
  4. public class CommandLibraryExtension : PixiEditorExtension
  5. {
  6. public override void OnInitialized()
  7. {
  8. CommandMetadata publicCommand = new CommandMetadata("PrintHelloWorld")
  9. {
  10. // All extensions can invoke this command
  11. InvokePermissions = InvokePermissions.Public
  12. };
  13. CommandMetadata internalCommand = new CommandMetadata("PrintHelloWorldFamily")
  14. {
  15. // All extensions with unique name starting with "yourCompany" can invoke this command
  16. InvokePermissions = InvokePermissions.Family
  17. };
  18. CommandMetadata privateCommand = new CommandMetadata("PrintHelloWorldPrivate")
  19. {
  20. // Only this extension can invoke this command
  21. InvokePermissions = InvokePermissions.Owner
  22. };
  23. CommandMetadata explicitCommand = new CommandMetadata("PrintHelloWorldExplicit")
  24. {
  25. // Only this extension and the ones listed in ExplicitlyAllowedExtensions can invoke this command
  26. InvokePermissions = InvokePermissions.Explicit,
  27. ExplicitlyAllowedExtensions = "yourCompany.Samples.Commands" // You can put multiple extensions by separating with ;
  28. };
  29. Api.Commands.RegisterCommand(publicCommand, () =>
  30. {
  31. Api.Logger.Log("Hello World from public command!");
  32. });
  33. Api.Commands.RegisterCommand(internalCommand, () =>
  34. {
  35. Api.Logger.Log("Hello World from internal command!");
  36. });
  37. Api.Commands.RegisterCommand(privateCommand, () =>
  38. {
  39. Api.Logger.Log("Hello World from private command!");
  40. });
  41. Api.Commands.RegisterCommand(explicitCommand, () =>
  42. {
  43. Api.Logger.Log("Hello World from explicit command!");
  44. });
  45. }
  46. }