Skip to content

Commit

Permalink
Merge pull request #1 from rizi/master
Browse files Browse the repository at this point in the history
Font size of region lines will be smaller.
  • Loading branch information
fsdsabel authored Apr 2, 2017
2 parents 248fa51 + d2870f7 commit c25b61c
Show file tree
Hide file tree
Showing 12 changed files with 534 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Metadata>
<Identity Id="ExpandRegions..a148547e-90e8-4d4e-8754-e5dcc169ae4c" Version="1.0" Language="en-US" Publisher="Daniel Sabel"/>
<DisplayName>ExpandRegions</DisplayName>
<Description xml:space="preserve">This extension expands all regions in C# and Visual Basic when a file is opened. It's a slimmed down version of "I Hate #Regions" for VS2017.</Description>
<Description xml:space="preserve">This extension expands all regions in C# and Visual Basic when a file is opened. It's a slimmed down version of \"I Hate #Regions\" for VS2017.</Description>
<License>license.txt</License>
</Metadata>
<Installation>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.ComponentModel.Composition;
using System.Windows.Media;

using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace ExpandRegions.Classifications
{
[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = Constants.ActiveRegionClassificationTypeNames)]
[Name(Constants.ActiveRegionName)]
[DisplayName(Constants.ActiveRegionName)]
[UserVisible(true)]
[Order(After = Constants.OrderAfterPriority, Before = Constants.OrderBeforePriority)]
internal sealed class ActiveRegionClassification : ClassificationFormatDefinition
{
#region Initialization

// Methods
public ActiveRegionClassification()
{
ForegroundColor = Colors.DarkGray;
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using System.Globalization;
using System.Windows;
using System.Windows.Media;

using Microsoft.VisualStudio.Text.Classification;

namespace ExpandRegions.Classifications
{
internal abstract class ClassificationFormatDefinition : EditorFormatDefinition
{
#region Protected Methods

protected override ResourceDictionary CreateResourceDictionaryFromDefinition()
{
ResourceDictionary resourceDictionary = new ResourceDictionary();
AddOverridableProperties(resourceDictionary);
if (ForegroundBrush != null)
{
resourceDictionary["Foreground"] = ForegroundBrush;
if (ForegroundBrush.Opacity != 1.0)
{
resourceDictionary["ForegroundOpacity"] = ForegroundBrush.Opacity;
}
}
if (BackgroundBrush != null)
{
resourceDictionary["Background"] = BackgroundBrush;
if (BackgroundBrush.Opacity != 1.0)
{
resourceDictionary["BackgroundOpacity"] = BackgroundBrush.Opacity;
}
}
if (FontTypeface != null)
{
resourceDictionary.Add("Typeface", FontTypeface);
if (FontTypeface.Weight == FontWeights.Bold)
{
resourceDictionary["IsBold"] = true;
}
if (FontTypeface.Style == FontStyles.Italic)
{
resourceDictionary["IsItalic"] = true;
}
}
if (FontRenderingSize.HasValue)
{
resourceDictionary.Add("FontRenderingSize", FontRenderingSize.Value);
}
if (FontHintingSize.HasValue)
{
resourceDictionary.Add("FontHintingSize", FontHintingSize.Value);
}
if (TextDecorations != null)
{
resourceDictionary.Add("TextDecorations", TextDecorations);
}
if (TextEffects != null)
{
resourceDictionary.Add("TextEffects", TextEffects);
}
if (CultureInfo != null)
{
resourceDictionary.Add("CultureInfo", CultureInfo);
}
return resourceDictionary;
}

#endregion

#region Private Methods

private void AddOverridableProperties(ResourceDictionary resourceDictionary)
{
if (ForegroundOpacity.HasValue)
{
resourceDictionary.Add("ForegroundOpacity", ForegroundOpacity.Value);
}
if (BackgroundOpacity.HasValue)
{
resourceDictionary.Add("BackgroundOpacity", BackgroundOpacity.Value);
}
if (IsBold.HasValue)
{
resourceDictionary.Add("IsBold", IsBold.Value);
}
if (IsItalic.HasValue)
{
resourceDictionary.Add("IsItalic", IsItalic.Value);
}
if (ForegroundColor.HasValue)
{
resourceDictionary["Foreground"] = new SolidColorBrush(ForegroundColor.Value);
}
if (BackgroundColor.HasValue)
{
resourceDictionary["Background"] = new SolidColorBrush(BackgroundColor.Value);
}
}

#endregion

#region Public Properties

public double? BackgroundOpacity
{
get;
protected set;
}

public CultureInfo CultureInfo
{
get;
protected set;
}

public double? FontHintingSize
{
get;
protected set;
}

public double? FontRenderingSize
{
get;
protected set;
}

public Typeface FontTypeface
{
get;
protected set;
}

public double? ForegroundOpacity
{
get;
protected set;
}

public bool? IsBold
{
get;
protected set;
}

public bool? IsItalic
{
get;
protected set;
}

public TextDecorationCollection TextDecorations
{
get;
protected set;
}

public TextEffectCollection TextEffects
{
get;
protected set;
}

#endregion
}
}
22 changes: 22 additions & 0 deletions ExpandRegions/ExpandRegions/Classifications/ClassifierProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.ComponentModel.Composition;

using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace ExpandRegions.Classifications
{
internal sealed class ClassifierProvider
{
#region Internal Fields

[Export]
[Name(Constants.ActiveRegionClassificationTypeNames)]
internal static ClassificationTypeDefinition ActiveRegionDefinition;

[Export]
[Name(Constants.InactiveRegionClassificationTypeNames)]
internal static ClassificationTypeDefinition InactiveRegionDefinition;

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.ComponentModel.Composition;
using System.Windows.Media;

using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace ExpandRegions.Classifications
{
[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = Constants.InactiveRegionClassificationTypeNames)]
[Name(Constants.InactiveRegionName)]
[DisplayName(Constants.InactiveRegionName)]
[UserVisible(true)]
[Order(After =Constants.OrderAfterPriority, Before = Constants.OrderBeforePriority)]
internal sealed class InactiveRegionClassification : ClassificationFormatDefinition
{
#region Initialization

// Methods
public InactiveRegionClassification()
{
ForegroundColor = Colors.Gray;
FontRenderingSize = 10;
ForegroundOpacity = 0.5;
}

#endregion
}
}
25 changes: 25 additions & 0 deletions ExpandRegions/ExpandRegions/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace ExpandRegions
{
internal static class Constants
{
#region Internal Fields

internal const char RegionIndicatorCharacter = '#';
internal const string RegionIndicator = "#region";

internal const string CSharpContentType = "CSharp";
internal const string BasicContentType = "Basic";

internal const string TextViewRole = "DOCUMENT";

internal const string ActiveRegionName = "Active Region";
internal const string InactiveRegionName = "Inactive Region";
internal const string ActiveRegionClassificationTypeNames = "activeRegion";
internal const string InactiveRegionClassificationTypeNames = "inactiveRegion";

internal const string OrderAfterPriority = "Default Priority";
internal const string OrderBeforePriority = "High Priority";

#endregion
}
}
12 changes: 12 additions & 0 deletions ExpandRegions/ExpandRegions/ExpandRegions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,29 @@
<HintPath>..\..\packages\Microsoft.VisualStudio.Text.UI.Wpf.15.0.26201\lib\net45\Microsoft.VisualStudio.Text.UI.Wpf.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Classifications\ClassifierProvider.cs" />
<Compile Include="Classifications\InactiveRegionClassification.cs" />
<Compile Include="Classifications\ActiveRegionClassification.cs" />
<Compile Include="Classifications\ClassificationFormatDefinition.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Tags\RegionTag.cs" />
<Compile Include="Tags\RegionTagger.cs" />
<Compile Include="Tags\RegionTaggerProvider.cs" />
<Compile Include="RegionTextViewHandler.cs" />
<Compile Include="TextViewCreationListener.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Loading

0 comments on commit c25b61c

Please sign in to comment.