private void ToolTipLegacy(SnapshotPoint triggerPoint, System.Windows.Point p)
        {
            var           span         = Get_Keyword_Span_At_Point(triggerPoint);
            ITrackingSpan applicableTo = this._textView.TextSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeInclusive);

            // check if a tooltip window is already visible for the applicable span
            if ((this._legacySpan != null) && this._legacySpan.OverlapsWith(span))
            {
                //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoController:ToolTipLegacy: tooltip is already visible. span = " + this._legacySpan.ToString() + ", content =" + applicableTo.GetText(this._textView.TextSnapshot));
                return;
            }

            string keyword = applicableTo.GetText(this._textView.TextSnapshot);

            Mnemonic mnemonic = AsmSourceTools.ParseMnemonic(keyword, false);

            if (mnemonic != Mnemonic.NONE)
            {
                var instructionTooltipWindow = new InstructionTooltipWindow(AsmDudeToolsStatic.Get_Font_Color())
                {
                    Owner = this // set the owner of this windows such that we can manually close this window
                };
                instructionTooltipWindow.SetDescription(mnemonic, AsmDudeTools.Instance);
                instructionTooltipWindow.SetPerformanceInfo(mnemonic, AsmDudeTools.Instance);
                instructionTooltipWindow.Margin = new Thickness(7.0);

                var border = new Border()
                {
                    BorderBrush     = System.Windows.Media.Brushes.LightGray,
                    BorderThickness = new Thickness(1.0),
                    CornerRadius    = new CornerRadius(2.0),
                    Background      = AsmDudeToolsStatic.Get_Background_Color(),
                    Child           = instructionTooltipWindow
                };

                // cleanup old window remnants
                if (this._legacyTooltipWindow != null)
                {
                    AsmDudeToolsStatic.Output_INFO("AsmQuickInfoController:ToolTipLegacy: going to cleanup old window remnants.");
                    if (this._legacyTooltipWindow.IsLoaded)
                    {
                        this._legacyTooltipWindow = null;
                    }
                    else
                    {
                        this._legacyTooltipWindow?.Close();
                    }
                }

                this._legacyTooltipWindow = new Window
                {
                    WindowStyle   = WindowStyle.None,
                    ResizeMode    = ResizeMode.NoResize,
                    SizeToContent = SizeToContent.WidthAndHeight,
                    Left          = p.X,
                    Top           = p.Y,
                    Content       = border
                };
                this._legacyTooltipWindow.LostKeyboardFocus += (o, i) =>
                {
                    //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoController:LostKeyboardFocus: going to close the tooltip window.");
                    try
                    {
                        (o as Window).Close();
                    }
                    catch (Exception e)
                    {
                        AsmDudeToolsStatic.Output_WARNING("AsmQuickInfoController:LostKeyboardFocus: e=" + e.Message);
                    }
                };
                this._legacySpan = span;
                this._legacyTooltipWindow.Show();
                this._legacyTooltipWindow.Focus(); //give the tooltip window focus, such that we can use the lostKeyboardFocus event to close this window;
            }
        }
示例#2
0
        private void Handle(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;
            DateTime time1 = DateTime.Now;

            ITextSnapshot snapshot     = this.textBuffer_.CurrentSnapshot;
            SnapshotPoint?triggerPoint = session.GetTriggerPoint(snapshot);

            if (!triggerPoint.HasValue)
            {
                AsmDudeToolsStatic.Output_WARNING(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:Handle: trigger point is null", this.ToString()));
                return;
            }

            Brush foreground = AsmDudeToolsStatic.GetFontColor();

            (AsmTokenTag tag, SnapshotSpan? keywordSpan) = AsmDudeToolsStatic.GetAsmTokenTag(this.aggregator_, triggerPoint.Value);
            if (keywordSpan.HasValue)
            {
                SnapshotSpan tagSpan        = keywordSpan.Value;
                string       keyword        = tagSpan.GetText();
                string       keyword_upcase = keyword.ToUpperInvariant();

                AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:Handle: keyword=\"{1}\"; type={2}; file=\"{3}\"", this.ToString(), keyword, tag.Type, AsmDudeToolsStatic.GetFilename(session.TextView.TextBuffer)));
                applicableToSpan = snapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeInclusive);

                TextBlock description = null;
                switch (tag.Type)
                {
                case AsmTokenType.Misc:
                {
                    description = new TextBlock();
                    description.Inlines.Add(Make_Run1("Keyword ", foreground));
                    description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Misc))));

                    string descr = this.asmDudeTools_.Get_Description(keyword_upcase);
                    if (descr.Length > 0)
                    {
                        if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2))
                        {
                            descr = "\n" + descr;
                        }

                        description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips))
                            {
                                Foreground = foreground,
                            });
                    }
                    break;
                }

                case AsmTokenType.Directive:
                {
                    description = new TextBlock();
                    description.Inlines.Add(Make_Run1("Directive ", foreground));
                    description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Directive))));

                    string descr = this.asmDudeTools_.Get_Description(keyword_upcase);
                    if (descr.Length > 0)
                    {
                        if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2))
                        {
                            descr = "\n" + descr;
                        }

                        description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips))
                            {
                                Foreground = foreground,
                            });
                    }
                    break;
                }

                case AsmTokenType.Register:
                {
                    int lineNumber = AsmDudeToolsStatic.Get_LineNumber(tagSpan);
                    if (keyword_upcase.StartsWith("%", StringComparison.Ordinal))
                    {
                        keyword_upcase = keyword_upcase.Substring(1);         // remove the preceding % in AT&T syntax
                    }

                    Rn reg = RegisterTools.ParseRn(keyword_upcase, true);
                    if (this.asmDudeTools_.RegisterSwitchedOn(reg))
                    {
                        RegisterTooltipWindow registerTooltipWindow = new RegisterTooltipWindow(foreground);
                        registerTooltipWindow.SetDescription(reg, this.asmDudeTools_);
                        registerTooltipWindow.SetAsmSim(this.asmSimulator_, reg, lineNumber, true);
                        quickInfoContent.Add(registerTooltipWindow);
                    }
                    break;
                }

                case AsmTokenType.Mnemonic:     // intentional fall through
                case AsmTokenType.MnemonicOff:  // intentional fall through
                case AsmTokenType.Jump:
                {
                    (Mnemonic mnemonic, _) = AsmSourceTools.ParseMnemonic_Att(keyword_upcase, true);
                    InstructionTooltipWindow instructionTooltipWindow = new InstructionTooltipWindow(foreground)
                    {
                        Session = session,         // set the owner of this windows such that we can manually close this window
                    };
                    instructionTooltipWindow.SetDescription(mnemonic, this.asmDudeTools_);
                    instructionTooltipWindow.SetPerformanceInfo(mnemonic, this.asmDudeTools_);
                    int lineNumber = AsmDudeToolsStatic.Get_LineNumber(tagSpan);
                    instructionTooltipWindow.SetAsmSim(this.asmSimulator_, lineNumber, true);
                    quickInfoContent.Add(instructionTooltipWindow);
                    break;
                }

                case AsmTokenType.Label:
                {
                    string label                = keyword;
                    string labelPrefix          = tag.Misc;
                    string full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(labelPrefix, label, AsmDudeToolsStatic.Used_Assembler);

                    description = new TextBlock();
                    description.Inlines.Add(Make_Run1("Label ", foreground));
                    description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label))));

                    string descr = this.Get_Label_Description(full_Qualified_Label);
                    if (descr.Length == 0)
                    {
                        descr = this.Get_Label_Description(label);
                    }
                    if (descr.Length > 0)
                    {
                        if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2))
                        {
                            descr = "\n" + descr;
                        }

                        description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips))
                            {
                                Foreground = foreground,
                            });
                    }
                    break;
                }

                case AsmTokenType.LabelDef:
                {
                    string label          = keyword;
                    string extra_Tag_Info = tag.Misc;
                    string full_Qualified_Label;
                    if ((extra_Tag_Info != null) && extra_Tag_Info.Equals(AsmTokenTag.MISC_KEYWORD_PROTO, StringComparison.Ordinal))
                    {
                        full_Qualified_Label = label;
                    }
                    else
                    {
                        full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(extra_Tag_Info, label, AsmDudeToolsStatic.Used_Assembler);
                    }

                    AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: found label def " + full_Qualified_Label);

                    description = new TextBlock();
                    description.Inlines.Add(Make_Run1("Label ", foreground));
                    description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label))));

                    string descr = this.Get_Label_Def_Description(full_Qualified_Label, label);
                    if (descr.Length > 0)
                    {
                        if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2))
                        {
                            descr = "\n" + descr;
                        }

                        description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips))
                            {
                                Foreground = foreground,
                            });
                    }
                    break;
                }

                case AsmTokenType.Constant:
                {
                    (bool valid, ulong value, int nBits) = AsmSourceTools.Evaluate_Constant(keyword);
                    string constantStr = valid
                                ? value + "d = " + value.ToString("X", AsmDudeToolsStatic.CultureUI) + "h = " + AsmSourceTools.ToStringBin(value, nBits) + "b"
                                : keyword;


                    if (false)         // experiment to get text selectable
                    {
                        TextBoxWindow myWindow = new TextBoxWindow();
                        myWindow.MouseRightButtonUp           += this.MyWindow_MouseRightButtonUp;
                        myWindow.MyContent.Text                = "Constant X: " + constantStr;
                        myWindow.MyContent.Foreground          = foreground;
                        myWindow.MyContent.MouseRightButtonUp += this.MyContent_MouseRightButtonUp;
                        quickInfoContent.Add(myWindow);
                    }
                    else
                    {
                        description = new SelectableTextBlock();
                        description.Inlines.Add(Make_Run1("Constant ", foreground));

                        description.Inlines.Add(Make_Run2(constantStr, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Constant))));
                    }
                    break;
                }

                case AsmTokenType.UserDefined1:
                {
                    description = new TextBlock();
                    description.Inlines.Add(Make_Run1("User defined 1: ", foreground));
                    description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined1))));

                    string descr = this.asmDudeTools_.Get_Description(keyword_upcase);
                    if (descr.Length > 0)
                    {
                        if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2))
                        {
                            descr = "\n" + descr;
                        }

                        description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips))
                            {
                                Foreground = foreground,
                            });
                    }
                    break;
                }

                case AsmTokenType.UserDefined2:
                {
                    description = new TextBlock();
                    description.Inlines.Add(Make_Run1("User defined 2: ", foreground));
                    description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined2))));

                    string descr = this.asmDudeTools_.Get_Description(keyword_upcase);
                    if (descr.Length > 0)
                    {
                        if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2))
                        {
                            descr = "\n" + descr;
                        }

                        description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips))
                            {
                                Foreground = foreground,
                            });
                    }
                    break;
                }

                case AsmTokenType.UserDefined3:
                {
                    description = new TextBlock();
                    description.Inlines.Add(Make_Run1("User defined 3: ", foreground));
                    description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined3))));

                    string descr = this.asmDudeTools_.Get_Description(keyword_upcase);
                    if (descr.Length > 0)
                    {
                        if (keyword.Length > (AsmDudePackage.MaxNumberOfCharsInToolTips / 2))
                        {
                            descr = "\n" + descr;
                        }

                        description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.MaxNumberOfCharsInToolTips))
                            {
                                Foreground = foreground,
                            });
                    }
                    break;
                }

                default:
                    //description = new TextBlock();
                    //description.Inlines.Add(makeRun1("Unused tagType " + asmTokenTag.Tag.type));
                    break;
                }
                if (description != null)
                {
                    description.Focusable  = true;
                    description.FontSize   = AsmDudeToolsStatic.GetFontSize() + 2;
                    description.FontFamily = AsmDudeToolsStatic.GetFontType();
                    //AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:AugmentQuickInfoSession; setting description fontSize={1}; fontFamily={2}", this.ToString(), description.FontSize, description.FontFamily));
                    quickInfoContent.Add(description);
                }
            }
            //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: applicableToSpan=\"" + applicableToSpan + "\"; quickInfoContent,Count=" + quickInfoContent.Count);
            AsmDudeToolsStatic.Print_Speed_Warning(time1, "QuickInfo");
        }
示例#3
0
        private void Handle(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan)
        {
            applicableToSpan = null;
            DateTime time1 = DateTime.Now;

            ITextSnapshot snapshot     = this._sourceBuffer.CurrentSnapshot;
            var           triggerPoint = (SnapshotPoint)session.GetTriggerPoint(snapshot);

            if (triggerPoint == null)
            {
                AsmDudeToolsStatic.Output_WARNING("AsmQuickInfoSource:AugmentQuickInfoSession: trigger point is null");
                return;
            }

            Brush foreground = AsmDudeToolsStatic.Get_Font_Color();

            var enumerator = this._aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint)).GetEnumerator();

            if (enumerator.MoveNext())
            {
                var asmTokenTag = enumerator.Current;

                var enumerator2 = asmTokenTag.Span.GetSpans(this._sourceBuffer).GetEnumerator();
                if (enumerator2.MoveNext())
                {
                    SnapshotSpan tagSpan      = enumerator2.Current;
                    string       keyword      = tagSpan.GetText();
                    string       keywordUpper = keyword.ToUpper();

                    #region Tests
                    // TODO: multiple tags at the provided triggerPoint is most likely the result of a bug in AsmTokenTagger, but it seems harmless...
                    if (false)
                    {
                        if (enumerator.MoveNext())
                        {
                            var asmTokenTagX = enumerator.Current;
                            var enumeratorX  = asmTokenTagX.Span.GetSpans(this._sourceBuffer).GetEnumerator();
                            enumeratorX.MoveNext();
                            AsmDudeToolsStatic.Output_WARNING(string.Format("{0}:AugmentQuickInfoSession. current keyword " + keyword + ": but span has more than one tag! next tag=\"{1}\"", ToString(), enumeratorX.Current.GetText()));
                        }
                    }
                    #endregion

                    //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: keyword=\""+ keyword + "\"; type=" + asmTokenTag.Tag.type +"; file="+AsmDudeToolsStatic.GetFileName(session.TextView.TextBuffer));
                    applicableToSpan = snapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeInclusive);

                    TextBlock    description = null;
                    AsmTokenType type        = asmTokenTag.Tag.Type;
                    switch (type)
                    {
                    case AsmTokenType.Misc:
                    {
                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("Keyword ", foreground));
                        description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Misc))));

                        string descr = this._asmDudeTools.Get_Description(keywordUpper);
                        if (descr.Length > 0)
                        {
                            if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2))
                            {
                                descr = "\n" + descr;
                            }
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = foreground
                                });
                        }
                        break;
                    }

                    case AsmTokenType.Directive:
                    {
                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("Directive ", foreground));
                        description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Directive))));

                        string descr = this._asmDudeTools.Get_Description(keywordUpper);
                        if (descr.Length > 0)
                        {
                            if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2))
                            {
                                descr = "\n" + descr;
                            }
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = foreground
                                });
                        }
                        break;
                    }

                    case AsmTokenType.Register:
                    {
                        int lineNumber = AsmDudeToolsStatic.Get_LineNumber(tagSpan);
                        if (keywordUpper.StartsWith("%"))
                        {
                            keywordUpper = keywordUpper.Substring(1);                                       // remove the preceding % in AT&T syntax
                        }
                        Rn reg = RegisterTools.ParseRn(keywordUpper, true);
                        if (this._asmDudeTools.RegisterSwitchedOn(reg))
                        {
                            var registerTooltipWindow = new RegisterTooltipWindow(foreground);
                            registerTooltipWindow.SetDescription(reg, this._asmDudeTools);
                            registerTooltipWindow.SetAsmSim(this._asmSimulator, reg, lineNumber, true);
                            quickInfoContent.Add(registerTooltipWindow);
                        }
                        break;
                    }

                    case AsmTokenType.Mnemonic:
                    case AsmTokenType.Jump:
                    {
                        int      lineNumber = AsmDudeToolsStatic.Get_LineNumber(tagSpan);
                        Mnemonic mnemonic   = AsmSourceTools.ParseMnemonic_Att(keywordUpper, true);
                        if (this._asmDudeTools.MnemonicSwitchedOn(mnemonic))
                        {
                            var instructionTooltipWindow = new InstructionTooltipWindow(foreground)
                            {
                                Session = session         // set the owner of this windows such that we can manually close this window
                            };
                            instructionTooltipWindow.SetDescription(mnemonic, this._asmDudeTools);
                            instructionTooltipWindow.SetPerformanceInfo(mnemonic, this._asmDudeTools, false);
                            instructionTooltipWindow.SetAsmSim(this._asmSimulator, lineNumber, true);
                            quickInfoContent.Add(instructionTooltipWindow);
                        }
                        break;
                    }

                    case AsmTokenType.Label:
                    {
                        string label                = keyword;
                        string labelPrefix          = asmTokenTag.Tag.Misc;
                        string full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(labelPrefix, label, AsmDudeToolsStatic.Used_Assembler);

                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("Label ", foreground));
                        description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label))));

                        string descr = Get_Label_Description(full_Qualified_Label);
                        if (descr.Length == 0)
                        {
                            descr = Get_Label_Description(label);
                        }
                        if (descr.Length > 0)
                        {
                            if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2))
                            {
                                descr = "\n" + descr;
                            }
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = foreground
                                });
                        }
                        break;
                    }

                    case AsmTokenType.LabelDef:
                    {
                        string label          = keyword;
                        string extra_Tag_Info = asmTokenTag.Tag.Misc;
                        string full_Qualified_Label;
                        if ((extra_Tag_Info != null) && extra_Tag_Info.Equals(AsmTokenTag.MISC_KEYWORD_PROTO))
                        {
                            full_Qualified_Label = label;
                        }
                        else
                        {
                            full_Qualified_Label = AsmDudeToolsStatic.Make_Full_Qualified_Label(extra_Tag_Info, label, AsmDudeToolsStatic.Used_Assembler);
                        }

                        AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: found label def " + full_Qualified_Label);

                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("Label ", foreground));
                        description.Inlines.Add(Make_Run2(full_Qualified_Label, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Label))));

                        string descr = Get_Label_Def_Description(full_Qualified_Label, label);
                        if (descr.Length > 0)
                        {
                            if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2))
                            {
                                descr = "\n" + descr;
                            }
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = foreground
                                });
                        }
                        break;
                    }

                    case AsmTokenType.Constant:
                    {
                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("Constant ", foreground));

                        var(Valid, Value, NBits) = AsmSourceTools.Evaluate_Constant(keyword);
                        string constantStr = (Valid)
                                    ? Value + "d = " + Value.ToString("X") + "h = " + AsmSourceTools.ToStringBin(Value, NBits) + "b"
                                    : keyword;

                        description.Inlines.Add(Make_Run2(constantStr, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Constant))));
                        break;
                    }

                    case AsmTokenType.UserDefined1:
                    {
                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("User defined 1: ", foreground));
                        description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined1))));

                        string descr = this._asmDudeTools.Get_Description(keywordUpper);
                        if (descr.Length > 0)
                        {
                            if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2))
                            {
                                descr = "\n" + descr;
                            }
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = foreground
                                });
                        }
                        break;
                    }

                    case AsmTokenType.UserDefined2:
                    {
                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("User defined 2: ", foreground));
                        description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined2))));

                        string descr = this._asmDudeTools.Get_Description(keywordUpper);
                        if (descr.Length > 0)
                        {
                            if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2))
                            {
                                descr = "\n" + descr;
                            }
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = foreground
                                });
                        }
                        break;
                    }

                    case AsmTokenType.UserDefined3:
                    {
                        description = new TextBlock();
                        description.Inlines.Add(Make_Run1("User defined 3: ", foreground));
                        description.Inlines.Add(Make_Run2(keyword, new SolidColorBrush(AsmDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Userdefined3))));

                        string descr = this._asmDudeTools.Get_Description(keywordUpper);
                        if (descr.Length > 0)
                        {
                            if (keyword.Length > (AsmDudePackage.maxNumberOfCharsInToolTips / 2))
                            {
                                descr = "\n" + descr;
                            }
                            description.Inlines.Add(new Run(AsmSourceTools.Linewrap(": " + descr, AsmDudePackage.maxNumberOfCharsInToolTips))
                                {
                                    Foreground = foreground
                                });
                        }
                        break;
                    }

                    default:
                        //description = new TextBlock();
                        //description.Inlines.Add(makeRun1("Unused tagType " + asmTokenTag.Tag.type));
                        break;
                    }
                    if (description != null)
                    {
                        description.FontSize   = AsmDudeToolsStatic.Get_Font_Size() + 2;
                        description.FontFamily = AsmDudeToolsStatic.Get_Font_Type();
                        //AsmDudeToolsStatic.Output_INFO(string.Format("{0}:AugmentQuickInfoSession; setting description fontSize={1}; fontFamily={2}", this.ToString(), description.FontSize, description.FontFamily));
                        quickInfoContent.Add(description);
                    }
                }
            }
            //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: applicableToSpan=\"" + applicableToSpan + "\"; quickInfoContent,Count=" + quickInfoContent.Count);
            AsmDudeToolsStatic.Print_Speed_Warning(time1, "QuickInfo");
        }
示例#4
0
        private void ToolTipLegacy(SnapshotPoint triggerPoint, Point p)
        {
            DateTime      time1    = DateTime.Now;
            ITextSnapshot snapshot = this.textView_.TextSnapshot;

            (AsmTokenTag tag, SnapshotSpan? keywordSpan) = AsmDudeToolsStatic.GetAsmTokenTag(this.aggregator_, triggerPoint);
            if (keywordSpan.HasValue)
            {
                SnapshotSpan tagSpan        = keywordSpan.Value;
                string       keyword        = tagSpan.GetText();
                string       keyword_upcase = keyword.ToUpperInvariant();

                //AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:ToolTipLegacy: keyword=\"{1}\"; type={2}; file=\"{3}\"", this.ToString(), keyword, tag.Type, AsmDudeToolsStatic.GetFilename(this._textView.TextBuffer)));
                ITrackingSpan applicableTo = snapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeInclusive);

                // check if a tooltip window is already visible for the applicable span
                if ((this.legacySpan_ != null) && this.legacySpan_.OverlapsWith(tagSpan))
                {
                    AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:ToolTipLegacy: tooltip is already visible. span = {1}, content = {2}", this.ToString(), this.legacySpan_.ToString(), applicableTo.GetText(this.textView_.TextSnapshot)));
                    return;
                }

                switch (tag.Type)
                {
                case AsmTokenType.Mnemonic:     // intentional fall through
                case AsmTokenType.Jump:
                {
                    (Mnemonic mnemonic, AttType type) = AsmSourceTools.ParseMnemonic_Att(keyword_upcase, true);

                    InstructionTooltipWindow instructionTooltipWindow = new InstructionTooltipWindow(AsmDudeToolsStatic.GetFontColor())
                    {
                        Owner = this,         // set the owner of this windows such that we can manually close this window
                    };
                    instructionTooltipWindow.SetDescription(mnemonic, AsmDudeTools.Instance);
                    instructionTooltipWindow.SetPerformanceInfo(mnemonic, AsmDudeTools.Instance);
                    instructionTooltipWindow.Margin = new Thickness(7.0);

                    Border border = new Border()
                    {
                        BorderBrush     = System.Windows.Media.Brushes.LightGray,
                        BorderThickness = new Thickness(1.0),
                        CornerRadius    = new CornerRadius(2.0),
                        Background      = AsmDudeToolsStatic.GetBackgroundColor(),
                        Child           = instructionTooltipWindow,
                    };

                    // cleanup old window remnants
                    if (this.legacyTooltipWindow_ != null)
                    {
                        AsmDudeToolsStatic.Output_INFO(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:ToolTipLegacy: going to cleanup old window remnants.", this.ToString()));
                        if (this.legacyTooltipWindow_.IsLoaded)
                        {
                            this.legacyTooltipWindow_ = null;
                        }
                        else
                        {
                            this.legacyTooltipWindow_?.Close();
                        }
                    }

                    this.legacyTooltipWindow_ = new Window
                    {
                        WindowStyle   = WindowStyle.None,
                        ResizeMode    = ResizeMode.NoResize,
                        SizeToContent = SizeToContent.WidthAndHeight,
                        ShowInTaskbar = false,
                        Left          = p.X + 15, // placement slightly to the right
                        Top           = p.Y + 5,  // placement slightly lower such that the code that is selected is visible
                        //TODO find the space to the left and if not enough space is available, place the window more to the left
                        Content = border,
                    };
                    this.legacyTooltipWindow_.LostKeyboardFocus += (o, i) =>
                    {
                        //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoController:LostKeyboardFocus: going to close the tooltip window.");
                        try
                        {
                            (o as Window).Close();
                        }
                        catch (Exception e)
                        {
                            AsmDudeToolsStatic.Output_WARNING(string.Format(AsmDudeToolsStatic.CultureUI, "{0}:ToolTipLegacy: e={1}", this.ToString(), e.Message));
                        }
                    };
                    this.legacySpan_ = tagSpan;
                    this.legacyTooltipWindow_.Show();
                    this.legacyTooltipWindow_.Focus();         //give the tooltip window focus, such that we can use the lostKeyboardFocus event to close this window;
                    break;
                }

                default: break;
                }
                //AsmDudeToolsStatic.Output_INFO("AsmQuickInfoSource:AugmentQuickInfoSession: applicableToSpan=\"" + applicableToSpan + "\"; quickInfoContent,Count=" + quickInfoContent.Count);
                AsmDudeToolsStatic.Print_Speed_Warning(time1, "QuickInfo ToolTipLegacy");
            }
        }