Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

IRichEditAndReviewingPaneCommandFactoryService Interface

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

Namespace: DevExpress.XtraRichEdit.Services

Assembly: DevExpress.RichEdit.v24.2.Core.dll

NuGet Package: DevExpress.RichEdit.Core

#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