Skip to content

Instantly share code, notes, and snippets.

@beachandbytes
Last active December 23, 2015 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beachandbytes/6619083 to your computer and use it in GitHub Desktop.
Save beachandbytes/6619083 to your computer and use it in GitHub Desktop.
Adds Toggle Line Numbers to Tools Menu I want to not add it to the toolbar instead of the tools menu.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.ComponentModel.Design;
using Microsoft.VisualStudio.Shell;
using EnvDTE;
using EnvDTE80;
namespace None.TLN
{
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[Guid(GuidList.guidTLNPkgString)]
public sealed class TLNPackage : Package
{
private DTE2 _applicationObject;
private bool _currentValue;
private List<string> _editorTypes;
protected override void Initialize()
{
_applicationObject = (DTE2)GetService(typeof(DTE));
_currentValue = (bool)_applicationObject.Properties[@"TextEditor", "Basic"].Item(@"ShowLineNumbers").Value;
_editorTypes = new List<string>{"PlainText","CSharp","HTML","C/C++","XML","CSS","Basic","CSS","FSharp","Javascript","Xaml"};
base.Initialize();
var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (null == mcs) return;
mcs.AddCommand(new MenuCommand(MenuItemCallback, new CommandID(GuidList.guidTLNCmdSet, (int)PkgCmdIDList.toggleLineNumbers)));
}
private void MenuItemCallback(object sender, EventArgs e)
{
for (var i = 0; i < _editorTypes.Count; i++)
{
_applicationObject.Properties[@"TextEditor", _editorTypes[i]].Item(@"ShowLineNumbers").Value = !_currentValue;
}
_currentValue = !_currentValue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment