protected override IDisposable SubscribeCore(IObserver <object> observer) { IAvaloniaObject instance; if (_sourceReference.TryGetTarget(out instance)) { if (_count++ == 0) { WeakSubscriptionManager.Subscribe( instance, nameof(instance.PropertyChanged), this); } observer.OnNext(instance.GetValue(_property)); return(Observable.Using(() => Disposable.Create(DecrementCount), _ => _changed) .Subscribe(observer)); } else { _changed.OnCompleted(); observer.OnCompleted(); return(Disposable.Empty); } }
protected override void SubscribeAndUpdate(WeakReference reference) { object target = reference.Target; CurrentValue = new WeakReference(GetValue(target)); var incc = target as INotifyCollectionChanged; if (incc != null) { WeakSubscriptionManager.Subscribe <NotifyCollectionChangedEventArgs>( incc, nameof(incc.CollectionChanged), this); } var inpc = target as INotifyPropertyChanged; if (inpc != null) { WeakSubscriptionManager.Subscribe <PropertyChangedEventArgs>( inpc, nameof(inpc.PropertyChanged), this); } }
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { _caretTimer.Tick += CaretTimerTick; disposables.Add(this.GetObservable(CaretIndexProperty) .Subscribe(CaretIndexChanged)); disposables.Add(DocumentLineTransformersProperty.Changed.Subscribe(o => { foreach (var item in DocumentLineTransformers) { WeakSubscriptionManager.Subscribe(item, nameof(IDocumentLineTransformer.DataChanged), documentLineTransformerChangedSubscriber); } WeakSubscriptionManager.Subscribe(DocumentLineTransformers, nameof(DocumentLineTransformers.CollectionChanged), documentLineTransformersChangedSubscriber); })); disposables.Add(FontSizeProperty.Changed.Subscribe(o => { GenerateTextProperties(); Invalidate(); })); disposables.Add(FontFamilyProperty.Changed.Subscribe(o => { GenerateTextProperties(); })); disposables.Add(FontStyleProperty.Changed.Subscribe(o => { GenerateTextProperties(); })); disposables.Add(FontWeightProperty.Changed.Subscribe(o => { GenerateTextProperties(); })); }
public Accessor( WeakReference reference, PropertyInfo property, Action <object> changed) { Contract.Requires <ArgumentNullException>(reference != null); Contract.Requires <ArgumentNullException>(property != null); _reference = reference; _property = property; _changed = changed; var inpc = reference.Target as INotifyPropertyChanged; if (inpc != null) { WeakSubscriptionManager.Subscribe( inpc, nameof(inpc.PropertyChanged), this); } else { Logger.Warning( LogArea.Binding, this, "Bound to property {Property} on {Source} which does not implement INotifyPropertyChanged", property.Name, reference.Target, reference.Target.GetType()); } }
public void AddListener(INotifyCollectionChanged collection, ICollectionChangedListener listener) { collection = collection ?? throw new ArgumentNullException(nameof(collection)); listener = listener ?? throw new ArgumentNullException(nameof(listener)); Dispatcher.UIThread.VerifyAccess(); if (!_entries.TryGetValue(collection, out var listeners)) { listeners = new List <WeakReference <ICollectionChangedListener> >(); _entries.Add(collection, listeners); WeakSubscriptionManager.Subscribe( collection, nameof(INotifyCollectionChanged.CollectionChanged), this); } foreach (var l in listeners) { if (l.TryGetTarget(out var target) && target == listener) { throw new InvalidOperationException( "Collection listener already added for this collection/listener combination."); } } listeners.Add(new WeakReference <ICollectionChangedListener>(listener)); }
/// <summary> /// Initializes a new instance of the <see cref="TopLevel"/> class. /// </summary> /// <param name="impl">The platform-specific window implementation.</param> /// <param name="dependencyResolver"> /// The dependency resolver to use. If null the default dependency resolver will be used. /// </param> public TopLevel(ITopLevelImpl impl, IAvaloniaDependencyResolver dependencyResolver) { if (impl == null) { throw new InvalidOperationException( "Could not create window implementation: maybe no windowing subsystem was initialized?"); } PlatformImpl = impl; dependencyResolver = dependencyResolver ?? AvaloniaLocator.Current; var styler = TryGetService <IStyler>(dependencyResolver); _accessKeyHandler = TryGetService <IAccessKeyHandler>(dependencyResolver); _inputManager = TryGetService <IInputManager>(dependencyResolver); _keyboardNavigationHandler = TryGetService <IKeyboardNavigationHandler>(dependencyResolver); _renderInterface = TryGetService <IPlatformRenderInterface>(dependencyResolver); _globalStyles = TryGetService <IGlobalStyles>(dependencyResolver); Renderer = impl.CreateRenderer(this); if (Renderer != null) { Renderer.SceneInvalidated += SceneInvalidated; } impl.SetInputRoot(this); impl.Closed = HandleClosed; impl.Input = HandleInput; impl.Paint = HandlePaint; impl.Resized = HandleResized; impl.ScalingChanged = HandleScalingChanged; _keyboardNavigationHandler?.SetOwner(this); _accessKeyHandler?.SetOwner(this); if (_globalStyles is object) { _globalStyles.GlobalStylesAdded += ((IStyleHost)this).StylesAdded; _globalStyles.GlobalStylesRemoved += ((IStyleHost)this).StylesRemoved; } styler?.ApplyStyles(this); ClientSize = impl.ClientSize; this.GetObservable(PointerOverElementProperty) .Select( x => (x as InputElement)?.GetObservable(CursorProperty) ?? Observable.Empty <Cursor>()) .Switch().Subscribe(cursor => PlatformImpl?.SetCursor(cursor?.PlatformCursor)); if (((IStyleHost)this).StylingParent is IResourceProvider applicationResources) { WeakSubscriptionManager.Subscribe( applicationResources, nameof(IResourceProvider.ResourcesChanged), this); } }
public static WeakSubscriber <T> Subscribe(object target, string eventName, Action <T> onEvent) { var result = new WeakSubscriber <T>(onEvent); WeakSubscriptionManager.Subscribe(target, eventName, result); return(result); }
public AboutWindowViewModel() { WeakSubscriptionManager.Subscribe(App.Current.LocaleManager, nameof(LocaleManager.UICultureChanged), this); AssemblyVersions = VersionStatistics.LoadedAssemblyVersions.Select(kvp => new AssemblyVersionViewModel(kvp.Key, kvp.Value)); CloseCommand = ReactiveCommand.Create(() => AttachedView.Close()); Changelog = File.ReadAllText("Changelog.md"); Attributions = new AttributionViewModel(); }
public Entry(INotifyCollectionChanged collection) { _collection = collection; Listeners = new List <WeakReference <ICollectionChangedListener> >(); WeakSubscriptionManager.Subscribe( _collection, nameof(INotifyCollectionChanged.CollectionChanged), this); }
public UpdateWindowViewModel(TagVersion updateVersion, string changelog) { UpdateVersion = updateVersion; Changelog = changelog; DialogResult = DialogResult.None; WeakSubscriptionManager.Subscribe(App.Current.Locales, nameof(LocaleManager.UICultureChanged), this); UpdateCommand = ReactiveCommand.Create(Update); CancelCommand = ReactiveCommand.Create(Cancel); }
public void EventShoudBePassedToSubscriber() { bool handled = false; var subscriber = new Subscriber(() => handled = true); var source = new EventSource(); WeakSubscriptionManager.Subscribe(source, "Event", subscriber); source.Fire(); Assert.True(handled); }
protected override void Initialize() { if (_sourceReference.TryGetTarget(out INotifyCollectionChanged instance)) { WeakSubscriptionManager.Subscribe( instance, nameof(instance.CollectionChanged), this); } }
/// <summary> /// Creates a new TextSegmentCollection that updates the offsets automatically. /// </summary> /// <param name="textDocument"> /// The document to which the text segments /// that will be added to the tree belong. When the document changes, the /// position of the text segments will be updated accordingly. /// </param> public TextSegmentCollection(TextDocument textDocument) { if (textDocument == null) { throw new ArgumentNullException("textDocument"); } textDocument.VerifyAccess(); isConnectedToDocument = true; WeakSubscriptionManager.Subscribe(textDocument, nameof(textDocument.Changed), this); }
public AboutWindowViewModel() { WeakSubscriptionManager.Subscribe(App.Current.Locales, nameof(LocaleManager.UICultureChanged), this); AssemblyVersions = VersionStatistics.LoadedAssemblyVersions.Select(kvp => new AssemblyVersionViewModel(kvp.Key, kvp.Value)); CloseCommand = ReactiveCommand.Create(() => AttachedView.Close()); var changelogFile = new FileInfo(Path.Combine(Program.ApplicationDirectory.FullName, "Changelog.md")); Changelog = changelogFile.Exists ? File.ReadAllText(changelogFile.FullName) : string.Empty; Attributions = new AttributionViewModel(); }
private void SubscribeToChanges() { var inpc = _reference.Target as INotifyPropertyChanged; if (inpc != null) { WeakSubscriptionManager.Subscribe <PropertyChangedEventArgs>( inpc, nameof(inpc.PropertyChanged), this); } }
private void SubscribeToChanges() { var inpc = GetReferenceTarget() as INotifyPropertyChanged; if (inpc != null) { WeakSubscriptionManager.Subscribe( inpc, nameof(inpc.PropertyChanged), this); } }
/// <summary> /// If the ItemsSource implements INotifyCollectionChanged update the visual when the collection changes. /// </summary> /// <param name="oldValue">The old ItemsSource</param> /// <param name="newValue">The new ItemsSource</param> private void SubscribeToCollectionChanged(IEnumerable oldValue, IEnumerable newValue) { if (oldValue is INotifyCollectionChanged collection) { WeakSubscriptionManager.Unsubscribe(collection, "CollectionChanged", eventListener); } collection = newValue as INotifyCollectionChanged; if (collection != null) { WeakSubscriptionManager.Subscribe(collection, "CollectionChanged", eventListener); } }
protected override void SubscribeCore() { var target = GetReferenceTarget() as INotifyDataErrorInfo; if (target != null) { WeakSubscriptionManager.Subscribe( target, nameof(target.ErrorsChanged), this); } base.SubscribeCore(); }
protected override void SubscribeCore(IObserver <object> observer) { var target = _reference.Target as INotifyDataErrorInfo; if (target != null) { WeakSubscriptionManager.Subscribe( target, nameof(target.ErrorsChanged), this); } base.SubscribeCore(observer); }
public ThemeViewModel(ITheme theme) { Theme = theme; string iconPath = Path.Combine(Program.ApplicationDirectory.FullName, "themes", "assets", "icons", theme.Name + ".png"); if (File.Exists(iconPath)) { Icon = new Bitmap(iconPath); } SelectCommand = ReactiveCommand.Create(Select); WeakSubscriptionManager.Subscribe(InternalEventManager, nameof(EventManager.SelectedThemeChanged), this); WeakSubscriptionManager.Subscribe(App.Current.Locales, nameof(LocaleManager.UICultureChanged), this); }
public IndeiValidationChecker(WeakReference reference, string name, IPropertyAccessor accessor, Action <IValidationStatus> callback) : base(reference, name, accessor, callback) { var target = reference.Target as INotifyDataErrorInfo; if (target != null) { if (target.HasErrors) { SendValidationCallback(new IndeiValidationStatus(target.GetErrors(name))); } WeakSubscriptionManager.Subscribe( target, nameof(target.ErrorsChanged), this); } }
protected override IDisposable SubscribeCore(IObserver <NotifyCollectionChangedEventArgs> observer) { if (_sourceReference.TryGetTarget(out INotifyCollectionChanged instance)) { if (_count++ == 0) { WeakSubscriptionManager.Subscribe( instance, nameof(instance.CollectionChanged), this); } return(Observable.Using(() => Disposable.Create(DecrementCount), _ => _changed) .Subscribe(observer)); } else { _changed.OnCompleted(); observer.OnCompleted(); return(Disposable.Empty); } }
public AssemblyVersionViewModel(Assembly assembly, string version) { AssemblyName = assembly.GetName() !.Name !; AssemblyVersion = version; WeakSubscriptionManager.Subscribe(App.Current.Locales, nameof(LocaleManager.UICultureChanged), this); }
private void AddSubscriber(EventSource source, string name, Action func) { WeakSubscriptionManager.Subscribe(source, name, new Subscriber(func)); }
public LocalizedResource(string key) { Key = key; Value = App.Current.LocaleManager.GetResource(Key); WeakSubscriptionManager.Subscribe(App.Current.LocaleManager, nameof(LocaleManager.UICultureChanged), this); }
public static void SubscribeWeak(IWeakSubscriber <EventArgs> subscriber) => WeakSubscriptionManager.Subscribe(InternalEventManager, nameof(EventManager.SelectedThemeChanged), subscriber);