|
|
@ -7,17 +7,18 @@ |
|
|
namespace Perspex.Styling |
|
|
namespace Perspex.Styling |
|
|
{ |
|
|
{ |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Collections.Generic; |
|
|
using System.Reactive.Linq; |
|
|
using System.Reactive.Linq; |
|
|
using Perspex.Controls; |
|
|
using Perspex.Controls; |
|
|
|
|
|
|
|
|
public static class Selectors |
|
|
public static class Selectors |
|
|
{ |
|
|
{ |
|
|
public static Selector Class(this Selector match, string name) |
|
|
public static Selector Class(this Selector previous, string name) |
|
|
{ |
|
|
{ |
|
|
Contract.Requires<ArgumentNullException>(match != null); |
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
Contract.Requires<ArgumentNullException>(name != null); |
|
|
Contract.Requires<ArgumentNullException>(name != null); |
|
|
|
|
|
|
|
|
return new Selector(match) |
|
|
return new Selector(previous) |
|
|
{ |
|
|
{ |
|
|
Observable = control => Observable |
|
|
Observable = control => Observable |
|
|
.Return(control.Classes.Contains(name)) |
|
|
.Return(control.Classes.Contains(name)) |
|
|
@ -26,39 +27,60 @@ namespace Perspex.Styling |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static Selector Descendent(this Selector match) |
|
|
public static Selector Descendent(this Selector previous) |
|
|
{ |
|
|
{ |
|
|
throw new NotImplementedException(); |
|
|
return new Selector(previous, stopTraversal: true) |
|
|
|
|
|
{ |
|
|
|
|
|
SelectorString = " ", |
|
|
|
|
|
Observable = control => |
|
|
|
|
|
{ |
|
|
|
|
|
ILogical c = (ILogical)control; |
|
|
|
|
|
List<IObservable<bool>> descendentMatches = new List<IObservable<bool>>(); |
|
|
|
|
|
|
|
|
|
|
|
while (c != null) |
|
|
|
|
|
{ |
|
|
|
|
|
c = c.LogicalParent; |
|
|
|
|
|
|
|
|
|
|
|
if (c is IStyleable) |
|
|
|
|
|
{ |
|
|
|
|
|
descendentMatches.Add(previous.Observable((IStyleable)c)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new Activator(descendentMatches, ActivatorMode.Or); |
|
|
|
|
|
}, |
|
|
|
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static Selector Id(this Selector match, string id) |
|
|
public static Selector Id(this Selector previous, string id) |
|
|
{ |
|
|
{ |
|
|
Contract.Requires<ArgumentNullException>(match != null); |
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
|
|
|
|
|
|
return new Selector(match) |
|
|
return new Selector(previous) |
|
|
{ |
|
|
{ |
|
|
Observable = control => Observable.Return(control.Id == id), |
|
|
Observable = control => Observable.Return(control.Id == id), |
|
|
SelectorString = '#' + id, |
|
|
SelectorString = '#' + id, |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static Selector OfType<T>(this Selector match) where T : IStyleable |
|
|
public static Selector OfType<T>(this Selector previous) where T : IStyleable |
|
|
{ |
|
|
{ |
|
|
Contract.Requires<ArgumentNullException>(match != null); |
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
|
|
|
|
|
|
return new Selector(match) |
|
|
return new Selector(previous) |
|
|
{ |
|
|
{ |
|
|
Observable = control => Observable.Return(control is T), |
|
|
Observable = control => Observable.Return(control is T), |
|
|
SelectorString = typeof(T).Name, |
|
|
SelectorString = typeof(T).Name, |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static Selector Template(this Selector match) |
|
|
public static Selector Template(this Selector previous) |
|
|
{ |
|
|
{ |
|
|
Contract.Requires<ArgumentNullException>(match != null); |
|
|
Contract.Requires<ArgumentNullException>(previous != null); |
|
|
|
|
|
|
|
|
return new Selector(match) |
|
|
return new Selector(previous) |
|
|
{ |
|
|
{ |
|
|
|
|
|
Observable = control => Observable.Return(control.TemplatedParent != null), |
|
|
SelectorString = " $ ", |
|
|
SelectorString = " $ ", |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|