@ -1,12 +1,11 @@
using System ;
using System.Reactive.Disposables ;
using System.Reactive.Linq ;
using Avalonia.Collections ;
using Avalonia.Controls ;
using Avalonia.Controls.Diagnostics ;
using Avalonia.Controls.Primitives ;
using Avalonia.Styling ;
using Avalonia.VisualTree ;
using Avalonia.Reactive ;
using Lifetimes = Avalonia . Controls . ApplicationLifetimes ;
using System.Linq ;
@ -61,9 +60,12 @@ namespace Avalonia.Diagnostics.ViewModels
IPopupHostProvider popupHostProvider ,
string? providerName = null )
{
return Observable . FromEvent < IPopupHost ? > (
x = > popupHostProvider . PopupHostChanged + = x ,
x = > popupHostProvider . PopupHostChanged - = x )
return Observable . Create < IPopupHost ? > ( observer = >
{
void Handler ( IPopupHost ? args ) = > observer . OnNext ( args ) ;
popupHostProvider . PopupHostChanged + = Handler ;
return Disposable . Create ( ( ) = > popupHostProvider . PopupHostChanged - = Handler ) ;
} )
. StartWith ( popupHostProvider . PopupHost )
. Select ( popupHost = >
{
@ -80,29 +82,39 @@ namespace Avalonia.Diagnostics.ViewModels
{
Popup p = > GetPopupHostObservable ( p ) ,
Control c = > Observable . CombineLatest (
c . GetObservable ( Control . ContextFlyoutProperty ) ,
c . GetObservable ( Control . ContextMenuProperty ) ,
c . GetObservable ( FlyoutBase . AttachedFlyoutProperty ) ,
c . GetObservable ( ToolTipDiagnostics . ToolTipProperty ) ,
c . GetObservable ( Button . FlyoutProperty ) ,
( ContextFlyout , ContextMenu , AttachedFlyout , ToolTip , ButtonFlyout ) = >
new IObservable < IPopupHostProvider ? > [ ]
{
c . GetObservable ( Control . ContextFlyoutProperty ) ,
c . GetObservable ( Control . ContextMenuProperty ) ,
c . GetObservable ( FlyoutBase . AttachedFlyoutProperty ) ,
c . GetObservable ( ToolTipDiagnostics . ToolTipProperty ) ,
c . GetObservable ( Button . FlyoutProperty )
} )
. Select (
items = >
{
if ( ContextMenu ! = null )
var contextFlyout = items [ 0 ] ;
var contextMenu = ( ContextMenu ? ) items [ 1 ] ;
var attachedFlyout = items [ 2 ] ;
var toolTip = items [ 3 ] ;
var buttonFlyout = items [ 4 ] ;
if ( contextMenu ! = null )
//Note: ContextMenus are special since all the items are added as visual children.
//So we don't need to go via Popup
return Observable . Return < PopupRoot ? > ( new PopupRoot ( ContextMenu ) ) ;
return Observable . Return < PopupRoot ? > ( new PopupRoot ( c ontextMenu) ) ;
if ( ContextFlyout ! = null )
return GetPopupHostObservable ( ContextFlyout , "ContextFlyout" ) ;
if ( c ontextFlyout ! = null )
return GetPopupHostObservable ( c ontextFlyout, "ContextFlyout" ) ;
if ( A ttachedFlyout ! = null )
return GetPopupHostObservable ( A ttachedFlyout, "AttachedFlyout" ) ;
if ( a ttachedFlyout ! = null )
return GetPopupHostObservable ( a ttachedFlyout, "AttachedFlyout" ) ;
if ( T oolTip ! = null )
return GetPopupHostObservable ( T oolTip, "ToolTip" ) ;
if ( t oolTip ! = null )
return GetPopupHostObservable ( t oolTip, "ToolTip" ) ;
if ( B uttonFlyout ! = null )
return GetPopupHostObservable ( B uttonFlyout, "Flyout" ) ;
if ( b uttonFlyout ! = null )
return GetPopupHostObservable ( b uttonFlyout, "Flyout" ) ;
return Observable . Return < PopupRoot ? > ( null ) ;
} )