Skip to content

Creating a Plugin

James Mr. Squirrely edited this page Nov 17, 2026 · 2 revisions

Creating a Plugin

A plugin is a .NET 10 class library that references WritingIDE's SDK and implements IWritingIdePlugin. This guide builds one step by step. samples/SampleExtension in the repository is a complete example, and WritingIDE-Plugins has four larger ones.

1. Create the project

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <!-- net10.0-windows and UseWPF if the plugin has a window. One with only rules, exporters and commands
         can target plain net10.0. -->
    <TargetFramework>net10.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <!-- Private=false: WritingIDE supplies the SDK and Core at run time. -->
    <ProjectReference Include="..\WritingIDE\src\WritingIDE.Sdk\WritingIDE.Sdk.csproj" Private="false" />
  </ItemGroup>

</Project>

2. Write the entry point

using WritingIDE.Sdk;

public sealed class MyPlugin : IWritingIdePlugin {
    public string Id => "com.example.myplugin";      // unique, and never changes
    public string Name => "My Plugin";
    public string Version => "1.0.0";
    public string Description => "What it does.";

    public void Initialize(IPluginHost host) {
        // Register things and subscribe to events here. Called once, when WritingIDE starts.
    }
}

3. Add what you need

A command in the Extensions menu

host.RegisterCommand(new PluginCommand("Word Count per Chapter", project => {
    foreach (ChapterInfo chapter in project.GetChapters()) {
        host.Log($"{chapter.Title}: {chapter.Words:N0} words");
    }
    host.Notify("Word counts written to the Output window.");
}) { Description = "Lists every chapter's word count." });

A grammar rule

Derive from GrammarRule. The rule runs on every chapter and its findings go to the Error List.

using System.Text.RegularExpressions;
using WritingIDE.Core.Grammar;

public sealed partial class VeryRule() : GrammarRule("SAMPLE001", "Avoid 'very'", RuleCategory.Style, DiagnosticSeverity.Message,
    "'Very' usually weakens the word it props up.") {
    public override IEnumerable<GrammarDiagnostic> Analyze(AnalysisContext context) {
        foreach (Match match in Very().Matches(context.Text)) {
            yield return Report(match.Index, match.Length, "Consider a stronger word instead of 'very ...'.");
        }
    }

    [GeneratedRegex(@"\b[Vv]ery\b")]
    private static partial Regex Very();
}

Register it with host.RegisterRule(new VeryRule());. The AnalysisContext gives a rule the chapter's Text, its Tokens and Sentences, the story elements (context.Options.Entities) and the chapter's place in the manuscript (context.Options.Position). Rules run on background threads, so keep what they read immutable.

An export format

public sealed class PlainTextExporter : IManuscriptExporter {
    public string Name => "Plain text";
    public string FileExtension => ".txt";

    public void Export(string path, IProjectApi project) {
        File.WriteAllText(path, string.Join("\n\n", project.GetChapters().Select(chapter => project.GetChapterText(chapter.Id))));
    }
}

Register it with host.RegisterExporter(new PlainTextExporter());. It appears in File > Export.

A window

host.RegisterToolWindow(new PluginToolWindow("stats", "My Stats", () => new MyStatsPanel(host)) {
    Description = "Shown as a tooltip in the Extensions menu."
});

CreateContent returns a WPF element (a UserControl, say). The window is listed in the Extensions menu, opens as a tab and can go in the second pane.

Two things to know:

  • A window is unloaded while its tab is hidden, which is whenever the writer is typing in a chapter. Keep state that must keep counting in an object that lives as long as the plugin, and let the window only display it. Subscribe in Loaded and unsubscribe in Unloaded.
  • Follow the theme with WritingIDE's brush keys: text.SetResourceReference(TextBlock.ForegroundProperty, "TextBrush");. Useful keys are TextBrush, SubtleTextBrush, LabelBrush, SurfaceBrush, PanelBrush, DividerBrush, AccentBrush, SuccessBrush, WarningBrush (see Themes/Light.xaml). The styles TileButton, LinkButton and FormTextBox match the app's buttons and boxes.

A command in the chapter's right-click menu

host.RegisterEditorCommand(new EditorCommand("Count Words in Selection", context =>
    host.Notify($"{context.SelectedText.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length} words selected.")) {
    IsAvailable = static context => context.SelectionLength > 0
});

The EditorContext has the chapter, the clicked offset, the selection, the word and the story element under the cursor.

4. What the host offers

Member Does
Project (IProjectApi) Read and edit the open project: chapters and their text, story elements (summary, notes, attributes, relationships), comments, the Error List, the genre, GetWritingStats, OpenEntity, Reanalyze, Save. Safe from any thread; text edits go through the editor, so the writer can undo them
Editor (IEditorApi) The active chapter, caret and selection; ReplaceSelection and Select
Storage (IPluginStorage) GetSetting/SetSetting (per user) and a DataDirectory for files; GetProjectValue/SetProjectValue (saved in the project file)
RegisterRule, RegisterExporter, RegisterCommand, RegisterToolWindow, RegisterEditorCommand As above
ShowToolWindow Opens one of your windows
Log, Notify, SetStatusText The Output window, a notification, the status bar
SdkVersion The running WritingIDE's SDK version

Events

Event When
ProjectOpened, ProjectClosed, ProjectSaved The project
ActiveChapterChanged The writer switched to another chapter (or to a tab that is not one)
ChapterTextChanged Every edit to an open chapter. Keep the handler quick: note the chapter and start a timer
SelectionChanged The caret moved or the selection changed
SprintFinished A writing sprint ended, with its words and minutes
DailyGoalReached Today's words reached the daily goal

Editor and project events are raised on the UI thread.

5. Try it

Build the plugin, copy its DLL (and any dependencies it brings, but not WritingIDE.Sdk.dll or WritingIDE.Core.dll) into its own folder under %LocalAppData%\WritingIDE\Extensions\, and restart WritingIDE. Tools > Extensions and API > Installed extensions shows whether it loaded and what it registered; errors go to the Output window.

6. Share it

See Publishing a Plugin.

Rules of the road

  • A plugin runs inside WritingIDE with the writer's rights. Read and write only what you need, and never leave the project folder with paths that came from a project file.
  • Plugins must be under a license compatible with the GPL (the GPL itself, MIT, Apache 2.0 and similar), because they are loaded into WritingIDE.
  • Exceptions in your commands and event handlers are caught and logged, but a slow handler makes typing slow.

Clone this wiki locally