Skip to content

Details on Using Selected ATF Components

gstaas edited this page Nov 6, 2014 · 5 revisions

Table of Contents

This section discusses details of how to use specific ATF components, using examples to illustrate. For a general discussion, see Using ATF Components.

StandardFileCommands

This component requires:

  • CommandService, DocumentRegistry, FileDialogService, and StatusService components.
  • Component that exports IDocumentClient.
For an explanation of these requirements, see Functionality Required From the Application.

The ATF Simple DOM Editor Sample uses StandardFileCommands. Examining this sample's Program.cs file shows that it also includes the ATF components in its MEF catalog to meet the other import requirements: CommandService, DocumentRegistry, FileDialogService, and StatusService (link to source).

This sample also provides an Editor component that exports and implements the IDocumentClient interface. Here is the Editor component class declaration (link to source):

[Export(typeof(IDocumentClient))]
[Export(typeof(Editor))]
[Export(typeof(IInitializable))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class Editor : IDocumentClient, IControlHostClient, IInitializable
Here is Editor's implementation of IDocumentClient (link to source):
#region IDocumentClient Members

/// <summary>
/// Gets information about the document client, such as the file type and file
/// extensions it supports, whether or not it allows multiple documents to be open, etc.</summary>
public DocumentClientInfo Info
{
    get { return DocumentClientInfo; }
}
...
/// <summary>
/// Closes the document and removes any views of it from the UI</summary>
/// <param name="document">Document to close</param>
public void Close(IDocument document)
{
    EventSequenceContext context = Adapters.As<EventSequenceContext>(document);
    m_controlHostService.UnregisterControl(context.ListView);
    context.ControlInfo = null;

    // close all active EditingContexts in the document
    foreach (DomNode node in context.DomNode.Subtree)
        foreach (EditingContext editingContext in node.AsAll<EditingContext>())
            m_contextRegistry.RemoveContext(editingContext);

    // close the document
    m_documentRegistry.Remove(document);
}

#endregion

For

StandardFileExitCommand

Along with StandardFileExitCommand, add CommandService to the MEF TypeCatalog. For a discussion of why this is required, see Functionality Required From Other Components.

Clone this wiki locally