WpfDesignerControl.Commands.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Windows.Input;
  3. namespace FastReport.Design
  4. {
  5. public partial class WpfDesignerControl
  6. {
  7. /// <summary>
  8. /// Represents a designer command.
  9. /// </summary>
  10. public class DesignerCommand : ICommand
  11. {
  12. internal FastReport.Design.DesignerCommand InnerCommand { get; }
  13. private bool lastEnabledState;
  14. /// <inheritdoc/>
  15. public event EventHandler CanExecuteChanged;
  16. /// <inheritdoc/>
  17. public bool CanExecute(object parameter) => InnerCommand.Enabled;
  18. /// <inheritdoc/>
  19. public void Execute(object parameter) => InnerCommand.Invoke();
  20. private void Designer_UIStateChanged(object sender, EventArgs e)
  21. {
  22. bool newEnabledState = InnerCommand.Enabled;
  23. if (newEnabledState != lastEnabledState)
  24. {
  25. lastEnabledState = newEnabledState;
  26. CanExecuteChanged?.Invoke(this, EventArgs.Empty);
  27. }
  28. }
  29. internal DesignerCommand(WpfDesignerControl designer, Design.DesignerCommand innerCommand)
  30. {
  31. InnerCommand = innerCommand;
  32. designer.UIStateChanged += Designer_UIStateChanged;
  33. }
  34. }
  35. /// <summary>
  36. /// Represents a designer "Open" command.
  37. /// </summary>
  38. public class OpenCommand : DesignerCommand
  39. {
  40. /// <summary>
  41. /// Loads a specified report file.
  42. /// </summary>
  43. /// <param name="fileName">File to load.</param>
  44. /// <param name="silent">true to suppress message dialog if load is failed.</param>
  45. public void LoadFile(string fileName, bool silent = false) => (InnerCommand as Design.OpenCommand).LoadFile(fileName, silent);
  46. internal OpenCommand(WpfDesignerControl designer, Design.OpenCommand innerCommand) : base(designer, innerCommand) { }
  47. }
  48. /// <summary>
  49. /// Represents a designer "Recent Files" command.
  50. /// </summary>
  51. public class RecentFilesCommand : DesignerCommand
  52. {
  53. /// <summary>
  54. /// Returns true if the file specified is a cloud file.
  55. /// </summary>
  56. /// <param name="fileName">File name to check.</param>
  57. /// <returns>true if file is a cloud file.</returns>
  58. public bool IsCloudFile(string fileName) => (InnerCommand as Design.RecentFilesCommand).IsCloudFile(fileName);
  59. /// <summary>
  60. /// Opens a recent file with specified name either from local PC or from cloud.
  61. /// </summary>
  62. /// <param name="fileName">File name to open.</param>
  63. public void LoadFile(string fileName) => (InnerCommand as Design.RecentFilesCommand).LoadFile(fileName);
  64. internal RecentFilesCommand(WpfDesignerControl designer, Design.RecentFilesCommand innerCommand) : base(designer, innerCommand) { }
  65. }
  66. }
  67. }