public bool BeforeInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
 {
     return(BeforeInsertContent(layout, anchorableToShow));
 }
예제 #2
0
        /// <summary>
        /// Method is invoked to complete a drag & drop operation with a (new) docking position
        /// by docking of the LayoutAnchorable <paramref name="floatingWindow"/> into this drop target.
        /// </summary>
        /// <param name="floatingWindow"></param>
        protected override void Drop(LayoutAnchorableFloatingWindow floatingWindow)
        {
            ILayoutDocumentPane targetModel = _targetPane.Model as ILayoutDocumentPane;

            switch (Type)
            {
            case DropTargetType.DocumentPaneDockBottom:

                #region DropTargetType.DocumentPaneDockBottom

            {
                var parentModel           = targetModel.Parent as LayoutDocumentPaneGroup;
                var newLayoutDocumentPane = new LayoutDocumentPane();

                if (parentModel == null)
                {
                    var parentContainer = targetModel.Parent as ILayoutContainer;
                    var newParentModel  = new LayoutDocumentPaneGroup()
                    {
                        Orientation = System.Windows.Controls.Orientation.Vertical
                    };
                    parentContainer.ReplaceChild(targetModel, newParentModel);
                    newParentModel.Children.Add(targetModel as LayoutDocumentPane);
                    newParentModel.Children.Add(newLayoutDocumentPane);
                }
                else
                {
                    var manager = parentModel.Root.Manager;
                    if (!manager.AllowMixedOrientation || parentModel.Orientation == System.Windows.Controls.Orientation.Vertical)
                    {
                        parentModel.Orientation = System.Windows.Controls.Orientation.Vertical;
                        int targetPaneIndex = parentModel.IndexOfChild(targetModel);
                        parentModel.Children.Insert(targetPaneIndex + 1, newLayoutDocumentPane);
                    }
                    else
                    {
                        LayoutDocumentPaneGroup newChildGroup = new LayoutDocumentPaneGroup();
                        newChildGroup.Orientation = System.Windows.Controls.Orientation.Vertical;
                        parentModel.ReplaceChild(targetModel, newChildGroup);
                        newChildGroup.Children.Add(targetModel);
                        newChildGroup.Children.Add(newLayoutDocumentPane);
                    }
                }

                foreach (var cntToTransfer in floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray())
                {
                    newLayoutDocumentPane.Children.Add(cntToTransfer);
                }
            }
            break;

                #endregion DropTargetType.DocumentPaneDockBottom

            case DropTargetType.DocumentPaneDockTop:

                #region DropTargetType.DocumentPaneDockTop

            {
                var parentModel           = targetModel.Parent as LayoutDocumentPaneGroup;
                var newLayoutDocumentPane = new LayoutDocumentPane();

                if (parentModel == null)
                {
                    var parentContainer = targetModel.Parent as ILayoutContainer;
                    var newParentModel  = new LayoutDocumentPaneGroup()
                    {
                        Orientation = System.Windows.Controls.Orientation.Vertical
                    };
                    parentContainer.ReplaceChild(targetModel, newParentModel);
                    newParentModel.Children.Add(newLayoutDocumentPane);
                    newParentModel.Children.Add(targetModel as LayoutDocumentPane);
                }
                else
                {
                    var manager = parentModel.Root.Manager;
                    if (!manager.AllowMixedOrientation || parentModel.Orientation == System.Windows.Controls.Orientation.Vertical)
                    {
                        parentModel.Orientation = System.Windows.Controls.Orientation.Vertical;
                        int targetPaneIndex = parentModel.IndexOfChild(targetModel);
                        parentModel.Children.Insert(targetPaneIndex, newLayoutDocumentPane);
                    }
                    else
                    {
                        LayoutDocumentPaneGroup newChildGroup = new LayoutDocumentPaneGroup();
                        newChildGroup.Orientation = System.Windows.Controls.Orientation.Vertical;
                        parentModel.ReplaceChild(targetModel, newChildGroup);
                        newChildGroup.Children.Add(newLayoutDocumentPane);
                        newChildGroup.Children.Add(targetModel);
                    }
                }

                foreach (var cntToTransfer in floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray())
                {
                    newLayoutDocumentPane.Children.Add(cntToTransfer);
                }
            }
            break;

                #endregion DropTargetType.DocumentPaneDockTop

            case DropTargetType.DocumentPaneDockLeft:

                #region DropTargetType.DocumentPaneDockLeft

            {
                var parentModel           = targetModel.Parent as LayoutDocumentPaneGroup;
                var newLayoutDocumentPane = new LayoutDocumentPane();

                if (parentModel == null)
                {
                    var parentContainer = targetModel.Parent as ILayoutContainer;
                    var newParentModel  = new LayoutDocumentPaneGroup()
                    {
                        Orientation = System.Windows.Controls.Orientation.Horizontal
                    };
                    parentContainer.ReplaceChild(targetModel, newParentModel);
                    newParentModel.Children.Add(newLayoutDocumentPane);
                    newParentModel.Children.Add(targetModel as LayoutDocumentPane);
                }
                else
                {
                    var manager = parentModel.Root.Manager;
                    if (!manager.AllowMixedOrientation || parentModel.Orientation == System.Windows.Controls.Orientation.Horizontal)
                    {
                        parentModel.Orientation = System.Windows.Controls.Orientation.Horizontal;
                        int targetPaneIndex = parentModel.IndexOfChild(targetModel);
                        parentModel.Children.Insert(targetPaneIndex, newLayoutDocumentPane);
                    }
                    else
                    {
                        LayoutDocumentPaneGroup newChildGroup = new LayoutDocumentPaneGroup();
                        newChildGroup.Orientation = System.Windows.Controls.Orientation.Horizontal;
                        parentModel.ReplaceChild(targetModel, newChildGroup);
                        newChildGroup.Children.Add(newLayoutDocumentPane);
                        newChildGroup.Children.Add(targetModel);
                    }
                }

                foreach (var cntToTransfer in floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray())
                {
                    newLayoutDocumentPane.Children.Add(cntToTransfer);
                }
            }
            break;

                #endregion DropTargetType.DocumentPaneDockLeft

            case DropTargetType.DocumentPaneDockRight:

                #region DropTargetType.DocumentPaneDockRight

            {
                var parentModel           = targetModel.Parent as LayoutDocumentPaneGroup;
                var newLayoutDocumentPane = new LayoutDocumentPane();

                if (parentModel == null)
                {
                    var parentContainer = targetModel.Parent as ILayoutContainer;
                    var newParentModel  = new LayoutDocumentPaneGroup()
                    {
                        Orientation = System.Windows.Controls.Orientation.Horizontal
                    };
                    parentContainer.ReplaceChild(targetModel, newParentModel);
                    newParentModel.Children.Add(targetModel as LayoutDocumentPane);
                    newParentModel.Children.Add(newLayoutDocumentPane);
                }
                else
                {
                    var manager = parentModel.Root.Manager;
                    if (!manager.AllowMixedOrientation || parentModel.Orientation == System.Windows.Controls.Orientation.Horizontal)
                    {
                        parentModel.Orientation = System.Windows.Controls.Orientation.Horizontal;
                        int targetPaneIndex = parentModel.IndexOfChild(targetModel);
                        parentModel.Children.Insert(targetPaneIndex + 1, newLayoutDocumentPane);
                    }
                    else
                    {
                        LayoutDocumentPaneGroup newChildGroup = new LayoutDocumentPaneGroup();
                        newChildGroup.Orientation = System.Windows.Controls.Orientation.Horizontal;
                        parentModel.ReplaceChild(targetModel, newChildGroup);
                        newChildGroup.Children.Add(targetModel);
                        newChildGroup.Children.Add(newLayoutDocumentPane);
                    }
                }

                foreach (var cntToTransfer in floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray())
                {
                    newLayoutDocumentPane.Children.Add(cntToTransfer);
                }
            }
            break;

                #endregion DropTargetType.DocumentPaneDockRight

            case DropTargetType.DocumentPaneDockInside:

                #region DropTargetType.DocumentPaneDockInside

            {
                var paneModel = targetModel as LayoutDocumentPane;
                var layoutAnchorablePaneGroup = floatingWindow.RootPanel as LayoutAnchorablePaneGroup;

                bool checkPreviousContainer = true;
                int  i = 0;
                if (_tabIndex != -1)
                {
                    i = _tabIndex;
                    checkPreviousContainer = false;
                }
                LayoutAnchorable anchorableToActivate = null;

                foreach (var anchorableToImport in layoutAnchorablePaneGroup.Descendents().OfType <LayoutAnchorable>().ToArray())
                {
                    if (checkPreviousContainer)
                    {
                        var previousContainer = ((ILayoutPreviousContainer)anchorableToImport).PreviousContainer;
                        if (object.ReferenceEquals(previousContainer, targetModel) && (anchorableToImport.PreviousContainerIndex != -1))
                        {
                            i = anchorableToImport.PreviousContainerIndex;
                        }
                        checkPreviousContainer = false;
                    }

                    // BD: 17.08.2020 Remove that bodge and handle CanClose=false && CanHide=true in XAML
                    //anchorableToImport.SetCanCloseInternal(true);

                    paneModel.Children.Insert(i, anchorableToImport);
                    i++;
                    anchorableToActivate = anchorableToImport;
                }

                anchorableToActivate.IsActive = true;
            }
            break;

                #endregion DropTargetType.DocumentPaneDockInside
            }

            base.Drop(floatingWindow);
        }
예제 #3
0
        protected override void Drop(LayoutAnchorableFloatingWindow floatingWindow)
        {
            ILayoutAnchorablePane model            = this._targetPane.Model as ILayoutAnchorablePane;
            LayoutAnchorable      layoutAnchorable = floatingWindow.Descendents().OfType <LayoutAnchorable>().FirstOrDefault <LayoutAnchorable>();

            switch (base.Type)
            {
            case DropTargetType.AnchorablePaneDockLeft:
            {
                ILayoutGroup           parent = model.Parent as ILayoutGroup;
                ILayoutOrientableGroup layoutOrientableGroup = model.Parent as ILayoutOrientableGroup;
                int num = parent.IndexOfChild(model);
                if (layoutOrientableGroup.Orientation != Orientation.Horizontal && parent.ChildrenCount == 1)
                {
                    layoutOrientableGroup.Orientation = Orientation.Horizontal;
                }
                if (layoutOrientableGroup.Orientation != Orientation.Horizontal)
                {
                    ILayoutPositionableElement layoutPositionableElement = model as ILayoutPositionableElement;
                    LayoutAnchorablePaneGroup  layoutAnchorablePaneGroup = new LayoutAnchorablePaneGroup()
                    {
                        Orientation = Orientation.Horizontal,
                        DockWidth   = layoutPositionableElement.DockWidth,
                        DockHeight  = layoutPositionableElement.DockHeight
                    };
                    parent.InsertChildAt(num, layoutAnchorablePaneGroup);
                    layoutAnchorablePaneGroup.Children.Add(model);
                    layoutAnchorablePaneGroup.Children.Insert(0, floatingWindow.RootPanel);
                    break;
                }
                else
                {
                    LayoutAnchorablePaneGroup rootPanel = floatingWindow.RootPanel;
                    if (rootPanel == null || rootPanel.Children.Count != 1 && rootPanel.Orientation != Orientation.Horizontal)
                    {
                        parent.InsertChildAt(num, floatingWindow.RootPanel);
                        break;
                    }
                    else
                    {
                        ILayoutAnchorablePane[] array = rootPanel.Children.ToArray <ILayoutAnchorablePane>();
                        for (int i = 0; i < (int)array.Length; i++)
                        {
                            parent.InsertChildAt(num + i, array[i]);
                        }
                        break;
                    }
                }
            }

            case DropTargetType.AnchorablePaneDockTop:
            {
                ILayoutGroup           layoutGroup = model.Parent as ILayoutGroup;
                ILayoutOrientableGroup parent1     = model.Parent as ILayoutOrientableGroup;
                int num1 = layoutGroup.IndexOfChild(model);
                if (parent1.Orientation != Orientation.Vertical && layoutGroup.ChildrenCount == 1)
                {
                    parent1.Orientation = Orientation.Vertical;
                }
                if (parent1.Orientation != Orientation.Vertical)
                {
                    ILayoutPositionableElement layoutPositionableElement1 = model as ILayoutPositionableElement;
                    LayoutAnchorablePaneGroup  layoutAnchorablePaneGroup1 = new LayoutAnchorablePaneGroup()
                    {
                        Orientation = Orientation.Vertical,
                        DockWidth   = layoutPositionableElement1.DockWidth,
                        DockHeight  = layoutPositionableElement1.DockHeight
                    };
                    layoutGroup.InsertChildAt(num1, layoutAnchorablePaneGroup1);
                    layoutAnchorablePaneGroup1.Children.Add(model);
                    layoutAnchorablePaneGroup1.Children.Insert(0, floatingWindow.RootPanel);
                    break;
                }
                else
                {
                    LayoutAnchorablePaneGroup rootPanel1 = floatingWindow.RootPanel;
                    if (rootPanel1 == null || rootPanel1.Children.Count != 1 && rootPanel1.Orientation != Orientation.Vertical)
                    {
                        layoutGroup.InsertChildAt(num1, floatingWindow.RootPanel);
                        break;
                    }
                    else
                    {
                        ILayoutAnchorablePane[] layoutAnchorablePaneArray = rootPanel1.Children.ToArray <ILayoutAnchorablePane>();
                        for (int j = 0; j < (int)layoutAnchorablePaneArray.Length; j++)
                        {
                            layoutGroup.InsertChildAt(num1 + j, layoutAnchorablePaneArray[j]);
                        }
                        break;
                    }
                }
            }

            case DropTargetType.AnchorablePaneDockRight:
            {
                ILayoutGroup           layoutGroup1           = model.Parent as ILayoutGroup;
                ILayoutOrientableGroup layoutOrientableGroup1 = model.Parent as ILayoutOrientableGroup;
                int num2 = layoutGroup1.IndexOfChild(model);
                if (layoutOrientableGroup1.Orientation != Orientation.Horizontal && layoutGroup1.ChildrenCount == 1)
                {
                    layoutOrientableGroup1.Orientation = Orientation.Horizontal;
                }
                if (layoutOrientableGroup1.Orientation != Orientation.Horizontal)
                {
                    ILayoutPositionableElement layoutPositionableElement2 = model as ILayoutPositionableElement;
                    LayoutAnchorablePaneGroup  layoutAnchorablePaneGroup2 = new LayoutAnchorablePaneGroup()
                    {
                        Orientation = Orientation.Horizontal,
                        DockWidth   = layoutPositionableElement2.DockWidth,
                        DockHeight  = layoutPositionableElement2.DockHeight
                    };
                    layoutGroup1.InsertChildAt(num2, layoutAnchorablePaneGroup2);
                    layoutAnchorablePaneGroup2.Children.Add(model);
                    layoutAnchorablePaneGroup2.Children.Add(floatingWindow.RootPanel);
                    break;
                }
                else
                {
                    LayoutAnchorablePaneGroup rootPanel2 = floatingWindow.RootPanel;
                    if (rootPanel2 == null || rootPanel2.Children.Count != 1 && rootPanel2.Orientation != Orientation.Horizontal)
                    {
                        layoutGroup1.InsertChildAt(num2 + 1, floatingWindow.RootPanel);
                        break;
                    }
                    else
                    {
                        ILayoutAnchorablePane[] array1 = rootPanel2.Children.ToArray <ILayoutAnchorablePane>();
                        for (int k = 0; k < (int)array1.Length; k++)
                        {
                            layoutGroup1.InsertChildAt(num2 + 1 + k, array1[k]);
                        }
                        break;
                    }
                }
            }

            case DropTargetType.AnchorablePaneDockBottom:
            {
                ILayoutGroup           parent2 = model.Parent as ILayoutGroup;
                ILayoutOrientableGroup layoutOrientableGroup2 = model.Parent as ILayoutOrientableGroup;
                int num3 = parent2.IndexOfChild(model);
                if (layoutOrientableGroup2.Orientation != Orientation.Vertical && parent2.ChildrenCount == 1)
                {
                    layoutOrientableGroup2.Orientation = Orientation.Vertical;
                }
                if (layoutOrientableGroup2.Orientation != Orientation.Vertical)
                {
                    ILayoutPositionableElement layoutPositionableElement3 = model as ILayoutPositionableElement;
                    LayoutAnchorablePaneGroup  layoutAnchorablePaneGroup3 = new LayoutAnchorablePaneGroup()
                    {
                        Orientation = Orientation.Vertical,
                        DockWidth   = layoutPositionableElement3.DockWidth,
                        DockHeight  = layoutPositionableElement3.DockHeight
                    };
                    parent2.InsertChildAt(num3, layoutAnchorablePaneGroup3);
                    layoutAnchorablePaneGroup3.Children.Add(model);
                    layoutAnchorablePaneGroup3.Children.Add(floatingWindow.RootPanel);
                    break;
                }
                else
                {
                    LayoutAnchorablePaneGroup rootPanel3 = floatingWindow.RootPanel;
                    if (rootPanel3 == null || rootPanel3.Children.Count != 1 && rootPanel3.Orientation != Orientation.Vertical)
                    {
                        parent2.InsertChildAt(num3 + 1, floatingWindow.RootPanel);
                        break;
                    }
                    else
                    {
                        ILayoutAnchorablePane[] layoutAnchorablePaneArray1 = rootPanel3.Children.ToArray <ILayoutAnchorablePane>();
                        for (int l = 0; l < (int)layoutAnchorablePaneArray1.Length; l++)
                        {
                            parent2.InsertChildAt(num3 + 1 + l, layoutAnchorablePaneArray1[l]);
                        }
                        break;
                    }
                }
            }

            case DropTargetType.AnchorablePaneDockInside:
            {
                LayoutAnchorablePane      layoutAnchorablePane = model as LayoutAnchorablePane;
                LayoutAnchorablePaneGroup rootPanel4           = floatingWindow.RootPanel;
                int num4 = (this._tabIndex == -1 ? 0 : this._tabIndex);
                LayoutAnchorable[] layoutAnchorableArray = rootPanel4.Descendents().OfType <LayoutAnchorable>().ToArray <LayoutAnchorable>();
                for (int m = 0; m < (int)layoutAnchorableArray.Length; m++)
                {
                    LayoutAnchorable layoutAnchorable1 = layoutAnchorableArray[m];
                    layoutAnchorablePane.Children.Insert(num4, layoutAnchorable1);
                    num4++;
                }
                break;
            }
            }
            layoutAnchorable.IsActive = true;
            base.Drop(floatingWindow);
        }
예제 #4
0
        private object ShowPluginWindow(IXbimXplorerPluginWindow pluginWindow, bool setCurrent = false)
        {
            // ReSharper disable once SuspiciousTypeConversion.Global
            var aswindow = pluginWindow as Window;

            if (aswindow != null)
            {
                var cmode = pluginWindow.GetUiContainerMode();
                if (cmode == PluginWindowUiContainerEnum.Dialog)
                {
                    pluginWindow.BindUi(MainWindow);
                    aswindow.ShowDialog();
                    var closeAction = pluginWindow.GetUiAttribute().CloseAction;
                    if (closeAction == PluginWindowCloseAction.Hide)
                    {
                        return(aswindow);
                    }
                }
                else
                {
                    Log.ErrorFormat("Plugin type {0} has unsuitable containermode ({1}).", aswindow.GetType().Name, cmode);
                }
                return(null);
            }

            var asControl = pluginWindow as UserControl;

            if (asControl != null)
            {
                if (!_pluginWindows.Contains(pluginWindow))
                {
                    _pluginWindows.Add(pluginWindow);
                }
                // preparing user control
                asControl.HorizontalAlignment = HorizontalAlignment.Stretch;
                asControl.VerticalAlignment   = VerticalAlignment.Stretch;

                //set data binding
                pluginWindow.BindUi(MainWindow);

                switch (pluginWindow.GetUiContainerMode())
                {
                case PluginWindowUiContainerEnum.LayoutAnchorable:
                {
                    // inner
                    var inner = new LayoutAnchorable()
                    {
                        Title   = pluginWindow.WindowTitle,
                        Content = asControl
                    };

                    if (!GetRightPane().Children.Contains(inner))
                    {
                        GetRightPane().Children.Add(inner);
                    }

                    if (setCurrent)
                    {
                        inner.IsActive = true;
                    }
                    return(inner);
                }

                case PluginWindowUiContainerEnum.LayoutDoc:
                {
                    var ld = new LayoutDocument
                    {
                        Title   = pluginWindow.WindowTitle,
                        Content = asControl
                    };
                    MainDocPane.Children.Add(ld);
                    ld.Closed += PluginWindowClosed;
                    if (setCurrent)
                    {
                        ld.IsActive = true;
                    }
                    return(ld);
                }

                default:
                    Log.ErrorFormat("Plugin type {0} has unsuitable containermode.", asControl.GetType().Name);
                    break;
                }
            }
            Log.ErrorFormat("{0} does not inherit from UserControl as expected", pluginWindow.GetType());
            return(null);
        }
예제 #5
0
 private void UpdateAssetPreviewAnchorable(LayoutAnchorable anchorable)
 {
     (Editor as GameStudioViewModel)?.Preview?.RenderPreviewCommand?.Execute(anchorable.IsSelected);
 }
예제 #6
0
        public void ProcessStaticPanelDefinitions()
        {
            var layoutGroupData = new Dictionary <LayoutAnchorable, LayoutAnchorablePane>();

            foreach (var definition in PanelManager.StaticPanelDefinitions)
            {
                var config = definition.OfType <StaticPanelConfiguration>().Single();

                var anchorable = new LayoutAnchorable();

                var view      = (UserControl)Activator.CreateInstance(definition.View);
                var viewModel = Container.Resolve(definition.IViewModel);
                view.DataContext = viewModel;

                anchorable.Content   = view;
                anchorable.ContentId = definition.View.GetGuid();
                anchorable.Title     = config.Title();

                LayoutAnchorablePane container = null;
                switch (config.Placement)
                {
                case PanelPlacement.TopLeft: { container = DockingView.UpperLeftArea; break; }

                case PanelPlacement.BottomLeft: { container = DockingView.BottomLeftArea; break; }

                case PanelPlacement.Center: { container = DockingView.CenterArea; break; }

                case PanelPlacement.TopRight: { container = DockingView.UpperRightArea; break; }

                case PanelPlacement.BottomRight: { container = DockingView.BottomRightArea; break; }

                default: { throw new Exception($"Internal Error : Unregistered panel placement group position added."); }
                }

                container.Children.Add(anchorable);
                layoutGroupData.Add(anchorable, container);

                anchorable.CanAutoHide = true;
                anchorable.CanFloat    = config.CanFloat();

                var canOpen  = config.CanOpen();
                var canClose = config.CanClose();

                if (canOpen == false && canClose == false)
                {
                    throw new Exception($"Error in static panel {definition.ViewModel} metadata. CanOpen() and CanClose() defined " +
                                        $"in the panel definition's configuration metadata can't both return false at the same time.");
                }

                var visibility = config.IsVisible() && config.CanOpen();

                VisibilityManager.SetVisibility(anchorable, visibility);
                if (visibility)
                {
                    anchorable.CanHide = config.CanClose();
                }


                anchorableDefinitions.Add(anchorable, definition);

                anchorable.Hiding += (sender, e) => {
                    var source = sender.SafeCast <LayoutAnchorable>();
                    if (source.IsVisible)
                    {
                        VisibilityManager.UpdateContainer(source);
                    }
                };

                foreach (var metadata in definition.OfType <IAutoInvalidateMetadata>())
                {
                    metadata.AttachMetadataDefinition(EventAggregator, () => InvalidateStaticPanel(definition), ThreadOption.PublisherThread);
                }

                foreach (var metadata in definition.OfType <IBringIntoViewOnEvent>())
                {
                    metadata.AttachToDefinition(EventAggregator, () =>
                    {
                        if (definition.OfType <StaticPanelConfiguration>().Single().CanOpen())
                        {
                            BringStaticPanelIntoViewInternal(definition);
                        }
                    });
                }
            }
            VisibilityManager.SetLayoutGroupData(layoutGroupData);
        }
예제 #7
0
 /// <summary>
 /// Makes the editor pane active and visible.
 /// </summary>
 /// <param name="editorPane"></param>
 private static void MakeActiveVisible([NotNull] LayoutAnchorable editorPane)
 {
     editorPane.IsActive = true;
     editorPane.Show();
 }
예제 #8
0
 internal override void Detach()
 {
     this._anchorable.IsVisibleChanged -= new EventHandler(this._anchorable_IsVisibleChanged);
     this._anchorable = null;
     base.Detach();
 }
 public static void SetYourCanHideProperty(LayoutAnchorable control, bool value)
 {
     window.SetValue(YourProperty, value);
 }
예제 #10
0
        /// <summary>
        /// Opens (and activates) an editor window for the given asset. If an editor window for this asset already exists, simply activates it.
        /// </summary>
        /// <param name="asset">The asset for which to show an editor window.</param>
        /// <param name="saveSettings">True if <see cref="MRUAdditionalData.OpenedAssets"/> should be updated, false otherwise. Note that if the editor fail to load it will not be updated.</param>
        /// <returns></returns>
        internal async Task OpenAssetEditorWindow([NotNull] AssetViewModel asset, bool saveSettings)
        {
            if (asset == null)
            {
                throw new ArgumentNullException(nameof(asset));
            }
            if (dockingLayoutManager == null)
            {
                throw new InvalidOperationException("This method can only be invoked on the IEditorDialogService that has the editor main window as parent.");
            }

            // Switch to the editor layout before adding any Pane
            if (assetEditors.Count == 0)
            {
                dockingLayoutManager.SwitchToEditorLayout();
            }

            using (await mutex.LockAsync())
            {
                LayoutAnchorable editorPane = null;
                IEditorView      view;
                // Asset already has an editor?
                if (asset.Editor != null)
                {
                    // Look for the corresponding pane
                    if (!assetEditors.TryGetValue(asset.Editor, out editorPane))
                    {
                        // Inconsistency, clean leaking editor
                        RemoveAssetEditor(asset);
                        // Try to find if another editor currently has this asset
                        var editor = assetEditors.Keys.OfType <IMultipleAssetEditorViewModel>().FirstOrDefault(x => x.OpenedAssets.Contains(asset));
                        if (editor != null)
                        {
                            editorPane   = assetEditors[editor];
                            asset.Editor = editor;
                        }
                    }
                }
                // Existing editor?
                if (editorPane != null)
                {
                    // Make the pane visible immediately
                    MakeActiveVisible(editorPane);
                    view = editorPane.Content as IEditorView;
                    if (view?.EditorInitialization != null)
                    {
                        // Wait for the end of the initialization
                        await view.EditorInitialization;
                    }
                    return;
                }

                // Create a new editor view
                view = asset.ServiceProvider.Get <IAssetsPluginService>().ConstructEditionView(asset);
                if (view != null)
                {
                    // Pane may already exists (e.g. created from layout saving)
                    editorPane = AvalonDockHelper.GetAllAnchorables(dockingLayoutManager.DockingManager).FirstOrDefault(p => p.Title == asset.Url);
                    if (editorPane == null)
                    {
                        editorPane = new LayoutAnchorable();
                        // Stack the asset in the dictionary of editor to prevent double-opening while double-clicking twice on the asset, since the initialization is async
                        AvalonDockHelper.GetDocumentPane(dockingLayoutManager.DockingManager).Children.Add(editorPane);
                    }
                    editorPane.IsActiveChanged += EditorPaneIsActiveChanged;
                    editorPane.Closing         += EditorPaneClosing;
                    editorPane.Closed          += EditorPaneClosed;
                    editorPane.Content          = view;
                    // Make the pane visible immediately
                    MakeActiveVisible(editorPane);
                    // Initialize the editor view
                    view.DataContext = asset;

                    // Create a binding for the title
                    var binding = new Binding(nameof(AssetViewModel.Url))
                    {
                        Mode = BindingMode.OneWay, Source = asset
                    };
                    BindingOperations.SetBinding(editorPane, LayoutContent.TitleProperty, binding);

                    var viewModel = await view.InitializeEditor(asset);

                    if (viewModel == null)
                    {
                        // Could not initialize editor
                        CleanEditorPane(editorPane);
                        RemoveEditorPane(editorPane);
                    }
                    else
                    {
                        assetEditors[viewModel] = editorPane;
                        openedAssets.Add(asset);
                        var multiEditor = viewModel as IMultipleAssetEditorViewModel;
                        if (multiEditor != null)
                        {
                            foreach (var item in multiEditor.OpenedAssets)
                            {
                                if (item.Editor != null)
                                {
                                    // Note: this could happen in some case after undo/redo that involves parenting of scenes
                                    RemoveAssetEditor(item);
                                }
                                item.Editor = viewModel;
                            }
                            multiEditor.OpenedAssets.CollectionChanged += (_, e) => MultiEditorOpenAssetsChanged(multiEditor, e);
                        }
                        else
                        {
                            asset.Editor = viewModel;
                        }
                    }
                }
            }

            // If the opening of the editor failed, go back to normal layout
            if (assetEditors.Count == 0)
            {
                dockingLayoutManager.SwitchToNormalLayout();
                return;
            }

            if (saveSettings)
            {
                dockingLayoutManager.SaveOpenAssets(OpenedAssets);
            }
        }
예제 #11
0
        protected override void Drop(LayoutAnchorableFloatingWindow floatingWindow)
        {
            ILayoutDocumentPane targetModel = _targetPane.Model as ILayoutDocumentPane;

            switch (Type)
            {
            case DropTargetType.DocumentPaneDockBottom:

                #region DropTargetType.DocumentPaneDockBottom

            {
                if (targetModel != null)
                {
                    var parentModel           = targetModel.Parent as LayoutDocumentPaneGroup;
                    var newLayoutDocumentPane = new LayoutDocumentPane();

                    if (parentModel == null)
                    {
                        var parentContainer = targetModel.Parent;
                        var newParentModel  = new LayoutDocumentPaneGroup()
                        {
                            Orientation = System.Windows.Controls.Orientation.Vertical
                        };
                        parentContainer.ReplaceChild(targetModel, newParentModel);
                        newParentModel.Children.Add(targetModel as LayoutDocumentPane);
                        newParentModel.Children.Add(newLayoutDocumentPane);
                    }
                    else
                    {
                        var manager = parentModel.Root.Manager;
                        if (!manager.AllowMixedOrientation || parentModel.Orientation == System.Windows.Controls.Orientation.Vertical)
                        {
                            parentModel.Orientation = System.Windows.Controls.Orientation.Vertical;
                            int targetPaneIndex = parentModel.IndexOfChild(targetModel);
                            parentModel.Children.Insert(targetPaneIndex + 1, newLayoutDocumentPane);
                        }
                        else
                        {
                            LayoutDocumentPaneGroup newChildGroup = new LayoutDocumentPaneGroup
                            {
                                Orientation = System.Windows.Controls.Orientation.Vertical
                            };
                            parentModel.ReplaceChild(targetModel, newChildGroup);
                            newChildGroup.Children.Add(targetModel);
                            newChildGroup.Children.Add(newLayoutDocumentPane);
                        }
                    }

                    foreach (var cntToTransfer in floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray())
                    {
                        newLayoutDocumentPane.Children.Add(cntToTransfer);
                    }
                }
            }
            break;

                #endregion

            case DropTargetType.DocumentPaneDockTop:

                #region DropTargetType.DocumentPaneDockTop

            {
                if (targetModel != null)
                {
                    var parentModel           = targetModel.Parent as LayoutDocumentPaneGroup;
                    var newLayoutDocumentPane = new LayoutDocumentPane();

                    if (parentModel == null)
                    {
                        var parentContainer = targetModel.Parent;
                        var newParentModel  = new LayoutDocumentPaneGroup()
                        {
                            Orientation = System.Windows.Controls.Orientation.Vertical
                        };
                        parentContainer.ReplaceChild(targetModel, newParentModel);
                        newParentModel.Children.Add(newLayoutDocumentPane);
                        newParentModel.Children.Add(targetModel as LayoutDocumentPane);
                    }
                    else
                    {
                        var manager = parentModel.Root.Manager;
                        if (!manager.AllowMixedOrientation || parentModel.Orientation == System.Windows.Controls.Orientation.Vertical)
                        {
                            parentModel.Orientation = System.Windows.Controls.Orientation.Vertical;
                            int targetPaneIndex = parentModel.IndexOfChild(targetModel);
                            parentModel.Children.Insert(targetPaneIndex, newLayoutDocumentPane);
                        }
                        else
                        {
                            LayoutDocumentPaneGroup newChildGroup = new LayoutDocumentPaneGroup
                            {
                                Orientation = System.Windows.Controls.Orientation.Vertical
                            };
                            parentModel.ReplaceChild(targetModel, newChildGroup);
                            newChildGroup.Children.Add(newLayoutDocumentPane);
                            newChildGroup.Children.Add(targetModel);
                        }
                    }

                    foreach (var cntToTransfer in floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray())
                    {
                        newLayoutDocumentPane.Children.Add(cntToTransfer);
                    }
                }
            }
            break;

                #endregion

            case DropTargetType.DocumentPaneDockLeft:

                #region DropTargetType.DocumentPaneDockLeft

            {
                if (targetModel != null)
                {
                    var parentModel           = targetModel.Parent as LayoutDocumentPaneGroup;
                    var newLayoutDocumentPane = new LayoutDocumentPane();

                    if (parentModel == null)
                    {
                        var parentContainer = targetModel.Parent;
                        var newParentModel  = new LayoutDocumentPaneGroup()
                        {
                            Orientation = System.Windows.Controls.Orientation.Horizontal
                        };
                        parentContainer.ReplaceChild(targetModel, newParentModel);
                        newParentModel.Children.Add(newLayoutDocumentPane);
                        newParentModel.Children.Add(targetModel as LayoutDocumentPane);
                    }
                    else
                    {
                        var manager = parentModel.Root.Manager;
                        if (!manager.AllowMixedOrientation || parentModel.Orientation == System.Windows.Controls.Orientation.Horizontal)
                        {
                            parentModel.Orientation = System.Windows.Controls.Orientation.Horizontal;
                            int targetPaneIndex = parentModel.IndexOfChild(targetModel);
                            parentModel.Children.Insert(targetPaneIndex, newLayoutDocumentPane);
                        }
                        else
                        {
                            LayoutDocumentPaneGroup newChildGroup = new LayoutDocumentPaneGroup
                            {
                                Orientation = System.Windows.Controls.Orientation.Horizontal
                            };
                            parentModel.ReplaceChild(targetModel, newChildGroup);
                            newChildGroup.Children.Add(newLayoutDocumentPane);
                            newChildGroup.Children.Add(targetModel);
                        }
                    }

                    foreach (var cntToTransfer in floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray())
                    {
                        newLayoutDocumentPane.Children.Add(cntToTransfer);
                    }
                }
            }
            break;

                #endregion

            case DropTargetType.DocumentPaneDockRight:

                #region DropTargetType.DocumentPaneDockRight

            {
                if (targetModel != null)
                {
                    var parentModel           = targetModel.Parent as LayoutDocumentPaneGroup;
                    var newLayoutDocumentPane = new LayoutDocumentPane();

                    if (parentModel == null)
                    {
                        var parentContainer = targetModel.Parent;
                        var newParentModel  = new LayoutDocumentPaneGroup()
                        {
                            Orientation = System.Windows.Controls.Orientation.Horizontal
                        };
                        parentContainer.ReplaceChild(targetModel, newParentModel);
                        newParentModel.Children.Add(targetModel as LayoutDocumentPane);
                        newParentModel.Children.Add(newLayoutDocumentPane);
                    }
                    else
                    {
                        var manager = parentModel.Root.Manager;
                        if (!manager.AllowMixedOrientation || parentModel.Orientation == System.Windows.Controls.Orientation.Horizontal)
                        {
                            parentModel.Orientation = System.Windows.Controls.Orientation.Horizontal;
                            int targetPaneIndex = parentModel.IndexOfChild(targetModel);
                            parentModel.Children.Insert(targetPaneIndex + 1, newLayoutDocumentPane);
                        }
                        else
                        {
                            LayoutDocumentPaneGroup newChildGroup = new LayoutDocumentPaneGroup
                            {
                                Orientation = System.Windows.Controls.Orientation.Horizontal
                            };
                            parentModel.ReplaceChild(targetModel, newChildGroup);
                            newChildGroup.Children.Add(targetModel);
                            newChildGroup.Children.Add(newLayoutDocumentPane);
                        }
                    }

                    foreach (var cntToTransfer in floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray())
                    {
                        newLayoutDocumentPane.Children.Add(cntToTransfer);
                    }
                }
            }
            break;

                #endregion

            case DropTargetType.DocumentPaneDockInside:

                #region DropTargetType.DocumentPaneDockInside

            {
                var paneModel = targetModel as LayoutDocumentPane;
                var layoutAnchorablePaneGroup = floatingWindow.RootPanel;

                int i = _tabIndex == -1 ? 0 : _tabIndex;
                LayoutAnchorable anchorableToActivate = null;
                foreach (var anchorableToImport in layoutAnchorablePaneGroup.Descendents().OfType <LayoutAnchorable>().ToArray())
                {
                    paneModel?.Children.Insert(i, anchorableToImport);
                    i++;
                    anchorableToActivate = anchorableToImport;
                }

                if (anchorableToActivate != null)
                {
                    anchorableToActivate.IsActive = true;
                }
            }
            break;

                #endregion
            }

            base.Drop(floatingWindow);
        }
예제 #12
0
        protected virtual void FixupLayout(LayoutRoot layout)
        {
            //fix container panes
            foreach (var lcToAttach in layout.Descendents().OfType <ILayoutPreviousContainer>().Where(lc => lc.PreviousContainerId != null))
            {
                var paneContainerToAttach = layout.Descendents().OfType <ILayoutPaneSerializable>().FirstOrDefault(lps => lps.Id == lcToAttach.PreviousContainerId);
                if (paneContainerToAttach == null)
                {
                    throw new ArgumentException(string.Format("Unable to find a pane with id ='{0}'", lcToAttach.PreviousContainerId));
                }

                lcToAttach.PreviousContainer = paneContainerToAttach as ILayoutContainer;
            }

            foreach (var lcToAttach in layout.Descendents().OfType <ILayoutInitialContainer>().Where(lc => lc.InitialContainerId != null))
            {
                var paneContainerToAttach = layout.Descendents().OfType <ILayoutPaneSerializable>().FirstOrDefault(lps => lps.Id == lcToAttach.InitialContainerId);
                if (paneContainerToAttach == null)
                {
                    throw new ArgumentException(string.Format("Unable to find a pane with id ='{0}'", lcToAttach.InitialContainerId));
                }

                lcToAttach.InitialContainer = paneContainerToAttach as ILayoutContainer;
            }


            //now fix the content of the layoutcontents
            foreach (var lcToFix in layout.Descendents().OfType <LayoutAnchorable>().Where(lc => lc.Content == null).ToArray())
            {
                LayoutAnchorable previousAchorable = null;
                if (lcToFix.ContentId != null)
                {
                    //try find the content in replaced layout
                    previousAchorable = _previousAnchorables.FirstOrDefault(a => a.ContentId == lcToFix.ContentId);
                }

                if (LayoutSerializationCallback != null)
                {
                    var args = new LayoutSerializationCallbackEventArgs(lcToFix, previousAchorable != null ? previousAchorable.Content : null);
                    LayoutSerializationCallback(this, args);
                    if (args.Cancel)
                    {
                        lcToFix.Close();
                    }
                    else if (args.Content != null)
                    {
                        lcToFix.Content = args.Content;
                    }
                    else if (args.Model.Content != null)
                    {
                        lcToFix.Hide(false);
                    }
                }
                else if (previousAchorable == null)
                {
                    lcToFix.Hide(false);
                }
                else
                {
                    lcToFix.Content    = previousAchorable.Content;
                    lcToFix.IconSource = previousAchorable.IconSource;
                }
            }


            foreach (var lcToFix in layout.Descendents().OfType <LayoutDocument>().Where(lc => lc.Content == null).ToArray())
            {
                LayoutDocument previousDocument = null;
                if (lcToFix.ContentId != null)
                {
                    //try find the content in replaced layout
                    previousDocument = _previousDocuments.FirstOrDefault(a => a.ContentId == lcToFix.ContentId);
                }

                if (LayoutSerializationCallback != null)
                {
                    var args = new LayoutSerializationCallbackEventArgs(lcToFix, previousDocument != null ? previousDocument.Content : null);
                    LayoutSerializationCallback(this, args);

                    if (args.Cancel)
                    {
                        lcToFix.Close();
                    }
                    else if (args.Content != null)
                    {
                        lcToFix.Content = args.Content;
                    }
                    else if (args.Model.Content != null)
                    {
                        lcToFix.Close();
                    }
                }
                else if (previousDocument == null)
                {
                    lcToFix.Close();
                }
                else
                {
                    lcToFix.Content    = previousDocument.Content;
                    lcToFix.IconSource = previousDocument.IconSource;
                }
            }

            layout.CollectGarbage();
        }
예제 #13
0
        protected override void Drop(LayoutAnchorableFloatingWindow floatingWindow)
        {
            LayoutAnchorable[] array;
            int i;
            ILayoutDocumentPane model = this._targetPane.Model as ILayoutDocumentPane;

            switch (base.Type)
            {
            case DropTargetType.DocumentPaneDockLeft:
            {
                LayoutDocumentPaneGroup parent             = model.Parent as LayoutDocumentPaneGroup;
                LayoutDocumentPane      layoutDocumentPane = new LayoutDocumentPane();
                if (parent == null)
                {
                    ILayoutContainer        layoutContainer         = model.Parent;
                    LayoutDocumentPaneGroup layoutDocumentPaneGroup = new LayoutDocumentPaneGroup()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    layoutContainer.ReplaceChild(model, layoutDocumentPaneGroup);
                    layoutDocumentPaneGroup.Children.Add(layoutDocumentPane);
                    layoutDocumentPaneGroup.Children.Add(model as LayoutDocumentPane);
                }
                else if (!parent.Root.Manager.AllowMixedOrientation || parent.Orientation == Orientation.Horizontal)
                {
                    parent.Orientation = Orientation.Horizontal;
                    int num = parent.IndexOfChild(model);
                    parent.Children.Insert(num, layoutDocumentPane);
                }
                else
                {
                    LayoutDocumentPaneGroup layoutDocumentPaneGroup1 = new LayoutDocumentPaneGroup()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    parent.ReplaceChild(model, layoutDocumentPaneGroup1);
                    layoutDocumentPaneGroup1.Children.Add(layoutDocumentPane);
                    layoutDocumentPaneGroup1.Children.Add(model);
                }
                array = floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray <LayoutAnchorable>();
                for (i = 0; i < (int)array.Length; i++)
                {
                    LayoutAnchorable layoutAnchorable = array[i];
                    layoutDocumentPane.Children.Add(layoutAnchorable);
                }
                break;
            }

            case DropTargetType.DocumentPaneDockTop:
            {
                LayoutDocumentPaneGroup parent1             = model.Parent as LayoutDocumentPaneGroup;
                LayoutDocumentPane      layoutDocumentPane1 = new LayoutDocumentPane();
                if (parent1 == null)
                {
                    ILayoutContainer        layoutContainer1         = model.Parent;
                    LayoutDocumentPaneGroup layoutDocumentPaneGroup2 = new LayoutDocumentPaneGroup()
                    {
                        Orientation = Orientation.Vertical
                    };
                    layoutContainer1.ReplaceChild(model, layoutDocumentPaneGroup2);
                    layoutDocumentPaneGroup2.Children.Add(layoutDocumentPane1);
                    layoutDocumentPaneGroup2.Children.Add(model as LayoutDocumentPane);
                }
                else if (!parent1.Root.Manager.AllowMixedOrientation || parent1.Orientation == Orientation.Vertical)
                {
                    parent1.Orientation = Orientation.Vertical;
                    int num1 = parent1.IndexOfChild(model);
                    parent1.Children.Insert(num1, layoutDocumentPane1);
                }
                else
                {
                    LayoutDocumentPaneGroup layoutDocumentPaneGroup3 = new LayoutDocumentPaneGroup()
                    {
                        Orientation = Orientation.Vertical
                    };
                    parent1.ReplaceChild(model, layoutDocumentPaneGroup3);
                    layoutDocumentPaneGroup3.Children.Add(layoutDocumentPane1);
                    layoutDocumentPaneGroup3.Children.Add(model);
                }
                array = floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray <LayoutAnchorable>();
                for (i = 0; i < (int)array.Length; i++)
                {
                    LayoutAnchorable layoutAnchorable1 = array[i];
                    layoutDocumentPane1.Children.Add(layoutAnchorable1);
                }
                break;
            }

            case DropTargetType.DocumentPaneDockRight:
            {
                LayoutDocumentPaneGroup parent2             = model.Parent as LayoutDocumentPaneGroup;
                LayoutDocumentPane      layoutDocumentPane2 = new LayoutDocumentPane();
                if (parent2 == null)
                {
                    ILayoutContainer        layoutContainer2         = model.Parent;
                    LayoutDocumentPaneGroup layoutDocumentPaneGroup4 = new LayoutDocumentPaneGroup()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    layoutContainer2.ReplaceChild(model, layoutDocumentPaneGroup4);
                    layoutDocumentPaneGroup4.Children.Add(model as LayoutDocumentPane);
                    layoutDocumentPaneGroup4.Children.Add(layoutDocumentPane2);
                }
                else if (!parent2.Root.Manager.AllowMixedOrientation || parent2.Orientation == Orientation.Horizontal)
                {
                    parent2.Orientation = Orientation.Horizontal;
                    int num2 = parent2.IndexOfChild(model);
                    parent2.Children.Insert(num2 + 1, layoutDocumentPane2);
                }
                else
                {
                    LayoutDocumentPaneGroup layoutDocumentPaneGroup5 = new LayoutDocumentPaneGroup()
                    {
                        Orientation = Orientation.Horizontal
                    };
                    parent2.ReplaceChild(model, layoutDocumentPaneGroup5);
                    layoutDocumentPaneGroup5.Children.Add(model);
                    layoutDocumentPaneGroup5.Children.Add(layoutDocumentPane2);
                }
                array = floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray <LayoutAnchorable>();
                for (i = 0; i < (int)array.Length; i++)
                {
                    LayoutAnchorable layoutAnchorable2 = array[i];
                    layoutDocumentPane2.Children.Add(layoutAnchorable2);
                }
                break;
            }

            case DropTargetType.DocumentPaneDockBottom:
            {
                LayoutDocumentPaneGroup parent3             = model.Parent as LayoutDocumentPaneGroup;
                LayoutDocumentPane      layoutDocumentPane3 = new LayoutDocumentPane();
                if (parent3 == null)
                {
                    ILayoutContainer        layoutContainer3         = model.Parent;
                    LayoutDocumentPaneGroup layoutDocumentPaneGroup6 = new LayoutDocumentPaneGroup()
                    {
                        Orientation = Orientation.Vertical
                    };
                    layoutContainer3.ReplaceChild(model, layoutDocumentPaneGroup6);
                    layoutDocumentPaneGroup6.Children.Add(model as LayoutDocumentPane);
                    layoutDocumentPaneGroup6.Children.Add(layoutDocumentPane3);
                }
                else if (!parent3.Root.Manager.AllowMixedOrientation || parent3.Orientation == Orientation.Vertical)
                {
                    parent3.Orientation = Orientation.Vertical;
                    int num3 = parent3.IndexOfChild(model);
                    parent3.Children.Insert(num3 + 1, layoutDocumentPane3);
                }
                else
                {
                    LayoutDocumentPaneGroup layoutDocumentPaneGroup7 = new LayoutDocumentPaneGroup()
                    {
                        Orientation = Orientation.Vertical
                    };
                    parent3.ReplaceChild(model, layoutDocumentPaneGroup7);
                    layoutDocumentPaneGroup7.Children.Add(model);
                    layoutDocumentPaneGroup7.Children.Add(layoutDocumentPane3);
                }
                array = floatingWindow.RootPanel.Descendents().OfType <LayoutAnchorable>().ToArray <LayoutAnchorable>();
                for (i = 0; i < (int)array.Length; i++)
                {
                    LayoutAnchorable layoutAnchorable3 = array[i];
                    layoutDocumentPane3.Children.Add(layoutAnchorable3);
                }
                break;
            }

            case DropTargetType.DocumentPaneDockInside:
            {
                LayoutDocumentPane        layoutDocumentPane4 = model as LayoutDocumentPane;
                LayoutAnchorablePaneGroup rootPanel           = floatingWindow.RootPanel;
                bool flag = true;
                int  previousContainerIndex = 0;
                if (this._tabIndex != -1)
                {
                    previousContainerIndex = this._tabIndex;
                    flag = false;
                }
                LayoutAnchorable layoutAnchorable4 = null;
                array = rootPanel.Descendents().OfType <LayoutAnchorable>().ToArray <LayoutAnchorable>();
                for (i = 0; i < (int)array.Length; i++)
                {
                    LayoutAnchorable layoutAnchorable5 = array[i];
                    if (flag)
                    {
                        if (((ILayoutPreviousContainer)layoutAnchorable5).PreviousContainer == model && layoutAnchorable5.PreviousContainerIndex != -1)
                        {
                            previousContainerIndex = layoutAnchorable5.PreviousContainerIndex;
                        }
                        flag = false;
                    }
                    layoutDocumentPane4.Children.Insert(previousContainerIndex, layoutAnchorable5);
                    previousContainerIndex++;
                    layoutAnchorable4 = layoutAnchorable5;
                }
                layoutAnchorable4.IsActive = true;
                break;
            }
            }
            base.Drop(floatingWindow);
        }
예제 #14
0
 public bool InsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableToShow, ILayoutContainer destinationContainer)
 {
     return(false);
 }
예제 #15
0
        /// <inheritdoc/>
        public void OpenCurveEditorWindow([NotNull] object curve, string name)
        {
            if (curve == null)
            {
                throw new ArgumentNullException(nameof(curve));
            }
            if (dockingLayoutManager == null)
            {
                throw new InvalidOperationException("This method can only be invoked on the IEditorDialogService that has the editor main window as parent.");
            }

            CurveEditorViewModel editorViewModel = null;
            LayoutAnchorable     editorPane      = null;

            if (curveEditor != null)
            {
                // curve editor already exists
                editorViewModel = curveEditor.Item1;
                editorPane      = curveEditor.Item2;
            }

            // Create the editor view model if needed
            if (editorViewModel == null)
            {
                editorViewModel = new CurveEditorViewModel(session.ServiceProvider, session);
            }

            // Populate the editor view model
            if (curve is IComputeCurve <Color4> )
            {
                editorViewModel.AddCurve((IComputeCurve <Color4>)curve, name);
            }
            else if (curve is IComputeCurve <float> )
            {
                editorViewModel.AddCurve((IComputeCurve <float>)curve, name);
            }
            else if (curve is IComputeCurve <Quaternion> )
            {
                editorViewModel.AddCurve((IComputeCurve <Quaternion>)curve, name);
            }
            else if (curve is IComputeCurve <Vector2> )
            {
                editorViewModel.AddCurve((IComputeCurve <Vector2>)curve, name);
            }
            else if (curve is IComputeCurve <Vector3> )
            {
                editorViewModel.AddCurve((IComputeCurve <Vector3>)curve, name);
            }
            else if (curve is IComputeCurve <Vector4> )
            {
                editorViewModel.AddCurve((IComputeCurve <Vector4>)curve, name);
            }

            editorViewModel.Focus();

            // Create the editor pane if needed
            if (editorPane == null)
            {
                editorPane = new LayoutAnchorable
                {
                    Content = new CurveEditorView {
                        DataContext = editorViewModel
                    },
                    Title = "Curve Editor",
                };

                editorPane.Closed += CurveEditorClosed;

                //editorPane.Closed += (s, e) =>
                //{
                //    if (((LayoutAnchorable)s).IsHidden)
                //    {
                //        RemoveCurveEditor(true);
                //    }
                //};

                AvalonDockHelper.GetDocumentPane(dockingLayoutManager.DockingManager).Children.Add(editorPane);
            }

            curveEditor = Tuple.Create(editorViewModel, editorPane);

            MakeActiveVisible(editorPane);
        }
예제 #16
0
 internal override void Attach(LayoutContent model)
 {
     this._anchorable = model as LayoutAnchorable;
     this._anchorable.IsVisibleChanged += new EventHandler(this._anchorable_IsVisibleChanged);
     base.Attach(model);
 }
        protected override void Drop(LayoutAnchorableFloatingWindow floatingWindow)
        {
            ILayoutAnchorablePane targetModel      = _targetPane.Model as ILayoutAnchorablePane;
            LayoutAnchorable      anchorableActive = floatingWindow.Descendents().OfType <LayoutAnchorable>().FirstOrDefault();

            switch (Type)
            {
            case DropTargetType.AnchorablePaneDockBottom:
                #region DropTargetType.AnchorablePaneDockBottom
            {
                var parentModel           = targetModel.Parent as ILayoutGroup;
                var parentModelOrientable = targetModel.Parent as ILayoutOrientableGroup;
                int insertToIndex         = parentModel.IndexOfChild(targetModel);

                if (parentModelOrientable.Orientation != System.Windows.Controls.Orientation.Vertical &&
                    parentModel.ChildrenCount == 1)
                {
                    parentModelOrientable.Orientation = System.Windows.Controls.Orientation.Vertical;
                }

                if (parentModelOrientable.Orientation == System.Windows.Controls.Orientation.Vertical)
                {
                    var layoutAnchorablePaneGroup = floatingWindow.RootPanel as LayoutAnchorablePaneGroup;
                    if (layoutAnchorablePaneGroup != null &&
                        (layoutAnchorablePaneGroup.Children.Count == 1 ||
                         layoutAnchorablePaneGroup.Orientation == System.Windows.Controls.Orientation.Vertical))
                    {
                        var anchorablesToMove = layoutAnchorablePaneGroup.Children.ToArray();
                        for (int i = 0; i < anchorablesToMove.Length; i++)
                        {
                            parentModel.InsertChildAt(insertToIndex + 1 + i, anchorablesToMove[i]);
                        }
                    }
                    else
                    {
                        parentModel.InsertChildAt(insertToIndex + 1, floatingWindow.RootPanel);
                    }
                }
                else
                {
                    var targetModelAsPositionableElement = targetModel as ILayoutPositionableElement;
                    var newOrientedPanel = new LayoutAnchorablePaneGroup()
                    {
                        Orientation = System.Windows.Controls.Orientation.Vertical,
                        DockWidth   = targetModelAsPositionableElement.DockWidth,
                        DockHeight  = targetModelAsPositionableElement.DockHeight,
                    };

                    parentModel.InsertChildAt(insertToIndex, newOrientedPanel);
                    newOrientedPanel.Children.Add(targetModel);
                    newOrientedPanel.Children.Add(floatingWindow.RootPanel);
                }
            }
            break;

                #endregion
            case DropTargetType.AnchorablePaneDockTop:
                #region DropTargetType.AnchorablePaneDockTop
            {
                var parentModel           = targetModel.Parent as ILayoutGroup;
                var parentModelOrientable = targetModel.Parent as ILayoutOrientableGroup;
                int insertToIndex         = parentModel.IndexOfChild(targetModel);

                if (parentModelOrientable.Orientation != System.Windows.Controls.Orientation.Vertical &&
                    parentModel.ChildrenCount == 1)
                {
                    parentModelOrientable.Orientation = System.Windows.Controls.Orientation.Vertical;
                }

                if (parentModelOrientable.Orientation == System.Windows.Controls.Orientation.Vertical)
                {
                    var layoutAnchorablePaneGroup = floatingWindow.RootPanel as LayoutAnchorablePaneGroup;
                    if (layoutAnchorablePaneGroup != null &&
                        (layoutAnchorablePaneGroup.Children.Count == 1 ||
                         layoutAnchorablePaneGroup.Orientation == System.Windows.Controls.Orientation.Vertical))
                    {
                        var anchorablesToMove = layoutAnchorablePaneGroup.Children.ToArray();
                        for (int i = 0; i < anchorablesToMove.Length; i++)
                        {
                            parentModel.InsertChildAt(insertToIndex + i, anchorablesToMove[i]);
                        }
                    }
                    else
                    {
                        parentModel.InsertChildAt(insertToIndex, floatingWindow.RootPanel);
                    }
                }
                else
                {
                    var targetModelAsPositionableElement = targetModel as ILayoutPositionableElement;
                    var newOrientedPanel = new LayoutAnchorablePaneGroup()
                    {
                        Orientation = System.Windows.Controls.Orientation.Vertical,
                        DockWidth   = targetModelAsPositionableElement.DockWidth,
                        DockHeight  = targetModelAsPositionableElement.DockHeight,
                    };

                    parentModel.InsertChildAt(insertToIndex, newOrientedPanel);
                    //the floating window must be added after the target modal as it could be raise a CollectGarbage call
                    newOrientedPanel.Children.Add(targetModel);
                    newOrientedPanel.Children.Insert(0, floatingWindow.RootPanel);
                }
            }
            break;

                #endregion
            case DropTargetType.AnchorablePaneDockLeft:
                #region DropTargetType.AnchorablePaneDockLeft
            {
                var parentModel           = targetModel.Parent as ILayoutGroup;
                var parentModelOrientable = targetModel.Parent as ILayoutOrientableGroup;
                int insertToIndex         = parentModel.IndexOfChild(targetModel);

                if (parentModelOrientable.Orientation != System.Windows.Controls.Orientation.Horizontal &&
                    parentModel.ChildrenCount == 1)
                {
                    parentModelOrientable.Orientation = System.Windows.Controls.Orientation.Horizontal;
                }

                if (parentModelOrientable.Orientation == System.Windows.Controls.Orientation.Horizontal)
                {
                    var layoutAnchorablePaneGroup = floatingWindow.RootPanel as LayoutAnchorablePaneGroup;
                    if (layoutAnchorablePaneGroup != null &&
                        (layoutAnchorablePaneGroup.Children.Count == 1 ||
                         layoutAnchorablePaneGroup.Orientation == System.Windows.Controls.Orientation.Horizontal))
                    {
                        var anchorablesToMove = layoutAnchorablePaneGroup.Children.ToArray();
                        for (int i = 0; i < anchorablesToMove.Length; i++)
                        {
                            parentModel.InsertChildAt(insertToIndex + i, anchorablesToMove[i]);
                        }
                    }
                    else
                    {
                        parentModel.InsertChildAt(insertToIndex, floatingWindow.RootPanel);
                    }
                }
                else
                {
                    var targetModelAsPositionableElement = targetModel as ILayoutPositionableElement;
                    var newOrientedPanel = new LayoutAnchorablePaneGroup()
                    {
                        Orientation = System.Windows.Controls.Orientation.Horizontal,
                        DockWidth   = targetModelAsPositionableElement.DockWidth,
                        DockHeight  = targetModelAsPositionableElement.DockHeight,
                    };

                    parentModel.InsertChildAt(insertToIndex, newOrientedPanel);
                    //the floating window must be added after the target modal as it could be raise a CollectGarbage call
                    newOrientedPanel.Children.Add(targetModel);
                    newOrientedPanel.Children.Insert(0, floatingWindow.RootPanel);
                }
            }
            break;

                #endregion
            case DropTargetType.AnchorablePaneDockRight:
                #region DropTargetType.AnchorablePaneDockRight
            {
                var parentModel           = targetModel.Parent as ILayoutGroup;
                var parentModelOrientable = targetModel.Parent as ILayoutOrientableGroup;
                int insertToIndex         = parentModel.IndexOfChild(targetModel);

                if (parentModelOrientable.Orientation != System.Windows.Controls.Orientation.Horizontal &&
                    parentModel.ChildrenCount == 1)
                {
                    parentModelOrientable.Orientation = System.Windows.Controls.Orientation.Horizontal;
                }

                if (parentModelOrientable.Orientation == System.Windows.Controls.Orientation.Horizontal)
                {
                    var layoutAnchorablePaneGroup = floatingWindow.RootPanel as LayoutAnchorablePaneGroup;
                    if (layoutAnchorablePaneGroup != null &&
                        (layoutAnchorablePaneGroup.Children.Count == 1 ||
                         layoutAnchorablePaneGroup.Orientation == System.Windows.Controls.Orientation.Horizontal))
                    {
                        var anchorablesToMove = layoutAnchorablePaneGroup.Children.ToArray();
                        for (int i = 0; i < anchorablesToMove.Length; i++)
                        {
                            parentModel.InsertChildAt(insertToIndex + 1 + i, anchorablesToMove[i]);
                        }
                    }
                    else
                    {
                        parentModel.InsertChildAt(insertToIndex + 1, floatingWindow.RootPanel);
                    }
                }
                else
                {
                    var targetModelAsPositionableElement = targetModel as ILayoutPositionableElement;
                    var newOrientedPanel = new LayoutAnchorablePaneGroup()
                    {
                        Orientation = System.Windows.Controls.Orientation.Horizontal,
                        DockWidth   = targetModelAsPositionableElement.DockWidth,
                        DockHeight  = targetModelAsPositionableElement.DockHeight,
                    };

                    parentModel.InsertChildAt(insertToIndex, newOrientedPanel);
                    newOrientedPanel.Children.Add(targetModel);
                    newOrientedPanel.Children.Add(floatingWindow.RootPanel);
                }
            }
            break;
                #endregion


            case DropTargetType.AnchorablePaneDockInside:
                #region DropTargetType.AnchorablePaneDockInside
            {
                var paneModel = targetModel as LayoutAnchorablePane;
                var layoutAnchorablePaneGroup = floatingWindow.RootPanel as LayoutAnchorablePaneGroup;

                int i = _tabIndex == -1 ? 0 : _tabIndex;
                foreach (var anchorableToImport in
                         layoutAnchorablePaneGroup.Descendents().OfType <LayoutAnchorable>().ToArray())
                {
                    paneModel.Children.Insert(i, anchorableToImport);
                    i++;
                }
            }
            break;
                #endregion
            }

            anchorableActive.IsActive = true;

            base.Drop(floatingWindow);
        }
예제 #18
0
 internal void UnregisterAssetPreview(LayoutAnchorable assetPreviewAnchorable)
 {
     assetPreviewAnchorable.IsSelectedChanged -= OnAssetPreviewAnchorable_IsSelectedChanged;
 }
예제 #19
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);
        }
 public void AfterInsertAnchorable(LayoutRoot layout, LayoutAnchorable anchorableShown)
 {
 }
예제 #21
0
        public void OnLayoutLoaded(LayoutLoadedArgs args)
        {
            var layoutGroupData = new Dictionary <LayoutAnchorable, LayoutAnchorablePane>();

            var oldViews = anchorableDefinitions.Select(o => o.Key.Content as UserControl).ToList();

            anchorableDefinitions.Clear();
            var staticAnchorables = args.LayoutAnchorables.Where(o => PanelManager.StaticPanelDefinitions.Any(def => def.View == o.Content.GetType() &&
                                                                                                              def.ViewModel == ((UserControl)o.Content).DataContext.GetType()));

            foreach (var anchorable in staticAnchorables)
            {
                var associatedDefinition = PanelManager.StaticPanelDefinitions.Single(o => o.View.GetGuid() == anchorable.Content.GetType().GetGuid() &&
                                                                                      o.ViewModel.GetGuid() == anchorable.Content.SafeCast <UserControl>().DataContext.GetType().GetGuid());
                anchorableDefinitions.Add(anchorable, associatedDefinition);
                anchorable.Hiding += (sender, e) =>
                {
                    var source = sender.SafeCast <LayoutAnchorable>();
                    VisibilityManager.UpdateContainer(source);
                };

                LayoutAnchorablePane layoutGroup = null;
                if (anchorable.Parent != null && anchorable.Parent is LayoutAnchorablePane)
                {
                    layoutGroup = anchorable.Parent as LayoutAnchorablePane;
                }
                else
                {
                    layoutGroup = anchorable.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).
                                  Single(prop => prop.Name == "PreviousContainer").GetValue(anchorable) as LayoutAnchorablePane;
                }

                layoutGroupData.Add(anchorable, layoutGroup);
            }

            // Resolve static panel definitions that were not included in the layout.
            var resolvedDefinitions = anchorableDefinitions.Select(o => o.Value);
            var newDefinitions      = PanelManager.StaticPanelDefinitions.Where(o => !resolvedDefinitions.Contains(o)).ToList();

            foreach (var definition in newDefinitions)
            {
                var config = definition.OfType <StaticPanelConfiguration>().Single();

                var anchorable = new LayoutAnchorable();

                var view = oldViews.Single(o => o.GetType() == definition.View);

                anchorable.Content   = view;
                anchorable.ContentId = definition.View.GetGuid();
                anchorable.Title     = config.Title();

                LayoutAnchorablePane container = null;

                if (anchorableDefinitions.Any(o => o.Value.OfType <StaticPanelConfiguration>().Single().Placement == config.Placement))
                {
                    container = anchorableDefinitions.Where(o => o.Value.OfType <StaticPanelConfiguration>().Single().Placement == config.Placement).Select(o => o.Key).
                                GroupBy(o => layoutGroupData[o]).OrderBy(o => o.Count()).Last().Key;
                }
                else
                {
                    container = DockingView.DockingManager.Layout.Descendents().OfType <LayoutAnchorablePane>().FirstOrDefault();
                }

                container.Children.Add(anchorable);

                anchorable.CanAutoHide = true;
                anchorable.CanFloat    = config.CanFloat();



                anchorable.Hiding += (sender, e) => {
                    var source = sender.SafeCast <LayoutAnchorable>();
                    if (source.IsVisible)
                    {
                        VisibilityManager.UpdateContainer(source);
                    }
                };

                anchorableDefinitions.Add(anchorable, definition);
                layoutGroupData.Add(anchorable, container);
            }

            VisibilityManager.SetLayoutGroupData(layoutGroupData);

            foreach (var definition in newDefinitions)
            {
                var config = definition.OfType <StaticPanelConfiguration>().Single();

                var canOpen    = config.CanOpen();
                var canClose   = config.CanClose();
                var visibility = config.IsVisible();

                if (canOpen == false && canClose == false)
                {
                    throw new Exception($"Error in static panel {definition.ViewModel} metadata. CanOpen() and CanClose() defined " +
                                        $"in the panel definition's configuration metadata can't both return false at the same time.");
                }

                if (!visibility && canClose)
                {
                    var anchorable = anchorableDefinitions.GetKeysForValue(definition).Single();
                    VisibilityManager.SetVisibility(anchorable, false);
                }
            }
        }