public void ActivateDocument(IDocumentView view)
        {
            if (view == null)
            {
                return;
            }
            foreach (DocumentView d in documentViews)
            {
                if (d.GetType() == view.GetType())
                {
                    if (d.DocumentName == view.DocumentName)
                    {
                        d.Activate();
                        return;
                    }
                }
            }
            DocumentView doc = view as DocumentView;

            if (doc != null)
            {
                doc.FormClosing += new FormClosingEventHandler(OnDocumentWindowClosing);
                documentViews.Add(doc);
                doc.Show(dockPanel, DockState.Document);
                Refresh();
            }
        }
Esempio n. 2
0
        private void CloseView(IDocumentView view)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }
            This.Logger.Verbose("Closing View.");
            view.Close();
            if (view is IDisposable)
            {
                var document = view.Document;
                var viewInfo = document == null?view.GetType() : document.GetType();

                This.Logger.Verbose(string.Format("Disposing view {0}", viewInfo));
                ((IDisposable)view).Dispose();
            }
        }
 private void CloseView(IDocumentView view)
 {
     if (view == null) throw new ArgumentNullException("view");
     This.Logger.Verbose("Closing View.");
     view.Close();
     if (view is IDisposable)
     {
         var document = view.Document;
         var viewInfo = document == null ? view.GetType() : document.GetType();
         This.Logger.Verbose(string.Format("Disposing view {0}", viewInfo));
         ((IDisposable)view).Dispose();
     }
 }
        private void ActivateTabForCurrentlySelectedDocumentView()
        {
            IDocumentView documentView = null;

            var selectedContent = _layoutDocumentPane.SelectedContent;

            documentView = AvalonDockHelper.ActivatedView;

            if (documentView == null)
            {
                if (selectedContent != null)
                {
                    documentView = selectedContent.Content as IDocumentView;

                    if (documentView == null)
                    {
                        var nestedDockingManager = selectedContent.Content as NestedDockingManager;

                        if (nestedDockingManager != null)
                        {
                            documentView = nestedDockingManager.ContentDocument.Content as IDocumentView;
                        }
                    }
                }


                if (documentView == null)
                {
                    Log.Debug("SelectedContent is not a document view, selecting home ribbon tab");

                    _ribbon.SelectTabItem(Orchestra.Properties.OrchestraResources.HomeRibbonTabName);
                    return;
                }
            }

            var documentViewType = documentView.GetType();

            if (!_viewSpecificRibbonItems.ContainsKey(documentViewType))
            {
                Log.Debug("SelectedContent does not have a ribbon tab, selecting home ribbon tab");
                _dispatcherService.BeginInvoke(() => _ribbon.SelectTabItem(Orchestra.Properties.OrchestraResources.HomeRibbonTabName));
                return;
            }

            var viewSpecificRibbonItems = _viewSpecificRibbonItems[documentViewType];

            foreach (var viewSpecificRibbonItem in viewSpecificRibbonItems)
            {
                if (viewSpecificRibbonItem.Context == RibbonContext.View)
                {
                    Log.Debug("Adding ribbon item '{0}' which has a view context", viewSpecificRibbonItem);

                    var contextualGroup = _ribbon.EnsureContextualTabGroup(viewSpecificRibbonItem.ContextualTabItemGroupName);
                    contextualGroup.Visibility = Visibility.Visible;
                }
            }

            var lastRibbonItem = viewSpecificRibbonItems.Last();

            if (lastRibbonItem.Behavior == RibbonBehavior.ActivateTab)
            {
                Log.Debug("Updating data context of ribbon");

                var ribbonBinding = new Binding("ViewModel");
                ribbonBinding.Source = documentView;
                _ribbon.SetBinding(Ribbon.DataContextProperty, ribbonBinding);

                _dispatcherService.BeginInvoke(() => _ribbon.SelectTabItem(lastRibbonItem.TabItemHeader));
            }
        }