/// <summary> /// Merge a Command into the merge menu. /// </summary> /// <param name="command">The command to merge.</param> /// <param name="menuPath">The menu path at which to merge the command. Generally, this /// will be either command.MainMenuPath or command.ContextMenuPath, but it can also be /// a totally custom menu path as well.</param> public void MergeCommand(Command command, string menuPath) { // Ensure that a menu path was specified. Debug.Assert(menuPath != null && menuPath.Length != 0, "No menu path specified"); if (menuPath == null || menuPath.Length == 0) { return; } // Parse the menu path into an array of menu path entries. string[] menuPathEntries = menuPath.Split(new char[] { '/' }); // Build the menu structure for this command from the array of menu path entries. For // example, &File@1/&Close@2 specifies that this command represents the Close command // of the File menu. It specifies that the Close MenuItem should appear at merge // position 2 of the File menu, and that the File menu should appear at merge position // 1 of the main menu. int lastEntry = menuPathEntries.Length - 1; MergeMenuEntry parentMergeMenuEntry = rootMergeMenuEntry; for (int entry = 0; entry <= lastEntry; entry++) { // Parse the menu path entry into text and position values. string text; int position; ParseMenuPathEntry(menuPathEntries[entry], out text, out position); // See if we have a merge menu entry for this text and position already. MergeMenuEntry mergeMenuEntry = (MergeMenuEntry)parentMergeMenuEntry[position, text]; if (entry == lastEntry) { // Create the merge menu entry for this menu path entry. parentMergeMenuEntry[position, text] = new MergeMenuEntry(position, text, command); } else { // If there isn't a merge menu entry for this intermediate menu path entry, // create it. if (mergeMenuEntry == null) { mergeMenuEntry = new MergeMenuEntry(position, text); parentMergeMenuEntry[position, text] = mergeMenuEntry; } // Set the root to this merge menu entry for the next loop iteration. parentMergeMenuEntry = mergeMenuEntry; } } }
/// <summary> /// Merge a Command into the merge menu. /// </summary> /// <param name="command">The command to merge.</param> /// <param name="menuPath">The menu path at which to merge the command. Generally, this /// will be either command.MainMenuPath or command.ContextMenuPath, but it can also be /// a totally custom menu path as well.</param> public void MergeCommand(Command command, string menuPath) { // Ensure that a menu path was specified. Debug.Assert(menuPath != null && menuPath.Length != 0, "No menu path specified"); if (menuPath == null || menuPath.Length == 0) return; // Parse the menu path into an array of menu path entries. string[] menuPathEntries = menuPath.Split(new char[] {'/'}); // Build the menu structure for this command from the array of menu path entries. For // example, &File@1/&Close@2 specifies that this command represents the Close command // of the File menu. It specifies that the Close MenuItem should appear at merge // position 2 of the File menu, and that the File menu should appear at merge position // 1 of the main menu. int lastEntry = menuPathEntries.Length-1; MergeMenuEntry parentMergeMenuEntry = rootMergeMenuEntry; for (int entry = 0; entry <= lastEntry; entry++) { // Parse the menu path entry into text and position values. string text; int position; ParseMenuPathEntry(menuPathEntries[entry], out text, out position); // See if we have a merge menu entry for this text and position already. MergeMenuEntry mergeMenuEntry = (MergeMenuEntry)parentMergeMenuEntry[position, text]; if (entry == lastEntry) { // Create the merge menu entry for this menu path entry. parentMergeMenuEntry[position, text] = new MergeMenuEntry(position, text, command); } else { // If there isn't a merge menu entry for this intermediate menu path entry, // create it. if (mergeMenuEntry == null) { mergeMenuEntry = new MergeMenuEntry(position, text); parentMergeMenuEntry[position, text] = mergeMenuEntry; } // Set the root to this merge menu entry for the next loop iteration. parentMergeMenuEntry = mergeMenuEntry; } } }