/// <summary>
        /// This is called when the component cache has finished being loaded and is available for use
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void componentCache_ComponentContainerLoaded(object sender, EventArgs e)
        {
            ProjectProperty syntaxFilterProp = null, presentationStyleProp = null;
            List <string>   allFilters;
            int             idx;

            if (this.IsDisposed)
            {
                return;
            }

            // May already be binding so preserve the original state
            bool isBinding = this.IsBinding;

            HashSet <string> generatorIds = new HashSet <string>(), presentationStyleIds = new HashSet <string>();

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                this.IsBinding = true;

                cboPresentationStyle.Enabled    = cblSyntaxFilters.Enabled = true;
                cboPresentationStyle.DataSource = null;

                cblSyntaxFilters.Items.Clear();
                cboPresentationStyle.Items.Clear();

                syntaxGenerators   = new List <ISyntaxGeneratorMetadata>();
                presentationStyles = new List <IPresentationStyleMetadata>();

                var generators = componentCache.ComponentContainer.GetExports <ISyntaxGeneratorFactory,
                                                                               ISyntaxGeneratorMetadata>().Select(g => g.Metadata).ToList();

                // There may be duplicate generator IDs across the assemblies found.  See
                // BuildComponentManger.GetComponentContainer() for the folder search precedence.  Only the
                // first component for a unique ID will be used.
                foreach (var generator in generators)
                {
                    if (!generatorIds.Contains(generator.Id))
                    {
                        syntaxGenerators.Add(generator);
                        generatorIds.Add(generator.Id);
                    }
                }

                var styles = componentCache.ComponentContainer.GetExports <PresentationStyleSettings,
                                                                           IPresentationStyleMetadata>().Select(g => g.Metadata).ToList();

                // As above for duplicates
                foreach (var style in styles)
                {
                    if (!presentationStyleIds.Contains(style.Id))
                    {
                        presentationStyles.Add(style);
                        presentationStyleIds.Add(style.Id);
                    }
                }

                cblSyntaxFilters.Items.AddRange(syntaxGenerators.Select(f => f.Id).OrderBy(f => f).ToArray());

                cboPresentationStyle.DisplayMember = "Title";
                cboPresentationStyle.ValueMember   = "Id";
                cboPresentationStyle.DataSource    = presentationStyles.OrderBy(s => s.IsDeprecated ? 1 : 0).ThenBy(
                    s => s.Id).ToList();
                cboPresentationStyle.SelectedValue = Constants.DefaultPresentationStyle;

                // Resize the syntax filter columns to the widest entry
                int width, maxWidth = 0;

                foreach (string s in cblSyntaxFilters.Items)
                {
                    width = TextRenderer.MeasureText(s, this.Font).Width;

                    if (width > maxWidth)
                    {
                        maxWidth = width;
                    }
                }

                cblSyntaxFilters.ColumnWidth = maxWidth + 20;

                if (cblSyntaxFilters.Items.Count != 0)
                {
                    cblSyntaxFilters.SelectedIndex = 0;
                }
                else
                {
                    MessageBox.Show("No valid syntax generators found", messageBoxTitle, MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

                if (cboPresentationStyle.Items.Count == 0)
                {
                    MessageBox.Show("No valid presentation styles found", messageBoxTitle, MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }

#if !STANDALONEGUI
                if (this.ProjectMgr != null)
                {
                    presentationStyleProp = this.ProjectMgr.BuildProject.GetProperty("PresentationStyle");
                    syntaxFilterProp      = this.ProjectMgr.BuildProject.GetProperty("SyntaxFilters");
                }
#else
                if (this.CurrentProject != null)
                {
                    presentationStyleProp = this.CurrentProject.MSBuildProject.GetProperty("PresentationStyle");
                    syntaxFilterProp      = this.CurrentProject.MSBuildProject.GetProperty("SyntaxFilters");
                }
#endif
                if (presentationStyleProp != null)
                {
                    var match = cboPresentationStyle.Items.Cast <IPresentationStyleMetadata>().FirstOrDefault(p =>
                                                                                                              p.Id == presentationStyleProp.UnevaluatedValue);

                    if (match != null)
                    {
                        cboPresentationStyle.SelectedValue = presentationStyleProp.UnevaluatedValue;
                    }
                }

                if (syntaxFilterProp != null)
                {
                    allFilters = ComponentUtilities.SyntaxFiltersFrom(syntaxGenerators,
                                                                      syntaxFilterProp.UnevaluatedValue).Select(f => f.Id).ToList();
                }
                else
                {
                    allFilters = ComponentUtilities.SyntaxFiltersFrom(syntaxGenerators, "Standard").Select(
                        f => f.Id).ToList();
                }

                foreach (string s in allFilters)
                {
                    idx = cblSyntaxFilters.FindStringExact(s);

                    if (idx != -1)
                    {
                        cblSyntaxFilters.SetItemChecked(idx, true);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());

                MessageBox.Show("Unexpected error loading syntax generators and presentation styles: " +
                                ex.Message, messageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.IsBinding = isBinding;
                Cursor.Current = Cursors.Default;
            }
        }
Exemple #2
0
        /// <inheritdoc />
        protected override bool BindControlValue(Control control)
        {
            ProjectProperty projProp = null;
            List <string>   allFilters;
            int             idx;

#if !STANDALONEGUI
            if (this.ProjectMgr == null)
            {
                return(false);
            }
#else
            if (this.CurrentProject == null)
            {
                return(false);
            }
#endif
            // Add the project's selected language to the list if it is not there
            if (control.Name == "cboLanguage")
            {
#if !STANDALONEGUI
                projProp = this.ProjectMgr.BuildProject.GetProperty("Language");
#else
                projProp = this.CurrentProject.MSBuildProject.GetProperty("Language");
#endif
                if (projProp != null)
                {
                    cboLanguage.SelectedItem = this.AddLanguage(projProp.UnevaluatedValue ?? "en-US");
                }
                else
                {
                    cboLanguage.SelectedItem = LanguageResourceConverter.StandardValues.First(
                        c => c.Name.Equals("en-US", StringComparison.OrdinalIgnoreCase));
                }

                return(true);
            }

            // Set the selected syntax filters
            if (control.Name == "cblSyntaxFilters")
            {
                for (idx = 0; idx < cblSyntaxFilters.Items.Count; idx++)
                {
                    cblSyntaxFilters.SetItemChecked(idx, false);
                }

#if !STANDALONEGUI
                SandcastleProject currentProject = null;

                if (base.ProjectMgr != null)
                {
                    currentProject = ((SandcastleBuilderProjectNode)base.ProjectMgr).SandcastleProject;
                }

                if (syntaxGenerators == null || presentationStyles == null || currentProject == null ||
                    currentProject.Filename != lastProjectName)
                {
                    this.LoadAvailableSyntaxGeneratorsAndPresentationStyles();
                }

                if (base.ProjectMgr != null)
                {
                    projProp = base.ProjectMgr.BuildProject.GetProperty("SyntaxFilters");
                }
#else
                if (syntaxGenerators == null || presentationStyles == null || base.CurrentProject == null ||
                    base.CurrentProject.Filename != lastProjectName)
                {
                    this.LoadAvailableSyntaxGeneratorsAndPresentationStyles();
                }

                if (base.CurrentProject != null)
                {
                    projProp = base.CurrentProject.MSBuildProject.GetProperty("SyntaxFilters");
                }
#endif

                if (projProp != null)
                {
                    allFilters = ComponentUtilities.SyntaxFiltersFrom(syntaxGenerators,
                                                                      projProp.UnevaluatedValue).Select(f => f.Id).ToList();
                }
                else
                {
                    allFilters = ComponentUtilities.SyntaxFiltersFrom(syntaxGenerators, "Standard").Select(
                        f => f.Id).ToList();
                }

                foreach (string s in allFilters)
                {
                    idx = cblSyntaxFilters.FindStringExact(s);

                    if (idx != -1)
                    {
                        cblSyntaxFilters.SetItemChecked(idx, true);
                    }
                }

                return(true);
            }

            return(false);
        }
Exemple #3
0
        /// <summary>
        /// This is called when the component cache has finished being loaded and is available for use
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void componentCache_ComponentContainerLoaded(object sender, EventArgs e)
        {
            BuildPropertiesNeededEventArgs projectSettings = new BuildPropertiesNeededEventArgs();

            this.BuildPropertiesNeeded?.Invoke(this, projectSettings);

            HashSet <string> generatorIds = new HashSet <string>(), presentationStyleIds = new HashSet <string>();

            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                isBinding            = true;

                cboPresentationStyle.IsEnabled   = lbSyntaxFilters.IsEnabled = lbHelpFileFormat.IsEnabled = true;
                cboPresentationStyle.ItemsSource = null;

                lbHelpFileFormat.Items.Clear();
                lbSyntaxFilters.Items.Clear();
                cboPresentationStyle.Items.Clear();

                syntaxGenerators   = new List <ISyntaxGeneratorMetadata>();
                presentationStyles = new List <IPresentationStyleMetadata>();

                var generators = componentCache.ComponentContainer.GetExports <ISyntaxGeneratorFactory,
                                                                               ISyntaxGeneratorMetadata>().Select(g => g.Metadata).ToList();

                // There may be duplicate generator IDs across the assemblies found.  See
                // BuildComponentManger.GetComponentContainer() for the folder search precedence.  Only the
                // first component for a unique ID will be used.
                foreach (var generator in generators)
                {
                    if (!generatorIds.Contains(generator.Id))
                    {
                        syntaxGenerators.Add(generator);
                        generatorIds.Add(generator.Id);
                    }
                }

                var styles = componentCache.ComponentContainer.GetExports <PresentationStyleSettings,
                                                                           IPresentationStyleMetadata>().Select(g => g.Metadata).ToList();

                // As above for duplicates
                foreach (var style in styles)
                {
                    if (!presentationStyleIds.Contains(style.Id))
                    {
                        presentationStyles.Add(style);
                        presentationStyleIds.Add(style.Id);
                    }
                }

                allSyntaxFilters = new List <SyntaxFilterItem>();

                foreach (var filter in syntaxGenerators.OrderBy(f => f.Id))
                {
                    allSyntaxFilters.Add(new SyntaxFilterItem {
                        Id = filter.Id
                    });
                }

                lbSyntaxFilters.ItemsSource = allSyntaxFilters;

                cboPresentationStyle.ItemsSource = presentationStyles.OrderBy(s => s.IsDeprecated ? 1 : 0).ThenBy(
                    s => s.Id).ToList();
                cboPresentationStyle.SelectedValue = Constants.DefaultPresentationStyle;

                if (lbSyntaxFilters.Items.Count != 0)
                {
                    lbSyntaxFilters.SelectedIndex = 0;
                }
                else
                {
                    MessageBox.Show("No valid syntax generators found", Constants.AppName, MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }

                if (cboPresentationStyle.Items.Count == 0)
                {
                    MessageBox.Show("No valid presentation styles found", Constants.AppName, MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }

                if (projectSettings.ProjectLoaded)
                {
                    if (!String.IsNullOrWhiteSpace(projectSettings.PresentationStyle))
                    {
                        var match = cboPresentationStyle.Items.Cast <IPresentationStyleMetadata>().FirstOrDefault(p =>
                                                                                                                  p.Id.Equals(projectSettings.PresentationStyle, StringComparison.OrdinalIgnoreCase));

                        if (match != null)
                        {
                            cboPresentationStyle.SelectedValue = match.Id;
                        }
                    }

                    if (!String.IsNullOrWhiteSpace(projectSettings.SyntaxFilters))
                    {
                        foreach (string filter in ComponentUtilities.SyntaxFiltersFrom(syntaxGenerators,
                                                                                       projectSettings.SyntaxFilters).Select(f => f.Id))
                        {
                            var match = allSyntaxFilters.FirstOrDefault(f => f.Id == filter);

                            if (match != null)
                            {
                                match.IsSelected = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());

                MessageBox.Show("Unexpected error loading syntax generators and presentation styles: " +
                                ex.Message, Constants.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.OverrideCursor = null;
                isBinding            = false;
            }
        }