https://github.com/nano-byte/structure-editor
WinForms library for building split-screen editors for data structures
https://github.com/nano-byte/structure-editor
editor split-screen winforms xml
Last synced: 11 days ago
JSON representation
WinForms library for building split-screen editors for data structures
- Host: GitHub
- URL: https://github.com/nano-byte/structure-editor
- Owner: nano-byte
- License: mit
- Created: 2018-11-13T17:15:10.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-12-30T14:13:43.000Z (about 1 month ago)
- Last Synced: 2026-01-03T02:36:08.038Z (about 1 month ago)
- Topics: editor, split-screen, winforms, xml
- Language: C#
- Homepage: https://structure-editor.nano-byte.net
- Size: 6.61 MB
- Stars: 12
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING.txt
Awesome Lists containing this project
README
# NanoByte Structure Editor
[](https://github.com/nano-byte/structure-editor/actions/workflows/build.yml)
[](https://www.nuget.org/packages/NanoByte.StructureEditor.WinForms/)
[](https://structure-editor.nano-byte.net/)
NanoByte Structure Editor is a WinForms library that helps you build split-screen editors for your data structures, consisting of:
1. a collapsible tree-view of the data structure,
2. a graphical editor for the currently selected node in the tree (`PropertyGrid` or custom) and
3. a text editor (based on [ICSharpCode.TextEditor](https://github.com/nano-byte/ICSharpCode.TextEditor)) with a serialized (XML) representation of the currently selected node.
This allows you to create an IDE-like experience for your users when editing complex domain specific languages, configuration files, etc..

## Usage
Add a reference to the [NanoByte.StructureEditor.WinForms](https://www.nuget.org/packages/NanoByte.StructureEditor.WinForms/) NuGet package to your project. It is available for .NET Framework 2.0+ and .NET 6.0+.
### Initialization
Create an instance of `StructureEditor` and add it to your Form:
```csharp
var editor = new StructureEditor();
Controls.Add(editor);
```
Alternatively, you may want to derive your own class from `StructureEditor`. This will allow you to use the graphical WinForms designer in Visual Studio (which does not support generic types) to place the Editor on your Form.
```csharp
public class MyDataEditor : StructureEditor
{}
```
You need to "describe" your data structure to the Editor. You can do this directly after instantiating the editor or in the constructor of your derived class.
- Call `DescribeRoot()` and then use the fluent API provided as a return value to describe the properties on your main data type.
- Call `Describe()` to describe the properties on a data type `TContainer` exposed by another property. You can use multiple calls with different type parameters to describe arbitrarily deep hierarchies.
The fluent API provides the following methods:
- `.AddProperty()` describes a simple value property.
- `.AddPlainList()` describes a non-polymorphic list.
- `.AddList()` describes a polymorphic list. After calling it you need to chain `.AddElement()` calls for each specific type of element the list can hold.
There are numerous overloads for each of these methods, e.g., allowing you to specify a custom editor control for a data type or to keep the auto-generated one.
```csharp
editor.DescribeRoot("Address Book")
.AddPlainList("Group", x => x.Groups);
editor.Describe()
.AddPlainList("Contact", x => x.Contacts);
editor.Describe()
.AddProperty("Home Address", x => PropertyPointer.For(() => x.HomeAddress))
.AddProperty("Work Address", x => PropertyPointer.For(() => x.WorkAddress))
.AddList(x => x.PhoneNumbers)
.AddElement("Landline Number", new LandlineNumber())
.AddElement("Mobile Number", new MobileNumber());
```
### Storage
Use the `Open()` method to load an XML file into the editor:
```csharp
editor.Open(CommandManager.Load(path));
```
Use the `Save()` method on the `CommandManager` property to save the editor's content as an XML file:
```csharp
editor.CommandManager.Save(path);
```
Take a look a the [sample project](src/Sample) for a more complete setup, including undo/redo functionality.
## Building
The source code is in [`src/`](src/), config for building the API documentation is in [`doc/`](doc/) and generated build artifacts are placed in `artifacts/`. The source code does not contain version numbers. Instead the version is determined during CI using [GitVersion](https://gitversion.net/).
To build install [Visual Studio 2022 v17.13 or newer](https://www.visualstudio.com/downloads/) and run `.\build.ps1`.
## Contributing
We welcome contributions to this project such as bug reports, recommendations and pull requests.
This repository contains an [EditorConfig](http://editorconfig.org/) file. Please make sure to use an editor that supports it to ensure consistent code style, file encoding, etc.. For full tooling support for all style and naming conventions consider using JetBrains' [ReSharper](https://www.jetbrains.com/resharper/) or [Rider](https://www.jetbrains.com/rider/) products.