Skip to content

Commit

Permalink
Changed updating logic to be much less aggressive, to prevent unneces…
Browse files Browse the repository at this point in the history
…sary updates to the format map if values are already corret (to prevent conflicts with other extensions that change the format map). Bumped version number to 1.4.
  • Loading branch information
Noah Richards committed Jan 29, 2010
1 parent 3605b3f commit 24a2fa2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions ViewCreationListener.cs
Expand Up @@ -27,7 +27,8 @@ internal sealed class ViewCreationListener : IWpfTextViewCreationListener
/// </summary>
public void TextViewCreated(IWpfTextView textView)
{
new FormatMapWatcher(textView, formatMapService.GetClassificationFormatMap(textView), typeRegistry);
textView.Properties.GetOrCreateSingletonProperty(() =>
new FormatMapWatcher(textView, formatMapService.GetClassificationFormatMap(textView), typeRegistry));
}
}

Expand Down Expand Up @@ -122,8 +123,12 @@ void Italicize(IClassificationType classification)
var properties = formatMap.GetTextProperties(classification);
var typeface = properties.Typeface;

// If this is already italic, skip it
if (typeface.Style == FontStyles.Italic)
return;

// Add italic and (possibly) remove bold, and change to a font that has good looking
// italics (i.e. *not* consolas)
// italics (i.e. *not* Consolas)
var newTypeface = new Typeface(new FontFamily("Lucida Sans"), FontStyles.Italic, FontWeights.Normal, typeface.Stretch);
properties = properties.SetTypeface(newTypeface);

Expand All @@ -139,13 +144,17 @@ void Fade(IClassificationType classification)
var textFormat = formatMap.GetTextProperties(text);
var properties = formatMap.GetTextProperties(classification);

var brush = properties.ForegroundBrush as SolidColorBrush;

// If the opacity is already not 1.0, skip this
if (brush == null || brush.Opacity != 1.0)
return;

// Make the font size a little bit smaller than the normal text size
properties = properties.SetFontRenderingEmSize(textFormat.FontRenderingEmSize - 1);

// Set the opacity to be a bit lighter (if it isn't already set)
var brush = properties.ForegroundBrush as SolidColorBrush;
if (brush != null && brush.Opacity == 1.0)
properties = properties.SetForegroundBrush(new SolidColorBrush(brush.Color) { Opacity = 0.7 });
// Set the opacity to be a bit lighter
properties = properties.SetForegroundBrush(new SolidColorBrush(brush.Color) { Opacity = 0.7 });

formatMap.SetTextProperties(classification, properties);
}
Expand Down
2 changes: 1 addition & 1 deletion source.extension.vsixmanifest
Expand Up @@ -3,7 +3,7 @@
<Identifier Id="ItalicComments">
<Name>ItalicComments</Name>
<Author>Noah Richards</Author>
<Version>1.31</Version>
<Version>1.4</Version>
<Description>Make comments italic.</Description>
<Locale>1033</Locale>
<MoreInfoUrl>http://blogs.msdn.com/noahric</MoreInfoUrl>
Expand Down

0 comments on commit 24a2fa2

Please sign in to comment.