瀏覽代碼

Added setting to show pull button; did some updates to DynamicContentDialog

Kenric Nugteren 11 月之前
父節點
當前提交
4aff4f8cbe

+ 5 - 0
InABox.Core/Postable/PostableSettings.cs

@@ -30,5 +30,10 @@ namespace InABox.Core
         [EditorSequence(4)]
         [CheckBoxEditor]
         public bool ShowClearButton { get; set; } = true;
+
+        [EditorSequence(5)]
+        [CheckBoxEditor]
+        [Caption("Show Import Button")]
+        public bool ShowPullButton { get; set; } = true;
     }
 }

+ 11 - 10
inabox.wpf/DynamicGrid/DynamicContentDialog.xaml

@@ -4,18 +4,19 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:local="clr-namespace:InABox.DynamicGrid"
-        mc:Ignorable="d" Height="450" Width="800">
-    <Window.Resources>
-        <Style TargetType="Button">
-            <Setter Property="Width" Value="80"/>
-            <Setter Property="Height" Value="35"/>
-            <Setter Property="Margin" Value="5,5,0,0"/>
-        </Style>
-    </Window.Resources>
+        mc:Ignorable="d" Height="450" Width="800"
+        x:Name="Window">
     <DockPanel Margin="5">
         <DockPanel x:Name="Buttons" DockPanel.Dock="Bottom" LastChildFill="False">
-            <Button x:Name="Cancel" DockPanel.Dock="Right" Content="Cancel" Click="Cancel_OnClick"/>
-            <Button x:Name="OK" DockPanel.Dock="Right" Content="OK" Click="OK_OnClick"/>
+            <Button x:Name="CancelButton" Click="CancelButton_Click"
+                    Content="Cancel"
+                    Margin="5,5,0,0" Padding="5" MinWidth="60"
+                    DockPanel.Dock="Right"/>
+            <Button x:Name="OKButton" Click="OKButton_Click"
+                    Content="OK"
+                    Margin="5,5,0,0" Padding="5" MinWidth="60"
+                    DockPanel.Dock="Right"
+                    IsEnabled="{Binding ElementName=Window,Path=CanSave}"/>
         </DockPanel>
         <ContentPresenter x:Name="Presenter" DockPanel.Dock="Top" />
     </DockPanel>

+ 28 - 22
inabox.wpf/DynamicGrid/DynamicContentDialog.xaml.cs

@@ -1,32 +1,38 @@
 using System.Windows;
 using NPOI.OpenXmlFormats.Spreadsheet;
 
-namespace InABox.DynamicGrid
+namespace InABox.DynamicGrid;
+
+public partial class DynamicContentDialog : Window
 {
-    public partial class DynamicContentDialog : Window
+    public static readonly DependencyProperty CanSaveProperty = DependencyProperty.Register(nameof(CanSave), typeof(bool), typeof(DynamicContentDialog));
+
+    public bool ButtonsVisible
     {
-        
-        public bool ButtonsVisible
-        {
-            get => Buttons.Visibility == Visibility.Visible;
-            set => Buttons.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
-        }
+        get => Buttons.Visibility == Visibility.Visible;
+        set => Buttons.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
+    }
 
-        public DynamicContentDialog(FrameworkElement element, bool buttonsvisible = true)
-        {
-            InitializeComponent();
-            ButtonsVisible = buttonsvisible;
-            Presenter.Content = element;
-        }
+    public bool CanSave
+    {
+        get => (bool)GetValue(CanSaveProperty);
+        set => SetValue(CanSaveProperty, value);
+    }
 
-        private void OK_OnClick(object sender, RoutedEventArgs e)
-        {
-            DialogResult = true;
-        }
+    public DynamicContentDialog(FrameworkElement element, bool buttonsvisible = true)
+    {
+        InitializeComponent();
+        ButtonsVisible = buttonsvisible;
+        Presenter.Content = element;
+    }
 
-        private void Cancel_OnClick(object sender, RoutedEventArgs e)
-        {
-            DialogResult = false;
-        }
+    private void OKButton_Click(object sender, RoutedEventArgs e)
+    {
+        DialogResult = true;
+    }
+
+    private void CancelButton_Click(object sender, RoutedEventArgs e)
+    {
+        DialogResult = false;
     }
 }

+ 14 - 0
inabox.wpf/Grids/PostableSettingsGrid.cs

@@ -45,6 +45,20 @@ public class PostableSettingsGrid : DynamicItemsListGrid<PostableSettings>
 
             combo.Buttons = [settingsButton, globalSettingsButton];
         }
+        else if(column.ColumnName == nameof(PostableSettings.ShowPullButton))
+        {
+            var entityType = CoreUtils.GetEntityOrNull(settings.PostableType);
+            var visible = false;
+            if (entityType is not null)
+            {
+                var engine = PosterUtils.GetEngine(entityType);
+                if(engine.Get(out var eType, out var _error))
+                {
+                    visible = eType.HasInterface(typeof(IPullerEngine<>));
+                }
+            }
+            editor.Editable = visible ? Editable.Enabled : Editable.Hidden;
+        }
     }
 
     private void ViewGlobalSettings(object editor, object? item)