Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 073b960

Browse files
authored
Merge pull request #86 from rionmonster/library-toggle
Glyphfriend 2.1 Release
2 parents 40320e2 + 8c7dea3 commit 073b960

File tree

3,239 files changed

+926
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,239 files changed

+926
-149
lines changed

Glyphfriend.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26020.0
4+
VisualStudioVersion = 15.0.26206.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Glyphfriend.Core", "src\Glyphfriend.Core\Glyphfriend.Core.shproj", "{8189A63E-D159-4195-BE2E-D44B022B45AB}"
77
EndProject

README.md

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,28 @@ Glyphfriend is a Visual Studio extension to enhance the existing Intellisense to
1818

1919
## Getting Started
2020

21-
Glyphfriend has a separate extension for both Visual Studio 2015 and Visual Studio 2017, so to get started, you'll simply need to download the version(s) that apply to you from the Visual Studio Marketplace :
21+
Glyphfriend has a separate extension for both Visual Studio 2015 and Visual Studio 2017, so to get started, you'll simply need to download the version(s) that apply to you from the Visual Studio Marketplace:
2222

2323
* [Download Glyphfriend 2015](https://marketplace.visualstudio.com/items?itemName=RionWilliams.Glyphfriend)
2424
* [Download Glyphfriend 2017](https://marketplace.visualstudio.com/items?itemName=RionWilliams.Glyphfriend2017)
2525

2626
You can also just search for it within the **Tools > Extensions and Updates** area of Visual Studio.
2727

28-
After installing the extension, that's it. Glyphfriend will automatically detect when a valid HTML flavored file is opened and it will add all of the supported icons to the autocompletion within `class` attributes as seen below :
28+
After installing the extension, that's it. Glyphfriend will automatically detect when a valid HTML flavored file is opened and it will add all of the supported icons to the autocompletion within `class` attributes as seen below:
2929

3030
![Glyphfriend in Action](https://raw.githubusercontent.com/rionmonster/Glyphfriend/develop/art/glyphfriend-in-action.gif)
3131

32+
## Setting Preferences
33+
34+
By default, Glyphfriend has support for Bootstrap Glyphicons enabled by default, however you can easily select the libraries that you prefer to use by simply **right-clicking and selecting the preferred library from the Glyphfriend context menu in any HTML-supported file** as seen below:
35+
36+
![Glyphfriend Library Toggling](https://raw.githubusercontent.com/rionmonster/Glyphfriend/develop/art/glyphfriend-toggling-support.gif)
37+
38+
It's important to note that **library preferences are persistent across Visual Studio sessions.** Basically, you will only need to define which libraries that you want to use and they will be available the next time you open Visual Studio.
39+
3240
## What's In Here?
3341

34-
Within this repository you'll find all of the necessary projects that make Glyphfriend work, which can be described below :
42+
Within this repository you'll find all of the necessary projects that make Glyphfriend work, which can be described below:
3543

3644
* **[Glyphfriend.Core](https://github.com/rionmonster/Glyphfriend/tree/develop/src/Glyphfriend.Core)** - This project is a Shared Library that contains all of the necessary code for the extension to work. Namely the autocompletion providers and the necessary code to handle deserializing the glyphs at run-time.
3745
* **[Glyphfriend.Packager](https://github.com/rionmonster/Glyphfriend/tree/develop/src/Glyphfriend.Packager)** - This project functions as a build-time dependency for the two extension projects and handles generating a binary file containing all of the glyph mappings (via Protobuf), which is consumed and deserialized within the Glyphfriend.Core package.
@@ -42,9 +50,11 @@ Within this repository you'll find all of the necessary projects that make Glyph
4250

4351
If you find an issue or encounter a problem with the extension, please don't hesitate to contact me or file an issue with the [Issues](https://github.com/Rionmonster/Glyphfriend/issues) are of this repository and I'll try to address it as soon as possible.
4452

45-
**If you use Resharper, then Glyphfriend may not work properly (or at all)**. This is a known issue and is outside of my control as many of the APIs that Glyphfriend relies on are overridden by Resharper and thus don't allow the extension to ever be accessed by Visual Studio directly.
53+
> **NOTE: If you use Resharper, then Glyphfriend may not work properly (or at all), so read this**.
54+
55+
Issues with Resharper and Glyphfriend have been widely reported (enough to warrant a spot here) and are outside of my control. Many of the APIs that Glyphfriend relies on are overridden by Resharper and thus don't allow the extension to ever be accessed by Visual Studio directly.
4656

47-
The following two options have been successful with other Resharper users, so I would highly recommend trying either of them :
57+
The following two options have been successful with other Resharper users, so I would highly recommend trying either of them:
4858

4959
* **Try disabling any HTML features within Resharper** - By disabling the HTML autocompletion and other features, this should hopefully allow for Glyphfriend to hook into the necessary APIs and work as expected.
5060
* **Consider downloading the [ResharperGlyphfriend Plug-in](https://github.com/Huntk23/ResharperGlyphfriend)** - A member of the community, [Kelby Hunt (Huntk23)](https://github.com/Huntk23) wrote a Resharper plug-in port of Glyphfriend, which attempts to implement much of the functionality of this extension. Consider downloading it if the previous approach didn't work as expected.
@@ -58,10 +68,12 @@ just clone this repository, make a fork and add your changes (and then just make
5868

5969
## Thanks
6070

61-
There are a few folks that I would like to give a special shout-out to several members of the Visual Studio Tooling team for the help and guidance in developing this project, and espeically during the migration over to Visual Studio 2017 :
71+
I would like to give a special shout-out to several members of the community, including a few from the Visual Studio Tooling team, for their assistance in evolving, developing, and testing Glyphfriend:
6272

63-
* **[Mads Kristensen](https://github.com/madskristensen)**
64-
* **[Alex Eyler](https://github.com/AlexEyler)**
6573
* **[Justin Clarebert](https://github.com/justcla)**
74+
* **[Alex Eyler](https://github.com/AlexEyler)**
75+
* **[Mads Kristensen](https://github.com/madskristensen)**
76+
* **[Allen Underwood](http://www.codingblocks.net/about#joezack)**
77+
* **[Joe Zack](http://www.codingblocks.net/about#joezack)**
6678

67-
Additionally, I want to thank everyone for their feedback on the extension, new feature ideas, and all of the folks that don't hesitate to shoot an e-mail my way regarding the project.
79+
Additionally, I want to thank everyone for their feedback on the extension, new feature ideas, and all of the folks that don't hesitate to shoot an e-mail my way regarding the project.

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 2.0.1.{build}
1+
version: 2.1.0.{build}
22
configuration: Release
33
image: Visual Studio 2017 RC
44
branches:
2.12 MB
Loading
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Microsoft.VisualStudio.Shell;
2+
using System;
3+
using System.ComponentModel.Design;
4+
5+
namespace Glyphfriend
6+
{
7+
internal sealed class ToggleLibraryCommand
8+
{
9+
public static ToggleLibraryCommand Instance { get; private set; }
10+
11+
private readonly Package _package;
12+
private IServiceProvider ServiceProvider => _package;
13+
14+
public static void Initialize(Package package)
15+
{
16+
Instance = new ToggleLibraryCommand(package);
17+
}
18+
19+
private ToggleLibraryCommand(Package package)
20+
{
21+
_package = package;
22+
23+
var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
24+
if (commandService != null)
25+
{
26+
foreach (var library in Constants.Libraries.Keys)
27+
{
28+
var command = CreateCommand(Constants.ToggleLibraryCommandSet, library);
29+
commandService.AddCommand(command);
30+
}
31+
}
32+
}
33+
34+
private MenuCommand CreateCommand(Guid commandSet, int commandId)
35+
{
36+
var library = Constants.Libraries[commandId];
37+
// Generate the command that will map this particular library to the appropriate button within the
38+
// .vsct file
39+
return new MenuCommand(ToggleLibrary, new CommandID(commandSet, commandId)) { Checked = library.Enabled };
40+
}
41+
42+
private void ToggleLibrary(object sender, EventArgs e)
43+
{
44+
var command = (MenuCommand)sender;
45+
command.Checked = !command.Checked;
46+
GlyphfriendPreferences.ToggleLibrary(command.CommandID.ID, command.Checked);
47+
}
48+
}
49+
}

src/Glyphfriend.Core/Completion/BaseClassCompletionListProvider.cs renamed to src/Glyphfriend.Core/Completion/BaseCompletionListProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Glyphfriend
88
{
9-
abstract class BaseClassCompletionProvider : IHtmlCompletionListProvider
9+
internal abstract class BaseHtmlCompletionListProvider : IHtmlCompletionListProvider
1010
{
1111
public abstract string CompletionType { get; }
1212

@@ -17,4 +17,4 @@ protected HtmlCompletion CreateItem(string name, ImageSource icon, ICompletionSe
1717
return new HtmlCompletion(name, name, name, icon, null, session);
1818
}
1919
}
20-
}
20+
}

src/Glyphfriend.Core/Completion/GlyphClassCompletionListProvider.cs renamed to src/Glyphfriend.Core/Completion/GlyphCompletionListProvider.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,44 @@
1-
using Glyphfriend.Extensions;
2-
using Microsoft.Html.Editor.Completion;
1+
using Microsoft.Html.Editor.Completion;
32
using Microsoft.Html.Editor.Completion.Def;
4-
using Microsoft.VisualStudio;
53
using Microsoft.VisualStudio.Shell;
64
using Microsoft.VisualStudio.Shell.Interop;
75
using Microsoft.VisualStudio.Utilities;
86
using System.Collections.Generic;
97
using System.ComponentModel.Composition;
8+
using System.Linq;
109

1110
namespace Glyphfriend
1211
{
1312
[HtmlCompletionProvider(CompletionTypes.Values, "*", "class")]
1413
[ContentType("htmlx")]
15-
class GlyphClassCompletionListProvider : BaseClassCompletionProvider
14+
internal class GlyphCompletionListProvider : BaseHtmlCompletionListProvider
1615
{
1716
[Import]
18-
protected SVsServiceProvider GlobalServiceProvider { get; private set; }
19-
public override string CompletionType => CompletionTypes.Values;
17+
protected SVsServiceProvider GlobalServiceProvider { get; private set; }
18+
19+
public override string CompletionType { get { return CompletionTypes.Values; } }
2020

2121
public override IList<HtmlCompletion> GetEntries(HtmlCompletionContext context)
2222
{
2323
VSPackage package = (VSPackage)EnsurePackageLoaded();
24-
if(package == null)
24+
if (package == null)
2525
{
26+
Logger.Log("Package failed to load properly!");
2627
return new List<HtmlCompletion>();
2728
}
28-
2929
var glyphCompletionItems = new List<HtmlCompletion>();
30-
foreach (var glyph in package.Glyphs)
30+
// Get the filtered set of enabled glyphs
31+
var enabledGlyphs = package.Glyphs.Where(g => g.Enabled);
32+
foreach (var glyph in enabledGlyphs)
3133
{
32-
glyphCompletionItems.Add(CreateItem(glyph.Key, glyph.Value, context.Session));
34+
glyphCompletionItems.Add(CreateItem(glyph.Name, glyph.Image, context.Session));
3335
}
3436
return glyphCompletionItems;
3537
}
3638

3739
private IVsPackage EnsurePackageLoaded()
3840
{
39-
IVsPackage package;
40-
// If the package failed to load or is null, explicitly load it
41-
if (!ErrorHandler.Succeeded(GlobalServiceProvider.GetShell().IsPackageLoaded(Constants.PackageGuid, out package)) || package == null)
42-
{
43-
package = GlobalServiceProvider.GetShell().LoadPackage<VSPackage>();
44-
}
45-
return package;
41+
return GlobalServiceProvider.GetShell().LoadPackage<VSPackage>();
4642
}
4743
}
4844
}

src/Glyphfriend.Core/Constants.cs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,50 @@
11
using System;
2+
using System.Collections.Generic;
23

34
namespace Glyphfriend
45
{
5-
class Constants
6+
internal class Constants
67
{
8+
/// <summary>
9+
/// These settings are specific to Glyphfriend itself and its associated commands
10+
/// </summary>
11+
public const string UserSettingsLibrary = "GlyphfriendLibraries";
12+
713
public const string HtmlFileLoadedContext = "21F5568E-A5DE-4821-AF39-F4F1049BB9CF";
814
public static readonly Guid PackageGuid = new Guid("21F5568E-A5DE-4821-AF39-F4F1049BB9CF");
15+
public static readonly Guid ToggleLibraryCommandSet = new Guid("faf962bd-d32b-4c73-a5d3-fcdf95277a21");
16+
17+
/// <summary>
18+
/// These commands are associated with the items found within the VSCT files and handles configuring
19+
/// the menu items that appear. Thus any new libraries will need to have key defined here and
20+
/// a button set within the VSCT file as well.
21+
/// </summary>
22+
public const int ToggleLibraryCommandId = 0x0100;
23+
24+
public const int ToggleBootstrapCommand = 0x1101;
25+
public const int ToggleEntypoCommand = 0x1102;
26+
public const int ToggleFontAwesomeCommand = 0x1103;
27+
public const int ToggleFoundationCommand = 0x1104;
28+
public const int ToggleIonicCommand = 0x1105;
29+
public const int ToggleMaterialDesignCommand = 0x1106;
30+
public const int ToggleMetroUiCommand = 0x1107;
31+
public const int ToggleOcticonsCommand = 0x1108;
32+
// public const int ToggleYourLibraryHereCommand = 0x1109;
33+
34+
/// <summary>
35+
/// These are all of the supported libraries in Glyphfriend along with their associated default
36+
/// values (i.e. only Bootstrap is enabled by default).
37+
/// </summary>
38+
public static readonly Dictionary<int, GlyphLibrary> Libraries = new Dictionary<int, GlyphLibrary>(){
39+
{ ToggleBootstrapCommand, new GlyphLibrary("Bootstrap", true) },
40+
{ ToggleEntypoCommand, new GlyphLibrary("Entypo", false) },
41+
{ ToggleFontAwesomeCommand, new GlyphLibrary("Font Awesome", false) },
42+
{ ToggleFoundationCommand, new GlyphLibrary("Foundation", false) },
43+
{ ToggleIonicCommand, new GlyphLibrary("Ionic", false) },
44+
{ ToggleMaterialDesignCommand, new GlyphLibrary("Material Design", false) },
45+
{ ToggleMetroUiCommand, new GlyphLibrary("Metro UI", false) },
46+
{ ToggleOcticonsCommand, new GlyphLibrary("Octicons", false) },
47+
// { ToggleYourLibraryHereCommand, new GlyphLibrary("Your Library", false) }
48+
};
949
}
10-
}
50+
}

src/Glyphfriend.Core/Extensions/ServiceProviderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Microsoft.VisualStudio.Shell.Interop;
44
using System;
55

6-
namespace Glyphfriend.Extensions
6+
namespace Glyphfriend
77
{
88
public static class ServiceProviderExtensions
99
{
@@ -25,4 +25,4 @@ public static T LoadPackage<T>(this IVsShell shell) where T : Package
2525
return (T)package;
2626
}
2727
}
28-
}
28+
}

src/Glyphfriend.Core/Glyph.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using ProtoBuf;
2+
using System.IO;
3+
using System.Windows.Media;
4+
using System.Windows.Media.Imaging;
5+
6+
namespace Glyphfriend
7+
{
8+
/// <summary>
9+
/// This class presents a single Glyph image and contains various informatio about it,
10+
/// its image contents, and a method to handle generating a usable ImageSource with
11+
/// the contents after it has been deserialized.
12+
/// </summary>
13+
[ProtoContract]
14+
internal class Glyph
15+
{
16+
[ProtoMember(1)]
17+
public string Name { get; private set; }
18+
19+
[ProtoMember(2)]
20+
public string Library { get; private set; }
21+
22+
[ProtoMember(3)]
23+
public byte[] ImageContent { get; private set; }
24+
25+
[ProtoIgnore]
26+
public bool Enabled { get; set; }
27+
28+
[ProtoIgnore]
29+
public ImageSource Image { get; set; }
30+
31+
public Glyph()
32+
{
33+
}
34+
35+
public Glyph(string name, string library, byte[] imageContent)
36+
{
37+
Name = name;
38+
Library = library;
39+
ImageContent = imageContent;
40+
}
41+
42+
public void GenerateImage()
43+
{
44+
var image = new BitmapImage();
45+
using (var ms = new MemoryStream(ImageContent))
46+
{
47+
image.BeginInit();
48+
image.StreamSource = ms;
49+
// This is required for images to be loaded by Visual Studio on-demand
50+
image.CacheOption = BitmapCacheOption.OnLoad;
51+
image.EndInit();
52+
}
53+
Image = image as ImageSource;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)