public EditSearchViewModel(ISqlSearch source) { var core = ((App)Application.Current).Core; this.library = core.Library; this.settings = core; this.unsubscribers = new CompositeDisposable(); this.PropertyList = FilePropertyManager.GetPropertyListToSearch() .Select(x => new KeyValuePair <string, PropertyContainer>(x.Key, new PropertyContainer(x.Value))) .ToList(); if (!source.IsUnit) { this.PropertyList.Add (new KeyValuePair <string, PropertyContainer> (settings.GetResourceString("MatchAll"), new PropertyContainer(ComplexMode.And))); this.PropertyList.Add (new KeyValuePair <string, PropertyContainer> (settings.GetResourceString("MatchAny"), new PropertyContainer(ComplexMode.Or))); } this.PropertyComboBoxDefault = settings.GetResourceString("Property"); this.TagComboBoxDefault = settings.GetResourceString("Tag"); this.CompareOperator = new List <KeyValuePair <string, CompareMode> >(); this.AddCompareSymbol(CompareMode.Great); this.AddCompareSymbol(CompareMode.GreatEqual); this.AddCompareSymbol(CompareMode.Equal); this.AddCompareSymbol(CompareMode.LessEqual); this.AddCompareSymbol(CompareMode.Less); this.AddCompareSymbol(CompareMode.NotEqual); this.EqualitySelector = new ObservableCollection <string>() { "", "" }; this.isSVO = settings.IsSVOLanguage; this.BelowRefString = settings.GetResourceString("BelowRef"); this.IsVString = settings.GetResourceString("IsV"); this.SourceItem = source; var unit = source.IsUnit ? (UnitSearch)source : null; this.Init(unit); this.IsEditing = new ReactiveProperty <bool>(true).AddTo(this.unsubscribers); this.OkCommand = this.PropertyListSelectedIndex .Select(x => x >= 0) .ToReactiveCommand() .WithSubscribe(_ => { this.Commit(); this.IsEditing.Value = false; }, this.unsubscribers); this.CancelCommand = new ReactiveCommand() .WithSubscribe(_ => this.IsEditing.Value = false, this.unsubscribers); var propertyObserver = this.PropertyListSelectedIndex .Select(x => { var container = this.GetProperty(x); return(new { Property = container.Property, Enable = (container.Complex == ComplexMode.None && container.IsValid) }); }) .Publish().RefCount(); this.CompareListVisibility = propertyObserver .Select(x => VisibilityHelper.Set(x.Enable && x.Property.IsComperable())) .ToReactiveProperty().AddTo(this.unsubscribers); this.EqualityListVisibility = propertyObserver .Select(x => VisibilityHelper.Set(x.Enable && !x.Property.IsComperable())) .ToReactiveProperty().AddTo(this.unsubscribers); this.NumericTextVisibility = propertyObserver .Select(x => VisibilityHelper.Set(x.Enable && x.Property.IsInteger())) .ToReactiveProperty().AddTo(this.unsubscribers); this.FloatTextVisibility = propertyObserver .Select(x => VisibilityHelper.Set(x.Enable && x.Property.IsFloat())) .ToReactiveProperty().AddTo(this.unsubscribers); this.DirectoryListVisibility = propertyObserver .Select(x => VisibilityHelper.Set(x.Enable && x.Property == FileProperty.DirectoryPathStartsWith)) .ToReactiveProperty().AddTo(this.unsubscribers); this.TagListVisibility = propertyObserver .Select(x => VisibilityHelper.Set(x.Enable && x.Property == FileProperty.ContainsTag)) .ToReactiveProperty().AddTo(this.unsubscribers); this.TextBoxVisibility = propertyObserver .Select(x => VisibilityHelper.Set(x.Enable && x.Property.IsText())) .ToReactiveProperty().AddTo(this.unsubscribers); this.DateVisibility = propertyObserver .Select(x => VisibilityHelper.Set(x.Enable && x.Property.IsDate())) .ToReactiveProperty().AddTo(this.unsubscribers); this.IsVStringVisibility = propertyObserver .Select(x => VisibilityHelper.Set(x.Enable && !this.isSVO)) .ToReactiveProperty().AddTo(this.unsubscribers); this.PropertyComboBoxDefaultVisibility = this.PropertyListSelectedIndex .Select(x => VisibilityHelper.Set(x < 0)) .ToReactiveProperty() .AddTo(this.unsubscribers); this.TagComboBoxDefaultVisibility = new[] { this.TagListSelectedIndex.Select(x => x < 0), propertyObserver.Select(x => x.Enable && x.Property == FileProperty.ContainsTag) } .CombineLatestValuesAreAllTrue() .Select(x => VisibilityHelper.Set(x)) .ToReactiveProperty() .AddTo(this.unsubscribers); propertyObserver.Subscribe(x => { if (x.Enable) { var currentIndex = this.EqualitySelectedIndex.Value; this.EqualitySelector[this.GetEqualitySelectorIndex(true)] = x.Property.GetEqualityLabel(true); this.EqualitySelector[this.GetEqualitySelectorIndex(false)] = x.Property.GetEqualityLabel(false); this.EqualitySelectedIndex.Value = currentIndex; } }).AddTo(this.unsubscribers); this.PropertyListSelectedIndex.Value = unit == null ? -1 : this.PropertyList.FindIndex(x => x.Value.Property == unit.Property); }