예제 #1
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);
        }
        /// <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;
        }
예제 #3
0
        //=====================================================================

        /// <summary>
        /// Load a resource items file for editing
        /// </summary>
        /// <param name="resourceItemsFile">The resource items file to load</param>
        /// <param name="project">The current Sandcastle Builder project</param>
        public void LoadResourceItemsFile(string resourceItemsFile, SandcastleProject project)
        {
            PresentationStyleSettings pss = null;
            string        presentationStylePath, shfbStyleContent;
            List <string> syntaxGeneratorFiles = new List <string>();

            if (resourceItemsFile == null)
            {
                throw new ArgumentNullException(nameof(resourceItemsFile));
            }

            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            try
            {
                Mouse.OverrideCursor = Cursors.Wait;

                resourceItemFilename = resourceItemsFile;

                using (var container = ComponentUtilities.CreateComponentContainer(project.ComponentSearchPaths,
                                                                                   CancellationToken.None))
                {
                    var presentationStyles = container.GetExports <PresentationStyleSettings, IPresentationStyleMetadata>();
                    var style = presentationStyles.FirstOrDefault(s => s.Metadata.Id.Equals(
                                                                      project.PresentationStyle, StringComparison.OrdinalIgnoreCase));

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

                    if (style != null)
                    {
                        pss = style.Value;
                    }
                    else
                    {
                        MessageBox.Show("Unable to locate the presentation style ID " + project.PresentationStyle,
                                        Constants.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    syntaxGeneratorFiles.AddRange(ComponentUtilities.SyntaxGeneratorResourceItemFiles(container, null));
                }

                // Get the presentation style folders
                presentationStylePath = pss.ResolvePath(pss.ResourceItemsPath);
                shfbStyleContent      = pss.ResolvePath(pss.ToolResourceItemsPath);

                // Use the language-specific files if they are present
                if (Directory.Exists(Path.Combine(presentationStylePath, project.Language.Name)))
                {
                    presentationStylePath = Path.Combine(presentationStylePath, project.Language.Name);
                }

                if (File.Exists(Path.Combine(shfbStyleContent, project.Language.Name + ".xml")))
                {
                    shfbStyleContent = Path.Combine(shfbStyleContent, project.Language.Name + ".xml");
                }
                else
                {
                    shfbStyleContent = Path.Combine(shfbStyleContent, "en-US.xml");
                }

                // Load the presentation style content files first followed by the syntax generator files, the
                // help file builder content items, and then the user's resource item file.
                foreach (string file in Directory.EnumerateFiles(presentationStylePath, "*.xml"))
                {
                    this.LoadItemFile(file, false);
                }

                foreach (string file in syntaxGeneratorFiles)
                {
                    this.LoadItemFile(file, false);
                }

                if (File.Exists(shfbStyleContent))
                {
                    this.LoadItemFile(shfbStyleContent, false);
                }

                this.LoadItemFile(resourceItemFilename, true);

                // Load everything into the list box
                resourceItems              = new BindingList <ResourceItem>(allItems.Values.ToArray());
                resourceItems.ListChanged += resourceItems_ListChanged;

                if (resourceItems.Count != 0)
                {
                    resourceItems[0].IsSelected = true;
                }

                lbResourceItems.ItemsSource = resourceItems;

                this.resourceItems_ListChanged(this, new ListChangedEventArgs(ListChangedType.Reset, -1));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);

                MessageBox.Show("Unable to load resource item files: " + ex.Message, Constants.AppName,
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
예제 #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;
        }