示例#1
0
        public void AutoCorrectContextMenu_Correct(Office.IRibbonControl control)
        {
            var correction = SpellingCorrection.Decode(control.Tag);

            try
            {
                Globals.ThisAddIn.Application.AutoCorrect.Entries.Add(correction.Word, correction.Correction);
                Range range = Globals.ThisAddIn.Application.Selection.Words.First;
                range      = GetTrimmedRange(range);
                range.Text = correction.Correction;
            }
            catch (Exception e)
            {
                MessageBox.Show($"Could not add AutoCorrect entry {correction}: {e.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#2
0
        private string BuildMenu(string word, SpellingSuggestions suggestions)
        {
            StringBuilder sb = new StringBuilder(@"<menu xmlns=""http://schemas.microsoft.com/office/2006/01/customui"" >");

            int index = 0;

            foreach (SpellingSuggestion suggestion in suggestions)
            {
                var correction = new SpellingCorrection(word, suggestion.Name);
                sb.Append($"<button id=\"AutoCorrectSuggestion{index}\" label=\"{suggestion.Name}\" onAction=\"AutoCorrectContextMenu_Correct\" tag=\"{SpellingCorrection.Encode(correction)}\" />");
                index += 1;
            }

            sb.Append(@"<menuSeparator id=""AutoCorrectSeparator"" />");
            sb.Append(@"<button idMso=""AutoCorrect"" />");
            sb.Append(@"</menu>");
            return(sb.ToString());
        }
 /// <summary>
 /// Encodes the correction as a string.
 /// </summary>
 /// <param name="correction">The correction to encode.</param>
 /// <returns>The encoded correction.</returns>
 public static string Encode(SpellingCorrection correction)
 {
     return $"{Base64Encode(correction.Word)}|{Base64Encode(correction.Correction)}";
 }
        private string BuildMenu(string word, SpellingSuggestions suggestions)
        {
            StringBuilder sb = new StringBuilder(@"<menu xmlns=""http://schemas.microsoft.com/office/2006/01/customui"" >");

            int index = 0;
            foreach (SpellingSuggestion suggestion in suggestions)
            {
                var correction = new SpellingCorrection(word, suggestion.Name);
                sb.Append($"<button id=\"AutoCorrectSuggestion{index}\" label=\"{suggestion.Name}\" onAction=\"AutoCorrectContextMenu_Correct\" tag=\"{SpellingCorrection.Encode(correction)}\" />");
                index += 1;
            }

            sb.Append(@"<menuSeparator id=""AutoCorrectSeparator"" />");
            sb.Append(@"<button idMso=""AutoCorrect"" />");
            sb.Append(@"</menu>");
            return sb.ToString();
        }
 /// <summary>
 /// Encodes the correction as a string.
 /// </summary>
 /// <param name="correction">The correction to encode.</param>
 /// <returns>The encoded correction.</returns>
 public static string Encode(SpellingCorrection correction)
 {
     return($"{Base64Encode(correction.Word)}|{Base64Encode(correction.Correction)}");
 }