tgjones / gemini

Gemini is an IDE framework similar in concept to the Visual Studio Shell. It uses AvalonDock and has an MVVM architecture based on Caliburn Micro.
Other
1.1k stars 299 forks source link

How to find out whether the Tool is Docked as a Document? #307

Open JobaDiniz opened 5 years ago

JobaDiniz commented 5 years ago

Within my ToolViewModel, how do I know if the tool is docked as a Document? Or if it is floating for example?

I made a tweak in the LayoutInitializer. I've changed PaneLocation enum, adding Floating and Document options:

public void AfterInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableShown)
        {
            // If this is the first anchorable added to this pane, then use the preferred size.
            var tool = anchorableShown.Content as ITool;
            if (tool != null)
            {
                var anchorablePane = anchorableShown.Parent as LayoutAnchorablePane;
                if (anchorablePane != null && anchorablePane.ChildrenCount == 1)
                {
                    switch (tool.PreferredLocation)
                    {
                        case PaneLocation.Left:
                        case PaneLocation.Right:
                            anchorablePane.DockWidth = new GridLength(tool.PreferredWidth, GridUnitType.Pixel);
                            break;
                        case PaneLocation.Bottom:
                            anchorablePane.DockHeight = new GridLength(tool.PreferredHeight, GridUnitType.Pixel);
                            break;
                        case PaneLocation.Floating:
                            {
                                anchorableShown.FloatingHeight = tool.PreferredHeight;
                                anchorableShown.FloatingWidth = tool.PreferredWidth;

                                var window = Application.Current.MainWindow;
                                var screen = System.Windows.Forms.Screen.FromHandle(new WindowInteropHelper(window).Handle);
                                anchorableShown.FloatingTop = (screen.WorkingArea.Height / 2d) - (anchorableShown.FloatingHeight / 2d);
                                anchorableShown.FloatingLeft = (screen.WorkingArea.Width / 2d) - (anchorableShown.FloatingWidth / 2d);
                                anchorableShown.Float();
                                break;
                            }
                        case PaneLocation.Document:
                            anchorableShown.DockAsDocument();
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
            }
        }

However, MVVM in Avalon is fairly difficult, so I couldn't figure it out how to find out whether my ToolViewModel is docked as document.

Any insights?

Dirkster99 commented 5 years ago

Here is an insight: https://github.com/xceedsoftware/wpftoolkit/issues/1437