Ejemplo n.º 1
0
        public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
        {
            var tool = anchorableToShow.Content as ITool;
            if (tool != null)
            {
                var preferredLocation = tool.PreferredLocation;
                string paneName = GetPaneName(preferredLocation);
                var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == paneName);
                if (toolsPane == null)
                {
                    switch (preferredLocation)
                    {
                        case PaneLocation.Left:
                            toolsPane = CreateAnchorablePane(layout, Orientation.Horizontal, paneName, InsertPosition.Start);
                            break;
                        case PaneLocation.Right:
                            toolsPane = CreateAnchorablePane(layout, Orientation.Horizontal, paneName, InsertPosition.End);
                            break;
                        case PaneLocation.Bottom:
                            toolsPane = CreateAnchorablePane(layout, Orientation.Vertical, paneName, InsertPosition.End);
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
                toolsPane.Children.Add(anchorableToShow);
                return true;
            }

            return false;
        }
Ejemplo n.º 2
0
        public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
        {           
            //Determine panel name for given view model type
            string destPaneName = string.Empty;
            if (anchorableToShow.Content is JadeControls.Workspace.ViewModel.WorkspaceViewModel ||
                anchorableToShow.Content is JadeControls.SymbolInspector.SymbolInspectorPaneViewModel ||
                anchorableToShow.Content is JadeControls.CursorInspector.CursorInspectorPaneViewModel)
            {
                destPaneName = "LeftToolPanel";
            }
            else if (anchorableToShow.Content is JadeControls.OutputControl.ViewModel.OutputViewModel ||
                    anchorableToShow.Content is JadeControls.SearchResultsControl.ViewModel.SearchResultsPaneViewModel)
            {
                destPaneName = "LowerToolPanel";
            }
            else if (anchorableToShow.Content is JadeControls.ContextTool.ContextPaneViewModel)
            {
                destPaneName = "RightToolPanel";
            }
            else
            {
                return false;
            }

            //Find pane
            var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == destPaneName);
            if (toolsPane != null)
            {
                //Add
                toolsPane.Children.Add(anchorableToShow);
                return true;
            } 
            return false;
        }
        private static LayoutAnchorablePane CreateAnchorablePane(LayoutRoot layout, Orientation orientation,
            string paneName, InsertPosition position)
        {
            var layoutPanels = layout.Descendents().OfType<LayoutPanel>().ToArray();
            var parent = layoutPanels.FirstOrDefault(d => d != null && d.Orientation == orientation);
            if (parent == null)
            {
                parent = layoutPanels.FirstOrDefault();
                position = InsertPosition.Start;
            }
            var toolsPane = new LayoutAnchorablePane { Name = paneName };
            if (parent != null)
            {
                if (position == InsertPosition.Start)
                    parent.InsertChildAt(0, toolsPane);
                else
                    parent.Children.Add(toolsPane);
            }
            else
            {
                var layoutAnchorableFloatingWindow = new LayoutAnchorableFloatingWindow();
                toolsPane.Parent = layoutAnchorableFloatingWindow;

            }
            return toolsPane;
        }
Ejemplo n.º 4
0
        public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
        {
            if (destinationContainer != null &&
                destinationContainer.FindParent<LayoutFloatingWindow>() != null)
            {
                return false;
            }

            foreach (var viewModelPane in ViewModelPanes)
            {
                if (viewModelPane.Item1.IsInstanceOfType(anchorableToShow.Content))
                {
                    var pane = layout
                        .Descendents()
                        .OfType<LayoutAnchorablePane>()
                        .SingleOrDefault(p => p.Name == viewModelPane.Item2);

                    if (pane != null)
                    {
                        pane.Children.Add(anchorableToShow);

                        if (viewModelPane.Item3)
                        {
                            anchorableToShow.ToggleAutoHide();
                        }

                        return true;
                    }
                }
            }

            return false;
        }
Ejemplo n.º 5
0
        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
            LayoutAnchorablePane destPane = destinationContainer as LayoutAnchorablePane;
            if (destinationContainer != null &&
                destinationContainer.FindParent<LayoutFloatingWindow>() != null)
                return false;

            if (anchorableToShow.Content is SectionBrowserViewModel)
            {
                var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "SectionBrowserPane");
                if (toolsPane != null)
                {
                   // anchorableToShow.CanHide = false;
                    toolsPane.Children.Add(anchorableToShow);
                    return true;
                }
            }

            if (anchorableToShow.Content is BlockGroupBrowserViewModel)
            {
                var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "BlockGroupBrowserPane");
                if (toolsPane != null)
                {
                   // anchorableToShow.CanHide = false;
                    toolsPane.Children.Add(anchorableToShow);
                    return true;
                }
            }

            if (anchorableToShow.Content is BlockOutputPreviewViewModel)
            {
                var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "BlockOutputPreviewPane");
                if (toolsPane != null)
                {
                    toolsPane.Children.Add(anchorableToShow);
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 6
0
        //http://avalondock.codeplex.com/wikipage?title=AvalonDock%202.0%20Getting%20Start%20Guide&referringTitle=Documentation
		public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
		{
            if (anchorableToShow.Content is ITool)
            {
                var preferredLocation = ((ITool) anchorableToShow.Content).PreferredLocation;
                string paneName = GetPaneName(preferredLocation);
                var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == paneName);
                if (toolsPane == null)
                {
                    switch (preferredLocation)
                    {
                        case PaneLocation.Left:
                        {
                            //TODO: this should use two steps: first, try to add to existing "LayoutAnchorablePane" if not create layoutAnchorGroup like below
                            var layoutAnchorSide = layout.Descendents().OfType<LayoutAnchorSide>().First(side => side.Side == AnchorSide.Left);
                            var layoutAnchorGroup = new LayoutAnchorGroup();
                            layoutAnchorGroup.InsertChildAt(0, anchorableToShow);
                            layoutAnchorSide.InsertChildAt(0, layoutAnchorGroup);
                            anchorableToShow.AutoHideWidth = 200;

                            //var parent = layout.Descendents().OfType<LayoutPanel>().First(d => d.Orientation == Orientation.Horizontal);
                            //toolsPane = new LayoutAnchorablePane { DockWidth = new GridLength(200, GridUnitType.Pixel) };
                        }
                            break;
                        case PaneLocation.Right:
                        {
                            var parent = layout.Descendents().OfType<LayoutPanel>().First(d => d.Orientation == Orientation.Horizontal);
                            toolsPane = new LayoutAnchorablePane { DockWidth = new GridLength(200, GridUnitType.Pixel) };
                            parent.Children.Add(toolsPane);
                        }
                            break;
                        case PaneLocation.Bottom:
                        {
                            var ds = layout.Descendents().ToList();
                            var items = layout.Descendents().OfType<LayoutPanel>().ToList();
                            var items2 = layout.Descendents().OfType<LayoutAnchorGroup>().ToList();
                            //var parent = items2.First();
                            var parent = layout.Descendents().OfType<LayoutPanel>().First(d => d.Orientation == Orientation.Vertical);
                            toolsPane = new LayoutAnchorablePane { DockHeight = new GridLength(300, GridUnitType.Pixel) };
                            parent.Children.Add(toolsPane);
                        }
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
                if(toolsPane != null)
                    toolsPane.Children.Add(anchorableToShow);
                return true;
            }

			return false;
		}
Ejemplo n.º 7
0
        public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
        {
            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 bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
        {
            var myViewModel = anchorableToShow.Content as IToolWindow;
            if (myViewModel != null)
            {
                var lap = layout.Descendents();
                var pane = lap.OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == myViewModel.DefaultDockingPane);
                if (pane != null)
                {
                    pane.Children.Add(anchorableToShow);
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 9
0
        public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorable, ILayoutContainer destination)
        {
            LayoutAnchorablePane pane = destination as LayoutAnchorablePane;
            if (destination != null && destination.FindParent<LayoutFloatingWindow>() != null)
            {
                return false;
            }

            LayoutAnchorablePane files = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == "pnFiles");
            if (files != null)
            {
                files.Children.Add(anchorable);
                return true;
            }
            return false;
        }
        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
            LayoutAnchorablePane 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;
        }
Ejemplo n.º 11
0
 private bool BeforeInsertContent(LayoutRoot layout, LayoutContent anchorableToShow)
 {
     var viewModel = (ViewModelBase) anchorableToShow.Content;
     var layoutContent =
         layout.Descendents().OfType<LayoutContent>().FirstOrDefault(x => x.ContentId == viewModel.ContextId);
     if (layoutContent == null)
         return false;
     layoutContent.Content = anchorableToShow.Content;
     // Add layoutContent to it's previous container
     var layoutContainer =
         layoutContent.GetType()
             .GetProperty("PreviousContainer", BindingFlags.NonPublic | BindingFlags.Instance)
             .GetValue(layoutContent, null) as ILayoutContainer;
     if (layoutContainer is LayoutAnchorablePane)
         (layoutContainer as LayoutAnchorablePane).Children.Add(layoutContent as LayoutAnchorable);
     else if (layoutContainer is LayoutDocumentPane)
         (layoutContainer as LayoutDocumentPane).Children.Add(layoutContent);
     else
         throw new NotSupportedException();
     return true;
 }
Ejemplo n.º 12
0
 private static LayoutAnchorablePane CreateAnchorablePane(LayoutRoot layout, Orientation orientation,
     string paneName, InsertPosition position)
 {
     var parent = layout.Descendents().OfType<LayoutPanel>().First(d => d.Orientation == orientation);
     var toolsPane = new LayoutAnchorablePane { Name = paneName };
     if (position == InsertPosition.Start)
         parent.InsertChildAt(0, toolsPane);
     else
         parent.Children.Add(toolsPane);
     return toolsPane;
 }
Ejemplo n.º 13
0
        private static LayoutAnchorablePane CreateAnchorablePane(
            LayoutRoot layout,
            Orientation orientation,
            string paneName,
            InsertPosition position)
        {
            var parent = layout.Descendents().OfType<LayoutPanel>().First();
            foreach (var panel in layout.Descendents().OfType<LayoutPanel>())
            {
                if (panel.Orientation == orientation)
                {
                    parent = panel;
                    break;
                }
            }

            var toolsPane = new LayoutAnchorablePane { Name = paneName };
            if (position == InsertPosition.Start)
            {
                parent.InsertChildAt(0, toolsPane);
            }
            else
            {
                parent.Children.Add(toolsPane);
            }

            return toolsPane;
        }
Ejemplo n.º 14
0
        public void ToggleAutoHide()
        {
            #region Anchorable is already auto hidden
            if (IsAutoHidden)
            {
                var parentGroup       = Parent as LayoutAnchorGroup;
                var parentSide        = parentGroup.Parent as LayoutAnchorSide;
                var previousContainer = (( ILayoutPreviousContainer )parentGroup).PreviousContainer as LayoutAnchorablePane;

                if (previousContainer == null)
                {
                    AnchorSide side = (parentGroup.Parent as LayoutAnchorSide).Side;
                    switch (side)
                    {
                    case AnchorSide.Right:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Horizontal)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            previousContainer.DockMinWidth = this.AutoHideMinWidth;
                            parentGroup.Root.RootPanel.Children.Add(previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Horizontal
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(oldRootPanel);
                            panel.Children.Add(previousContainer);
                        }
                        break;

                    case AnchorSide.Left:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Horizontal)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            previousContainer.DockMinWidth = this.AutoHideMinWidth;
                            parentGroup.Root.RootPanel.Children.Insert(0, previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Horizontal
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(previousContainer);
                            panel.Children.Add(oldRootPanel);
                        }
                        break;

                    case AnchorSide.Top:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Vertical)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            previousContainer.DockMinHeight = this.AutoHideMinHeight;
                            parentGroup.Root.RootPanel.Children.Insert(0, previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Vertical
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(previousContainer);
                            panel.Children.Add(oldRootPanel);
                        }
                        break;

                    case AnchorSide.Bottom:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Vertical)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            previousContainer.DockMinHeight = this.AutoHideMinHeight;
                            parentGroup.Root.RootPanel.Children.Add(previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Vertical
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(oldRootPanel);
                            panel.Children.Add(previousContainer);
                        }
                        break;
                    }
                }
                else
                {
                    //I'm about to remove parentGroup, redirect any content (ie hidden contents) that point to it
                    //to previousContainer
                    LayoutRoot root = parentGroup.Root as LayoutRoot;
                    foreach (var cnt in root.Descendents().OfType <ILayoutPreviousContainer>().Where(c => c.PreviousContainer == parentGroup))
                    {
                        cnt.PreviousContainer = previousContainer;
                    }
                }

                foreach (var anchorableToToggle in parentGroup.Children.ToArray())
                {
                    previousContainer.Children.Add(anchorableToToggle);
                }

                if (previousContainer.Children.Count > 0)
                {
                    // Select the LayoutContent where the Toggle pin button was pressed.
                    previousContainer.SelectedContentIndex = previousContainer.Children.IndexOf(this);
                }

                parentSide.Children.Remove(parentGroup);

                var parent = previousContainer.Parent as LayoutGroupBase;
                while ((parent != null))
                {
                    if (parent is LayoutGroup <ILayoutPanelElement> )
                    {
                        ((LayoutGroup <ILayoutPanelElement>)parent).ComputeVisibility();
                    }
                    parent = parent.Parent as LayoutGroupBase;
                }
            }
            #endregion

            #region Anchorable is docked
            else if (Parent is LayoutAnchorablePane)
            {
                var root       = Root;
                var parentPane = Parent as LayoutAnchorablePane;

                var newAnchorGroup = new LayoutAnchorGroup();

                (( ILayoutPreviousContainer )newAnchorGroup).PreviousContainer = parentPane;

                foreach (var anchorableToImport in parentPane.Children.ToArray())
                {
                    newAnchorGroup.Children.Add(anchorableToImport);
                }

                //detect anchor side for the pane
                var anchorSide = parentPane.GetSide();

                switch (anchorSide)
                {
                case AnchorSide.Right:
                    if (root.RightSide != null)
                    {
                        root.RightSide.Children.Add(newAnchorGroup);
                    }
                    break;

                case AnchorSide.Left:
                    if (root.LeftSide != null)
                    {
                        root.LeftSide.Children.Add(newAnchorGroup);
                    }
                    break;

                case AnchorSide.Top:
                    if (root.TopSide != null)
                    {
                        root.TopSide.Children.Add(newAnchorGroup);
                    }
                    break;

                case AnchorSide.Bottom:
                    if (root.BottomSide != null)
                    {
                        root.BottomSide.Children.Add(newAnchorGroup);
                    }
                    break;
                }
            }
            #endregion
        }
Ejemplo n.º 15
0
        public void ToggleAutoHide()
        {
            #region Anchorable is already auto hidden
            if (IsAutoHidden)
            {
                var parentGroup       = Parent as LayoutAnchorGroup;
                var parentSide        = parentGroup.Parent as LayoutAnchorSide;
                var previousContainer = ((ILayoutPreviousContainer)parentGroup).PreviousContainer as LayoutAnchorablePane;

                if (previousContainer == null)
                {
                    AnchorSide side = (parentGroup.Parent as LayoutAnchorSide).Side;
                    switch (side)
                    {
                    case AnchorSide.Right:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Horizontal)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Add(previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Horizontal
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(oldRootPanel);
                            panel.Children.Add(previousContainer);
                        }
                        break;

                    case AnchorSide.Left:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Horizontal)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Insert(0, previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Horizontal
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(previousContainer);
                            panel.Children.Add(oldRootPanel);
                        }
                        break;

                    case AnchorSide.Top:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Vertical)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Insert(0, previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Vertical
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(previousContainer);
                            panel.Children.Add(oldRootPanel);
                        }
                        break;

                    case AnchorSide.Bottom:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Vertical)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Add(previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Vertical
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(oldRootPanel);
                            panel.Children.Add(previousContainer);
                        }
                        break;
                    }
                }
                else
                {
                    //I'm about to remove parentGroup, redirect any content (ie hidden contents) that point to it
                    //to previousContainer
                    LayoutRoot root = parentGroup.Root as LayoutRoot;
                    foreach (var cnt in root.Descendents().OfType <ILayoutPreviousContainer>().Where(c => c.PreviousContainer == parentGroup))
                    {
                        cnt.PreviousContainer = previousContainer;
                    }
                }


                foreach (var anchorableToToggle in parentGroup.Children.ToArray())
                {
                    previousContainer.Children.Add(anchorableToToggle);
                }

                parentSide.Children.Remove(parentGroup);
            }
            #endregion
            #region Anchorable is docked
            else if (Parent is LayoutAnchorablePane)
            {
                var root       = Root;
                var parentPane = Parent as LayoutAnchorablePane;

                var newAnchorGroup = new LayoutAnchorGroup();

                ((ILayoutPreviousContainer)newAnchorGroup).PreviousContainer = parentPane;

                foreach (var anchorableToImport in parentPane.Children.ToArray())
                {
                    newAnchorGroup.Children.Add(anchorableToImport);
                }

                //detect anchor side for the pane
                var anchorSide = parentPane.GetSide();

                switch (anchorSide)
                {
                case AnchorSide.Right:
                    root.RightSide.Children.Add(newAnchorGroup);
                    break;

                case AnchorSide.Left:
                    root.LeftSide.Children.Add(newAnchorGroup);
                    break;

                case AnchorSide.Top:
                    root.TopSide.Children.Add(newAnchorGroup);
                    break;

                case AnchorSide.Bottom:
                    root.BottomSide.Children.Add(newAnchorGroup);
                    break;
                }
            }
            #endregion
        }
Ejemplo n.º 16
0
        public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow,
            ILayoutContainer destinationContainer)
        {
            var destPane = destinationContainer as LayoutAnchorablePane;

            if (destinationContainer != null &&
                destinationContainer.FindParent<LayoutFloatingWindow>() != null)
                return false;

            var content = anchorableToShow.Content;
            bool result;
            if (destinationContainer != null && destinationContainer.FindParent<LayoutFloatingWindow>() != null)
            {
                result = false;
            }
            else
            {
                var layoutAnchorablePane =
                    layout.Descendents()
                        .OfType<LayoutAnchorablePane>()
                        .FirstOrDefault(d => d.Name == "BottomPane");
                var layoutAnchorablePane2 =
                    layout.Descendents()
                        .OfType<LayoutAnchorablePane>()
                        .FirstOrDefault(d => d.Name == "LeftPane");
                var layoutAnchorablePane3 =
                    layout.Descendents()
                        .OfType<LayoutAnchorablePane>()
                        .FirstOrDefault(d => d.Name == "RightPane");
                switch (((ToolViewModel) content).DefaultPane)
                {
                    case DefaultToolPane.Left:
                        if (layoutAnchorablePane2 != null)
                        {
                            layoutAnchorablePane2.Children.Add(anchorableToShow);
                            result = true;
                            return result;
                        }
                        break;
                    case DefaultToolPane.Right:
                        if (layoutAnchorablePane3 != null)
                        {
                            layoutAnchorablePane3.Children.Add(anchorableToShow);
                            result = true;
                            return result;
                        }
                        break;
                    case DefaultToolPane.Bottom:
                        if (layoutAnchorablePane != null)
                        {
                            layoutAnchorablePane.Children.Add(anchorableToShow);
                            result = true;
                            return result;
                        }
                        break;
                }
                var layoutAnchorablePane4 =
                    layout.Descendents()
                        .OfType<LayoutAnchorablePane>()
                        .FirstOrDefault((LayoutAnchorablePane d) => d.Name == "ToolsPane");
                if (layoutAnchorablePane4 != null)
                {
                    layoutAnchorablePane4.Children.Add(anchorableToShow);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            return result;
        }
Ejemplo n.º 17
0
        public void ToggleAutoHide()
        {
            #region Anchorable is already auto hidden
            if (IsAutoHidden)
            {
                var parentGroup       = Parent as LayoutAnchorGroup;
                var parentSide        = parentGroup.Parent as LayoutAnchorSide;
                var previousContainer = ((ILayoutPreviousContainer)parentGroup).PreviousContainer as LayoutAnchorablePane;

                if (previousContainer == null)
                {
                    AnchorSide side = (parentGroup.Parent as LayoutAnchorSide).Side;
                    switch (side)
                    {
                    case AnchorSide.Right:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Horizontal)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Add(previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Horizontal
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(oldRootPanel);
                            panel.Children.Add(previousContainer);
                        }
                        break;

                    case AnchorSide.Left:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Horizontal)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Insert(0, previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Horizontal
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(previousContainer);
                            panel.Children.Add(oldRootPanel);
                        }
                        break;

                    case AnchorSide.Top:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Vertical)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Insert(0, previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Vertical
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(previousContainer);
                            panel.Children.Add(oldRootPanel);
                        }
                        break;

                    case AnchorSide.Bottom:
                        if (parentGroup.Root.RootPanel.Orientation == Orientation.Vertical)
                        {
                            previousContainer = new LayoutAnchorablePane();
                            parentGroup.Root.RootPanel.Children.Add(previousContainer);
                        }
                        else
                        {
                            previousContainer = new LayoutAnchorablePane();
                            LayoutPanel panel = new LayoutPanel()
                            {
                                Orientation = Orientation.Vertical
                            };
                            LayoutRoot  root         = parentGroup.Root as LayoutRoot;
                            LayoutPanel oldRootPanel = parentGroup.Root.RootPanel as LayoutPanel;
                            root.RootPanel = panel;
                            panel.Children.Add(oldRootPanel);
                            panel.Children.Add(previousContainer);
                        }
                        break;
                    }
                    // Do something about initializing the docks of previousContainer
                    GridLength[] defaultdock = LayoutSetting.GetDefaultDockAnchorable(Title);
                    previousContainer.DockWidth  = defaultdock[0];
                    previousContainer.DockHeight = defaultdock[1];
                }
                else
                {
                    //I'm about to remove parentGroup, redirect any content (ie hidden contents) that point to it
                    //to previousContainer
                    LayoutRoot root = parentGroup.Root as LayoutRoot;
                    foreach (var cnt in root.Descendents().OfType <ILayoutPreviousContainer>().Where(c => c.PreviousContainer == parentGroup))
                    {
                        cnt.PreviousContainer = previousContainer;
                    }
                }

                foreach (var anchorableToToggle in parentGroup.Children.ToArray())
                {
                    previousContainer.Children.Add(anchorableToToggle);
                }

                parentSide.Children.Remove(parentGroup);
                IsDock = true;
            }
            #endregion
            #region Anchorable is docked
            else if (Parent is LayoutAnchorablePane)
            {
                IsActive = false;
                IsDock   = false;
                IsFloat  = false;

                var root       = Root;
                var parentPane = Parent as LayoutAnchorablePane;

                var newAnchorGroup = new LayoutAnchorGroup();

                ((ILayoutPreviousContainer)newAnchorGroup).PreviousContainer = parentPane;

                foreach (var anchorableToImport in parentPane.Children.ToArray())
                {
                    newAnchorGroup.Children.Add(anchorableToImport);
                }

                //detect anchor side for the pane
                var anchorSide = parentPane.GetSide();

                switch (anchorSide)
                {
                case AnchorSide.Right:
                    root.RightSide.Children.Add(newAnchorGroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "RIGHT");
                    break;

                case AnchorSide.Left:
                    root.LeftSide.Children.Add(newAnchorGroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "LEFT");
                    break;

                case AnchorSide.Top:
                    root.TopSide.Children.Add(newAnchorGroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "TOP");
                    break;

                case AnchorSide.Bottom:
                    root.BottomSide.Children.Add(newAnchorGroup);
                    LayoutSetting.AddDefaultSideAnchorable(Title, "BOTTOM");
                    break;
                }
            }
            #endregion
        }
        void DetachDocumentsSource(LayoutRoot layout, IEnumerable documentsSource)
        {
            if (documentsSource == null)
                return;

            if (layout == null)
                return;

            var documentsToRemove = layout.Descendents().OfType<LayoutDocument>()
                .Where(d => documentsSource.Contains(d.Content)).ToArray();

            foreach (var documentToRemove in documentsToRemove)
            {
                (documentToRemove.Parent as ILayoutContainer).RemoveChild(
                    documentToRemove);
            }

            var documentsSourceAsNotifier = documentsSource as INotifyCollectionChanged;
            if (documentsSourceAsNotifier != null)
                documentsSourceAsNotifier.CollectionChanged -= new NotifyCollectionChangedEventHandler(documentsSourceElementsChanged);
        }
        void DetachAnchorablesSource(LayoutRoot layout, IEnumerable anchorablesSource)
        {
            if (anchorablesSource == null)
                return;

            if (layout == null)
                return;

            var anchorablesToRemove = layout.Descendents().OfType<LayoutAnchorable>()
                .Where(d => anchorablesSource.Contains(d.Content)).ToArray();

            foreach (var anchorableToRemove in anchorablesToRemove)
            {
                (anchorableToRemove.Parent as ILayoutContainer).RemoveChild(
                    anchorableToRemove);
            }

            var anchorablesSourceAsNotifier = anchorablesSource as INotifyCollectionChanged;
            if (anchorablesSourceAsNotifier != null)
                anchorablesSourceAsNotifier.CollectionChanged -= new NotifyCollectionChangedEventHandler(anchorablesSourceElementsChanged);
        }
        void AttachDocumentsSource(LayoutRoot layout, IEnumerable documentsSource)
        {
            if (documentsSource == null)
                return;

            if (layout == null)
                return;

            //if (layout.Descendents().OfType<LayoutDocument>().Any())
            //    throw new InvalidOperationException("Unable to set the DocumentsSource property if LayoutDocument objects are already present in the model");
            var documentsImported = layout.Descendents().OfType<LayoutDocument>().Select(d => d.Content).ToArray();
            var documents = documentsSource as IEnumerable;
            var listOfDocumentsToImport = new List<object>(documents.OfType<object>());

            foreach (var document in listOfDocumentsToImport.ToArray())
            {
                if (documentsImported.Contains(document))
                    listOfDocumentsToImport.Remove(document);
            }

            LayoutDocumentPane documentPane = null;
            if (layout.LastFocusedDocument != null)
            {
                documentPane = layout.LastFocusedDocument.Parent as LayoutDocumentPane;
            }

            if (documentPane == null)
            {
                documentPane = layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault();
            }

            //if (documentPane == null)
            //    throw new InvalidOperationException("Layout must contains at least one LayoutDocumentPane in order to host documents");

            _suspendLayoutItemCreation = true;
            foreach (var documentContentToImport in listOfDocumentsToImport)
            {

                //documentPane.Children.Add(new LayoutDocument() { Content = documentToImport });

                var documentToImport = new LayoutDocument()
                {
                    Content = documentContentToImport
                };

                bool added = false;
                if (LayoutUpdateStrategy != null)
                {
                    added = LayoutUpdateStrategy.BeforeInsertDocument(layout, documentToImport, documentPane);
                }

                if (!added)
                {
                    if (documentPane == null)
                        throw new InvalidOperationException("Layout must contains at least one LayoutDocumentPane in order to host documents");

                    documentPane.Children.Add(documentToImport);
                    added = true;
                }

                if (LayoutUpdateStrategy != null)
                    LayoutUpdateStrategy.AfterInsertDocument(layout, documentToImport);

                CreateDocumentLayoutItem(documentToImport);

            }
            _suspendLayoutItemCreation = true;

            var documentsSourceAsNotifier = documentsSource as INotifyCollectionChanged;
            if (documentsSourceAsNotifier != null)
                documentsSourceAsNotifier.CollectionChanged += new NotifyCollectionChangedEventHandler(documentsSourceElementsChanged);
        }
        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 as IEnumerable;
            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
                };

                bool 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 += new NotifyCollectionChangedEventHandler(anchorablesSourceElementsChanged);
        }
Ejemplo n.º 22
-1
        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
            //LayoutAnchorablePane destPane = destinationContainer as LayoutAnchorablePane;
            if (destinationContainer != null &&
                destinationContainer.FindParent<LayoutFloatingWindow>() != null)
                return false;

            var content = anchorableToShow.Content;
            string destPaneName = "";
            if(content is IdInfoTablePane2ViewModel)
            {
                destPaneName = "IdInfoTablePane";
                ////layout.BottomSide.InsertChildAt(0, anchorableToShow);
                //layout.BottomSide.Children[0].Children.Add(anchorableToShow);
                //return true;
            }
            else if(content is CategoryTreePaneViewModel)
            {
                destPaneName = "CategoryTreePane";
            }
            else if (content is WpfApplication1.Workspace.ParameterFileTreePaneViewModel)
            {
                destPaneName = "ParameterFileTreePane";
            }
            else if(content is FileSharePaneViewModel)
            {
                destPaneName = "FileSharePane";
            }
            else if(content is ParameterTab2ViewModel)
            {
                destPaneName = "ParameterTabPane";
            }
            else
            { return false; }

            foreach(var pane in layout.Descendents().OfType<LayoutAnchorablePane>().Where(p=>p.ChildrenCount  >= 1))
            {
                for (int i = 0; i < pane.ChildrenCount; ++i)
                {
                    var child = pane.Children[i];
                    if (child.Content == null)
                    {
                        child.IsVisible = false;
                        --i;
                    }
                }
            }

            var toolsPane = layout.Descendents().OfType<LayoutAnchorablePane>().FirstOrDefault(d => d.Name == destPaneName);
            if (toolsPane != null)
            {
                toolsPane.Children.Add(anchorableToShow);
                return true;
            }

            return false;
        }