Skip to content

Commit

Permalink
Worked around beta 2 bug, where format map change events weren't bein…
Browse files Browse the repository at this point in the history
…g sent out. Updated the version number to 1.31.
  • Loading branch information
Noah Richards committed Jan 29, 2010
1 parent 4692b2c commit 3605b3f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions ViewCreationListener.cs
Expand Up @@ -6,6 +6,8 @@
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;
using System;
using System.Diagnostics;

namespace ItalicComments
{
Expand All @@ -25,7 +27,7 @@ internal sealed class ViewCreationListener : IWpfTextViewCreationListener
/// </summary>
public void TextViewCreated(IWpfTextView textView)
{
new FormatMapWatcher(formatMapService.GetClassificationFormatMap(textView), typeRegistry);
new FormatMapWatcher(textView, formatMapService.GetClassificationFormatMap(textView), typeRegistry);
}
}

Expand All @@ -36,17 +38,31 @@ internal sealed class FormatMapWatcher
IClassificationTypeRegistryService typeRegistry;
IClassificationType text;

static List<string> CommentTypes = new List<string>() { "comment", "xml doc comment" };
static List<string> DocTagTypes = new List<string>() { "xml doc tag" };
static List<string> CommentTypes = new List<string>() { "comment", "xml doc comment", "vb xml doc comment" };
static List<string> DocTagTypes = new List<string>() { "xml doc tag", "vb xml doc tag" };

public FormatMapWatcher(IClassificationFormatMap formatMap, IClassificationTypeRegistryService typeRegistry)
public FormatMapWatcher(ITextView view, IClassificationFormatMap formatMap, IClassificationTypeRegistryService typeRegistry)
{
this.formatMap = formatMap;
this.text = typeRegistry.GetClassificationType("text");
this.typeRegistry = typeRegistry;
this.FixComments();

this.formatMap.ClassificationFormatMappingChanged += FormatMapChanged;

// Bug workaround for Beta 2:
// The format map doesn't sent out changed events when items are *added* to the map, which includes language specific items
// like the ones we want (xml doc comment, for example). As such, do an extra format when the view first gains focus.
view.GotAggregateFocus += FirstGotFocus;
}

void FirstGotFocus(object sender, EventArgs e)
{
((ITextView)sender).GotAggregateFocus -= FirstGotFocus;

Debug.Assert(!inUpdate, "How can we be updating *while* the view is getting focus?");

this.FixComments();
}

void FormatMapChanged(object sender, System.EventArgs e)
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.3</Version>
<Version>1.31</Version>
<Description>Make comments italic.</Description>
<Locale>1033</Locale>
<MoreInfoUrl>http://blogs.msdn.com/noahric</MoreInfoUrl>
Expand Down

0 comments on commit 3605b3f

Please sign in to comment.