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

IRichEditCommandFactoryService Interface

Defines a service that is used to create RichEdit commands.

Namespace: DevExpress.XtraRichEdit.Services

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

Declaration

[ComVisible(true)]
public interface IRichEditCommandFactoryService

Remarks

The code below implements the IRichEditCommandFactoryService descendant, which generates customized SaveDocumentCommand and SaveDocumentAsCommand commands. The command descendants override the ExecuteCore methods to display a message after a document has been saved. The IsModified internal property indicates unsaved changes in the document. If this property is not changed to false after a document is saved, it signals that the save action failed.

public class CustomRichEditCommandFactoryService : IRichEditCommandFactoryService {
    readonly IRichEditCommandFactoryService service;
    readonly RichEditControl control;

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

    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);
    }
}

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");
        }
    }
}


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");    
        }                
    }
}

The following code replaces the IRichEditCommandFactoryService service with its descendant.

richEditControl.Text = "A message box is displayed when a document is saved on the 'Save' or 'Save As' button click since custom commands are used.";
var myCommandFactory = new CustomRichEditCommandFactoryService(richEditControl, richEditControl.GetService<IRichEditCommandFactoryService>());
richEditControl.ReplaceService<IRichEditCommandFactoryService>(myCommandFactory);

The following code snippets (auto-collected from DevExpress Examples) contain references to the IRichEditCommandFactoryService interface.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also