예제 #1
0
        private void SelectNewViewPresenter(IVsUIDataSource dataContext, ContentControl contentHost)
        {
            Shell.ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                ProviderDataSourceWrapper providerModel = new ProviderDataSourceWrapper(dataContext);

                VsUIElementDescriptor newViewDescriptor = GetAppropriateViewDescriptor(providerModel);

                Telemetry.Client.TrackPageView(providerModel.Name);

                // Decide if the view should change, or if we can just update the datasource on the existing view.
                if (ShouldChangeView(newViewDescriptor))
                {
                    // Update the new content and Dispose of the old
                    using IDisposable oldContent = contentHost.Content as IDisposable;
                    SetNewView(contentHost, newViewDescriptor, providerModel.ViewModel);
                }
                else
                {
                    // Use the same view, just update the data context.
                    UpdateCurrentViewElementModel(contentHost, providerModel.ViewModel);
                }
            }
            catch (ViewCreationException ex)
            {
                HandleViewCreationException(contentHost, ex);
            }
            catch (UIFactoryException ex)
            {
                HandleViewCreationException(contentHost, ex);
            }
        }
예제 #2
0
        private void SetNewView(ContentControl contentHost, VsUIElementDescriptor viewDescriptor, object viewModel)
        {
            IVsUIElement uiElement = UIFactoryHelper.GetViewFromUIFactory(viewDescriptor);

            contentHost.Content =
                (uiElement == null)
                ? this.EmptyView
                : UIFactoryHelper.ResolveWpfViewAndSetDataContext(uiElement, viewModel);

            this.currentViewDescriptor = viewDescriptor;
            this.currentViewElement    = uiElement;
        }
예제 #3
0
 public Provider(
     Guid providerGuid,
     string name,
     Guid package,
     VsUIElementDescriptor viewDescriptor)
 {
     SetValue(ProviderProperty, providerGuid);
     SetValue(NameProperty, VsShellUtilities.LookupPackageString(package, name));
     SetValue(PackageProperty, package);
     SetValue(ViewFactoryProperty, viewDescriptor.Factory);
     SetValue(ViewProperty, viewDescriptor.ElementID);
 }
예제 #4
0
        /// <summary>
        /// Given the diagnostics data model of a single Component Diagnostics provider,
        /// select the appropriate view. If the "ViewFactory" property contains a Guid
        /// then use that, along with the "View" field to create a new UI element from
        /// a UI factory.
        /// </summary>
        /// <param name="provider">Data model of the selected provider</param>
        /// <returns>A descriptor of the view to display</returns>
        /// <exception cref="ArgumentNullException">The provider is null</exception>
        /// <exception cref="ViewCreationException">The view could not be created for the
        /// reason given in the exception message</exception>
        static VsUIElementDescriptor GetAppropriateViewDescriptor(ProviderDataSourceWrapper provider)
        {
            if (provider == null)
            {
                throw new ViewCreationException(Messages.ProviderIsNull);
            }

            VsUIElementDescriptor viewDescriptor = provider.ViewDescriptor;

            // If no factory was specified, then use the default view
            if (viewDescriptor.Factory == Guid.Empty)
            {
                viewDescriptor = DefaultViewDescriptor;
            }

            return(viewDescriptor);
        }
예제 #5
0
        /// <summary>
        /// When the ContentControl is reloaded, recreate the current view
        /// </summary>
        void viewPresenter_Reloaded(object sender, RoutedEventArgs e)
        {
            Shell.ThreadHelper.ThrowIfNotOnUIThread();
            ContentControl contentHost = (ContentControl)sender;

            contentHost.Loaded -= viewPresenter_Reloaded;

            try
            {
                ProviderDataSourceWrapper providerModel  = new ProviderDataSourceWrapper(contentHost.DataContext as IVsUIDataSource);
                VsUIElementDescriptor     viewDescriptor = GetAppropriateViewDescriptor(providerModel);
                SetNewView(contentHost, viewDescriptor, providerModel.ViewModel);
            }
            catch (ViewCreationException ex)
            {
                HandleViewCreationException(contentHost, ex);
            }
            catch (UIFactoryException ex)
            {
                HandleViewCreationException(contentHost, ex);
            }
        }
예제 #6
0
 /// <summary>
 /// Determine if the view needs to change.
 /// </summary>
 /// <param name="newViewDescriptor">The new view descriptor determined by calling GetAppropriateViewDescriptor</param>
 /// <returns>true if the view should change, false if the view should stay the same</returns>
 bool ShouldChangeView(VsUIElementDescriptor newViewDescriptor)
 {
     return(this.currentViewElement == null || !this.currentViewDescriptor.Equals(newViewDescriptor));
 }