Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

IRichEditAndReviewingPaneCommandFactoryService Interface

Defines a service used to create RichEdit with Reviewing Pane commands.

Namespace: DevExpress.XtraRichEdit.Services

Assembly: DevExpress.RichEdit.v21.1.Core.dll

Declaration

[ComVisible(true)]
public interface IRichEditAndReviewingPaneCommandFactoryService :
    IRichEditCommandFactoryService

Remarks

Use this service instead of IRichEditCommandFactoryService to replace RichEditControl’s built-in commands when the Review Pane is displayed.

Example

The code sample below replaces the IRichEditCommandFactoryService service with the IRichEditAndReviewingPaneCommandFactoryService implementation to use a custom Save As command:

public partial class Form1 : RibbonForm
{
  public Form1()
  {
      InitializeComponent();

      // Replace service with a custom implementation:
      var myCommandFactory = new CustomRichEditCommandFactoryService(richEditControl1, richEditControl1.GetService<IRichEditCommandFactoryService>() as IRichEditAndReviewingPaneCommandFactoryService);
      richEditControl1.ReplaceService<IRichEditCommandFactoryService>(myCommandFactory);
  }
}

public class CustomRichEditCommandFactoryService : IRichEditAndReviewingPaneCommandFactoryService
{
  readonly IRichEditAndReviewingPaneCommandFactoryService service;
  readonly IRichEditControl control;

  public CustomRichEditCommandFactoryService(IRichEditControl control, IRichEditAndReviewingPaneCommandFactoryService service)
  {
      DevExpress.Utils.Guard.ArgumentNotNull(control, "control");
      DevExpress.Utils.Guard.ArgumentNotNull(service, "service");
      this.control = control;
      this.service = service;
  }

  // Override service methods to execute custom commands:
  public RichEditCommand CreateCommand(RichEditCommandId id, IRichEditControl control)
  {
      if (id == RichEditCommandId.FileSaveAs)
      {
          return new CustomSaveDocumentAsCommand(control);
      }
      if (id == RichEditCommandId.FileSave)
      {
          return new CustomSaveDocumentCommand(control);
      }
      return service.CreateCommand(id, control);
  }

  public RichEditCommand CreateCommand(RichEditCommandId id)
  {
      if (id == RichEditCommandId.FileSaveAs)
      {
          return new CustomSaveDocumentAsCommand(control);
      }
      if (id == RichEditCommandId.FileSave)
      {
          return new CustomSaveDocumentCommand(control);
      }
      return service.CreateCommand(id);
  }
}

// Create a custom Save command:
public class CustomSaveDocumentCommand : SaveDocumentCommand
{
    public CustomSaveDocumentCommand(IRichEditControl richEdit) : base(richEdit) { }

    protected override void ExecuteCore()
    {
        base.ExecuteCore();
        if (!DocumentServer.Modified)
        {
            MessageBox.Show("Document is saved successfully");
        }
    }
}

// Create a custom Save As command:
public class CustomSaveDocumentAsCommand : SaveDocumentAsCommand
{
    public CustomSaveDocumentAsCommand(IRichEditControl richEdit) : base(richEdit) { }

    protected override void ExecuteCore()
    {
        DocumentServer.Modified = true;
        base.ExecuteCore();
        if (!DocumentServer.Modified)
        {
            MessageBox.Show("Document is saved successfully");
        }
    }
}
See Also