Exemple #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handler for the Click event for items on the spelling context menu.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        void spellingMenuItemClick(object sender, EventArgs e)
        {
            SpellCorrectMenuItem item = sender as SpellCorrectMenuItem;

            if (item == null)
            {
                AddToDictMenuItem dict = sender as AddToDictMenuItem;
                Debug.Assert(dict != null, "invalid sender of spell check item");
                dict.AddWordToDictionary();
            }
            else
            {
                item.DoIt();
            }
        }
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// If the mousePos is part of a word that is not properly spelled, add to the menu
		/// options for correcting it.
		/// </summary>
		/// <param name="pt">The location on the screen of the word for which we want spelling
		/// suggestions (usually the mouse position)</param>
		/// <param name="rootsite">The focused rootsite</param>
		/// <param name="menu">to add items to.</param>
		/// <returns>the number of menu items added (not counting a possible separator line)</returns>
		/// -----------------------------------------------------------------------------------
		public virtual int MakeSpellCheckMenuOptions(Point pt, SimpleRootSite rootsite,
			ContextMenuStrip menu)
		{
			int hvoObj, tag, wsAlt, wsText;
			string word;
			ISpellEngine dict;
			bool nonSpellingError;
			ICollection<SpellCorrectMenuItem> suggestions = GetSuggestions(pt, rootsite,
				out hvoObj, out tag, out wsAlt, out wsText, out word, out dict, out nonSpellingError);
			if (suggestions == null)
				return 0;
			// no detectable spelling problem.

			// Note that items are inserted in order starting at the beginning, rather than
			// added to the end.  This is to support TE-6901.
			// If the menu isn't empty, add a separator.
			if (menu.Items.Count > 0)
				menu.Items.Insert(0, new ToolStripSeparator());

			// Make the menu option.
			ToolStripMenuItem itemExtras = null;
			int cSuggestions = 0;
			int iMenuItem = 0;
			IVwRootBox rootb = rootsite.RootBox;
			foreach (SpellCorrectMenuItem subItem in suggestions)
			{
				subItem.Click += spellingMenuItemClick;
				if (cSuggestions++ < RootSiteEditingHelper.kMaxSpellingSuggestionsInRootMenu)
				{
					Font createdFont = null;
					try
					{
					Font font = subItem.Font;
					if (wsText != 0)
					{
							font = createdFont = EditingHelper.GetFontForNormalStyle(wsText, rootb.Stylesheet,
							rootb.DataAccess.WritingSystemFactory);
						//string familyName = rootb.DataAccess.WritingSystemFactory.get_EngineOrNull(wsText).DefaultBodyFont;
						//font = new Font(familyName, font.Size, FontStyle.Bold);
					}

					subItem.Font = new Font(font, FontStyle.Bold);

					menu.Items.Insert(iMenuItem++, subItem);
				}
					finally
					{
						if (createdFont != null)
							createdFont.Dispose();
					}
				}
				else
				{
					if (itemExtras == null)
					{
						itemExtras = new ToolStripMenuItem(RootSiteStrings.ksAdditionalSuggestions);
						menu.Items.Insert(iMenuItem++, itemExtras);
					}
					itemExtras.DropDownItems.Add(subItem);
				}
			}
			if (suggestions.Count == 0)
			{
				ToolStripMenuItem noSuggestItems = new ToolStripMenuItem(RootSiteStrings.ksNoSuggestions);
				menu.Items.Insert(iMenuItem++, noSuggestItems);
				noSuggestItems.Enabled = false;
			}
			ToolStripMenuItem itemAdd = new AddToDictMenuItem(dict, word, rootb,
				hvoObj, tag, wsAlt, wsText, RootSiteStrings.ksAddToDictionary, m_cache);
			if (nonSpellingError)
				itemAdd.Enabled = false;
			menu.Items.Insert(iMenuItem++, itemAdd);
			itemAdd.Image = SIL.FieldWorks.Resources.ResourceHelper.SpellingIcon;
			itemAdd.Click += spellingMenuItemClick;
			return iMenuItem;
		}
Exemple #3
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// If the mousePos is part of a word that is not properly spelled, add to the menu
        /// options for correcting it.
        /// </summary>
        /// <param name="pt">The location on the screen of the word for which we want spelling
        /// suggestions (usually the mouse position)</param>
        /// <param name="rootsite">The focused rootsite</param>
        /// <param name="menu">to add items to.</param>
        /// <returns>the number of menu items added (not counting a possible separator line)</returns>
        /// -----------------------------------------------------------------------------------
        public virtual int MakeSpellCheckMenuOptions(Point pt, SimpleRootSite rootsite,
                                                     ContextMenuStrip menu)
        {
            int          hvoObj, tag, wsAlt, wsText;
            string       word;
            ISpellEngine dict;
            bool         nonSpellingError;
            ICollection <SpellCorrectMenuItem> suggestions = GetSuggestions(pt, rootsite,
                                                                            out hvoObj, out tag, out wsAlt, out wsText, out word, out dict, out nonSpellingError);

            if (suggestions == null)
            {
                return(0);
            }
            // no detectable spelling problem.

            // Note that items are inserted in order starting at the beginning, rather than
            // added to the end.  This is to support TE-6901.
            // If the menu isn't empty, add a separator.
            if (menu.Items.Count > 0)
            {
                menu.Items.Insert(0, new ToolStripSeparator());
            }

            // Make the menu option.
            ToolStripMenuItem itemExtras = null;
            int        cSuggestions      = 0;
            int        iMenuItem         = 0;
            IVwRootBox rootb             = rootsite.RootBox;

            foreach (SpellCorrectMenuItem subItem in suggestions)
            {
                subItem.Click += spellingMenuItemClick;
                if (cSuggestions++ < RootSiteEditingHelper.kMaxSpellingSuggestionsInRootMenu)
                {
                    Font createdFont = null;
                    try
                    {
                        Font font = subItem.Font;
                        if (wsText != 0)
                        {
                            font = createdFont = EditingHelper.GetFontForNormalStyle(wsText, rootb.Stylesheet,
                                                                                     rootb.DataAccess.WritingSystemFactory);
                            //string familyName = rootb.DataAccess.WritingSystemFactory.get_EngineOrNull(wsText).DefaultBodyFont;
                            //font = new Font(familyName, font.Size, FontStyle.Bold);
                        }

                        subItem.Font = new Font(font, FontStyle.Bold);

                        menu.Items.Insert(iMenuItem++, subItem);
                    }
                    finally
                    {
                        if (createdFont != null)
                        {
                            createdFont.Dispose();
                        }
                    }
                }
                else
                {
                    if (itemExtras == null)
                    {
                        itemExtras = new ToolStripMenuItem(RootSiteStrings.ksAdditionalSuggestions);
                        menu.Items.Insert(iMenuItem++, itemExtras);
                    }
                    itemExtras.DropDownItems.Add(subItem);
                }
            }
            if (suggestions.Count == 0)
            {
                ToolStripMenuItem noSuggestItems = new ToolStripMenuItem(RootSiteStrings.ksNoSuggestions);
                menu.Items.Insert(iMenuItem++, noSuggestItems);
                noSuggestItems.Enabled = false;
            }
            ToolStripMenuItem itemAdd = new AddToDictMenuItem(dict, word, rootb,
                                                              hvoObj, tag, wsAlt, wsText, RootSiteStrings.ksAddToDictionary, m_cache);

            if (nonSpellingError)
            {
                itemAdd.Enabled = false;
            }
            menu.Items.Insert(iMenuItem++, itemAdd);
            itemAdd.Image  = Resources.ResourceHelper.SpellingIcon;
            itemAdd.Click += spellingMenuItemClick;
            return(iMenuItem);
        }