private void AddLayoutAnchorable(LayoutAnchorable layoutAnchorable, ToolViewLocation toolViewLocation) { LayoutAnchorablePaneGroup layoutAnchorablePaneGroup; if (!Enum.IsDefined(typeof(ToolViewLocation), toolViewLocation)) { throw new InvalidEnumArgumentException(nameof(toolViewLocation), (int)toolViewLocation, typeof(ToolViewLocation)); } switch (toolViewLocation) { case ToolViewLocation.Left: if (LeftLayoutAnchorablePaneGroup.Parent == null) { LeftLayoutAnchorablePaneGroup.Children.Add(new LayoutAnchorablePane()); LeftRightLayoutTarget.Children.Insert(0, LeftLayoutAnchorablePaneGroup); } layoutAnchorablePaneGroup = LeftLayoutAnchorablePaneGroup; break; case ToolViewLocation.Bottom: if (BottomLayoutAnchorablePaneGroup.Parent == null) { BottomLayoutAnchorablePaneGroup.Children.Add(new LayoutAnchorablePane()); BottomLayoutTarget.Children.Add(BottomLayoutAnchorablePaneGroup); } layoutAnchorablePaneGroup = BottomLayoutAnchorablePaneGroup; break; case ToolViewLocation.Right: if (RightLayoutAnchorablePaneGroup.Parent == null) { RightLayoutAnchorablePaneGroup.Children.Add(new LayoutAnchorablePane()); LeftRightLayoutTarget.Children.Add(RightLayoutAnchorablePaneGroup); } layoutAnchorablePaneGroup = RightLayoutAnchorablePaneGroup; break; default: throw new NotSupportedException(); } layoutAnchorablePaneGroup.Descendents() .OfType <LayoutAnchorablePane>() .First() .Children.Add(layoutAnchorable); }
public void AddToolView_WithAllParameters_ViewAddedWithExpectedProperties(ToolViewLocation toolViewLocation) { // Setup using (var avalonDockViewHost = new AvalonDockViewHost()) { const string title = "Random title"; const string symbol = "Random symbol"; var fontFamily = new FontFamily(); var testView = new TestView(); // Call avalonDockViewHost.AddToolView(testView, toolViewLocation, title, symbol, fontFamily); // Assert CustomLayoutAnchorable layoutAnchorable = GetLayoutAnchorable(avalonDockViewHost, testView, toolViewLocation); Assert.AreEqual(title, layoutAnchorable.Title); Assert.AreEqual(symbol, layoutAnchorable.Symbol); Assert.AreSame(fontFamily, layoutAnchorable.FontFamily); } }
public void AddToolView(IView view, ToolViewLocation toolViewLocation, string title, string symbol, FontFamily fontFamily) { var control = view as Control; if (control == null) { return; } // If the view was already added, just bring it to front if (documentViews.Contains(view) || toolViews.Contains(view)) { BringToFront(view); return; } var hostControl = new WindowsFormsHost { Child = control }; var layoutAnchorable = new CustomLayoutAnchorable { Content = hostControl, Title = title, Symbol = symbol, FontFamily = fontFamily }; PerformWithoutChangingActiveContent(() => AddLayoutAnchorable(layoutAnchorable, toolViewLocation)); BringToFront(layoutAnchorable); toolViews.Add(view); hostControls.Add(hostControl); layoutAnchorable.Hiding += OnLayoutAnchorableHiding; layoutAnchorable.Closing += OnLayoutAnchorableClosing; OnViewOpened(view); }
public void AddToolView_TestViews_ViewAddedAndViewOpenedEventFired(ToolViewLocation toolViewLocation) { // Setup var testView = new TestView(); IEnumerable <ToolViewLocation> otherToolViewLocations = Enum.GetValues(typeof(ToolViewLocation)) .Cast <ToolViewLocation>() .Except(new[] { toolViewLocation }); using (var avalonDockViewHost = new AvalonDockViewHost()) { var viewOpenedCounter = 0; avalonDockViewHost.ViewOpened += (sender, args) => { Assert.AreSame(testView, args.View); viewOpenedCounter++; }; // Call avalonDockViewHost.AddToolView(testView, toolViewLocation, string.Empty, string.Empty, null); // Assert CollectionAssert.AreEqual( new[] { testView }, avalonDockViewHost.ToolViews); Assert.IsTrue(IsToolViewPresent(avalonDockViewHost, testView, toolViewLocation)); Assert.IsFalse(otherToolViewLocations.Any(tvl => IsToolViewPresent(avalonDockViewHost, testView, tvl))); Assert.AreEqual(1, viewOpenedCounter); } }
private static bool IsToolViewPresent(AvalonDockViewHost avalonDockViewHost, IView toolView, ToolViewLocation toolViewLocation) { return(GetLayoutAnchorable(avalonDockViewHost, toolView, toolViewLocation) != null); }
private static CustomLayoutAnchorable GetLayoutAnchorable(AvalonDockViewHost avalonDockViewHost, IView toolView, ToolViewLocation toolViewLocation) { string paneField; switch (toolViewLocation) { case ToolViewLocation.Left: paneField = "LeftLayoutAnchorablePaneGroup"; break; case ToolViewLocation.Right: paneField = "RightLayoutAnchorablePaneGroup"; break; case ToolViewLocation.Bottom: paneField = "BottomLayoutAnchorablePaneGroup"; break; default: paneField = ""; break; } var layoutAnchorablePaneGroup = TypeUtils.GetField <LayoutAnchorablePaneGroup>(avalonDockViewHost, paneField); return(layoutAnchorablePaneGroup.Descendents() .OfType <LayoutAnchorablePane>() .First() .Children .Cast <CustomLayoutAnchorable>() .FirstOrDefault(c => ((WindowsFormsHost)c.Content).Child == toolView)); }