Back to Devexpress

IRichEditAndReviewingPaneCommandFactoryService Interface

officefileapi-devexpress-dot-xtrarichedit-dot-services-d90d715c.md

latest6.9 KB
Original Source

IRichEditAndReviewingPaneCommandFactoryService Interface

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

Namespace : DevExpress.XtraRichEdit.Services

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
[ComVisible(true)]
public interface IRichEditAndReviewingPaneCommandFactoryService :
    IRichEditCommandFactoryService
vb
<ComVisible(True)>
Public Interface IRichEditAndReviewingPaneCommandFactoryService
    Inherits 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:

csharp
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");
        }
    }
}
vb
Partial Public Class Form1
Inherits RibbonForm

Public Sub New()
  InitializeComponent()

  ' Replace service with a custom implementation:
  Dim myCommandFactory = New CustomRichEditCommandFactoryService(richEditControl1, TryCast(richEditControl1.GetService(Of IRichEditCommandFactoryService)(), IRichEditAndReviewingPaneCommandFactoryService))
  richEditControl1.ReplaceService(Of IRichEditCommandFactoryService)(myCommandFactory)
End Sub

Public Class CustomRichEditCommandFactoryService
  Implements IRichEditAndReviewingPaneCommandFactoryService

  Private ReadOnly service As IRichEditAndReviewingPaneCommandFactoryService
  Private ReadOnly control As IRichEditControl

  Public Sub New(ByVal control As IRichEditControl, ByVal service As IRichEditAndReviewingPaneCommandFactoryService)
    DevExpress.Utils.Guard.ArgumentNotNull(control, "control")
    DevExpress.Utils.Guard.ArgumentNotNull(service, "service")
    Me.control = control
    Me.service = service
  End Sub

  ' Override service methods to execute custom commands:
  Public Function CreateCommand(ByVal id As RichEditCommandId, ByVal control As IRichEditControl) As RichEditCommand
    If id Is RichEditCommandId.FileSaveAs Then
      Return New CustomSaveDocumentAsCommand(control)
    End If
    If id Is RichEditCommandId.FileSave Then
      Return New CustomSaveDocumentCommand(control)
    End If
    Return service.CreateCommand(id, control)
  End Function

  Public Function CreateCommand(ByVal id As RichEditCommandId) As RichEditCommand
    If id Is RichEditCommandId.FileSaveAs Then
      Return New CustomSaveDocumentAsCommand(control)
    End If
    If id Is RichEditCommandId.FileSave Then
      Return New CustomSaveDocumentCommand(control)
    End If
    Return service.CreateCommand(id)
  End Function
End Class

  ' Create a custom Save command:
Public Class CustomSaveDocumentCommand
  Inherits SaveDocumentCommand

  Public Sub New(ByVal richEdit As IRichEditControl)
    MyBase.New(richEdit)
  End Sub

  Protected Overrides Sub ExecuteCore()
    MyBase.ExecuteCore()
    If Not DocumentServer.Modified Then
      MessageBox.Show("Document is saved successfully")
    End If
  End Sub
End Class

' Create a custom Save As command:
Public Class CustomSaveDocumentAsCommand
  Inherits SaveDocumentAsCommand

  Public Sub New(ByVal richEdit As IRichEditControl)
    MyBase.New(richEdit)
  End Sub

  Protected Overrides Sub ExecuteCore()
    DocumentServer.Modified = True
    MyBase.ExecuteCore()
    If Not DocumentServer.Modified Then
      MessageBox.Show("Document is saved successfully")
    End If
  End Sub
End Class

See Also

IRichEditAndReviewingPaneCommandFactoryService Members

DevExpress.XtraRichEdit.Services Namespace