Esempio n. 1
0
		protected bool GetHelpText (string id, ref string caption, out string text)
		{
			text  ="";
			if (id == null)
				id = "MissingHelpId";

			XmlNode match = null;
			if (!m_helpIdToElt.ContainsKey(id))
			{
				// Not in Dictioanry, so try and get a new one, or null.
				match = m_document.SelectSingleNode(String.Format("strings/item[@id='{0}']", id));
				m_helpIdToElt[id] = match; // even if null!
			}
			match = m_helpIdToElt[id];

			if (match != null)
			{
				text = match.InnerText;
				text = m_mediator.StringTbl.LocalizeLiteralValue(text);
				if (String.IsNullOrEmpty(caption))
				{
					caption = XmlUtils.GetOptionalAttributeValue(match, "caption", "");
					caption = m_mediator.StringTbl.LocalizeAttributeValue(caption);
				}
				else
				{
					string sCaptionFormat = XmlUtils.GetOptionalAttributeValue(match, "captionformat");
					sCaptionFormat = m_mediator.StringTbl.LocalizeAttributeValue(sCaptionFormat);
					if (!String.IsNullOrEmpty(sCaptionFormat) && sCaptionFormat.IndexOf("{0}") >= 0)
						caption = String.Format(sCaptionFormat, caption);
				}
				// Insert some command specific text if the tooltip needs formatting.
				if (m_mediator.CommandSet != null)
				{
					Command command = m_mediator.CommandSet[id] as Command;
					if (command != null && command.ToolTipInsert != null &&
						command.ToolTipInsert != string.Empty)
					{
						string formattedText = String.Format(text, command.ToolTipInsert);
						if (formattedText != string.Empty && formattedText != text)
							text = formattedText;
					}
				}
			}

			if (text.Contains("{0}"))
			{
				// indicates the target wants to customize it.
				Command command = m_mediator.CommandSet[id] as Command;
				if (command != null && !string.IsNullOrEmpty(command.MessageString))
				{
					var holder = new ToolTipHolder();
					holder.ToolTip = text;
					m_mediator.SendMessage(command.MessageString + "ToolTip", holder);
					text = holder.ToolTip;
				}
			}

			if (text == "" && id != "NoHelp")
			{
				// We don't have text, so see if we want to display a "NoHelp" message instead.
				string noHelpCaption = caption;
				GetHelpText("NoHelp", ref noHelpCaption, out text);
				// if we got a NoHelp text, see if we can format it to insert debug info.
				if (text != string.Empty)
				{
					string formattedText = String.Format(text, id, caption);
					if (formattedText != string.Empty && formattedText != text)
						text = formattedText;
				}
				if (match == null)
				{
					if (noHelpCaption != string.Empty)
						caption = noHelpCaption;
					else
						caption = xCoreInterfaces.HelpFileProblem;
				}
			}
			else if (match != null)
			{
				// we matched something.
				return true;
			}
			return false;	//there was no real match
		}
Esempio n. 2
0
        protected bool GetHelpText(string id, ref string caption, out string text)
        {
            text = "";
            if (id == null)
            {
                id = "MissingHelpId";
            }

            XmlNode match = null;

            if (!m_helpIdToElt.ContainsKey(id))
            {
                // Not in Dictionary, so try and get a new one, or null.
                match             = m_document.SelectSingleNode(String.Format("strings/item[@id='{0}']", id));
                m_helpIdToElt[id] = match;                 // even if null!
            }
            match = m_helpIdToElt[id];

            if (match != null)
            {
                text = match.InnerText;
                text = StringTable.Table.LocalizeLiteralValue(text);
                if (String.IsNullOrEmpty(caption))
                {
                    caption = XmlUtils.GetOptionalAttributeValue(match, "caption", "");
                    caption = StringTable.Table.LocalizeAttributeValue(caption);
                }
                else
                {
                    string sCaptionFormat = XmlUtils.GetOptionalAttributeValue(match, "captionformat");
                    sCaptionFormat = StringTable.Table.LocalizeAttributeValue(sCaptionFormat);
                    if (!String.IsNullOrEmpty(sCaptionFormat) && sCaptionFormat.IndexOf("{0}") >= 0)
                    {
                        caption = String.Format(sCaptionFormat, caption);
                    }
                }
                // Insert some command specific text if the tooltip needs formatting.
                if (m_mediator.CommandSet != null)
                {
                    Command command = m_mediator.CommandSet[id] as Command;
                    if (command != null && command.ToolTipInsert != null &&
                        command.ToolTipInsert != string.Empty)
                    {
                        string formattedText = String.Format(text, command.ToolTipInsert);
                        if (formattedText != string.Empty && formattedText != text)
                        {
                            text = formattedText;
                        }
                    }
                }
            }

            if (text.Contains("{0}"))
            {
                // indicates the target wants to customize it.
                Command command = m_mediator.CommandSet[id] as Command;
                if (command != null && !string.IsNullOrEmpty(command.MessageString))
                {
                    var holder = new ToolTipHolder();
                    holder.ToolTip = text;
                    m_mediator.SendMessage(command.MessageString + "ToolTip", holder);
                    text = holder.ToolTip;
                }
            }

            if (text == "" && id != "NoHelp")
            {
                // We don't have text, so see if we want to display a "NoHelp" message instead.
                string noHelpCaption = caption;
                GetHelpText("NoHelp", ref noHelpCaption, out text);
                // if we got a NoHelp text, see if we can format it to insert debug info.
                if (text != string.Empty)
                {
                    string formattedText = String.Format(text, id, caption);
                    if (formattedText != string.Empty && formattedText != text)
                    {
                        text = formattedText;
                    }
                }
                if (match == null)
                {
                    if (noHelpCaption != string.Empty)
                    {
                        caption = noHelpCaption;
                    }
                    else
                    {
                        caption = xCoreInterfaces.HelpFileProblem;
                    }
                }
            }
            else if (match != null)
            {
                // we matched something.
                return(true);
            }
            return(false);              //there was no real match
        }