CustomCommands.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Windows.Input;
  4. namespace ComPDFKit.Tool
  5. {
  6. public static class CustomCommands
  7. {
  8. internal enum CustomCommandId
  9. {
  10. PasteMatchStyle
  11. }
  12. public class CustomCommand: RoutedUICommand
  13. {
  14. internal CustomCommandId Id;
  15. public CustomCommand(string name, string text) : base(text, name, typeof(CustomCommands))
  16. {
  17. }
  18. }
  19. private static List<CustomCommand> Commands { get; set; }=new List<CustomCommand>();
  20. /// <summary>
  21. /// Pastes text matching style.
  22. /// </summary>
  23. public static RoutedUICommand PasteWithoutStyle => EnsureCommand(CustomCommandId.PasteMatchStyle);
  24. private static RoutedUICommand EnsureCommand(CustomCommandId idCommand)
  25. {
  26. CustomCommand command = null;
  27. if (Commands!=null && Commands.Count>0)
  28. {
  29. command = Commands.AsEnumerable().FirstOrDefault(x => x.Id == idCommand);
  30. }
  31. if(command == null)
  32. {
  33. command= new CustomCommand("PasteWithoutStyle", "Paste Without Style");
  34. command.Id = idCommand;
  35. Commands?.Add(command);
  36. }
  37. return command;
  38. }
  39. }
  40. }