-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,400 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System.Collections; | ||
using System.Collections.Specialized; | ||
using System.Windows; | ||
using phirSOFT.TopologicalComparison; | ||
using Prism.Regions; | ||
|
||
namespace phirSOFT.FluentRegionAdapters | ||
{ | ||
public abstract class ContraintedRegionAdapter<TContainer> : RegionAdapterBase<TContainer> | ||
where TContainer : DependencyObject | ||
{ | ||
public static readonly DependencyProperty ConstraintComparerProperty = DependencyProperty.RegisterAttached( | ||
"ConstraintComparer", typeof(ITopologicalComparer), typeof(ContraintedRegionAdapter<TContainer>), | ||
new PropertyMetadata(new DefaultComparer())); | ||
|
||
protected ContraintedRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) : base(regionBehaviorFactory) | ||
{ | ||
} | ||
|
||
public static void SetConstraintComparer(DependencyObject element, ITopologicalComparer value) | ||
{ | ||
element.SetValue(ConstraintComparerProperty, value); | ||
} | ||
|
||
public static ITopologicalComparer GetConstraintComparer(DependencyObject element) | ||
{ | ||
return (ITopologicalComparer) element.GetValue(ConstraintComparerProperty); | ||
} | ||
|
||
|
||
protected override void Adapt(IRegion region, TContainer regionTarget) | ||
{ | ||
region.Views.CollectionChanged += (sender, args) => UpdateRegion(sender, args, regionTarget); | ||
//region.ActiveViews.CollectionChanged += (sender, args) => ActivateView(sender, args); | ||
} | ||
|
||
|
||
protected virtual void UpdateRegion(object sender, NotifyCollectionChangedEventArgs args, | ||
TContainer regionTarget) | ||
{ | ||
switch (args.Action) | ||
{ | ||
case NotifyCollectionChangedAction.Add: | ||
foreach (DependencyObject item in args.NewItems) | ||
{ | ||
var list = GetItemCollection(regionTarget, item); | ||
list.Insert(item, GetConstraintComparer(regionTarget)); | ||
} | ||
|
||
break; | ||
case NotifyCollectionChangedAction.Remove: | ||
foreach (DependencyObject item in args.NewItems) | ||
{ | ||
var list = GetItemCollection(regionTarget, item); | ||
list.Remove(item); | ||
} | ||
break; | ||
case NotifyCollectionChangedAction.Replace: | ||
break; | ||
case NotifyCollectionChangedAction.Move: | ||
break; | ||
case NotifyCollectionChangedAction.Reset: | ||
break; | ||
} | ||
} | ||
|
||
|
||
protected abstract IList GetItemCollection(TContainer container); | ||
|
||
protected virtual IList GetItemCollection(TContainer container, DependencyObject item) | ||
{ | ||
return GetItemCollection(container); | ||
} | ||
|
||
protected override IRegion CreateRegion() | ||
{ | ||
return new Region(); | ||
} | ||
|
||
private class DefaultComparer : ITopologicalComparer | ||
{ | ||
public int Compare(object x, object y) | ||
{ | ||
return 0; | ||
} | ||
|
||
public bool CanCompare(object x, object y) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Windows; | ||
using Fluent; | ||
|
||
namespace phirSOFT.FluentRegionAdapters | ||
{ | ||
public class GroupConstraint : PositionConstraint | ||
{ | ||
public static readonly DependencyProperty GroupProperty = DependencyProperty.RegisterAttached( | ||
"Group", typeof(int), typeof(GroupConstraint), new PropertyMetadata(default(int))); | ||
|
||
public static void SetGroup(DependencyObject element, int value) | ||
{ | ||
element.SetValue(GroupProperty, value); | ||
} | ||
|
||
public static int GetGroup(DependencyObject element) | ||
{ | ||
return (int) element.GetValue(GroupProperty); | ||
} | ||
|
||
public override bool CanCompare(DependencyObject x, DependencyObject y) | ||
{ | ||
return x is RibbonTabItem && y is RibbonTabItem; | ||
} | ||
|
||
public override int Compare(DependencyObject x, DependencyObject y) | ||
{ | ||
var left = GetGroup(x); | ||
var right = GetGroup(y); | ||
|
||
return left - right; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
using System.Collections.Generic; | ||
using System.Windows; | ||
using phirSOFT.TopologicalComparison; | ||
|
||
namespace phirSOFT.FluentRegionAdapters | ||
{ | ||
public abstract class PositionConstraint<T> : Comparer<T> | ||
public abstract class PositionConstraint : ITopologicalComparer<DependencyObject>, ITopologicalComparer | ||
{ | ||
protected abstract bool CanCompare(T left, T right); | ||
public int Compare(object x, object y) | ||
{ | ||
return Compare(x as DependencyObject, y as DependencyObject); | ||
} | ||
|
||
protected static bool CanCompare(PositionConstraint<T> comparer, T left, T rigt) | ||
public bool CanCompare(object x, object y) | ||
{ | ||
return comparer.CanCompare(left, rigt); | ||
return x is DependencyObject xx && y is DependencyObject yy && CanCompare(xx, yy); | ||
} | ||
|
||
public abstract bool CanCompare(DependencyObject x, DependencyObject y); | ||
|
||
public abstract int Compare(DependencyObject x, DependencyObject y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.