Syntax editor multiple tooltips

1 Answer 20 Views
SyntaxEditor
Greg
Top achievements
Rank 1
Greg asked on 06 Apr 2022, 05:58 PM

Tried extending the a custom tooltip tagger to recognize multiple words/tooltips but no luck. Below is my custom tooltip tagger, any thoughts on where I am going wrong?


using System.Collections.Generic;
using Telerik.Windows.SyntaxEditor.Core.Editor;
using Telerik.Windows.SyntaxEditor.Core.Tagging;
using Telerik.Windows.SyntaxEditor.Core.Text;

namespace QuickMeasuresPro
{
    class DAXTooltipTagger : TaggerBase<ToolTipTag>
    {
        private string searchWord;

        private static readonly string[] Keywords = new string[]
        {
            "APPROXIMATEDISTINCTCOUNT","AVERAGE","AVERAGEA","AVERAGEX"
        };

        private static readonly string[] Tooltips = new string[]
        {
            "APPROXIMATEDISTINCTCOUNT(<columnName>)\r\nReturns the approximate number of rows that contain distinct values in a column.",
            "AVERAGE(<column>)\r\nReturns the average (arithmetic mean) of all the numbers in a column.",
            "AVERAGEA(<column>)\r\nReturns the average (arithmetic mean) of the values in a column.",
            "AVERAGEX(<table>,<expression>)\r\nCalculates the average (arithmetic mean) of a set of expressions evaluated over a table.",
        };

        public DAXTooltipTagger(ITextDocumentEditor editor)
            : base(editor)
        {
        }

        public override IEnumerable<TagSpan<ToolTipTag>> GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (string.IsNullOrEmpty(this.searchWord))
            {
                yield break;
            }

            TextSnapshot snapshot = this.Document.CurrentSnapshot;
            foreach (TextSnapshotSpan snapshotSpan in spans)
            {
                string lineString = snapshotSpan.GetText();
                int i = 0;
                foreach (string keyword in Keywords)
                {
                    string tooltip = Tooltips[i];
                    i++;
                    int index = lineString.IndexOf(keyword);
                    while (index != -1)
                    {
                        TextSnapshotSpan tempSnapshotSpan = new TextSnapshotSpan(snapshot,
                            new Span(snapshotSpan.Start + index, keyword.Length));

                        yield return new TagSpan<ToolTipTag>(tempSnapshotSpan, new ToolTipTag(tooltip));

                        index = lineString.IndexOf(keyword, index + keyword.Length);
                    }
                }
            }
        }

        public void UpdateSearchWord(string newSearchWord)
        {
            this.searchWord = newSearchWord;
            this.CallOnTagsChanged(this.Document.CurrentSnapshot.Span);
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 08 Apr 2022, 08:02 AM

Hi Greg,

You need to call the method UpdateSearchWord() which calls the CallOnTagsChanged() which starts the tagging iteration process. In your case , I guess you want to prepare tooltips for all keywords, so searchword is not mandatory, you can remove the if in the GetTags(). On a button click, when I call the UpdateSearchWord(), I successfully see the tooltips when later hover the keywords with mouse:

       private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.daxtooltipTagger.UpdateSearchWord("AVERAGE");
        }

Regards,
Petar Mladenov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Greg
Top achievements
Rank 1
commented on 08 Apr 2022, 01:36 PM

Thanks, yeah should have updated this, I did figure that out to call UpdateSearchWord () and it worked. Then I had to change things up a bit to actually use some regex to find potential matches and iterate through the keywords in order to prevent both SUM and SUMX from matching SUMX for example.
Tags
SyntaxEditor
Asked by
Greg
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or