Exemplo n.º 1
0
        //=====================================================================

        /// <summary>
        /// This is used to get the current plug-in settings from the project when needed
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void ucPlugInPropertiesPageContent_ComponentSettingsNeeded(object sender,
                                                                           ComponentSettingsNeededEventArgs e)
        {
            ProjectProperty plugInsProp;

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

            plugInsProp = this.ProjectMgr.BuildProject.GetProperty("PlugInConfigurations");
#else
            if (this.IsDisposed || this.CurrentProject == null)
            {
                return;
            }

            plugInsProp = this.CurrentProject.MSBuildProject.GetProperty("PlugInConfigurations");
#endif
            var currentConfigs = new PlugInConfigurationDictionary();

            if (plugInsProp != null && !String.IsNullOrEmpty(plugInsProp.UnevaluatedValue))
            {
                currentConfigs.FromXml(plugInsProp.UnevaluatedValue);
            }

            e.ProjectLoaded = true;
            e.PlugIns       = currentConfigs;
        }
        //=====================================================================

        /// <inheritdoc />
        protected override bool BindControlValue(Control control)
        {
            ProjectProperty projProp;
            int idx;

            lbProjectPlugIns.Items.Clear();
            btnConfigure.Enabled = btnDelete.Enabled = false;

#if !STANDALONEGUI
            SandcastleProject currentProject = null;

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

            if(componentContainer == null || currentProject == null || currentProject.Filename != lastProjectName)
                this.LoadAvailablePlugInMetadata();

            if(this.ProjectMgr == null || currentProject == null)
                return false;

            projProp = this.ProjectMgr.BuildProject.GetProperty("PlugInConfigurations");
#else
            if(componentContainer == null || base.CurrentProject == null ||
              base.CurrentProject.Filename != lastProjectName)
                this.LoadAvailablePlugInMetadata();

            if(base.CurrentProject == null)
                return false;

            projProp = base.CurrentProject.MSBuildProject.GetProperty("PlugInConfigurations");
#endif
            currentConfigs = new PlugInConfigurationDictionary();

            if(projProp != null && !String.IsNullOrEmpty(projProp.UnevaluatedValue))
                currentConfigs.FromXml(projProp.UnevaluatedValue);

            foreach(string key in currentConfigs.Keys)
            {
                idx = lbProjectPlugIns.Items.Add(key);
                lbProjectPlugIns.SetItemChecked(idx, currentConfigs[key].Enabled);
            }

            if(lbProjectPlugIns.Items.Count != 0)
            {
                lbProjectPlugIns.SelectedIndex = 0;
                btnConfigure.Enabled = btnDelete.Enabled = true;
            }

            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)
        {
            ProjectProperty projProp;
            int idx;

            if(this.IsDisposed)
                return;

            lbAvailablePlugIns.Items.Clear();

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

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                lbProjectPlugIns.Items.Clear();

                availablePlugIns = componentCache.ComponentContainer.GetExports<IPlugIn, IPlugInMetadata>().ToList();

                // There may be duplicate component IDs across the assemblies found.  See
                // BuildComponentManger.GetComponentContainer() for the folder search precedence.  Only the first
                // component for a unique ID will be used.  We also ignore hidden plug-ins.
                foreach(var plugIn in availablePlugIns)
                    if(!plugIn.Metadata.IsHidden && !plugInIds.Contains(plugIn.Metadata.Id))
                    {
                        lbAvailablePlugIns.Items.Add(plugIn.Metadata.Id);
                        plugInIds.Add(plugIn.Metadata.Id);
                    }
            }
            catch(Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());

                MessageBox.Show("Unexpected error loading build components: " + ex.Message, messageBoxTitle,
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

            if(lbAvailablePlugIns.Items.Count != 0)
            {
                lbAvailablePlugIns.SelectedIndex = 0;
                gbAvailablePlugIns.Enabled = gbProjectAddIns.Enabled = true;
            }
            else
            {
                MessageBox.Show("No valid build components found", messageBoxTitle, MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                gbAvailablePlugIns.Enabled = gbProjectAddIns.Enabled = false;
                return;
            }

#if !STANDALONEGUI
            if(this.ProjectMgr == null)
                return;

            projProp = this.ProjectMgr.BuildProject.GetProperty("PlugInConfigurations");
#else
            if(this.CurrentProject == null)
                return;

            projProp = this.CurrentProject.MSBuildProject.GetProperty("PlugInConfigurations");
#endif
            currentConfigs = new PlugInConfigurationDictionary();

            if(projProp != null && !String.IsNullOrEmpty(projProp.UnevaluatedValue))
                currentConfigs.FromXml(projProp.UnevaluatedValue);

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

            try
            {
                this.IsBinding = true;

                foreach(string key in currentConfigs.Keys)
                {
                    idx = lbProjectPlugIns.Items.Add(key);
                    lbProjectPlugIns.SetItemChecked(idx, currentConfigs[key].Enabled);
                }

                if(lbProjectPlugIns.Items.Count != 0)
                {
                    lbProjectPlugIns.SelectedIndex = 0;
                    btnConfigure.Enabled = btnDelete.Enabled = true;
                }
                else
                    btnConfigure.Enabled = btnDelete.Enabled = false;
            }
            finally
            {
                this.IsBinding = isBinding;
            }
        }
Exemplo n.º 4
0
        //=====================================================================

        /// <inheritdoc />
        protected override bool BindControlValue(Control control)
        {
            ProjectProperty projProp;
            int             idx;

            lbProjectPlugIns.Items.Clear();
            btnConfigure.Enabled = btnDelete.Enabled = false;

#if !STANDALONEGUI
            SandcastleProject currentProject = null;

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

            if (componentContainer == null || currentProject == null || currentProject.Filename != lastProjectName)
            {
                this.LoadAvailablePlugInMetadata();
            }

            if (this.ProjectMgr == null || currentProject == null)
            {
                return(false);
            }

            currentConfigs = new PlugInConfigurationDictionary(currentProject);
            projProp       = this.ProjectMgr.BuildProject.GetProperty("PlugInConfigurations");
#else
            if (componentContainer == null || base.CurrentProject == null ||
                base.CurrentProject.Filename != lastProjectName)
            {
                this.LoadAvailablePlugInMetadata();
            }

            if (base.CurrentProject == null)
            {
                return(false);
            }

            currentConfigs = new PlugInConfigurationDictionary(base.CurrentProject);
            projProp       = base.CurrentProject.MSBuildProject.GetProperty("PlugInConfigurations");
#endif
            if (projProp != null && !String.IsNullOrEmpty(projProp.UnevaluatedValue))
            {
                currentConfigs.FromXml(projProp.UnevaluatedValue);
            }

            foreach (string key in currentConfigs.Keys)
            {
                idx = lbProjectPlugIns.Items.Add(key);
                lbProjectPlugIns.SetItemChecked(idx, currentConfigs[key].Enabled);
            }

            if (lbProjectPlugIns.Items.Count != 0)
            {
                lbProjectPlugIns.SelectedIndex = 0;
                btnConfigure.Enabled           = btnDelete.Enabled = true;
            }

            return(true);
        }
Exemplo n.º 5
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)
        {
            ProjectProperty projProp;
            int             idx;

            if (this.IsDisposed)
            {
                return;
            }

            lbAvailablePlugIns.Items.Clear();

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

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                lbProjectPlugIns.Items.Clear();

                availablePlugIns = componentCache.ComponentContainer.GetExports <IPlugIn, IPlugInMetadata>().ToList();

                // There may be duplicate component IDs across the assemblies found.  See
                // BuildComponentManger.GetComponentContainer() for the folder search precedence.  Only the first
                // component for a unique ID will be used.  We also ignore hidden plug-ins.
                foreach (var plugIn in availablePlugIns)
                {
                    if (!plugIn.Metadata.IsHidden && !plugInIds.Contains(plugIn.Metadata.Id))
                    {
                        lbAvailablePlugIns.Items.Add(plugIn.Metadata.Id);
                        plugInIds.Add(plugIn.Metadata.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());

                MessageBox.Show("Unexpected error loading build components: " + ex.Message, messageBoxTitle,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

            if (lbAvailablePlugIns.Items.Count != 0)
            {
                lbAvailablePlugIns.SelectedIndex = 0;
                gbAvailablePlugIns.Enabled       = gbProjectAddIns.Enabled = true;
            }
            else
            {
                MessageBox.Show("No valid build components found", messageBoxTitle, MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                gbAvailablePlugIns.Enabled = gbProjectAddIns.Enabled = false;
                return;
            }

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

            projProp = this.ProjectMgr.BuildProject.GetProperty("PlugInConfigurations");
#else
            if (this.CurrentProject == null)
            {
                return;
            }

            projProp = this.CurrentProject.MSBuildProject.GetProperty("PlugInConfigurations");
#endif
            currentConfigs = new PlugInConfigurationDictionary();

            if (projProp != null && !String.IsNullOrEmpty(projProp.UnevaluatedValue))
            {
                currentConfigs.FromXml(projProp.UnevaluatedValue);
            }

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

            try
            {
                this.IsBinding = true;

                foreach (string key in currentConfigs.Keys)
                {
                    idx = lbProjectPlugIns.Items.Add(key);
                    lbProjectPlugIns.SetItemChecked(idx, currentConfigs[key].Enabled);
                }

                if (lbProjectPlugIns.Items.Count != 0)
                {
                    lbProjectPlugIns.SelectedIndex = 0;
                    btnConfigure.Enabled           = btnDelete.Enabled = true;
                }
                else
                {
                    btnConfigure.Enabled = btnDelete.Enabled = false;
                }
            }
            finally
            {
                this.IsBinding = isBinding;
            }
        }