using System; using System.Windows.Input; namespace FastReport.Design { public partial class WpfDesignerControl { /// /// Represents a designer command. /// public class DesignerCommand : ICommand { internal FastReport.Design.DesignerCommand InnerCommand { get; } private bool lastEnabledState; /// public event EventHandler CanExecuteChanged; /// public bool CanExecute(object parameter) => InnerCommand.Enabled; /// public void Execute(object parameter) => InnerCommand.Invoke(); private void Designer_UIStateChanged(object sender, EventArgs e) { bool newEnabledState = InnerCommand.Enabled; if (newEnabledState != lastEnabledState) { lastEnabledState = newEnabledState; CanExecuteChanged?.Invoke(this, EventArgs.Empty); } } internal DesignerCommand(WpfDesignerControl designer, Design.DesignerCommand innerCommand) { InnerCommand = innerCommand; designer.UIStateChanged += Designer_UIStateChanged; } } /// /// Represents a designer "Open" command. /// public class OpenCommand : DesignerCommand { /// /// Loads a specified report file. /// /// File to load. /// true to suppress message dialog if load is failed. public void LoadFile(string fileName, bool silent = false) => (InnerCommand as Design.OpenCommand).LoadFile(fileName, silent); internal OpenCommand(WpfDesignerControl designer, Design.OpenCommand innerCommand) : base(designer, innerCommand) { } } /// /// Represents a designer "Recent Files" command. /// public class RecentFilesCommand : DesignerCommand { /// /// Returns true if the file specified is a cloud file. /// /// File name to check. /// true if file is a cloud file. public bool IsCloudFile(string fileName) => (InnerCommand as Design.RecentFilesCommand).IsCloudFile(fileName); /// /// Opens a recent file with specified name either from local PC or from cloud. /// /// File name to open. public void LoadFile(string fileName) => (InnerCommand as Design.RecentFilesCommand).LoadFile(fileName); internal RecentFilesCommand(WpfDesignerControl designer, Design.RecentFilesCommand innerCommand) : base(designer, innerCommand) { } } } }