PageRenderTime 31ms CodeModel.GetById 23ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/Source/HtmlToMaml/MSHelpKeywordCollection.cs

#
C# | 98 lines | 46 code | 9 blank | 43 comment | 1 complexity | 51f4a4f094ef95133fa779b65d5fb496 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
 1//=============================================================================
 2// System  : Sandcastle Help File Builder Utilities
 3// File    : MSHelpKeywordCollection.cs
 4// Author  : Eric Woodruff  (Eric@EWoodruff.us)
 5// Updated : 09/16/2008
 6// Note    : Copyright 2008, Eric Woodruff, All rights reserved
 7// Compiler: Microsoft Visual C#
 8//
 9// This file contains a collection class used to hold the help index keyword
10// information.
11//
12// This code is published under the Microsoft Public License (Ms-PL).  A copy
13// of the license should be distributed with the code.  It can also be found
14// at the project website: http://www.CodePlex.com/SandcastleStyles.   This
15// notice, the author's name, and all copyright notices must remain intact in
16// all applications, documentation, and source files.
17//
18// Version     Date     Who  Comments
19// ============================================================================
20// 1.6.0.7  03/25/2008  EFW  Created the code
21//=============================================================================
22
23using System;
24using System.Collections.Generic;
25using System.ComponentModel;
26using System.IO;
27using System.Text;
28using System.Xml;
29
30namespace SandcastleBuilder.Utils
31{
32    /// <summary>
33    /// This collection class is used to hold the help index keyword items for
34    /// a project.
35    /// </summary>
36    public class MSHelpKeywordCollection : BindingList<MSHelpKeyword>
37    {
38        #region Sort collection
39        //=====================================================================
40        // Sort the collection
41
42        /// <summary>
43        /// This is used to sort the collection
44        /// </summary>
45        /// <remarks>Values are sorted by index name and term</remarks>
46        public void Sort()
47        {
48            ((List<MSHelpKeyword>)base.Items).Sort(
49                delegate(MSHelpKeyword x, MSHelpKeyword y)
50                {
51                    return Comparer<MSHelpKeyword>.Default.Compare(x, y);
52                });
53        }
54        #endregion
55
56        #region Read/write as XML
57        //=====================================================================
58
59        /// <summary>
60        /// This is used to save the keyword collection to the project
61        /// file.
62        /// </summary>
63        /// <param name="xw">The XML text writer to which the information
64        /// is written.</param>
65        public void WriteXml(XmlWriter xw)
66        {
67            if(base.Count > 0)
68            {
69                xw.WriteStartElement("HelpKeywords");
70
71                foreach(MSHelpKeyword kw in this)
72                {
73                    xw.WriteStartElement("HelpKeyword");
74                    xw.WriteAttributeString("index", kw.Index);
75                    xw.WriteAttributeString("term", kw.Term);
76                    xw.WriteEndElement();
77                }
78
79                xw.WriteEndElement();
80            }
81        }
82        #endregion
83
84        #region Helper methods
85        //=====================================================================
86
87        /// <summary>
88        /// This is used to mark the collection as changed when there is no
89        /// associated project.
90        /// </summary>
91        public void MarkAsDirty()
92        {
93            this.OnListChanged(new ListChangedEventArgs(
94                ListChangedType.ItemChanged, -1));
95        }
96        #endregion
97    }
98}