public SearchOptionsProxy([NotNull] SearchMetadata searchMetadata, [NotNull] Action <SearchMetadata> changeScopeAction, [NotNull] IColourProvider colourProvider, [NotNull] IThemeProvider themeProvider, [NotNull] IconSelector iconSelector, [NotNull] Action <SearchMetadata> removeAction, [NotNull] IDefaultIconSelector defaultIconSelector, Guid parentId) { if (changeScopeAction == null) { throw new ArgumentNullException(nameof(changeScopeAction)); } if (colourProvider == null) { throw new ArgumentNullException(nameof(colourProvider)); } if (themeProvider == null) { throw new ArgumentNullException(nameof(themeProvider)); } if (removeAction == null) { throw new ArgumentNullException(nameof(removeAction)); } _searchMetadata = searchMetadata ?? throw new ArgumentNullException(nameof(searchMetadata)); _defaultIconSelector = defaultIconSelector ?? throw new ArgumentNullException(nameof(defaultIconSelector)); IconSelector = iconSelector ?? throw new ArgumentNullException(nameof(iconSelector)); ParentId = parentId; Highlight = _searchMetadata.Highlight; Filter = _searchMetadata.Filter; UseRegex = searchMetadata.UseRegex; CaseSensitive = !searchMetadata.IgnoreCase; Position = searchMetadata.Position; Hues = colourProvider.Hues; HighlightHue = searchMetadata.HighlightHue; IsGlobal = searchMetadata.IsGlobal; IsExclusion = searchMetadata.IsExclusion; ShowIconSelectorCommand = new Command(async() => await ShowIconSelector()); RemoveCommand = new Command(() => removeAction(searchMetadata)); ChangeScopeCommand = new Command(() => changeScopeAction((SearchMetadata)this)); HighlightCommand = new Command <Hue>(newHue => { HighlightHue = newHue; }); IconKind = _searchMetadata.IconKind.ParseEnum <PackIconKind>() .ValueOr(() => PackIconKind.ArrowRightBold); //combine system with user choice. var defaultHue = this.WhenValueChanged(vm => vm.HighlightHue) .CombineLatest(themeProvider.Accent, (user, system) => user == Hue.NotSpecified ? system : user) .Publish(); Foreground = defaultHue.Select(h => h.ForegroundBrush).ForBinding(); Background = defaultHue.Select(h => h.BackgroundBrush).ForBinding(); _cleanUp = new CompositeDisposable(IconSelector, Foreground, Background, defaultHue.Connect()); }
public SearchOptionsProxy([NotNull] SearchMetadata searchMetadata, [NotNull] IColourProvider colourProvider, [NotNull] IconSelector iconSelector, [NotNull] Action <SearchMetadata> removeAction, [NotNull] IDefaultIconSelector defaultIconSelector, Guid parentId) { if (searchMetadata == null) { throw new ArgumentNullException(nameof(searchMetadata)); } if (colourProvider == null) { throw new ArgumentNullException(nameof(colourProvider)); } if (iconSelector == null) { throw new ArgumentNullException(nameof(iconSelector)); } if (removeAction == null) { throw new ArgumentNullException(nameof(removeAction)); } if (defaultIconSelector == null) { throw new ArgumentNullException(nameof(defaultIconSelector)); } _searchMetadata = searchMetadata; _defaultIconSelector = defaultIconSelector; IconSelector = iconSelector; ShowIconSelectorCommand = new Command(ShowIconSelector); RemoveCommand = new Command(() => removeAction(searchMetadata)); HighlightCommand = new Command <Hue>(newHue => { HighlightHue = newHue; }); ParentId = parentId; Highlight = _searchMetadata.Highlight; Filter = _searchMetadata.Filter; UseRegex = searchMetadata.UseRegex; IgnoreCase = searchMetadata.IgnoreCase; Position = searchMetadata.Position; Hues = colourProvider.Hues; HighlightHue = searchMetadata.HighlightHue; IconKind = _searchMetadata.IconKind.ParseEnum <PackIconKind>() .ValueOr(() => PackIconKind.ArrowRightBold); Foreground = this.WhenValueChanged(vm => vm.HighlightHue) .Select(h => h.ForegroundBrush) .ForBinding(); Background = this.WhenValueChanged(vm => vm.HighlightHue) .Select(h => h.BackgroundBrush) .ForBinding(); _cleanUp = new CompositeDisposable(IconSelector, Foreground, Background); }