Преглед на файлове

Merge remote-tracking branch 'origin/kenric' into frank

frogsoftware преди 2 месеца
родител
ревизия
8a22311626

+ 17 - 0
InABox.Avalonia/Components/AvaloniaDataGrid/AvaloniaDataGrid.axaml.cs

@@ -6,6 +6,7 @@ using Avalonia.Controls.Primitives;
 using Avalonia.Data;
 using Avalonia.Data.Converters;
 using Avalonia.Input;
+using Avalonia.Threading;
 using Avalonia.VisualTree;
 using CommunityToolkit.Mvvm.Input;
 using InABox.Core;
@@ -133,6 +134,14 @@ public partial class AvaloniaDataGrid : UserControl, INotifyPropertyChanged
     private static void ItemsSource_Changed(AvaloniaDataGrid grid, AvaloniaPropertyChangedEventArgs args)
     {
         grid.Grid.ItemsSource = grid.ItemsSource;
+        if(args.OldValue is ICoreRepository oldRepo)
+        {
+            oldRepo.Changed -= grid.Repository_Changed;
+        }
+        if(grid.ItemsSource is ICoreRepository repo)
+        {
+            repo.Changed += grid.Repository_Changed;
+        }
         if (grid.Grid.CollectionView is not null)
         {
             grid.Grid.CollectionView.CollectionChanged -= grid.CollectionView_CollectionChanged;
@@ -141,6 +150,14 @@ public partial class AvaloniaDataGrid : UserControl, INotifyPropertyChanged
         grid.ItemsChanged();
     }
 
+    private void Repository_Changed(object sender, CoreRepositoryChangedEventArgs args)
+    {
+        Dispatcher.UIThread.InvokeAsync(() =>
+        {
+            Grid.CollectionView?.Refresh();
+        });
+    }
+
     #endregion
 
     public AvaloniaDataGrid()

+ 42 - 9
InABox.Avalonia/DataModels/CoreRepository.cs

@@ -1,5 +1,6 @@
 using System.Collections;
 using System.Collections.ObjectModel;
+using System.Collections.Specialized;
 using System.ComponentModel;
 using System.Diagnostics.CodeAnalysis;
 using System.Linq.Expressions;
@@ -111,7 +112,11 @@ namespace InABox.Avalonia
         protected CoreRepository(IModelHost host, Func<Filter<TEntity>> filter, Func<string>? filename = null)
         {
             AllItems = new CoreObservableCollection<TItem>();
-            AllItems.CollectionChanged += (sender, args) => ItemsChanged(AllItems);
+            AllItems.CollectionChanged += (sender, args) =>
+            {
+                _items = null;
+                ItemsChanged(AllItems);
+            };
             // EnableSynchronization(AllItems);
 
             //Items = new CoreObservableCollection<TItem>(); 
@@ -325,7 +330,15 @@ namespace InABox.Avalonia
         
         private CoreTable _table = new CoreTable();
 
-        public IEnumerable<TItem> Items => SearchAndSort();
+        private IEnumerable<TItem>? _items;
+        public IEnumerable<TItem> Items
+        {
+            get
+            {
+                _items ??= SearchAndSort();
+                return _items;
+            }
+        }
 
         public int ItemCount => Items.Count();
         
@@ -398,14 +411,33 @@ namespace InABox.Avalonia
         void ICoreRepository.ToggleSelection(object item) => ToggleSelection(item as TItem);
         bool ICoreRepository.IsSelected(object item) => IsSelected(item as TItem);
         void ICoreRepository.SetSelectedItems(IEnumerable<object> items) => SetSelectedItems(items.OfType<TItem>());
-        
+
         #endregion
-        
+
         #region Searching
-        
-        public Func<TItem, bool>? SearchPredicate { get; set; }
-        
-        public Func<List<TItem>,List<TItem>>? SortPredicate { get; set; }
+
+        private Func<TItem, bool>? _searchPredicate;
+        public Func<TItem, bool>? SearchPredicate
+        {
+            get => _searchPredicate;
+            set
+            {
+                _searchPredicate = value;
+                _items = null;
+            }
+        }
+
+        private Func<List<TItem>, List<TItem>>? _sortPredicate;
+        public Func<List<TItem>,List<TItem>>? SortPredicate
+        {
+            get => _sortPredicate;
+            set
+            {
+                _sortPredicate = value;
+                _items = null;
+            }
+        }
+            
 
         public ICoreRepository Search(Func<TItem, bool> searchpredicate, Func<List<TItem>,List<TItem>> sortpredicate)
         {
@@ -446,6 +478,7 @@ namespace InABox.Avalonia
         
         public ICoreRepository Search()
         {
+            _items = null;
             OnPropertyChanged(nameof(Items));
             OnPropertyChanged(nameof(ItemCount));
             return this;
@@ -692,7 +725,7 @@ namespace InABox.Avalonia
         #region CRUD Operations
         
         public event CoreRepositoryItemCreatedEvent<TItem>? ItemAdded;
-        
+
         private T CreateItem<T>(CoreRow row) 
             where T : Shell<TParent,TEntity>, new()
         {

+ 5 - 0
InABox.Avalonia/Theme/Classes/Image.axaml

@@ -1,6 +1,11 @@
 <Styles xmlns="https://github.com/avaloniaui"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
     
+    <Style Selector="Image.ExtraSmall">
+        <Setter Property="Height" Value="{DynamicResource PrsExtraSmallImageHeight}" />
+        <Setter Property="Width" Value="{DynamicResource PrsExtraSmallImageWidth}" />
+    </Style>
+    
     <Style Selector="Image.Small">
         <Setter Property="Height" Value="{DynamicResource PrsSmallImageHeight}" />
         <Setter Property="Width" Value="{DynamicResource PrsSmallImageWidth}" />

+ 3 - 0
InABox.Avalonia/Theme/Classes/Label.axaml

@@ -27,4 +27,7 @@
         <Setter Property="FontSize" Value="{DynamicResource PrsFontSizeExtraLarge}" />
     </Style>
 
+    <Style Selector="Label.Bold">
+        <Setter Property="FontWeight" Value="{DynamicResource PrsFontWeightBold}" />
+    </Style>
 </Styles>

+ 33 - 0
InABox.Avalonia/Theme/Classes/TextBlock.axaml

@@ -0,0 +1,33 @@
+<Styles xmlns="https://github.com/avaloniaui"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+    <Design.PreviewWith>
+        <Border Padding="20">
+            <!-- Add Controls for Previewer Here -->
+        </Border>
+    </Design.PreviewWith>
+
+    <Style Selector="TextBlock.ExtraSmall">
+        <Setter Property="FontSize" Value="{DynamicResource PrsFontSizeExtraSmall}" />
+    </Style>
+
+    <Style Selector="TextBlock.Small">
+        <Setter Property="FontSize" Value="{DynamicResource PrsFontSizeSmall}" />
+    </Style>
+
+    <Style Selector="TextBlock.Large">
+        <Setter Property="FontSize" Value="{DynamicResource PrsFontSizeLarge}" />
+    </Style>
+
+    <Style Selector="TextBlock.ExtraLarge">
+        <Setter Property="FontSize" Value="{DynamicResource PrsFontSizeExtraLarge}" />
+    </Style>
+
+    <Style Selector="TextBlock.Bold">
+        <Setter Property="FontWeight" Value="{DynamicResource PrsFontWeightBold}" />
+    </Style>
+
+    <Style Selector="TextBlock.Italic">
+        <Setter Property="FontStyle" Value="{DynamicResource PrsFontStylItalic}" />
+    </Style>
+
+</Styles>

+ 3 - 0
InABox.Avalonia/Theme/Layouts.axaml

@@ -17,6 +17,9 @@
     
     <CornerRadius x:Key="PrsCornerRadius">4</CornerRadius>
 
+    <system:Double x:Key="PrsExtraSmallImageWidth">16</system:Double>
+    <system:Double x:Key="PrsExtraSmallImageHeight">16</system:Double>
+
     <system:Double x:Key="PrsSmallImageWidth">20</system:Double>
     <system:Double x:Key="PrsSmallImageHeight">20</system:Double>
 

+ 1 - 0
InABox.Avalonia/Theme/Styles.axaml

@@ -15,6 +15,7 @@
 	<StyleInclude Source="/Theme/Classes/Separator.axaml" />
 	<StyleInclude Source="/Theme/Classes/TabItem.axaml" />
 	<StyleInclude Source="/Theme/Classes/TabStrip.axaml" />
+	<StyleInclude Source="/Theme/Classes/TextBlock.axaml" />
 	<StyleInclude Source="/Theme/Classes/TextBox.axaml" />
 	<StyleInclude Source="/Theme/Classes/TimeSelectorButton.axaml" />
 	<StyleInclude Source="/Theme/Classes/ZoomPanel.axaml" />

+ 14 - 0
InABox.Core/Configuration/LocalConfiguration.cs

@@ -11,6 +11,20 @@ namespace InABox.Configuration
     {
     }
 
+    public static class LocalConfiguration
+    {
+        public static T Load<T>(bool useCache = true, string section = "")
+            where T : ILocalConfigurationSettings, new()
+        {
+            return new LocalConfiguration<T>(section).Load(useCache: useCache);
+        }
+        public static void Save<T>(T obj, string section = "")
+            where T : ILocalConfigurationSettings, new()
+        {
+            new LocalConfiguration<T>(section).Save(obj);
+        }
+    }
+
     public class LocalConfiguration<T> : Configuration<T>, IDisposable 
         where T : ILocalConfigurationSettings, new()
     {