Browse Source

Added a hack to modify DatabaseSchema with custom custom properties

Kenric Nugteren 6 months ago
parent
commit
747b3f3d22

+ 25 - 0
InABox.Core/DatabaseSchema/DatabaseSchema.cs

@@ -271,6 +271,20 @@ namespace InABox.Core
 
             _properties[master] = newDict.ToImmutableSortedDictionary();
         }
+        private static void UnregisterProperties(Type master, IEnumerable<IProperty> toRemove)
+        {
+            if (!_properties.TryGetValue(master, out var properties))
+            {
+                properties = ImmutableSortedDictionary<string, IProperty>.Empty;
+            }
+            var newDict = properties.ToDictionary(x => x.Key, x => x.Value);
+            foreach(var prop in toRemove)
+            {
+                newDict.Remove(prop.Name);
+            }
+
+            _properties[master] = newDict.ToImmutableSortedDictionary();
+        }
         
         public static void RegisterProperty(IProperty entry)
         {
@@ -295,6 +309,17 @@ namespace InABox.Core
             }
         }
 
+        public static void Unload(CustomProperty[] customProperties)
+        {
+            var perType = customProperties.GroupBy(x => x.ClassType);
+            foreach(var group in perType)
+            {
+                if (group.Key is null) continue;
+
+                UnregisterProperties(group.Key, group);
+            }
+        }
+
         private static ImmutableSortedDictionary<string, IProperty>? CheckPropertiesInternal(Type type)
         {
             try

+ 1 - 1
inabox.wpf/Editors/TextBoxDialog.xaml

@@ -5,7 +5,7 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:wpf="clr-namespace:InABox.Wpf"
         mc:Ignorable="d"
-        Title="MemoEditor" Height="450" Width="800">
+        Title="MemoEditor" Height="450" Width="800" WindowStartupLocation="CenterScreen">
     <Grid Margin="5">
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="*" />