Project files

You can add custom files managed by the extension to an RC+ project.

To use this extension point, create a class that implements the IRCXProjectFileProvider interface and export it.

[Export(typeof(IRCXProjectFileProvider))]
public partial class ProjectFileEditorProjectFile : IRCXProjectFileProvider
{
    /// <inheritdoc />
    public string Id => Main.CommonId;

    /// <inheritdoc />
    public string FileTypeName => "MyExtensionFiles";

    /// <inheritdoc />
    public string Extension => ".ext";

    /// <inheritdoc />
    public bool UseDefaultProjectExplorerItem => true;

    /// <inheritdoc />
    public RCXCaption ProjectExplorerRootItemCaption => new(Main.CommonId, Caption.FileCategory);

    /// <inheritdoc />
    public ImageSource? ProjectExplorerRootItemIconData => Main.CommonIcon;

    /// <inheritdoc />
    public ImageSource? FileIcon => Main.CommonIcon;

    /// <inheritdoc />
    public RCXCaption FileTypeNameCaption => new(Main.CommonId, Caption.FileTypeName);

    /// <inheritdoc />
    public async Task OpenAsync(
        string fileName
    )
    {
        // Open project file editor window
        ProjectFileEditor editorControl = new();

        if (editorControl.DataContext is ProjectFileEditorViewModel editorViewModel)
        {
            editorViewModel.FileName = fileName;
            editorViewModel.LoadContent();
            await Main.GetAPI<IRCXWindowAPI>().ShowDockingWindowAsync(editorViewModel, editorControl);
        }
    }

    /// <inheritdoc />
    public void WriteInitialContent(
        FileStream fileStream
    )
    {
        try
        {
            // Write initial content of the file (optional)
            using var writer = new StreamWriter(fileStream, Encoding.UTF8);
            writer.WriteLine("ProjectFile Initial Content");
        }
        catch (Exception)
        {
            // Handle Error
        }
    }
}

In an extension, the following processes are implemented.

  1. File open process (OpenAsync)
    • Custom project files are typically supplied together with an editor used to edit those files. An editor that uses a docking window is implemented in the same way as the docking windows described above. A typical implementation would be to create an editor control, pass the contents read from the file to its view model, and display the editor window, as shown above.
  2. Processing to write initial content when creating a file (WriteInitialContent)
    • When this method is called, an empty file is created and the FileStream associated with the file is passed. If the initial content is empty, no special processing is required in this method.

When the UseDefaultProjectExplorerItem flag is set to true, a tree item for the extension can be added to the Project Explorer. (If you do not use this feature, you must use the extension points described in the next section.)

The tree items are configured as follows.

  • Parent item indicating the extension file type
    • It has an "Add New Item" context menu consisting of two submenus: "New File..." and "Existing File...".
  • Child item indicating the file name of the file being added
    • It has a context menu consisting of three items: "Open," "Exclude from Project," and "Delete."