|
@@ -7,78 +7,90 @@ using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
-namespace InABox.Wpf
|
|
|
+namespace InABox.Wpf;
|
|
|
+
|
|
|
+public class PostableSettingsGrid : DynamicItemsListGrid<PostableSettings>
|
|
|
{
|
|
|
- public class PostableSettingsGrid : DynamicItemsListGrid<PostableSettings>
|
|
|
+ public PostableSettingsGrid()
|
|
|
+ {
|
|
|
+ OnCustomiseEditor += PostableSettingsGrid_OnCustomiseEditor;
|
|
|
+ OnEditorValueChanged += PostableSettingsGrid_OnEditorValueChanged;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Dictionary<string, object?> PostableSettingsGrid_OnEditorValueChanged(object sender, string name, object value)
|
|
|
{
|
|
|
- public PostableSettingsGrid()
|
|
|
+ var editorForm = (IDynamicEditorForm)sender;
|
|
|
+ if (name == nameof(PostableSettings.PosterType))
|
|
|
{
|
|
|
- OnCustomiseEditor += PostableSettingsGrid_OnCustomiseEditor;
|
|
|
- OnEditorValueChanged += PostableSettingsGrid_OnEditorValueChanged;
|
|
|
+ var editor = (editorForm.FindEditor(name) as LookupEditorControl)!;
|
|
|
+ (editor.EditorDefinition as ComboLookupEditor)!.Buttons![0].SetEnabled(!string.IsNullOrWhiteSpace(value as string));
|
|
|
+ (editor.EditorDefinition as ComboLookupEditor)!.Buttons![1].SetVisible(
|
|
|
+ CoreUtils.GetEntityOrNull(value as string)?.IsAssignableTo(typeof(IGlobalSettingsPoster)) == true);
|
|
|
}
|
|
|
+ return new();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PostableSettingsGrid_OnCustomiseEditor(IDynamicEditorForm sender, PostableSettings[]? items, DynamicGridColumn column, BaseEditor editor)
|
|
|
+ {
|
|
|
+ var settings = items?.FirstOrDefault();
|
|
|
+ if (settings is null) return;
|
|
|
|
|
|
- private Dictionary<string, object?> PostableSettingsGrid_OnEditorValueChanged(object sender, string name, object value)
|
|
|
+ if(column.ColumnName == nameof(PostableSettings.PosterType) && editor is ComboLookupEditor combo)
|
|
|
{
|
|
|
- var editorForm = (IDynamicEditorForm)sender;
|
|
|
- if (name == nameof(PostableSettings.PosterType))
|
|
|
- {
|
|
|
- var editor = (editorForm.FindEditor(name) as LookupEditorControl)!;
|
|
|
- (editor.EditorDefinition as ComboLookupEditor)!.Buttons![0].SetEnabled(!string.IsNullOrWhiteSpace(value as string));
|
|
|
- (editor.EditorDefinition as ComboLookupEditor)!.Buttons![1].SetVisible(
|
|
|
- CoreUtils.GetEntityOrNull(value as string)?.IsAssignableTo(typeof(IGlobalSettingsPoster)) == true);
|
|
|
- }
|
|
|
- return new();
|
|
|
+ var settingsButton = new EditorButton(settings, "Settings", 60, ViewSettings, false);
|
|
|
+ settingsButton.SetEnabled(!string.IsNullOrWhiteSpace(settings.PosterType));
|
|
|
+
|
|
|
+ var globalSettingsButton = new EditorButton(settings, "Global Settings", 100, ViewGlobalSettings, false);
|
|
|
+ globalSettingsButton.SetVisible(CoreUtils.GetEntityOrNull(settings.PosterType)?.IsAssignableTo(typeof(IGlobalSettingsPoster)) == true);
|
|
|
+
|
|
|
+ combo.Buttons = [settingsButton, globalSettingsButton];
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private void PostableSettingsGrid_OnCustomiseEditor(IDynamicEditorForm sender, PostableSettings[]? items, DynamicGridColumn column, BaseEditor editor)
|
|
|
- {
|
|
|
- var settings = items?.FirstOrDefault();
|
|
|
- if (settings is null) return;
|
|
|
+ private void ViewGlobalSettings(object editor, object? item)
|
|
|
+ {
|
|
|
+ if (item is not PostableSettings settings) return;
|
|
|
+
|
|
|
+ var posterType = CoreUtils.GetEntityOrNull(settings.PosterType);
|
|
|
+ var globalSettingsType = posterType?.GetInterfaceDefinition(typeof(IGlobalSettingsPoster<>))?.GenericTypeArguments[0];
|
|
|
+ if (globalSettingsType is null) return;
|
|
|
|
|
|
- if(column.ColumnName == nameof(PostableSettings.PosterType) && editor is ComboLookupEditor combo)
|
|
|
- {
|
|
|
- var settingsButton = new EditorButton(settings, "Settings", 60, ViewSettings, false);
|
|
|
- settingsButton.SetEnabled(!string.IsNullOrWhiteSpace(settings.PosterType));
|
|
|
+ ConfigureGlobalPosterSettings(globalSettingsType);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ViewSettings(object editor, object? item)
|
|
|
+ {
|
|
|
+ if (item is not PostableSettings settings) return;
|
|
|
|
|
|
- var globalSettingsButton = new EditorButton(settings, "Global Settings", 100, ViewGlobalSettings, false);
|
|
|
- globalSettingsButton.SetVisible(CoreUtils.GetEntityOrNull(settings.PosterType)?.IsAssignableTo(typeof(IGlobalSettingsPoster)) == true);
|
|
|
+ var entityType = CoreUtils.GetEntityOrNull(settings.PostableType);
|
|
|
+ if (entityType is null) return;
|
|
|
|
|
|
- combo.Buttons = [settingsButton, globalSettingsButton];
|
|
|
- }
|
|
|
- }
|
|
|
+ var posterType = CoreUtils.GetEntityOrNull(settings.PosterType);
|
|
|
+ var settingsType = posterType?.GetInterfaceDefinition(typeof(IPoster<,>))!.GenericTypeArguments[1];
|
|
|
|
|
|
- private void ViewGlobalSettings(object editor, object? item)
|
|
|
+ ConfigurePosterSettings(entityType, settingsType);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void ConfigureGlobalPosterSettings(Type globalSettingsType)
|
|
|
+ {
|
|
|
+ var globalPosterSettings = PosterUtils.LoadGlobalPosterSettings(globalSettingsType);
|
|
|
+ var grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicItemsListGrid<>), globalSettingsType);
|
|
|
+ if(grid.EditItems(new object[] { globalPosterSettings }))
|
|
|
{
|
|
|
- if (item is not PostableSettings settings) return;
|
|
|
-
|
|
|
- var posterType = CoreUtils.GetEntityOrNull(settings.PosterType);
|
|
|
- var globalSettingsType = posterType?.GetInterfaceDefinition(typeof(IGlobalSettingsPoster<>))?.GenericTypeArguments[0];
|
|
|
- if (globalSettingsType is null) return;
|
|
|
-
|
|
|
- var globalPosterSettings = PosterUtils.LoadGlobalPosterSettings(globalSettingsType);
|
|
|
- var grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicItemsListGrid<>), globalSettingsType);
|
|
|
- if(grid.EditItems(new object[] { globalPosterSettings }))
|
|
|
- {
|
|
|
- PosterUtils.SaveGlobalPosterSettings(globalSettingsType, globalPosterSettings);
|
|
|
- }
|
|
|
+ PosterUtils.SaveGlobalPosterSettings(globalSettingsType, globalPosterSettings);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- private void ViewSettings(object editor, object? item)
|
|
|
+ public static void ConfigurePosterSettings(Type entityType, Type settingsType)
|
|
|
+ {
|
|
|
+ var posterSettings = PosterUtils.LoadPosterSettings(entityType, settingsType);
|
|
|
+ var grid = DynamicGridUtils.CreateDynamicGrid(typeof(PosterSettingsGrid<>), settingsType);
|
|
|
+ if(grid.EditItems(new object[] { posterSettings }))
|
|
|
{
|
|
|
- if (item is not PostableSettings settings) return;
|
|
|
-
|
|
|
- var entityType = CoreUtils.GetEntityOrNull(settings.PostableType);
|
|
|
- if (entityType is null) return;
|
|
|
-
|
|
|
- var posterType = CoreUtils.GetEntityOrNull(settings.PosterType);
|
|
|
- var settingsType = posterType?.GetInterfaceDefinition(typeof(IPoster<,>))!.GenericTypeArguments[1];
|
|
|
-
|
|
|
- var posterSettings = PosterUtils.LoadPosterSettings(entityType, settingsType);
|
|
|
- var grid = DynamicGridUtils.CreateDynamicGrid(typeof(PosterSettingsGrid<>), settingsType);
|
|
|
- if(grid.EditItems(new object[] { posterSettings }))
|
|
|
- {
|
|
|
- PosterUtils.SavePosterSettings(entityType, settingsType, posterSettings);
|
|
|
- }
|
|
|
+ PosterUtils.SavePosterSettings(entityType, settingsType, posterSettings);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static void ConfigurePosterSettings<T>(Type settingsType)
|
|
|
+ where T : Entity, IPostable, IRemotable, IPersistent, new() => ConfigurePosterSettings(typeof(T), settingsType);
|
|
|
}
|