コード例 #1
0
        //=====================================================================

        /// <summary>
        /// Show the selected transformation argument value
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void lbArguments_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (currentArg != null)
            {
                if (changingArg)
                {
                    return;
                }

                // Revert to the previous item if it's not valid
                if (!this.IsValid)
                {
                    changingArg = e.Handled = true;
                    lbArguments.SelectedItem = currentArg;
                    changingArg = false;
                    return;
                }
            }

            if (lbArguments.SelectedItem == null || !lbArguments.IsEnabled)
            {
                currentArg = null;
                return;
            }

            currentArg = (TransformComponentArgument)lbArguments.SelectedItem;

            txtDescription.Text = currentArg.Description;
            chkIsForConceptualBuild.IsChecked = currentArg.IsForConceptualBuild;
            chkIsForReferenceBuild.IsChecked  = currentArg.IsForReferenceBuild;

            changingArg = true;

            if (currentArg.Value != null || currentArg.Content == null)
            {
                txtValue.AcceptsReturn               = false;
                txtValue.VerticalAlignment           = VerticalAlignment.Top;
                txtValue.VerticalScrollBarVisibility = txtValue.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
                txtValue.Text = currentArg.Value;
            }
            else
            {
                txtValue.AcceptsReturn               = true;
                txtValue.VerticalAlignment           = VerticalAlignment.Stretch;
                txtValue.VerticalScrollBarVisibility = txtValue.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;

                var reader = currentArg.Content.CreateReader();
                reader.MoveToContent();
                txtValue.Text = reader.ReadInnerXml();
            }

            changingArg = false;
        }
コード例 #2
0
        /// <inheritdoc />
        protected override bool BindControlValue(Control control)
        {
            PresentationStyleSettings  pss = null;
            ProjectProperty            argsProp, styleProp;
            TransformComponentArgument tca, clone;
            TreeNode t;

#if !STANDALONEGUI
            SandcastleProject currentProject = null;

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

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

            if (base.ProjectMgr == null || currentProject == null)
            {
                tvArguments.Nodes.Clear();
                return(false);
            }

            argsProp  = this.ProjectMgr.BuildProject.GetProperty("TransformComponentArguments");
            styleProp = this.ProjectMgr.BuildProject.GetProperty("PresentationStyle");
#else
            if (presentationStyles == null || base.CurrentProject == null || base.CurrentProject.Filename != lastProjectName)
            {
                this.LoadAvailablePresentationStyles();
            }

            if (this.CurrentProject == null)
            {
                tvArguments.Nodes.Clear();
                return(false);
            }

            argsProp  = this.CurrentProject.MSBuildProject.GetProperty("TransformComponentArguments");
            styleProp = this.CurrentProject.MSBuildProject.GetProperty("PresentationStyle");
#endif
            if ((styleProp == null && lastStyle != null) || (styleProp != null &&
                                                             !String.IsNullOrEmpty(styleProp.UnevaluatedValue) &&
                                                             styleProp.UnevaluatedValue.Equals(lastStyle, StringComparison.OrdinalIgnoreCase)))
            {
                return(true);
            }

            tvArguments.Nodes.Clear();

            var transformComponentArgs = new Dictionary <string, TransformComponentArgument>();

            try
            {
                // Get the transform component arguments defined in the project if any
                if (argsProp != null && !String.IsNullOrEmpty(argsProp.UnevaluatedValue))
                {
                    using (var xr = new XmlTextReader("<Args>" + argsProp.UnevaluatedValue + "</Args>",
                                                      XmlNodeType.Element, new XmlParserContext(null, null, null, XmlSpace.Preserve)))
                    {
                        xr.Namespaces = false;
                        xr.MoveToContent();

                        foreach (var arg in XElement.Load(xr, LoadOptions.PreserveWhitespace).Descendants("Argument"))
                        {
                            tca = new TransformComponentArgument(arg);
                            transformComponentArgs.Add(tca.Key, tca);
                        }
                    }
                }

                if (styleProp != null && !String.IsNullOrWhiteSpace(styleProp.UnevaluatedValue))
                {
                    var style = presentationStyles.FirstOrDefault(s => s.Metadata.Id.Equals(
                                                                      styleProp.UnevaluatedValue, StringComparison.OrdinalIgnoreCase));

                    if (style != null)
                    {
                        pss = style.Value;
                    }
                }

                if (pss == null)
                {
                    var style = presentationStyles.FirstOrDefault(s => s.Metadata.Id.Equals(
                                                                      Constants.DefaultPresentationStyle, StringComparison.OrdinalIgnoreCase));

                    if (style != null)
                    {
                        pss = style.Value;
                    }
                    else
                    {
                        pss = presentationStyles.First().Value;
                    }
                }

                lastStyle = (styleProp != null) ? styleProp.UnevaluatedValue : Constants.DefaultPresentationStyle;

                // Create an entry for each transform component argument in the presentation style
                foreach (var arg in pss.TransformComponentArguments)
                {
                    t     = tvArguments.Nodes.Add(arg.Key);
                    t.Tag = clone = arg.Clone();

                    // Use the value from the project or the cloned default if not present
                    if (transformComponentArgs.TryGetValue(arg.Key, out tca))
                    {
                        clone.Value   = tca.Value;
                        clone.Content = tca.Content;
                    }
                }
            }
            catch (Exception ex)
            {
#if !STANDALONEGUI
                MessageBox.Show("Unable to load transform component arguments.  Error " + ex.Message,
                                Resources.PackageTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
                MessageBox.Show("Unable to load transform component arguments.  Error " + ex.Message,
                                Sandcastle.Core.Constants.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }

            if (tvArguments.Nodes.Count != 0)
            {
                tvArguments.SelectedNode = tvArguments.Nodes[0];
                txtValue.Enabled         = true;
            }
            else
            {
                txtValue.Enabled = false;
            }

            return(true);
        }
コード例 #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)
        {
            PresentationStyleSettings  pss = null;
            ProjectProperty            argsProp, styleProp;
            TransformComponentArgument tca, clone;
            TreeNode t;

#if !STANDALONEGUI
            if (this.IsDisposed || this.ProjectMgr == null)
            {
                return;
            }

            argsProp  = this.ProjectMgr.BuildProject.GetProperty("TransformComponentArguments");
            styleProp = this.ProjectMgr.BuildProject.GetProperty("PresentationStyle");
#else
            if (this.IsDisposed || this.CurrentProject == null)
            {
                return;
            }

            argsProp  = this.CurrentProject.MSBuildProject.GetProperty("TransformComponentArguments");
            styleProp = this.CurrentProject.MSBuildProject.GetProperty("PresentationStyle");
#endif
            // Skip it if already loaded and nothing changed
            if ((styleProp == null && lastStyle != null) || (styleProp != null &&
                                                             !String.IsNullOrEmpty(styleProp.UnevaluatedValue) &&
                                                             styleProp.UnevaluatedValue.Equals(lastStyle, StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }

            tvArguments.Enabled = true;
            tvArguments.Nodes.Clear();

            var transformComponentArgs = new Dictionary <string, TransformComponentArgument>();

            try
            {
                Cursor.Current = Cursors.WaitCursor;
                tvArguments.BeginUpdate();

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

                presentationStyles = new List <Lazy <PresentationStyleSettings, IPresentationStyleMetadata> >();

                // There may be duplicate presentation style 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 style in componentCache.ComponentContainer.GetExports <PresentationStyleSettings,
                                                                                    IPresentationStyleMetadata>())
                {
                    if (!presentationStyleIds.Contains(style.Metadata.Id))
                    {
                        presentationStyles.Add(style);
                        presentationStyleIds.Add(style.Metadata.Id);
                    }
                }

                // Get the transform component arguments defined in the project if any
                if (argsProp != null && !String.IsNullOrEmpty(argsProp.UnevaluatedValue))
                {
                    using (var xr = new XmlTextReader("<Args>" + argsProp.UnevaluatedValue + "</Args>",
                                                      XmlNodeType.Element, new XmlParserContext(null, null, null, XmlSpace.Preserve)))
                    {
                        xr.Namespaces = false;
                        xr.MoveToContent();

                        foreach (var arg in XElement.Load(xr, LoadOptions.PreserveWhitespace).Descendants("Argument"))
                        {
                            tca = new TransformComponentArgument(arg);
                            transformComponentArgs.Add(tca.Key, tca);
                        }
                    }
                }

                if (styleProp != null && !String.IsNullOrWhiteSpace(styleProp.UnevaluatedValue))
                {
                    var style = presentationStyles.FirstOrDefault(s => s.Metadata.Id.Equals(
                                                                      styleProp.UnevaluatedValue, StringComparison.OrdinalIgnoreCase));

                    if (style != null)
                    {
                        pss = style.Value;
                    }
                }

                if (pss == null)
                {
                    var style = presentationStyles.FirstOrDefault(s => s.Metadata.Id.Equals(
                                                                      Constants.DefaultPresentationStyle, StringComparison.OrdinalIgnoreCase));

                    if (style != null)
                    {
                        pss = style.Value;
                    }
                    else
                    {
                        pss = presentationStyles.First().Value;
                    }
                }

                lastStyle = (styleProp != null) ? styleProp.UnevaluatedValue : Constants.DefaultPresentationStyle;

                // Create an entry for each transform component argument in the presentation style
                foreach (var arg in pss.TransformComponentArguments)
                {
                    t     = tvArguments.Nodes.Add(arg.Key);
                    t.Tag = clone = arg.Clone();

                    // Use the value from the project or the cloned default if not present
                    if (transformComponentArgs.TryGetValue(arg.Key, out tca))
                    {
                        clone.Value   = tca.Value;
                        clone.Content = tca.Content;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);

                MessageBox.Show("Unable to load transform component arguments.  Error " + ex.Message,
                                messageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                tvArguments.EndUpdate();
                Cursor.Current = Cursors.Default;
            }

            if (tvArguments.Nodes.Count != 0)
            {
                tvArguments.SelectedNode = tvArguments.Nodes[0];
                txtValue.Enabled         = true;
            }
            else
            {
                txtValue.Enabled = false;
            }

            loadingInfo = false;
        }
コード例 #4
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)
        {
            PresentationStyleSettingsNeededEventArgs projectSettings = new PresentationStyleSettingsNeededEventArgs();
            PresentationStyleSettings  pss = null;
            TransformComponentArgument tca, clone;

            if (refreshingArgs)
            {
                return;
            }

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

            // Skip it if there is no project or if already loaded and nothing changed
            if (!projectSettings.ProjectLoaded || (lastStyle != null &&
                                                   (projectSettings.PresentationStyle ?? String.Empty).Equals(lastStyle, StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }

            try
            {
                refreshingArgs = true;
                currentArg     = null;

                Mouse.OverrideCursor = Cursors.Wait;

                lbArguments.IsEnabled = true;
                lbArguments.Items.Clear();

                var presentationStyleIds   = new HashSet <string>();
                var presentationStyles     = new List <Lazy <PresentationStyleSettings, IPresentationStyleMetadata> >();
                var transformComponentArgs = new Dictionary <string, TransformComponentArgument>();

                // There may be duplicate presentation style 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 style in componentCache.ComponentContainer.GetExports <PresentationStyleSettings,
                                                                                    IPresentationStyleMetadata>())
                {
                    if (!presentationStyleIds.Contains(style.Metadata.Id))
                    {
                        presentationStyles.Add(style);
                        presentationStyleIds.Add(style.Metadata.Id);
                    }
                }

                // Get the transform component arguments defined in the project if any
                if (!String.IsNullOrEmpty(projectSettings.TransformComponentArguments))
                {
                    using (var xr = new XmlTextReader("<Args>" + projectSettings.TransformComponentArguments + "</Args>",
                                                      XmlNodeType.Element, new XmlParserContext(null, null, null, XmlSpace.Preserve)))
                    {
                        xr.Namespaces = false;
                        xr.MoveToContent();

                        foreach (var arg in XElement.Load(xr, LoadOptions.PreserveWhitespace).Descendants("Argument"))
                        {
                            tca = new TransformComponentArgument(arg);
                            transformComponentArgs.Add(tca.Key, tca);
                        }
                    }
                }

                if (!String.IsNullOrWhiteSpace(projectSettings.PresentationStyle))
                {
                    var style = presentationStyles.FirstOrDefault(s => s.Metadata.Id.Equals(
                                                                      projectSettings.PresentationStyle, StringComparison.OrdinalIgnoreCase));

                    if (style != null)
                    {
                        pss = style.Value;
                    }
                }

                if (pss == null)
                {
                    var style = presentationStyles.FirstOrDefault(s => s.Metadata.Id.Equals(
                                                                      Constants.DefaultPresentationStyle, StringComparison.OrdinalIgnoreCase));

                    if (style != null)
                    {
                        pss = style.Value;
                    }
                    else
                    {
                        pss = presentationStyles.First().Value;
                    }
                }

                lastStyle = projectSettings.PresentationStyle;

                // Create an entry for each transform component argument in the presentation style
                foreach (var arg in pss.TransformComponentArguments)
                {
                    clone = arg.Clone();

                    // Use the value from the project or the cloned default if not present
                    if (transformComponentArgs.TryGetValue(arg.Key, out tca))
                    {
                        clone.Value   = tca.Value;
                        clone.Content = tca.Content;
                    }

                    lbArguments.Items.Add(clone);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);

                MessageBox.Show("Unable to load transform component arguments.  Error " + ex.Message,
                                Constants.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.OverrideCursor = null;
                refreshingArgs       = false;
            }

            if (lbArguments.Items.Count != 0)
            {
                lbArguments.SelectedIndex = 0;
                txtValue.IsEnabled        = true;
            }
            else
            {
                txtValue.IsEnabled = false;
            }

            loadingInfo = false;
        }