Skip to content

Plugins

tomdam edited this page Jun 17, 2020 · 1 revision

One of the ways to extend SPCoder is by creating and registering a Plugin.

Definition

A Plugin is a class that derives from abstract SPCoder.Core.Plugins.BasePlugin class.

To register a plugin you need to save it as .csx file to the Scripts\CSharp\Plugins folder relative to the SPCoder.exe file's location.

When you register a plugin in SPCoder, it will become available as an item in context menu of the Explorer's treeview (when you right-click the item of appropriate type). In the example below you can see the SPExcelWorksheetDataGetter plugin which works on files of type xlsx.

Plugin

Existing plugins

SPCoder contains following plugins:

  • SPExcelWorksheetDataGetter - gets the first sheet of an excel file and shows it in GridViewer
  • SPSharePointListItemsGetter - gets the items from SharePoint list or library and shows them in GridViewer
  • SPSharePointWebPnpTemplateGetter - generates PnP template xml from SharePoint site, which can be used to create a new site with the same structure

Implementation

The code for registering plugins is located in Scripts\CSharp\SPPluginsScripts.csx autorun script file.

To implement a new plugin, you need to create a class, inherit the SPCoder.Core.Plugins.BasePlugin class and override public abstract void Execute(Object target); method. When run, this method will be called by SPCoder app and it will receive an object from treeview as a parameter.

You can also register a callback which will be called by SPCoder after the Execute method returns the result. The callback can be registered during the registration of the plugin. In this example you can see how to register a callback that would create new code window with some source code:

SPSharePointWebPnpTemplateGetter webPnPTemplateGetter = new SPSharePointWebPnpTemplateGetter();
webPnPTemplateGetter.Callback += GenerateNewSourceTab;
PluginContainer.Register(webPnPTemplateGetter);

The rest of the implementation is up to your requirements.

You can check the existing plugins to see how to show data in GridViewer or how to create new code editor and put text (source code) in it.

Clone this wiki locally