diff --git a/Library/Interfaces/ILibraryContainer.cs b/Library/Interfaces/ILibraryContainer.cs index 9b7d91546..a49cc167a 100644 --- a/Library/Interfaces/ILibraryContainer.cs +++ b/Library/Interfaces/ILibraryContainer.cs @@ -59,6 +59,8 @@ namespace MatterHackers.MatterControl.Library public interface ILibraryWritableContainer : ILibraryContainer { + event EventHandler ItemContentChanged; + void Add(IEnumerable items); void Remove(IEnumerable items); void Rename(ILibraryItem item, string revisedName); @@ -75,4 +77,14 @@ namespace MatterHackers.MatterControl.Library RenameItems, RemoveItems } + + public class ItemChangedEventArgs : EventArgs + { + public ILibraryItem LibraryItem { get; } + + public ItemChangedEventArgs(ILibraryItem libraryItem) + { + this.LibraryItem = libraryItem; + } + } } diff --git a/Library/Providers/FileSystem/FileSystemItem.cs b/Library/Providers/FileSystem/FileSystemItem.cs index b546c631c..1d992d8d6 100644 --- a/Library/Providers/FileSystem/FileSystemItem.cs +++ b/Library/Providers/FileSystem/FileSystemItem.cs @@ -69,4 +69,15 @@ namespace MatterHackers.MatterControl.Library } } } + + public class MockLibraryItem : ILibraryItem + { + public string ID { get; set; } + + public string Name { get; set; } + + public bool IsProtected => true; + + public bool IsVisible => true; + } } diff --git a/Library/Providers/WritableContainer.cs b/Library/Providers/WritableContainer.cs index e48cac409..1cc75699e 100644 --- a/Library/Providers/WritableContainer.cs +++ b/Library/Providers/WritableContainer.cs @@ -27,6 +27,7 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the FreeBSD Project. */ +using System; using System.Collections.Generic; using MatterHackers.Agg.Image; @@ -34,6 +35,13 @@ namespace MatterHackers.MatterControl.Library { public abstract class WritableContainer : LibraryContainer, ILibraryWritableContainer { + public event EventHandler ItemContentChanged; + + public virtual void OnItemContentChanged(ItemChangedEventArgs args) + { + ItemContentChanged?.Invoke(this, args); + } + public virtual void Add(IEnumerable items) { } diff --git a/Library/Widgets/ListView/ListView.cs b/Library/Widgets/ListView/ListView.cs index 86bd3d89d..5e6e501ef 100644 --- a/Library/Widgets/ListView/ListView.cs +++ b/Library/Widgets/ListView/ListView.cs @@ -132,6 +132,11 @@ namespace MatterHackers.MatterControl.CustomWidgets /// The container to load private void DisplayContainerContent(ILibraryContainer sourceContainer) { + if (this.ActiveContainer is ILibraryWritableContainer activeWritable) + { + activeWritable.ItemContentChanged -= WritableContainer_ItemContentChanged; + } + UiThread.RunOnIdle(() => { if (sourceContainer == null) @@ -180,10 +185,25 @@ namespace MatterHackers.MatterControl.CustomWidgets } } + if (sourceContainer is ILibraryWritableContainer writableContainer) + { + writableContainer.ItemContentChanged += WritableContainer_ItemContentChanged; + } + this.Invalidate(); }); } + private void WritableContainer_ItemContentChanged(object sender, ItemChangedEventArgs e) + { + var firstItem = items.Where(i => i.Model.ID == e.LibraryItem.ID).FirstOrDefault(); + if (firstItem != null) + { + firstItem.ViewWidget.LoadItemThumbnail().ConfigureAwait(false); + firstItem.ViewWidget.Invalidate(); + } + } + public enum ViewMode { Icons, diff --git a/Library/Widgets/ListView/ListViewItemBase.cs b/Library/Widgets/ListView/ListViewItemBase.cs index 43887938c..4e0593f50 100644 --- a/Library/Widgets/ListView/ListViewItemBase.cs +++ b/Library/Widgets/ListView/ListViewItemBase.cs @@ -88,7 +88,7 @@ namespace MatterHackers.MatterControl.CustomWidgets return true; } - protected async Task LoadItemThumbnail() + public async Task LoadItemThumbnail() { var listView = listViewItem.ListView;