Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CreateGUIDVSPlugin/CreateGUIDVSPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RenewGuidCommand.cs" />
<Compile Include="RenewGuidCurrentCommand.cs" />
<Compile Include="Utility\Configuration.cs" />
<Compile Include="Utility\FormatGuid.cs" />
<Compile Include="Utility\ProcessTemplate.cs" />
Expand All @@ -90,6 +91,7 @@
<Content Include="Resources\CopyGuidCommand.png" />
<Content Include="Resources\InsertGuidCommand.png" />
<Content Include="Resources\RenewGuidCommand.png" />
<Content Include="Resources\RenewGuidCurrentCommand.png" />
<Content Include="Resources\VSPackage.ico" />
<Content Include="stylesheet.css" />
<VSCTCompile Include="VSPackage.vsct">
Expand Down
146 changes: 146 additions & 0 deletions CreateGUIDVSPlugin/RenewGuidCurrentCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using System;
using System.ComponentModel.Design;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using CreateGUIDVSPlugin.Utility;

namespace CreateGUIDVSPlugin
{
/// <summary>
/// Command handler
/// </summary>
internal sealed class RenewGuidCurrentCommand
{
/// <summary>
/// Command ID.
/// </summary>
public const int CommandId = 4131;

/// <summary>
/// Command menu group (command set GUID).
/// </summary>
public static readonly Guid CommandSet = new Guid("21faf2f8-6789-4d5a-bda3-c063d68e1b7d");

/// <summary>
/// VS Package that provides this command, not null.
/// </summary>
private readonly VSPackage package;

/// <summary>
/// default command text
/// </summary>
private const string DefaultCommandText = "Renew Guid for current document";

/// <summary>
/// control whether an menu item is displayed or not.
/// </summary>
private void BeforeQueryStatus(object sender, EventArgs e)
{
OleMenuCommand command = sender as OleMenuCommand;
if (command != null)
{
var dte = this.package.GetDTE();
var activeDocument = dte.ActiveDocument;
if (activeDocument != null)
{
command.Enabled = true;
command.Text = DefaultCommandText;
}
else
{
command.Enabled = false;
command.Text = DefaultCommandText + " (activate document to enable this command)";
}
}
}

/// <summary>
/// Initializes a new instance of the <see cref="RenewGuidCurrentCommand"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
private RenewGuidCurrentCommand(VSPackage package)
{
if (package == null)
{
throw new ArgumentNullException("package");
}

this.package = package;

OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new OleMenuCommand(this.MenuItemCallback, menuCommandID);
menuItem.BeforeQueryStatus += this.BeforeQueryStatus;
commandService.AddCommand(menuItem);
}
}

/// <summary>
/// Gets the instance of the command.
/// </summary>
public static RenewGuidCurrentCommand Instance
{
get;
private set;
}

/// <summary>
/// Gets the service provider from the owner package.
/// </summary>
private IServiceProvider ServiceProvider
{
get
{
return this.package;
}
}

/// <summary>
/// Initializes the singleton instance of the command.
/// </summary>
/// <param name="package">Owner package, not null.</param>
public static void Initialize(VSPackage package)
{
Instance = new RenewGuidCurrentCommand(package);
}

/// <summary>
/// This function is the callback used to execute the command when the menu item is clicked.
/// See the constructor to see how the menu item is associated with this function using
/// OleMenuCommandService service and MenuCommand class.
/// </summary>
/// <param name="sender">Event sender.</param>
/// <param name="e">Event args.</param>
private void MenuItemCallback(object sender, EventArgs e)
{
var dte = this.package.GetDTE();
var activeDocument = dte.ActiveDocument;

if (activeDocument != null)
{
var textView = this.package.GetTextView();
if (textView != null)
{
if (textView.HasAggregateFocus)
{
var buffer = textView.TextBuffer;
var edit = buffer.CreateEdit();

var snapshot = buffer.CurrentSnapshot;
var replaceWithNewGuid = new ReplaceWithNewGuid();
var output = replaceWithNewGuid.ReplaceSameGuidToSameGuid(snapshot.GetText());

edit.Replace(0, buffer.CurrentSnapshot.Length, output);
edit.Apply();
}
}
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions CreateGUIDVSPlugin/VSPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ protected override void Initialize()
CopyGuidCommand.Initialize(this);
InsertGuidCommand.Initialize(this);
RenewGuidCommand.Initialize(this);
RenewGuidCurrentCommand.Initialize(this);

#if DEBUG
AddOutputWindow("Create GUID");
Expand Down
40 changes: 31 additions & 9 deletions CreateGUIDVSPlugin/VSPackage.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@
<ButtonText>Renew Guid</ButtonText>
</Strings>
</Button>
<Button guid="guidVSPackageCmdSet" id="cmdidRenewGuidCurrentCommand" priority="0x0100" type="Button">
<Parent guid="guidVSPackageCmdSet" id="MyMenuGroup" />
<Icon guid="guidImages3" id="bmpPic1" />
<CommandFlag>IconIsMoniker</CommandFlag>
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<CommandFlag>TextChanges</CommandFlag>
<Strings>
<ButtonText>Renew Guid in current docuemnt</ButtonText>
</Strings>
</Button>
</Buttons>

<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
Expand All @@ -97,6 +108,7 @@
<Bitmap guid="guidImages" href="Resources\CopyGuidCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
<Bitmap guid="guidImages1" href="Resources\InsertGuidCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
<Bitmap guid="guidImages2" href="Resources\RenewGuidCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
<Bitmap guid="guidImages3" href="Resources\RenewGuidCurrentCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough" />
</Bitmaps>
</Commands>

Expand Down Expand Up @@ -133,6 +145,7 @@
<IDSymbol name="CopyGuidCommandId" value="0x0100" />
<IDSymbol value="4129" name="cmdidInsertGuidCommand" />
<IDSymbol value="4130" name="cmdidRenewGuidCommand" />
<IDSymbol value="4131" name="cmdidRenewGuidCurrentCommand" />
</GuidSymbol>

<GuidSymbol name="guidImages" value="{7ab86d3e-1142-4cbd-a3b5-72d3b744ec50}">
Expand All @@ -152,6 +165,24 @@
<IDSymbol name="bmpPicArrows" value="5" />
<IDSymbol name="bmpPicStrikethrough" value="6" />
</GuidSymbol>

<GuidSymbol value="{7e549cd1-1a8b-424c-93d4-b6e16a8912b5}" name="guidImages2">
<IDSymbol name="bmpPic1" value="1" />
<IDSymbol name="bmpPic2" value="2" />
<IDSymbol name="bmpPicSearch" value="3" />
<IDSymbol name="bmpPicX" value="4" />
<IDSymbol name="bmpPicArrows" value="5" />
<IDSymbol name="bmpPicStrikethrough" value="6" />
</GuidSymbol>

<GuidSymbol value="{ba788c3f-281f-4450-8428-7bf39b53619c}" name="guidImages3">
<IDSymbol name="bmpPic1" value="1" />
<IDSymbol name="bmpPic2" value="2" />
<IDSymbol name="bmpPicSearch" value="3" />
<IDSymbol name="bmpPicX" value="4" />
<IDSymbol name="bmpPicArrows" value="5" />
<IDSymbol name="bmpPicStrikethrough" value="6" />
</GuidSymbol>

<!-- GUID and ID for not defined Visual Studio SDK -->

Expand All @@ -169,14 +200,5 @@
<GuidSymbol name="guidJSONDocumentContextMenu" value="{f718ca06-cf4f-4a0c-9106-e79e9ee5e7cd}">
<IDSymbol name="idJSONContextMenu" value="0x3" />
</GuidSymbol>

<GuidSymbol value="{7e549cd1-1a8b-424c-93d4-b6e16a8912b5}" name="guidImages2">
<IDSymbol name="bmpPic1" value="1" />
<IDSymbol name="bmpPic2" value="2" />
<IDSymbol name="bmpPicSearch" value="3" />
<IDSymbol name="bmpPicX" value="4" />
<IDSymbol name="bmpPicArrows" value="5" />
<IDSymbol name="bmpPicStrikethrough" value="6" />
</GuidSymbol>
</Symbols>
</CommandTable>