Example #1
0
        /// <summary>
        /// Saves the given collection property into the given node.
        /// </summary>
        /// <param name="rootNode">The node under which to store the new property node.</param>
        /// <param name="property">The property to save.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <returns>Returns true if the property was written.</returns>
        private static bool SaveCollectionProperty(XmlNode rootNode, CollectionProperty property, string propertyName)
        {
            Param.AssertNotNull(rootNode, "rootNode");
            Param.AssertNotNull(property, "property");
            Param.AssertValidString(propertyName, "propertyName");

            if (property.Values.Count > 0)
            {
                // Create and append the root node for this property.
                XmlNode propertyNode = rootNode.OwnerDocument.CreateElement("CollectionProperty");
                rootNode.AppendChild(propertyNode);

                XmlAttribute propertyNameAttribute = rootNode.OwnerDocument.CreateAttribute("Name");
                propertyNameAttribute.Value = propertyName;
                propertyNode.Attributes.Append(propertyNameAttribute);

                // Add sub-nodes for each property value.
                foreach (string value in property.Values)
                {
                    XmlNode valueNode = rootNode.OwnerDocument.CreateElement("Value");
                    valueNode.InnerText = value;
                    propertyNode.AppendChild(valueNode);
                }

                return(true);
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Merges two collection properties together.
        /// </summary>
        /// <param name="mergedPropertyCollection">
        /// The merged property collection.
        /// </param>
        /// <param name="originalProperty">
        /// The original property to merge.
        /// </param>
        /// <param name="overridingProperty">
        /// The overriding property to merge.
        /// </param>
        private static void MergeCollectionProperties(PropertyCollection mergedPropertyCollection, PropertyValue originalProperty, PropertyValue overridingProperty)
        {
            Param.AssertNotNull(mergedPropertyCollection, "mergedPropertyCollection");
            Param.AssertNotNull(originalProperty, "originalProperty");
            Param.AssertNotNull(overridingProperty, "overridingProperty");

            CollectionProperty originalCollectionProperty   = (CollectionProperty)originalProperty;
            CollectionProperty overridingCollectionProperty = (CollectionProperty)overridingProperty;

            // Create a new merged collection property.
            CollectionProperty mergedCollectionProperty = new CollectionProperty((CollectionPropertyDescriptor)originalCollectionProperty.PropertyDescriptor);

            mergedPropertyCollection.Add(mergedCollectionProperty);

            // Add each of the strings from the overriding collection.
            foreach (string value in overridingCollectionProperty.Values)
            {
                mergedCollectionProperty.Add(value);
            }

            // If necessary, also add the strings from the original collection.
            if (originalCollectionProperty.Aggregate)
            {
                foreach (string value in originalCollectionProperty.Values)
                {
                    if (!mergedCollectionProperty.Contains(value))
                    {
                        mergedCollectionProperty.Add(value);
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Determines whether this property overrides the given property.
        /// </summary>
        /// <param name="parentProperty">The parent property to compare with.</param>
        /// <returns>Returns true if this property overrides the given property.</returns>
        public override bool OverridesProperty(PropertyValue parentProperty)
        {
            Param.RequireNotNull(parentProperty, "parentProperty");

            CollectionProperty parentCollectionProperty = parentProperty as CollectionProperty;

            if (parentCollectionProperty == null || this.Aggregate != parentCollectionProperty.Aggregate)
            {
                throw new ArgumentException(Strings.ComparingDifferentPropertyTypes, "parentProperty");
            }

            return(OverridesPropertyCollection(this.collection, parentCollectionProperty.Values, this.Aggregate));
        }
Example #4
0
        /// <summary>
        /// Loads and stores a collection property.
        /// </summary>
        /// <param name="propertyName">The name of the property to load.</param>
        /// <param name="propertyNode">The node containing the property.</param>
        /// <param name="properties">The collection in which to store the property.</param>
        /// <param name="propertyDescriptors">The collection of property descriptors.</param>
        private static void LoadCollectionProperty(
            string propertyName,
            XmlNode propertyNode,
            PropertyCollection properties,
            PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.AssertNotNull(propertyNode, "propertyNode");
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Create and load the inner property collection.
            List <string> innerCollection = new List <string>();

            // Load the value list.
            XmlNodeList valueNodes = propertyNode.SelectNodes("Value");

            if (valueNodes != null && valueNodes.Count > 0)
            {
                foreach (XmlNode valueNode in valueNodes)
                {
                    if (!string.IsNullOrEmpty(valueNode.InnerText))
                    {
                        innerCollection.Add(valueNode.InnerText);
                    }
                }
            }

            // If at least one value was loaded, save the proeprty.
            if (innerCollection.Count > 0)
            {
                // Get the property descriptor.
                CollectionPropertyDescriptor descriptor = propertyDescriptors[propertyName] as CollectionPropertyDescriptor;

                if (descriptor != null)
                {
                    // Create the collection node and pass in the inner collection.
                    CollectionProperty collectionProperty = new CollectionProperty(descriptor, innerCollection);

                    // Add this property to the parent collection.
                    properties.Add(collectionProperty);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Adds values from the parent settings.
        /// </summary>
        private void AddParentSettingsValues()
        {
            if (this.tabControl.ParentSettings != null)
            {
                PropertyCollection globalPropertyCollection = this.tabControl.ParentSettings.GlobalSettings;

                CollectionProperty parentProperty = globalPropertyCollection.GetProperty(RecognizedWordsPropertyName) as CollectionProperty;

                if (parentProperty != null)
                {
                    if (parentProperty.Values.Count > 0)
                    {
                        foreach (string value in parentProperty)
                        {
                            if (!string.IsNullOrEmpty(value))
                            {
                                ListViewItem item = this.recognizedWordsListView.Items.Add(value);
                                item.Tag = false;
                            }
                        }
                    }
                }

                parentProperty = globalPropertyCollection.GetProperty(DeprecatedWordsPropertyName) as CollectionProperty;

                if (parentProperty != null)
                {
                    if (parentProperty.Values.Count > 0)
                    {
                        foreach (string value in parentProperty)
                        {
                            if (!string.IsNullOrEmpty(value))
                            {
                                string[] splitValue = value.Split(',');
                                if (splitValue.Length == 2)
                                {
                                    ListViewItem item = this.deprecatedWordsListView.Items.Add(splitValue[0].Trim() + ", " + splitValue[1].Trim());
                                    item.Tag = false;
                                }
                            }
                        }
                    }
                }

                parentProperty = globalPropertyCollection.GetProperty(DictionaryFoldersPropertyName) as CollectionProperty;

                if (parentProperty != null)
                {
                    if (parentProperty.Values.Count > 0)
                    {
                        foreach (string value in parentProperty)
                        {
                            if (!string.IsNullOrEmpty(value))
                            {
                                ListViewItem item = this.foldersListView.Items.Add(value);
                                item.Tag = false;
                            }
                        }
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// Initializes the page.
        /// </summary>
        /// <param name="propertyControl">
        /// The tab control object.
        /// </param>
        public void Initialize(PropertyControl propertyControl)
        {
            Param.AssertNotNull(propertyControl, "propertyControl");

            this.tabControl = propertyControl;

            // Get the list of allowed words from the parent settings.
            this.AddParentSettingsValues();

            // Get the list of allowed words from the local settings.
            CollectionProperty recognizedWordsProperty = this.tabControl.LocalSettings.GlobalSettings.GetProperty(RecognizedWordsPropertyName) as CollectionProperty;

            if (recognizedWordsProperty != null && recognizedWordsProperty.Values.Count > 0)
            {
                foreach (string value in recognizedWordsProperty)
                {
                    if (!string.IsNullOrEmpty(value))
                    {
                        ListViewItem item = this.recognizedWordsListView.Items.Add(value);
                        item.Tag = true;
                        this.SetBoldState(item, this.recognizedWordsListView);
                    }
                }
            }

            // Select the first item in the list.
            if (this.recognizedWordsListView.Items.Count > 0)
            {
                this.recognizedWordsListView.Items[0].Selected = true;
            }

            // Get the list of deprecated words from the local settings.
            CollectionProperty deprecatedWordsProperty = this.tabControl.LocalSettings.GlobalSettings.GetProperty(DeprecatedWordsPropertyName) as CollectionProperty;

            if (deprecatedWordsProperty != null && deprecatedWordsProperty.Values.Count > 0)
            {
                foreach (string value in deprecatedWordsProperty)
                {
                    if (!string.IsNullOrEmpty(value))
                    {
                        string[] valueParts = value.Split(',');
                        if (valueParts.Length == 2)
                        {
                            ListViewItem item = this.deprecatedWordsListView.Items.Add(valueParts[0].Trim() + ", " + valueParts[1].Trim());
                            item.Tag = true;
                            this.SetBoldState(item, this.deprecatedWordsListView);
                        }
                    }
                }
            }

            // Select the first item in the list.
            if (this.deprecatedWordsListView.Items.Count > 0)
            {
                this.deprecatedWordsListView.Items[0].Selected = true;
            }

            // Get the list of folders from the local settings.
            CollectionProperty dictionaryFoldersProperty = this.tabControl.LocalSettings.GlobalSettings.GetProperty(DictionaryFoldersPropertyName) as CollectionProperty;

            if (dictionaryFoldersProperty != null && dictionaryFoldersProperty.Values.Count > 0)
            {
                foreach (string value in dictionaryFoldersProperty)
                {
                    if (!string.IsNullOrEmpty(value))
                    {
                        ListViewItem item = this.foldersListView.Items.Add(value);
                        item.Tag = true;
                        this.SetBoldState(item, this.foldersListView);
                    }
                }
            }

            // Select the first item in the list.
            if (this.foldersListView.Items.Count > 0)
            {
                this.foldersListView.Items[0].Selected = true;
            }

            this.EnableDisableRemoveButtons();

            this.dirty = false;
            this.tabControl.DirtyChanged();
        }