/// <summary>
 /// Adds the entries from the specified MenuDefinitionEntryCollection to the end of this MenuDefinitionEntryCollection.
 /// </summary>
 /// <param name="value">The MenuDefinitionEntryCollection to be added to the end of this MenuDefinitionEntryCollection.</param>
 public void AddRange(MenuDefinitionEntryCollection value)
 {
     foreach (MenuDefinitionEntry commandBarEntry in value)
     {
         Add(commandBarEntry);
     }
 }
Пример #2
0
        /// <summary>
        /// Creates menu items for the specified MenuDefinitionEntryCollection.
        /// </summary>
        ///	<param name="commandManager">The CommandManager to use.</param>
        /// <param name="menuDefinitionEntryCollection">The MenuDefinitionEntryCollection to create menu items for.</param>
        /// <returns>The menu items.</returns>
        public static MenuItem[] CreateMenuItems(CommandManager commandManager, MenuType menuType, MenuDefinitionEntryCollection menuDefinitionEntryCollection)
        {
            ArrayList menuItemArrayList = new ArrayList();
            for (int position = 0; position < menuDefinitionEntryCollection.Count; position++)
            {
                MenuItem[] menuItems = menuDefinitionEntryCollection[position].GetMenuItems(commandManager, menuType);
                if (menuItems != null)
                    menuItemArrayList.AddRange(menuItems);
            }

            // remove leading, trailing, and adjacent separators
            for (int i = menuItemArrayList.Count - 1; i >= 0; i--)
            {
                if (((MenuItem)menuItemArrayList[i]).Text == "-")
                {
                    if (i == 0 ||  // leading
                        i == menuItemArrayList.Count - 1 ||  // trailing
                        ((MenuItem)menuItemArrayList[i - 1]).Text == "-")  // adjacent
                    {
                        menuItemArrayList.RemoveAt(i);
                    }
                }
            }

            return (menuItemArrayList.Count == 0) ? null : (MenuItem[])menuItemArrayList.ToArray(typeof(MenuItem));
        }
        private MenuDefinitionEntryCollection GetSpellingSuggestions()
        {
            CommandManager commandManager = _spellingManager.CommandManager;
            MenuDefinitionEntryCollection listOfSuggestions = new MenuDefinitionEntryCollection();
            commandManager.SuppressEvents = true;
            commandManager.BeginUpdate();
            try
            {
                // provide suggestions
                SpellingSuggestion[] suggestions = _spellingManager.SpellingChecker.Suggest(_currentWord, DEFAULT_MAX_SUGGESTIONS, SUGGESTION_DEPTH ) ;
                bool foundSuggestion = false;
                if ( suggestions.Length > 0 )
                {
                    // add suggestions to list (stop adding when the quality of scores
                    // declines precipitously)
                    short lastScore = suggestions[0].Score ;
                    for (int i = 0; i < suggestions.Length; i++)
                    {
                        SpellingSuggestion suggestion = suggestions[i];

                        //note: in some weird cases, like 's, a suggestion is returned but lacks a suggested replacement, so need to check that case
                        if ( (lastScore-suggestion.Score) < SCORE_GAP_FILTER && (suggestion.Suggestion != null))
                        {
                            Command FixSpellingCommand = new Command(CommandId.FixWordSpelling);
                            FixSpellingCommand.Identifier += suggestion.Suggestion;
                            FixSpellingCommand.Text = suggestion.Suggestion;
                            FixSpellingCommand.MenuText = suggestion.Suggestion;
                            FixSpellingCommand.Execute += new EventHandler(_spellingManager.fixSpellingApplyCommand_Execute);
                            FixSpellingCommand.Tag = suggestion.Suggestion;
                            commandManager.Add(FixSpellingCommand);

                            listOfSuggestions.Add(FixSpellingCommand.Identifier, false, i == suggestions.Length - 1);
                            foundSuggestion = true;
                        }
                        else
                            break ;

                        // update last score
                        lastScore = suggestion.Score ;
                    }
                }
                if (!foundSuggestion)
                {
                    Command FixSpellingCommand = new Command(CommandId.FixWordSpelling);
                    FixSpellingCommand.Enabled = false;

                    commandManager.Add(FixSpellingCommand);
                    listOfSuggestions.Add(CommandId.FixWordSpelling, false, true);
                }
            }
            finally
            {
                commandManager.EndUpdate();
                commandManager.SuppressEvents = false;
            }
            return listOfSuggestions;
        }
        /// <summary>
        /// Sets the specified array as the items of the collection.
        /// </summary>
        /// <param name="editValue">The collection to edit.</param>
        /// <param name="value">An array of objects to set as the collection items.</param>
        /// <returns>The newly created collection object or, otherwise, the collection indicated by the editValue parameter.</returns>
        protected override object SetItems(object editValue, object[] value)
        {
            MenuDefinitionEntryCollection commandContextMenuDefinitionEntryCollection = (MenuDefinitionEntryCollection)editValue;

            commandContextMenuDefinitionEntryCollection.Clear();
            foreach (MenuDefinitionEntry commandContextMenuDefinitionEntry in value)
            {
                commandContextMenuDefinitionEntryCollection.Add(commandContextMenuDefinitionEntry);
            }
            return(commandContextMenuDefinitionEntryCollection);
        }
        /// <summary>
        /// Gets an array of objects containing the specified collection.
        /// </summary>
        /// <param name="editValue">The collection to edit.</param>
        /// <returns>An array containing the collection objects.</returns>
        protected override object[] GetItems(object editValue)
        {
            MenuDefinitionEntryCollection commandContextMenuDefinitionEntryCollection = (MenuDefinitionEntryCollection)editValue;

            MenuDefinitionEntry[] commandContextMenuDefinitionEntries = new MenuDefinitionEntry[commandContextMenuDefinitionEntryCollection.Count];
            if (commandContextMenuDefinitionEntryCollection.Count > 0)
            {
                commandContextMenuDefinitionEntryCollection.CopyTo(commandContextMenuDefinitionEntries, 0);
            }
            return(commandContextMenuDefinitionEntries);
        }
 /// <summary>
 /// Initializes a new instance of the MenuDefinitionEntryCollection class.
 /// </summary>
 /// <param name="value">Command bar entry collection to initializes this command bar entry collection with.</param>
 public MenuDefinitionEntryCollection(MenuDefinitionEntryCollection value)
 {
     AddRange(value);
 }
 /// <summary>
 /// Initializes a new instance of the MenuDefinitionEntryEnumerator class.
 /// </summary>
 /// <param name="mappings">The MenuDefinitionEntryCollection to enumerate.</param>
 public MenuDefinitionEntryEnumerator(MenuDefinitionEntryCollection mappings)
 {
     temp           = (IEnumerable)mappings;
     baseEnumerator = temp.GetEnumerator();
 }
 /// <summary>
 /// Adds the entries from the specified MenuDefinitionEntryCollection to the end of this MenuDefinitionEntryCollection.
 /// </summary>
 /// <param name="value">The MenuDefinitionEntryCollection to be added to the end of this MenuDefinitionEntryCollection.</param>
 public void AddRange(MenuDefinitionEntryCollection value)
 {
     foreach (MenuDefinitionEntry commandBarEntry in value)
         Add(commandBarEntry);
 }
 /// <summary>
 /// Initializes a new instance of the MenuDefinitionEntryCollection class.
 /// </summary>
 /// <param name="value">Command bar entry collection to initializes this command bar entry collection with.</param>
 public MenuDefinitionEntryCollection(MenuDefinitionEntryCollection value)
 {
     AddRange(value);
 }
 /// <summary>
 /// Initializes a new instance of the MenuDefinitionEntryEnumerator class.
 /// </summary>
 /// <param name="mappings">The MenuDefinitionEntryCollection to enumerate.</param>
 public MenuDefinitionEntryEnumerator(MenuDefinitionEntryCollection mappings)
 {
     temp = (IEnumerable)mappings;
     baseEnumerator = temp.GetEnumerator();
 }
Пример #11
0
        /// <summary>
        /// Creates menu items for the specified MenuDefinitionEntryCollection.
        /// </summary>
        ///	<param name="commandManager">The CommandManager to use.</param>
        /// <param name="menuDefinitionEntryCollection">The MenuDefinitionEntryCollection to create menu items for.</param>
        /// <returns>The menu items.</returns>
        public static MenuItem[] CreateMenuItems(CommandManager commandManager, MenuType menuType, MenuDefinitionEntryCollection menuDefinitionEntryCollection)
        {
            ArrayList menuItemArrayList = new ArrayList();

            for (int position = 0; position < menuDefinitionEntryCollection.Count; position++)
            {
                MenuItem[] menuItems = menuDefinitionEntryCollection[position].GetMenuItems(commandManager, menuType);
                if (menuItems != null)
                {
                    menuItemArrayList.AddRange(menuItems);
                }
            }

            // remove leading, trailing, and adjacent separators
            for (int i = menuItemArrayList.Count - 1; i >= 0; i--)
            {
                if (((MenuItem)menuItemArrayList[i]).Text == "-")
                {
                    if (i == 0 ||                                         // leading
                        i == menuItemArrayList.Count - 1 ||               // trailing
                        ((MenuItem)menuItemArrayList[i - 1]).Text == "-") // adjacent
                    {
                        menuItemArrayList.RemoveAt(i);
                    }
                }
            }

            return((menuItemArrayList.Count == 0) ? null : (MenuItem[])menuItemArrayList.ToArray(typeof(MenuItem)));
        }