Exemplo n.º 1
0
        /// <summary>
        /// Parses nodes from the text
        /// </summary>
        /// <param name="itemstext">text containing the items</param>
        /// <param name="parentItem">parent index item</param>
        /// <param name="arrNodes">arraylist where the nodes should be added</param>
        /// <param name="chmFile">CHMFile instance</param>
        private static void ParseItems(string itemstext, HtmlHelpIndexItem parentItem,
                                       List <HtmlHelpIndexItem> arrNodes, CHMFile chmFile)
        {
            int innerTextIdx  = ObjectRE.GroupNumberFromName("innerText");
            int innerPTextIdx = ParamRE.GroupNumberFromName("innerText");

            // get group-name indexes
            int nameIndex  = AttributesRE.GroupNumberFromName("attributeName");
            int valueIndex = AttributesRE.GroupNumberFromName("attributeValue");
            int tdIndex    = AttributesRE.GroupNumberFromName("attributeTD");

            int    nObjStartIndex     = 0;
            int    nLastObjStartIndex = 0;
            string sKeyword           = "";

            while (ObjectRE.IsMatch(itemstext, nObjStartIndex))
            {
                Match m = ObjectRE.Match(itemstext, nObjStartIndex);

                string innerText = m.Groups[innerTextIdx].Value;

                HtmlHelpIndexItem idxItem = new HtmlHelpIndexItem();

                // read parameters
                int nParamIndex = 0;
                int nNameCnt    = 0;

                string paramTitle = "";
                string paramLocal = "";
                bool   bAdded     = false;

                while (ParamRE.IsMatch(innerText, nParamIndex))
                {
                    Match mP = ParamRE.Match(innerText, nParamIndex);

                    string innerP = mP.Groups[innerPTextIdx].Value;

                    string paramName  = "";
                    string paramValue = "";

                    int nAttrIdx = 0;
                    //sKeyword = "";

                    while (AttributesRE.IsMatch(innerP, nAttrIdx))
                    {
                        Match mA = AttributesRE.Match(innerP, nAttrIdx);

                        string attributeName  = mA.Groups[nameIndex].Value;
                        string attributeValue = mA.Groups[valueIndex].Value;
                        string attributeTD    = mA.Groups[tdIndex].Value;

                        if (attributeTD.Length > 0)
                        {
                            // delete the trailing textqualifier
                            if (attributeValue.Length > 0)
                            {
                                int ltqi = attributeValue.LastIndexOf(attributeTD);

                                if (ltqi >= 0)
                                {
                                    attributeValue = attributeValue.Substring(0, ltqi);
                                }
                            }
                        }

                        if (attributeName.ToLower() == "name")
                        {
                            paramName = HttpUtility.HtmlDecode(attributeValue);                             // for unicode encoded values
                            nNameCnt++;
                        }

                        if (attributeName.ToLower() == "value")
                        {
                            paramValue = HttpUtility.HtmlDecode(attributeValue);                             // for unicode encoded values
                            // delete trailing /
                            while ((paramValue.Length > 0) && (paramValue[paramValue.Length - 1] == '/'))
                            {
                                paramValue = paramValue.Substring(0, paramValue.Length - 1);
                            }
                        }

                        nAttrIdx = mA.Index + mA.Length;
                    }

                    if (nNameCnt == 1)                     // first "Name" param = keyword
                    {
                        sKeyword = "";

                        if (parentItem != null)
                        {
                            sKeyword = parentItem.KeyWordPath + ",";
                        }

                        string sOldKW = sKeyword;

                        sKeyword += paramValue;

                        HtmlHelpIndexItem idxFind = FindByKeyword(arrNodes, sKeyword);

                        if (idxFind != null)
                        {
                            idxItem = idxFind;
                        }
                        else
                        {
                            if (sKeyword.Split(new char[] { ',' }).Length > 1)
                            {
                                idxItem.CharIndex = sKeyword.Length - paramValue.Length;
                            }
                            else
                            {
                                sKeyword          = paramValue;
                                sOldKW            = sKeyword;
                                idxItem.CharIndex = 0;
                            }

                            idxItem.KeyWordPath = sKeyword;
                            idxItem.Indent      = sKeyword.Split(new char[] { ',' }).Length - 1;
                            idxItem.IsSeeAlso   = false;

                            sKeyword = sOldKW;
                        }
                    }
                    else
                    {
                        if ((nNameCnt > 2) && (paramName.ToLower() == "name"))
                        {
                            bAdded = true;
                            HtmlHelpIndexTopic idxTopic = new HtmlHelpIndexTopic(paramTitle, paramLocal, chmFile.CompileFile, chmFile.ChmFilePath);

                            idxItem.Topics.Add(idxTopic);

                            paramTitle = "";
                            paramLocal = "";
                        }

                        switch (paramName.ToLower())
                        {
                        case "name":
                            //case "keyword":
                        {
                            paramTitle = paramValue;
                        }; break;

                        case "local":
                        {
                            paramLocal = paramValue.Replace("../", "").Replace("./", "");
                        }; break;

                        case "type":                                    // information type assignment for item
                        {
                            idxItem.InfoTypeStrings.Add(paramValue);
                        }; break;

                        case "see also":
                        {
                            idxItem.AddSeeAlso(paramValue);
                            idxItem.IsSeeAlso = true;
                            bAdded            = true;
                        }; break;
                        }
                    }

                    nParamIndex = mP.Index + mP.Length;
                }

                if (!bAdded)
                {
                    bAdded = false;
                    HtmlHelpIndexTopic idxTopic = new HtmlHelpIndexTopic(paramTitle, paramLocal, chmFile.CompileFile, chmFile.ChmFilePath);

                    idxItem.Topics.Add(idxTopic);

                    paramTitle = "";
                    paramLocal = "";
                }

                idxItem.ChmFile = chmFile;
                arrNodes.Add(idxItem);

                nLastObjStartIndex = nObjStartIndex;
                nObjStartIndex     = m.Index + m.Length;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Shows help for a specific keyword
        /// </summary>
        /// <param name="namespaceFilter">namespace filter (used for merged files)</param>
        /// <param name="hlpNavigator">navigator value</param>
        /// <param name="keyword">keyword</param>
        /// <param name="url">url</param>
        void IHelpViewer.ShowHelp(string namespaceFilter, HelpNavigator hlpNavigator, string keyword, string url)
        {
            switch (hlpNavigator)
            {
            case HelpNavigator.AssociateIndex:
            {
                HtmlHelpIndexItem foundIdx = _reader.Index.SearchIndex(keyword, IndexType.AssiciativeLinks);
                if (foundIdx != null)
                {
                    if (foundIdx.Topics.Count > 0)
                    {
                        HtmlHelpIndexTopic topic = foundIdx.Topics[0];

                        if (topic.Local.Length > 0)
                        {
                            NavigateBrowser(topic.URL);
                        }
                    }
                }
            }
            break;

            case HelpNavigator.Find:
            {
                this.Cursor = Cursors.WaitCursor;
                this.helpSearch.SetSearchText(keyword);
                DataTable dtResults = _reader.PerformSearch(keyword, 500, true, false);
                this.helpSearch.SetResults(dtResults);
                this.Cursor = Cursors.Arrow;
                this.helpSearch.Focus();
            }
            break;

            case HelpNavigator.Index:
            {
                ((IHelpViewer)this).ShowHelpIndex(url);
            }
            break;

            case HelpNavigator.KeywordIndex:
            {
                HtmlHelpIndexItem foundIdx = _reader.Index.SearchIndex(keyword, IndexType.KeywordLinks);
                if (foundIdx != null)
                {
                    if (foundIdx.Topics.Count == 1)
                    {
                        HtmlHelpIndexTopic topic = foundIdx.Topics[0];

                        if (topic.Local.Length > 0)
                        {
                            NavigateBrowser(topic.URL);
                        }
                    }
                    else if (foundIdx.Topics.Count > 1)
                    {
                        this.helpIndex.SelectText(foundIdx.IndentKeyWord);
                    }
                }
                this.helpIndex.Focus();
            }
            break;

            case HelpNavigator.TableOfContents:
            {
                HtmlHelpTocItem foundTOC = _reader.HtmlHelpToc.SearchTopic(keyword);
                if (foundTOC != null)
                {
                    if (foundTOC.Local.Length > 0)
                    {
                        NavigateBrowser(foundTOC.Url);
                    }
                }
                this.helpTocTree.Focus();
            }
            break;

            case HelpNavigator.Topic:
            {
                HtmlHelpTocItem foundTOC = _reader.HtmlHelpToc.SearchTopic(keyword);
                if (foundTOC != null)
                {
                    if (foundTOC.Local.Length > 0)
                    {
                        NavigateBrowser(foundTOC.Url);
                    }
                }
            }
            break;
            }
        }