/* ----------------------------------------------------------------- */ /// /// ImageEntry /// /// <summary> /// Initializes a new instance of the ImageItem class with the /// specified arguments. /// </summary> /// /// <param name="image">Delegation to get an image.</param> /// <param name="selection">Shared object for selection.</param> /// <param name="preferences">Image preferences.</param> /// /* ----------------------------------------------------------------- */ public ImageItem(Func <ImageItem, ImageSource> image, ImageSelection selection, ImagePreferences preferences) { _dispose = new OnceAction <bool>(Dispose); _image = image; _selection = selection; _preferences = preferences; _preferences.PropertyChanged += WhenPreferencesChanged; }
/* ----------------------------------------------------------------- */ /// /// ImageCollection /// /// <summary> /// Initializes a new instance of the ImageCollection class with /// the specified arguments. /// </summary> /// /// <param name="getter">Function to get the renderer.</param> /// <param name="context">Synchronization context.</param> /// /* ----------------------------------------------------------------- */ public ImageCollection(Func <string, IDocumentRenderer> getter, SynchronizationContext context) { ImageSource create(ImageItem e) => getter(e.RawObject.File.FullName).Create(e); void update(string s) { if (s == nameof(Preferences.VisibleLast)) { Reschedule(null); } }; _inner = new ObservableCollection <ImageItem>(); _cache = new CacheCollection <ImageItem, ImageSource>(create); _inner.CollectionChanged += (s, e) => OnCollectionChanged(e); _cache.Created += (s, e) => e.Key.Refresh(); _cache.Failed += (s, e) => this.LogDebug($"[{e.Key.Index}] {e.Value.GetType().Name}"); Selection = new ImageSelection { Context = context }; Preferences = new ImagePreferences { Context = context }; Create = (i, r) => { if (i < 0 || i >= Count) { return(null); } var src = _inner[i].RawObject; return(getter(src.File.FullName).Create(src, r)); }; Convert = (e) => Preferences.FrameOnly ? null : _cache.TryGetValue(e, out var dest) ? dest : Preferences.Dummy; Preferences.PropertyChanged += (s, e) => update(e.PropertyName); }