Ejemplo n.º 1
0
 private bool SearchIndex(
     string keyword)
 {
     if (chm.HasIndex)
     {
         IndexItem item = chm.Index.SearchIndex(keyword,
                                                IndexType.KeywordLinks);
         if (item != null && item.Topics.Count > 0)
         {
             WriteIfVerbose(String.Format("Keyword {0} found in index",
                                          item.KeyWord));
             IndexTopic indexTopic = item.Topics[0] as IndexTopic;
             return(DisplayResult(keyword,
                                  indexTopic));
         }
         else
         {
             WriteIfVerbose(String.Format("Keyword {0} not found in index",
                                          keyword));
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
        private bool DisplayResult(string keyword,
                                   IndexTopic indexTopic)
        {
            keyword = keyword.Trim().ToLower();
            string url = indexTopic.URL;

            WriteIfVerbose(String.Format("URL from index search {0}",
                                         url));
            string prototype = ExtractPrototype(url);

            if (prototype == null || prototype.Trim().Equals(String.Empty))
            {
                return(false);
            }
            string formattedPrototype = FormatPrototype(prototype);

            Say(formattedPrototype);
            return(true);
        }
Ejemplo n.º 3
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, IndexItem parentItem, ArrayList 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;

                IndexItem idxItem = new IndexItem();

                // 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;

                        IndexItem 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;
                            IndexTopic idxTopic = new IndexTopic(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;
                    IndexTopic idxTopic = new IndexTopic(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;
            }
        }
Ejemplo n.º 4
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:
            {
                IndexItem foundIdx = _reader.Index.SearchIndex(keyword, IndexType.AssiciativeLinks);
                if (foundIdx != null)
                {
                    if (foundIdx.Topics.Count > 0)
                    {
                        IndexTopic topic = foundIdx.Topics[0] as IndexTopic;

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

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

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

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

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

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

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