/* ----------------------------------------------------------------- */ /// /// ImageEntry /// /// <summary> /// Initializes a new instance of the ImageItem class with the /// specified arguments. /// </summary> /// /// <param name="getter">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> getter, ImageSelection selection, ImagePreference preferences) { _getter = getter; _selection = selection; _preferences = preferences; _preferences.PropertyChanged += WhenPreferencesChanged; }
/* ----------------------------------------------------------------- */ /// /// 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) { _image = image; _selection = selection; _preferences = preferences; _preferences.PropertyChanged += WhenPreferencesChanged; }
/* ----------------------------------------------------------------- */ /// /// 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; }
/* ----------------------------------------------------------------- */ /// /// Create /// /// <summary> /// Creates a new instance of the SaveOption class. /// </summary> /// /* ----------------------------------------------------------------- */ private SaveOption Create(ImageSelection src, IO io, Invoker invoker) { var target = src.Count > 0 ? SaveTarget.Selected : SaveTarget.All; return(new SaveOption(io, invoker) { Target = target }); }
/* ----------------------------------------------------------------- */ /// /// 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); } }; _dispose = new OnceAction <bool>(Dispose); _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}"); Context = context; 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); }
/* ----------------------------------------------------------------- */ /// /// ExtractViewModel /// /// <summary> /// Initializes a new instance of the RemoveViewModel with the /// specified arguments. /// </summary> /// /// <param name="callback">Callback method when applied.</param> /// <param name="selection">Page selection.</param> /// <param name="count">Number of pages.</param> /// <param name="io">I/O handler.</param> /// <param name="context">Synchronization context.</param> /// /* ----------------------------------------------------------------- */ public ExtractViewModel(Action <SaveOption> callback, ImageSelection selection, int count, IO io, SynchronizationContext context ) : base(new ExtractFacade(selection, count, io, new ContextInvoker(context, false)), new Aggregator(), context ) { OK.Command = new DelegateCommand( () => Track(() => { callback(Facade.Value); Send <CloseMessage>(); }), () => Facade.Value.Destination.HasValue() && !io.Get(Facade.Value.Destination).IsDirectory ).Associate(Facade.Value, nameof(SaveOption.Destination)); }
/* ----------------------------------------------------------------- */ /// /// 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="invoker">Invoker object.</param> /// /* ----------------------------------------------------------------- */ public ImageCollection(Func <string, IDocumentRenderer> getter, Invoker invoker) { _getter = getter; _inner = new ObservableCollection <ImageItem>(); _inner.CollectionChanged += (s, e) => OnCollectionChanged(e); _cache = new CacheCollection <ImageItem, ImageSource>(e => getter(e.RawObject.File.FullName).Create(e).ToBitmapImage(true)); _cache.Created += (s, e) => e.Key.Refresh(); _cache.Failed += (s, e) => this.LogDebug($"[{e.Key.Index}] {e.Value.GetType().Name}"); Invoker = invoker; Selection = new ImageSelection(invoker); Preferences = new ImagePreference(invoker); Preferences.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(Preferences.VisibleLast)) { Reschedule(null); } }; }
/* ----------------------------------------------------------------- */ /// /// ExtractFacade /// /// <summary> /// Initializes a new instance of the ExtractFacade class with the /// specified arguments. /// </summary> /// /// <param name="selection">Page selection.</param> /// <param name="count">Number of pages.</param> /// <param name="io">I/O handler.</param> /// <param name="invoker">Invoker object.</param> /// /* ----------------------------------------------------------------- */ public ExtractFacade(ImageSelection selection, int count, IO io, Invoker invoker) { Count = count; Selection = selection; Value = Create(selection, io, invoker); }