Skip to content

Commit

Permalink
Text in QuickInfoTooltips is taken from the current color theme
Browse files Browse the repository at this point in the history
  • Loading branch information
HJLebbink committed Jan 2, 2017
1 parent 66f3f14 commit dd3fb3f
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ internal sealed class IntrinsicsQuickInfoSource : IQuickInfoSource
private readonly ITextBuffer _sourceBuffer;
private readonly ITagAggregator<IntrinsicTokenTag> _aggregator;
private readonly IntrinsicsDudeTools _intrinsicDudeTools;
private readonly Brush _textForegroundColor;

public object CSharpEditorResources { get; private set; }

public IntrinsicsQuickInfoSource(
ITextBuffer buffer,
ITagAggregator<IntrinsicTokenTag> aggregator)
ITextBuffer buffer,
ITagAggregator<IntrinsicTokenTag> aggregator)
{
this._sourceBuffer = buffer;
this._aggregator = aggregator;
this._intrinsicDudeTools = IntrinsicsDudeTools.Instance;
this._textForegroundColor = IntrinsicsDudeToolsStatic.GetFontColor();
}

/// <summary>
Expand All @@ -74,6 +76,8 @@ public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qui
return;
}

Brush foreground = IntrinsicsDudeToolsStatic.GetFontColor();

IEnumerable<IMappingTagSpan<IntrinsicTokenTag>> enumerator = this._aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint));
if (enumerator.Count() > 1)
{
Expand All @@ -91,7 +95,7 @@ public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qui
applicableToSpan = snapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive);

//IntrinsicsDudeToolsStatic.Output("INFO: IntrinsicsQuickInfoSource: AugmentQuickInfoSession: keyword=" + keyword);
Intrinsic intrinsic = IntrinsicTools.GarseIntrinsic(keyword, false);
Intrinsic intrinsic = IntrinsicTools.ParseIntrinsic(keyword, false);
if (intrinsic != Intrinsic.NONE)
{
IList<IntrinsicDataElement> dataElements = this._intrinsicDudeTools.IntrinsicStore.Get(intrinsic);
Expand All @@ -103,7 +107,7 @@ public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> qui
//IntrinsicsDudeToolsStatic.Output("INFO: IntrinsicsQuickInfoSource: AugmentQuickInfoSession: removing existing content: intrinsic=" + intrinsic + "; " + quickInfoContent[0].ToString());
quickInfoContent.Clear(); // throw the existing quickinfo away
}
quickInfoContent.Add(dataElements[0].DocumentationTextBlock); //only show the description of the first intrinsic data element
quickInfoContent.Add(dataElements[0].DocumentationTextBlock(foreground)); //only show the description of the first intrinsic data element
}
}
}
Expand Down Expand Up @@ -147,25 +151,26 @@ public void Dispose()
private TextBlock MakeRegisterDescription(SimdRegisterType reg)
{
TextBlock description = new TextBlock();
description.Inlines.Add(MakeRunBold(reg.ToString()));
description.Inlines.Add(MakeRunBold(reg.ToString(), this._textForegroundColor));
return description;
}

private static Run MakeRunBold(string str)
private static Run MakeRunBold(string str, Brush foreGround)
{
Run r1 = new Run(str)
{
FontWeight = FontWeights.Bold
FontWeight = FontWeights.Bold,
Foreground = foreGround
};
return r1;
}

private static Run MakeRun2(string str, System.Drawing.Color color)
private static Run MakeRun2(string str, Brush foreground) ///System.Drawing.Color color)
{
Run r1 = new Run(str)
{
FontWeight = FontWeights.Bold,
Foreground = new SolidColorBrush(IntrinsicsDudeToolsStatic.ConvertColor(color))
Foreground = foreground // new SolidColorBrush(IntrinsicsDudeToolsStatic.ConvertColor(color))
};
return r1;
}
Expand Down
117 changes: 64 additions & 53 deletions VS/CSHARP/intrinsics-dude-vsix/Tools/IntrinsicDataElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
using static IntrinsicsDude.Tools.IntrinsicTools;

namespace IntrinsicsDude.Tools
Expand All @@ -53,56 +55,59 @@ public IntrinsicDataElement()
this.cpuID = CpuID.NONE;
}

public TextBlock DocumentationTextBlock {
get {
StringBuilder sb = new StringBuilder();
sb.Append(IntrinsicTools.ToString(this.returnType));
public TextBlock DocumentationTextBlock(Brush foreground)
{
StringBuilder sb = new StringBuilder();
sb.Append(IntrinsicTools.ToString(this.returnType));
sb.Append(". .");
sb.Append(this.intrinsic.ToString().ToLower());
sb.Append(".(.");
foreach (Tuple<ParamType, string> param in this.parameters)
{
sb.Append(IntrinsicTools.ToString(param.Item1));
sb.Append(". .");
sb.Append(this.intrinsic.ToString().ToLower());
sb.Append(".(.");
foreach (Tuple<ParamType, string> param in this.parameters)
{
sb.Append(IntrinsicTools.ToString(param.Item1));
sb.Append(". .");
sb.Append(param.Item2);
sb.Append("., .");
}
if (this.parameters.Count > 0)
{
sb.Length -= 4; // remove the last comma
}
sb.Append(".)");

TextBlock description = this.AddSyntaxHighlighting(sb.ToString());
sb.Append(param.Item2);
sb.Append("., .");
}
if (this.parameters.Count > 0)
{
sb.Length -= 4; // remove the last comma
}
sb.Append(".)");

description.Inlines.Add(MakeRunBold(" ["+IntrinsicTools.ToString(this.cpuID)+ "]\n"));
description.Inlines.Add(new Run(IntrinsicTools.Linewrap(this.description, IntrinsicsDudePackage.maxNumberOfCharsInToolTips)));
TextBlock description = this.AddSyntaxHighlighting(sb.ToString(), foreground);

if ((this.operation != null) && (this.operation.Length > 0))
description.Inlines.Add(MakeRunBold(" [" + IntrinsicTools.ToString(this.cpuID) + "]\n", foreground));
description.Inlines.Add(new Run(IntrinsicTools.Linewrap(this.description, IntrinsicsDudePackage.maxNumberOfCharsInToolTips))
{
Foreground = IntrinsicsDudeToolsStatic.GetFontColor()
});

if ((this.operation != null) && (this.operation.Length > 0))
{
description.Inlines.Add(MakeRunBold("\n\nOperation:\n", foreground));
description.Inlines.Add(new Run(this.operation)
{
description.Inlines.Add(MakeRunBold("\n\nOperation:\n"));
Run run = new Run(this.operation)
{
FontFamily = new FontFamily("Consolas")
};
description.Inlines.Add(run);
FontFamily = new FontFamily("Consolas"),
Foreground = foreground
}
);
}

if ((this.performance != null) && (this.performance.Length > 0))
if ((this.performance != null) && (this.performance.Length > 0))
{
description.Inlines.Add(MakeRunBold("\n\nPerformance:\n", foreground));
foreach (Run run in MakePerformance(this.performance, foreground))
{
description.Inlines.Add(MakeRunBold("\n\nPerformance:\n"));
foreach (Run run in MakePerformance(this.performance))
{
description.Inlines.Add(run);
}
description.Inlines.Add(run);
}
}

description.FontSize = IntrinsicsDudeToolsStatic.GetFontSize() + 2;
//description.FontFamily = IntrinsicsDudeToolsStatic.getFontType();
//IntrinsicsDudeToolsStatic.Output(string.Format("INFO: {0}:AugmentQuickInfoSession; setting description fontSize={1}; fontFamily={2}", this.ToString(), description.FontSize, description.FontFamily));
description.FontSize = IntrinsicsDudeToolsStatic.GetFontSize() + 2;
//description.FontFamily = IntrinsicsDudeToolsStatic.getFontType();
//IntrinsicsDudeToolsStatic.Output(string.Format("INFO: {0}:AugmentQuickInfoSession; setting description fontSize={1}; fontFamily={2}", this.ToString(), description.FontSize, description.FontFamily));

return description;
}
return description;
}

public string DocumenationString {
Expand Down Expand Up @@ -143,7 +148,7 @@ public string DocumenationString {

#region Private Methods

private TextBlock AddSyntaxHighlighting(string str)
private TextBlock AddSyntaxHighlighting(string str, Brush foreground)
{
TextBlock textBlock = new TextBlock();

Expand All @@ -153,11 +158,11 @@ private TextBlock AddSyntaxHighlighting(string str)
string str2 = a2[i2];
if (IntrinsicTools.ParseSimdRegisterType(str2, false) != SimdRegisterType.NONE)
{
textBlock.Inlines.Add(MakeRun2(str2, Settings.Default.SyntaxHighlighting_Register));
textBlock.Inlines.Add(MakeRun2(str2, new SolidColorBrush(IntrinsicsDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Register))));
}
else if (IntrinsicTools.GarseIntrinsic(str2, false) != Intrinsic.NONE)
else if (IntrinsicTools.ParseIntrinsic(str2, false) != Intrinsic.NONE)
{
textBlock.Inlines.Add(MakeRun2(str2, Settings.Default.SyntaxHighlighting_Intrinsic));
textBlock.Inlines.Add(MakeRun2(str2, new SolidColorBrush(IntrinsicsDudeToolsStatic.ConvertColor(Settings.Default.SyntaxHighlighting_Intrinsic))));
}
else
{
Expand All @@ -182,10 +187,10 @@ private TextBlock AddSyntaxHighlighting(string str)
case "int":
case "double":
case "float":
textBlock.Inlines.Add(MakeRun2(str3, System.Drawing.Color.Blue));
textBlock.Inlines.Add(MakeRun2(str3, new SolidColorBrush(IntrinsicsDudeToolsStatic.ConvertColor(System.Drawing.Color.Blue))));
break;
default:
textBlock.Inlines.Add(MakeRunBold(str3));
textBlock.Inlines.Add(MakeRunBold(str3, foreground));
break;
}
if (i3 < a3.Length - 1)
Expand All @@ -198,34 +203,39 @@ private TextBlock AddSyntaxHighlighting(string str)
return textBlock;
}

private static Run MakeRunBold(string str)
private static Run MakeRunBold(string str, Brush foreground)
{
Run r1 = new Run(str)
{
FontWeight = FontWeights.Bold
FontWeight = FontWeights.Bold,
Foreground = foreground //new SolidColorBrush(IntrinsicsDudeToolsStatic.ConvertColor(Settings.Default.TextEditorColorForeGround))
};
return r1;
}

private static Run MakeRun2(string str, System.Drawing.Color color)
private static Run MakeRun2(string str, Brush foreground)
{
Run r1 = new Run(str)
{
FontWeight = FontWeights.Bold,
Foreground = new SolidColorBrush(IntrinsicsDudeToolsStatic.ConvertColor(color))
Foreground = foreground
};
return r1;
}

private static IList<Run> MakePerformance(string str)
private static IList<Run> MakePerformance(string str, Brush foreground)
{
FontFamily family = new FontFamily("Consolas");
IList<Run> list = new List<Run>();

Run run = new Run(string.Format("{0,-20}{1,-10}{2,-10}\n", "Architecture", "Latency", "Throughput"))
{
FontFamily = family,
FontStyle = FontStyles.Italic
FontStyle = FontStyles.Italic,
Foreground = foreground
};
run.SetResourceReference(Border.BackgroundProperty, VsBrushes.ToolWindowTextKey);

list.Add(run);

string str2 = str.Replace("&lt;", "<").Replace("&gt;", ">").Replace("<tbody>", "").Replace("</tbody>", "").Replace("<tr>", "").Replace("<td>", "");
Expand All @@ -237,7 +247,8 @@ private static IList<Run> MakePerformance(string str)
{
Run run1 = new Run(string.Format("{0,-20}{1,-10}{2,-10}\n", elements[0], elements[1], elements[2]))
{
FontFamily = family
FontFamily = family,
Foreground = foreground
};
list.Add(run1);
}
Expand Down
27 changes: 24 additions & 3 deletions VS/CSHARP/intrinsics-dude-vsix/Tools/IntrinsicsDudeToolsStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using IntrinsicsDude.ErrorSquiggles;
using IntrinsicsDude.SyntaxHighlighting;
using EnvDTE;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Operations;
using Microsoft.VisualStudio.Text.Tagging;
using Microsoft.VisualStudio.TextManager.Interop;
using System;
Expand All @@ -36,6 +33,7 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using static IntrinsicsDude.Tools.IntrinsicTools;
//using System.Drawing;

namespace IntrinsicsDude.Tools
{
Expand Down Expand Up @@ -104,6 +102,29 @@ public static FontFamily GetFontType()
return new FontFamily(font);
}

public static Brush GetFontColor() {
try {
DTE dte = Package.GetGlobalService(typeof(SDTE)) as DTE;
EnvDTE.Properties propertiesList = dte.get_Properties("FontsAndColors", "TextEditor");
Property prop = propertiesList.Item("FontsAndColorsItems");

FontsAndColorsItems fci = (FontsAndColorsItems)prop.Object;

for (int i = 1; i<fci.Count; ++i) {
ColorableItems ci = fci.Item(i);
if (ci.Name.Equals("PLAIN TEXT", StringComparison.OrdinalIgnoreCase))
{
//IntrinsicsDudeToolsStatic.Output("INFO:GetFontColor: i=" + i + ": " + ci.Name + "; " + ci.Foreground);
return new SolidColorBrush(ConvertColor(System.Drawing.ColorTranslator.FromOle((int)ci.Foreground)));
}
}
} catch (Exception e) {
IntrinsicsDudeToolsStatic.Output(string.Format(CultureInfo.CurrentCulture, "ERROR: IntrinsicsDudeToolsStatic:GetFontColor {0}", e.Message));
}
IntrinsicsDudeToolsStatic.Output(string.Format(CultureInfo.CurrentCulture, "WARNING: IntrinsicsDudeToolsStatic:GetFontColor: could not retrieve text color"));
return new SolidColorBrush(Colors.Gray);
}

/// <summary>
/// Get the path where this visual studio extension is installed.
/// </summary>
Expand Down

0 comments on commit dd3fb3f

Please sign in to comment.