Example #1
0
        /// <summary>
        /// Called when the parent settings have changed.
        /// </summary>
        public void RefreshMergedSettings()
        {
            // Set the contents of the parent settings file.
            SettingsMerger merger = new SettingsMerger(this.localSettings, this.core.Environment);

            this.parentSettings = merger.ParentMergedSettings;
            this.mergedSettings = merger.MergedSettings;

            // Set up the settings comparer.
            this.settingsComparer = new SettingsComparer(this.localSettings, this.parentSettings);

            for (int i = 0; i < this.pageInterfaces.Count; ++i)
            {
                if (this.pageInterfaces[i] != null)
                {
                    this.pageInterfaces[i].RefreshSettingsOverrideState();
                }
            }
        }
Example #2
0
        /// <summary>
        /// The control must be initialized by calling this method during the host's OnLoad event.
        /// </summary>
        /// <param name="hostInstance">Interface implemented by the host object.</param>
        /// <param name="propertyPages">The array of pages to display on the tab control.</param>
        /// <param name="settings">The settings to read from and write to.</param>
        /// <param name="coreInstance">The StyleCop core instance.</param>
        /// <param name="contextItem">The context for the property control.</param>
        internal void Initialize(
            IPropertyControlHost hostInstance,
            IList <IPropertyControlPage> propertyPages,
            WritableSettings settings,
            StyleCopCore coreInstance,
            params object[] contextItem)
        {
            Param.AssertNotNull(hostInstance, "hostInstance");
            Param.Assert(propertyPages != null && propertyPages.Count > 0, "propertyPages", "Cannot be null or empty");
            Param.AssertNotNull(settings, "settings");
            Param.AssertNotNull(coreInstance, "coreInstance");
            Param.Ignore(contextItem);

            // Make sure we haven't already been intialized.
            if (this.host != null)
            {
                throw new StyleCopException(Strings.PropertyControlAlreadyInitialized);
            }

            this.host           = hostInstance;
            this.pageInterfaces = propertyPages;
            this.localSettings  = settings;
            this.core           = coreInstance;
            this.context        = contextItem;

            // Set the contents of the parent settings file.
            SettingsMerger merger = new SettingsMerger(this.localSettings, this.core.Environment);

            this.parentSettings = merger.ParentMergedSettings;
            this.mergedSettings = merger.MergedSettings;

            // Set up the settings comparer.
            this.settingsComparer = new SettingsComparer(this.localSettings, this.parentSettings);

            // Make sure the context is non-null.
            if (this.context == null)
            {
                this.context = new object[] { };
            }

            this.tabPages = new TabPage[propertyPages.Count];
            this.pages    = new UserControl[propertyPages.Count];

            // Add each of the property pages.
            int pageCount = 0;

            // Initialize the settings pages.
            for (int i = 0; i < propertyPages.Count; ++i)
            {
                this.pages[pageCount] = (UserControl)this.pageInterfaces[i];
                TabPage tabPage = new TabPage(this.pageInterfaces[i].TabName);

                this.tabPages[pageCount] = tabPage;
                tabPage.Controls.Add(this.pages[i]);
                this.Controls.Add(tabPage);

                this.pages[i].Dock = DockStyle.Fill;
                this.SizePage(i);

                // The first page has already been initialized.
                this.pageInterfaces[i].Initialize(this);

                ++pageCount;
            }

            // Activate the first page.
            if (this.TabPages[0] != null)
            {
                this.SelectedTab = this.tabPages[0];
                this.pageInterfaces[0].Activate(true);
            }

            this.SizeChanged += new System.EventHandler(this.OnSizeChanged);
        }
Example #3
0
        /// <summary>
        /// Called when the parent settings have changed.
        /// </summary>
        public void RefreshMergedSettings()
        {
            // Set the contents of the parent settings file.
            SettingsMerger merger = new SettingsMerger(this.localSettings, this.core.Environment);
            this.parentSettings = merger.ParentMergedSettings;
            this.mergedSettings = merger.MergedSettings;

            // Set up the settings comparer.
            this.settingsComparer = new SettingsComparer(this.localSettings, this.parentSettings);

            for (int i = 0; i < this.pageInterfaces.Count; ++i)
            {
                if (this.pageInterfaces[i] != null)
                {
                    this.pageInterfaces[i].RefreshSettingsOverrideState();
                }
            }
        }
Example #4
0
        /// <summary>
        /// The control must be initialized by calling this method during the host's OnLoad event.
        /// </summary>
        /// <param name="hostInstance">
        /// Interface implemented by the host object.
        /// </param>
        /// <param name="propertyPages">
        /// The array of pages to display on the tab control.
        /// </param>
        /// <param name="settings">
        /// The settings to read from and write to.
        /// </param>
        /// <param name="coreInstance">
        /// The StyleCop core instance.
        /// </param>
        /// <param name="contextItem">
        /// The context for the property control.
        /// </param>
        internal void Initialize(
            IPropertyControlHost hostInstance, 
            IList<IPropertyControlPage> propertyPages, 
            WritableSettings settings, 
            StyleCopCore coreInstance, 
            params object[] contextItem)
        {
            Param.AssertNotNull(hostInstance, "hostInstance");
            Param.Assert(propertyPages != null && propertyPages.Count > 0, "propertyPages", "Cannot be null or empty");
            Param.AssertNotNull(settings, "settings");
            Param.AssertNotNull(coreInstance, "coreInstance");
            Param.Ignore(contextItem);

            // Make sure we haven't already been intialized.
            if (this.host != null)
            {
                throw new StyleCopException(Strings.PropertyControlAlreadyInitialized);
            }

            this.host = hostInstance;
            this.pageInterfaces = propertyPages;
            this.localSettings = settings;
            this.core = coreInstance;
            this.context = contextItem;

            // Set the contents of the parent settings file.
            SettingsMerger merger = new SettingsMerger(this.localSettings, this.core.Environment);
            this.parentSettings = merger.ParentMergedSettings;
            this.mergedSettings = merger.MergedSettings;

            // Set up the settings comparer.
            this.settingsComparer = new SettingsComparer(this.localSettings, this.parentSettings);

            // Make sure the context is non-null.
            if (this.context == null)
            {
                this.context = new object[] { };
            }

            this.tabPages = new TabPage[propertyPages.Count];
            this.pages = new UserControl[propertyPages.Count];

            // Add each of the property pages.
            int pageCount = 0;

            // Initialize the settings pages.
            for (int i = 0; i < propertyPages.Count; ++i)
            {
                this.pages[pageCount] = (UserControl)this.pageInterfaces[i];
                TabPage tabPage = new TabPage(this.pageInterfaces[i].TabName);

                this.tabPages[pageCount] = tabPage;
                tabPage.Controls.Add(this.pages[i]);
                this.Controls.Add(tabPage);

                this.pages[i].Dock = DockStyle.Fill;
                this.SizePage(i);

                // The first page has already been initialized.
                this.pageInterfaces[i].Initialize(this);

                ++pageCount;
            }

            // Activate the first page.
            if (this.TabPages[0] != null)
            {
                this.SelectedTab = this.tabPages[0];
                this.pageInterfaces[0].Activate(true);
            }

            this.SizeChanged += this.OnSizeChanged;
        }
Example #5
0
        /// <summary>
        /// Saves the given property collection.
        /// </summary>
        /// <param name="rootNode">The node to store the property collection beneath.</param>
        /// <param name="nodeName">The name of the new property collection node.</param>
        /// <param name="properties">The property collection to store.</param>
        /// <param name="parentProperties">The corresponding property collection from the parent settings, if any.</param>
        /// <param name="aggregate">Indicates whether the collection is aggregated with the parent collection.</param>
        /// <param name="nodeNameAttribute">An optional name attribute value for the new property node.</param>
        /// <returns>Returns true if at least one property was saved.</returns>
        private static bool SavePropertyCollection(
            XmlNode rootNode,
            string nodeName,
            PropertyCollection properties,
            PropertyCollection parentProperties,
            bool aggregate,
            string nodeNameAttribute)
        {
            Param.AssertNotNull(rootNode, "rootNode");
            Param.AssertValidString(nodeName, "nodeName");
            Param.AssertNotNull(properties, "properties");
            Param.Ignore(parentProperties);
            Param.Ignore(aggregate);
            Param.Ignore(nodeNameAttribute);

            // If there are no properties in the collection, don't save anything.
            if (properties.Count == 0)
            {
                return(false);
            }

            bool propertyWritten = false;

            // Create the root node for this property collection.
            Debug.Assert(rootNode.OwnerDocument != null, "The root node has not been attached to a document.");
            XmlElement rootCollectionNode = rootNode.OwnerDocument.CreateElement(nodeName);

            if (!string.IsNullOrEmpty(nodeNameAttribute))
            {
                XmlAttribute rootCollectionNodeNameAttribute = rootNode.OwnerDocument.CreateAttribute("Name");
                rootCollectionNodeNameAttribute.Value = nodeNameAttribute;
                rootCollectionNode.Attributes.Append(rootCollectionNodeNameAttribute);
            }

            // Add each property in the collection.
            foreach (PropertyValue property in properties)
            {
                bool          skip           = false;
                PropertyValue parentProperty = null;

                if (parentProperties != null)
                {
                    parentProperty = parentProperties[property.PropertyName];

                    // If the property also exists in the parent collection, determine whether the local property
                    // is an override. If not, there is no need to add it.
                    if (aggregate && parentProperty != null)
                    {
                        if (!SettingsComparer.IsSettingOverwritten(property, parentProperty))
                        {
                            skip = true;
                        }
                    }
                    else if (property.IsDefault)
                    {
                        skip = true;
                    }
                }
                else if (property.IsDefault)
                {
                    skip = true;
                }

                if (!skip)
                {
                    // If the property is a rule setting, then add it under the rules section.
                    int index = property.PropertyName.IndexOf('#');
                    if (index > 0)
                    {
                        propertyWritten |= SaveRuleProperty(
                            rootNode,
                            property,
                            property.PropertyName.Substring(0, index),
                            property.PropertyName.Substring(index + 1, property.PropertyName.Length - index - 1));
                    }
                    else
                    {
                        // Just save the property value under this add-in's settings since it is
                        // not a rule property.
                        propertyWritten |= SavePropertyValue(rootCollectionNode, property, property.PropertyName);
                    }
                }
            }

            // If at least one property was saved, add the property collection node into the document.
            if (propertyWritten)
            {
                rootNode.AppendChild(rootCollectionNode);
            }

            return(propertyWritten);
        }