Skip to content

Commit f1c6e9c

Browse files
committed
Create multiple editors for classes themselves (ComponentEditor) or classes as properties (UITypeEditor) for HS64 Electrical/Optical stimulators.
- Carry this pattern over to all other devices with a custom editor if we want to implement this, ignoring all devices that use the GenericDeviceDialog since it is useless for a single device
1 parent a04551b commit f1c6e9c

7 files changed

+73
-27
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Windows.Forms;
4+
using Bonsai.Design;
5+
6+
namespace OpenEphys.Onix1.Design
7+
{
8+
/// <inheritdoc/>
9+
internal class Headstage64ElectricalStimulatorComponentEditor : WorkflowComponentEditor
10+
{
11+
public override bool EditComponent(ITypeDescriptorContext context, object component, IServiceProvider provider, IWin32Window owner)
12+
{
13+
if (provider != null)
14+
{
15+
var editorState = (IWorkflowEditorState)provider.GetService(typeof(IWorkflowEditorState));
16+
if (editorState != null && !editorState.WorkflowRunning && component is ConfigureHeadstage64ElectricalStimulator configureNode)
17+
{
18+
using var editorDialog = new Headstage64ElectricalStimulatorSequenceDialog(configureNode);
19+
20+
if (editorDialog.ShowDialog() == DialogResult.OK)
21+
{
22+
DesignHelper.CopyProperties(editorDialog.ElectricalStimulator, configureNode);
23+
24+
return true;
25+
}
26+
}
27+
}
28+
29+
return false;
30+
}
31+
}
32+
}

OpenEphys.Onix1.Design/Headstage64ElectricalStimulatorSequenceEditor.cs renamed to OpenEphys.Onix1.Design/Headstage64ElectricalStimulatorUITypeEditor.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace OpenEphys.Onix1.Design
1010
/// <summary>
1111
/// Class that opens a new dialog for a <see cref="ConfigureHeadstage64ElectricalStimulator"/>.
1212
/// </summary>
13-
public class Headstage64ElectricalStimulatorSequenceEditor : UITypeEditor
13+
public class Headstage64ElectricalStimulatorUITypeEditor : UITypeEditor
1414
{
1515
/// <inheritdoc/>
1616
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
@@ -26,18 +26,9 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide
2626
var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
2727
var editorState = (IWorkflowEditorState)provider.GetService(typeof(IWorkflowEditorState));
2828

29-
ConfigureHeadstage64ElectricalStimulator configureHeadstage64ElectricalStimulator;
30-
31-
if (context.Instance.GetType() == typeof(ConfigureHeadstage64ElectricalStimulator))
32-
configureHeadstage64ElectricalStimulator = (ConfigureHeadstage64ElectricalStimulator)context.Instance;
33-
else if (value.GetType() == typeof(ConfigureHeadstage64ElectricalStimulator))
34-
configureHeadstage64ElectricalStimulator = (ConfigureHeadstage64ElectricalStimulator)value;
35-
else
36-
throw new Exception($"Invalid input given to {nameof(Headstage64ElectricalStimulatorSequenceEditor)}.");
37-
38-
if (editorService != null && editorState != null && !editorState.WorkflowRunning)
29+
if (editorService != null && editorState != null && !editorState.WorkflowRunning && value is ConfigureHeadstage64ElectricalStimulator configureNode)
3930
{
40-
using var editorDialog = new Headstage64ElectricalStimulatorSequenceDialog(configureHeadstage64ElectricalStimulator);
31+
using var editorDialog = new Headstage64ElectricalStimulatorSequenceDialog(configureNode);
4132

4233
if (editorDialog.ShowDialog() == DialogResult.OK)
4334
{
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Windows.Forms;
4+
using Bonsai.Design;
5+
6+
namespace OpenEphys.Onix1.Design
7+
{
8+
internal class Headstage64OpticalStimulatorComponentEditor : WorkflowComponentEditor
9+
{
10+
public override bool EditComponent(ITypeDescriptorContext context, object component, IServiceProvider provider, IWin32Window owner)
11+
{
12+
if (provider != null)
13+
{
14+
var editorState = (IWorkflowEditorState)provider.GetService(typeof(IWorkflowEditorState));
15+
if (editorState != null && !editorState.WorkflowRunning && component is ConfigureHeadstage64OpticalStimulator configureNode)
16+
{
17+
using var editorDialog = new Headstage64OpticalStimulatorSequenceDialog(configureNode);
18+
19+
if (editorDialog.ShowDialog() == DialogResult.OK)
20+
{
21+
DesignHelper.CopyProperties(editorDialog.OpticalStimulator, configureNode);
22+
23+
return true;
24+
}
25+
}
26+
}
27+
28+
return false;
29+
}
30+
}
31+
}

OpenEphys.Onix1.Design/Headstage64OpticalStimulatorSequenceEditor.cs renamed to OpenEphys.Onix1.Design/Headstage64OpticalStimulatorUITypeEditor.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace OpenEphys.Onix1.Design
1010
/// <summary>
1111
/// Class that opens a new dialog for a <see cref="ConfigureHeadstage64OpticalStimulator"/>.
1212
/// </summary>
13-
public class Headstage64OpticalStimulatorSequenceEditor : UITypeEditor
13+
public class Headstage64OpticalStimulatorUITypeEditor : UITypeEditor
1414
{
1515
/// <inheritdoc/>
1616
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
@@ -26,18 +26,9 @@ public override object EditValue(ITypeDescriptorContext context, IServiceProvide
2626
var editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
2727
var editorState = (IWorkflowEditorState)provider.GetService(typeof(IWorkflowEditorState));
2828

29-
ConfigureHeadstage64OpticalStimulator configureHeadstage64OpticalStimulator;
30-
31-
if (context.Instance.GetType() == typeof(ConfigureHeadstage64OpticalStimulator))
32-
configureHeadstage64OpticalStimulator = (ConfigureHeadstage64OpticalStimulator)context.Instance;
33-
else if (value.GetType() == typeof(ConfigureHeadstage64OpticalStimulator))
34-
configureHeadstage64OpticalStimulator = (ConfigureHeadstage64OpticalStimulator)value;
35-
else
36-
throw new Exception($"Invalid input given to {nameof(Headstage64OpticalStimulatorSequenceEditor)}.");
37-
38-
if (editorService != null && editorState != null && !editorState.WorkflowRunning)
29+
if (editorService != null && editorState != null && !editorState.WorkflowRunning && value is ConfigureHeadstage64OpticalStimulator configureNode)
3930
{
40-
using var editorDialog = new Headstage64OpticalStimulatorSequenceDialog(configureHeadstage64OpticalStimulator);
31+
using var editorDialog = new Headstage64OpticalStimulatorSequenceDialog(configureNode);
4132

4233
if (editorDialog.ShowDialog() == DialogResult.OK)
4334
{

OpenEphys.Onix1/ConfigureHeadstage64.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public ConfigureHeadstage64()
7575
[Category(DevicesCategory)]
7676
[TypeConverter(typeof(SingleDeviceFactoryConverter))]
7777
[Description("Specifies the configuration for the ElectricalStimulator device in the headstage-64.")]
78-
[Editor("OpenEphys.Onix1.Design.Headstage64ElectricalStimulatorSequenceEditor, OpenEphys.Onix1.Design", typeof(UITypeEditor))]
78+
[Editor("OpenEphys.Onix1.Design.Headstage64ElectricalStimulatorUITypeEditor, OpenEphys.Onix1.Design", typeof(UITypeEditor))]
7979
public ConfigureHeadstage64ElectricalStimulator ElectricalStimulator { get; set; } = new();
8080

8181
/// <summary>
@@ -85,7 +85,7 @@ public ConfigureHeadstage64()
8585
[Category(DevicesCategory)]
8686
[TypeConverter(typeof(SingleDeviceFactoryConverter))]
8787
[Description("Specifies the configuration for the OpticalStimulator device in the headstage-64.")]
88-
[Editor("OpenEphys.Onix1.Design.Headstage64OpticalStimulatorSequenceEditor, OpenEphys.Onix1.Design", typeof(UITypeEditor))]
88+
[Editor("OpenEphys.Onix1.Design.Headstage64OpticalStimulatorUITypeEditor, OpenEphys.Onix1.Design", typeof(UITypeEditor))]
8989
public ConfigureHeadstage64OpticalStimulator OpticalStimulator { get; set; } = new();
9090

9191
/// <summary>

OpenEphys.Onix1/ConfigureHeadstage64ElectricalStimulator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace OpenEphys.Onix1
1616
/// <c>DeviceName</c>.
1717
/// </remarks>
1818
[Description("Configures a headstage-64 onboard electrical stimulator.")]
19+
[Editor("OpenEphys.Onix1.Design.Headstage64ElectricalStimulatorComponentEditor, OpenEphys.Onix1.Design", typeof(ComponentEditor))]
1920
public class ConfigureHeadstage64ElectricalStimulator : SingleDeviceFactory
2021
{
2122
readonly BehaviorSubject<double> phaseOneCurrent = new(0);

OpenEphys.Onix1/ConfigureHeadstage64OpticalStimulator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ namespace OpenEphys.Onix1
1515
/// cref="Headstage64OpticalStimulatorTrigger"/>, using a shared
1616
/// <c>DeviceName</c>.
1717
/// </remarks>
18-
[Editor("OpenEphys.Onix1.Design.Headstage64OpticalStimulatorSequenceEditor, OpenEphys.Onix1.Design", typeof(ComponentEditor))]
1918
[Description("Configures a headstage-64 dual-channel optical stimulator.")]
19+
[Editor("OpenEphys.Onix1.Design.Headstage64OpticalStimulatorComponentEditor, OpenEphys.Onix1.Design", typeof(ComponentEditor))]
2020
public class ConfigureHeadstage64OpticalStimulator : SingleDeviceFactory
2121
{
2222
readonly BehaviorSubject<bool> enable = new(true);

0 commit comments

Comments
 (0)