Skip to content

Commit

Permalink
Modified to only update format map if it needs to be, to prevent unne…
Browse files Browse the repository at this point in the history
…cessary changes and conflicts with other extensions that change format maps. Bumped version to 1.2.
  • Loading branch information
Noah Richards committed Jan 29, 2010
1 parent 5d09977 commit 3d81607
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
33 changes: 28 additions & 5 deletions ViewCreationListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ internal sealed class ViewCreationListener : IWpfTextViewCreationListener
/// </summary>
public void TextViewCreated(IWpfTextView textView)
{
new FormatMapWatcher(textView, formatMapService.GetEditorFormatMap(textView));
textView.Properties.GetOrCreateSingletonProperty(() =>
new FormatMapWatcher(textView, formatMapService.GetEditorFormatMap(textView)));
}
}

Expand Down Expand Up @@ -99,22 +100,44 @@ void SetGradientBrush()
{
// Change the selected text properties to use a gradient brush and an outline pen
var properties = formatMap.GetProperties("Selected Text");
properties[EditorFormatDefinition.BackgroundBrushId] = gradientBrush;
properties["BackgroundPen"] = gradientBorder;
formatMap.SetProperties("Selected Text", properties);

bool modified = false;

if (properties[EditorFormatDefinition.BackgroundBrushId] != gradientBrush)
{
modified = true;
properties[EditorFormatDefinition.BackgroundBrushId] = gradientBrush;
}
if (properties["BackgroundPen"] != gradientBorder)
{
modified = true;
properties["BackgroundPen"] = gradientBorder;
}

if (modified)
formatMap.SetProperties("Selected Text", properties);
}

void ClearGradientBrush()
{
// Clear out the gradient brush and outline pen
var properties = formatMap.GetProperties("Selected Text");

bool modified = false;

if (properties[EditorFormatDefinition.BackgroundBrushId] == gradientBrush)
{
modified = true;
properties.Remove(EditorFormatDefinition.BackgroundBrushId);
}
if (properties["BackgroundPen"] == gradientBorder)
{
modified = true;
properties.Remove("BackgroundPen");
}

formatMap.SetProperties("Selected Text", properties);
if (modified)
formatMap.SetProperties("Selected Text", properties);
}
}
}
2 changes: 1 addition & 1 deletion source.extension.vsixmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Identifier Id="GradientSelection">
<Name>Gradient Selection</Name>
<Author>Noah Richards</Author>
<Version>1.1</Version>
<Version>1.2</Version>
<Description>Make the selection use a gradient brush in rich client experience mode.</Description>
<Locale>1033</Locale>
<MoreInfoUrl>http://blogs.msdn.com/noahric</MoreInfoUrl>
Expand Down

0 comments on commit 3d81607

Please sign in to comment.