internal override void Attach(LayoutContent model) { _anchorable = model as LayoutAnchorable; _anchorable.IsVisibleChanged += _anchorable_IsVisibleChanged; base.Attach(model); }
internal LayoutAnchorControl(LayoutAnchorable model) { _model = model; _model.IsActiveChanged += _model_IsActiveChanged; _model.IsSelectedChanged += _model_IsSelectedChanged; SetSide(_model.FindParent<LayoutAnchorSide>().Side); }
public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer) { //AD wants to add the anchorable into destinationContainer //just for test provide a new anchorablepane //if the pane is floating let the manager go ahead var destPane = destinationContainer as LayoutAnchorablePane; if (destinationContainer != null && destinationContainer.FindParent<LayoutFloatingWindow>() != null) return false; var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "ToolsPane"); if (toolsPane != null) { toolsPane.Children.Add(anchorableToShow); return true; } return false; }
public void AfterInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableShown) { }
internal override void Detach() { _anchorable.IsVisibleChanged -= _anchorable_IsVisibleChanged; _anchorable = null; base.Detach(); }
internal void Hide() { if (_model == null) return; _model.PropertyChanged -= _model_PropertyChanged; RemoveInternalGrid(); _anchor = null; _model = null; _manager = null; Visibility = Visibility.Hidden; Trace.WriteLine("LayoutAutoHideWindowControl.Hide()"); }
internal void Show(LayoutAnchorControl anchor) { if (_model != null) throw new InvalidOperationException(); _anchor = anchor; _model = anchor.Model as LayoutAnchorable; _side = (anchor.Model.Parent.Parent as LayoutAnchorSide).Side; _manager = _model.Root.Manager; CreateInternalGrid(); _model.PropertyChanged += _model_PropertyChanged; Visibility = Visibility.Visible; InvalidateMeasure(); UpdateWindowPos(); Trace.WriteLine("LayoutAutoHideWindowControl.Show()"); }
internal void _ExecuteDockCommand(LayoutAnchorable anchorable) { anchorable.Dock(); }
private void CreateAnchorableLayoutItem(LayoutAnchorable contentToAttach) { if (_layoutItems.Any(item => item.LayoutElement == contentToAttach)) return; var layoutItem = new LayoutAnchorableItem(); layoutItem.Attach(contentToAttach); ApplyStyleToLayoutItem(layoutItem); _layoutItems.Add(layoutItem); if (contentToAttach != null && contentToAttach.Content != null && contentToAttach.Content is UIElement) { InternalAddLogicalChild(contentToAttach.Content); } }
internal void _ExecuteAutoHideCommand(LayoutAnchorable _anchorable) { _anchorable.ToggleAutoHide(); }
internal void _ExecuteHideCommand(LayoutAnchorable anchorable) { var model = anchorable; if (model != null) { //by default hide the anchorable model.Hide(); } }
internal void _ExecuteCloseCommand(LayoutAnchorable anchorable) { var model = anchorable; if (model != null && model.TestCanClose()) { if (model.IsAutoHidden) model.ToggleAutoHide(); model.Close(); } }
private void anchorablesSourceElementsChanged(object sender, NotifyCollectionChangedEventArgs e) { if (Layout == null) return; //When deserializing documents are created automatically by the deserializer if (SuspendAnchorablesSourceBinding) return; //handle remove if (e.Action == NotifyCollectionChangedAction.Remove || e.Action == NotifyCollectionChangedAction.Replace) { if (e.OldItems != null) { var anchorablesToRemove = Layout.Descendents() .OfType<LayoutAnchorable>() .Where(d => e.OldItems.Contains(d.Content)) .ToArray(); foreach (var anchorableToRemove in anchorablesToRemove) { anchorableToRemove.Parent.RemoveChild( anchorableToRemove); } } } //handle add if (e.NewItems != null && (e.Action == NotifyCollectionChangedAction.Add || e.Action == NotifyCollectionChangedAction.Replace)) { if (e.NewItems != null) { LayoutAnchorablePane anchorablePane = null; if (Layout.ActiveContent != null) { //look for active content parent pane anchorablePane = Layout.ActiveContent.Parent as LayoutAnchorablePane; } if (anchorablePane == null) { //look for a pane on the right side anchorablePane = Layout.Descendents() .OfType<LayoutAnchorablePane>() .Where(pane => !pane.IsHostedInFloatingWindow && pane.GetSide() == AnchorSide.Right) .FirstOrDefault(); } if (anchorablePane == null) { //look for an available pane anchorablePane = Layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(); } _suspendLayoutItemCreation = true; foreach (var anchorableContentToImport in e.NewItems) { var anchorableToImport = new LayoutAnchorable { Content = anchorableContentToImport }; var added = false; if (LayoutUpdateStrategy != null) { added = LayoutUpdateStrategy.BeforeInsertAnchorable(Layout, anchorableToImport, anchorablePane); } if (!added) { if (anchorablePane == null) { var mainLayoutPanel = new LayoutPanel {Orientation = Orientation.Horizontal}; if (Layout.RootPanel != null) { mainLayoutPanel.Children.Add(Layout.RootPanel); } Layout.RootPanel = mainLayoutPanel; anchorablePane = new LayoutAnchorablePane { DockWidth = new GridLength(200.0, GridUnitType.Pixel) }; mainLayoutPanel.Children.Add(anchorablePane); } anchorablePane.Children.Add(anchorableToImport); added = true; } if (LayoutUpdateStrategy != null) { LayoutUpdateStrategy.AfterInsertAnchorable(Layout, anchorableToImport); } var root = anchorableToImport.Root; if (root != null && root.Manager == this) { CreateAnchorableLayoutItem(anchorableToImport); } } _suspendLayoutItemCreation = false; } } if (e.Action == NotifyCollectionChangedAction.Reset) { //NOTE: I'm going to clear every anchorable present in layout but //some anchorable may have been added directly to the layout, for now I clear them too var anchorablesToRemove = Layout.Descendents().OfType<LayoutAnchorable>().ToArray(); foreach (var anchorableToRemove in anchorablesToRemove) { anchorableToRemove.Parent.RemoveChild( anchorableToRemove); } } if (Layout != null) Layout.CollectGarbage(); }
private void AttachAnchorablesSource(LayoutRoot layout, IEnumerable anchorablesSource) { if (anchorablesSource == null) return; if (layout == null) return; //if (layout.Descendents().OfType<LayoutAnchorable>().Any()) // throw new InvalidOperationException("Unable to set the AnchorablesSource property if LayoutAnchorable objects are already present in the model"); var anchorablesImported = layout.Descendents().OfType<LayoutAnchorable>().Select(d => d.Content).ToArray(); var anchorables = anchorablesSource; var listOfAnchorablesToImport = new List<object>(anchorables.OfType<object>()); foreach (var document in listOfAnchorablesToImport.ToArray()) { if (anchorablesImported.Contains(document)) listOfAnchorablesToImport.Remove(document); } LayoutAnchorablePane anchorablePane = null; if (layout.ActiveContent != null) { //look for active content parent pane anchorablePane = layout.ActiveContent.Parent as LayoutAnchorablePane; } if (anchorablePane == null) { //look for a pane on the right side anchorablePane = layout.Descendents() .OfType<LayoutAnchorablePane>() .Where(pane => !pane.IsHostedInFloatingWindow && pane.GetSide() == AnchorSide.Right) .FirstOrDefault(); } if (anchorablePane == null) { //look for an available pane anchorablePane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(); } _suspendLayoutItemCreation = true; foreach (var anchorableContentToImport in listOfAnchorablesToImport) { var anchorableToImport = new LayoutAnchorable { Content = anchorableContentToImport }; var added = false; if (LayoutUpdateStrategy != null) { added = LayoutUpdateStrategy.BeforeInsertAnchorable(layout, anchorableToImport, anchorablePane); } if (!added) { if (anchorablePane == null) { var mainLayoutPanel = new LayoutPanel {Orientation = Orientation.Horizontal}; if (layout.RootPanel != null) { mainLayoutPanel.Children.Add(layout.RootPanel); } layout.RootPanel = mainLayoutPanel; anchorablePane = new LayoutAnchorablePane { DockWidth = new GridLength(200.0, GridUnitType.Pixel) }; mainLayoutPanel.Children.Add(anchorablePane); } anchorablePane.Children.Add(anchorableToImport); added = true; } if (LayoutUpdateStrategy != null) LayoutUpdateStrategy.AfterInsertAnchorable(layout, anchorableToImport); CreateAnchorableLayoutItem(anchorableToImport); } _suspendLayoutItemCreation = false; var anchorablesSourceAsNotifier = anchorablesSource as INotifyCollectionChanged; if (anchorablesSourceAsNotifier != null) anchorablesSourceAsNotifier.CollectionChanged += anchorablesSourceElementsChanged; }