Skip to content

Commit

Permalink
feat: Add TGit's menus to the file tab context menu and the file cont…
Browse files Browse the repository at this point in the history
…ent menu in solution explorer #65
  • Loading branch information
Samir Boulema committed Nov 25, 2021
1 parent 83535ee commit bea5957
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- 'feature/**'

env:
version: '5.1.${{ github.run_number }}'
version: '5.2.${{ github.run_number }}'
repoUrl: ${{ github.server_url }}/${{ github.repository }}

jobs:
Expand Down
40 changes: 33 additions & 7 deletions TGit/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ namespace SamirBoulema.TGit.Helpers
public static class FileHelper
{
public static string GetTortoiseGitProc()
{
return (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\TortoiseGit", "ProcPath", @"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe");
}
=> (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\TortoiseGit",
"ProcPath", @"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe");

public static string GetTortoiseGitPlink()
{
return (string)Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\TortoiseGit", "ProcPath", @"C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe");
}
=> (string)Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\TortoiseGit",
"ProcPath", @"C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe");

public static string GetMSysGit()
{
var regPath = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\TortoiseGit", "MSysGit", @"C:\Program Files (x86)\Git\bin\git.exe");
var regPath = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\TortoiseGit",
"MSysGit", @"C:\Program Files (x86)\Git\bin\git.exe");
return Path.Combine(regPath, "git.exe");
}

Expand Down Expand Up @@ -146,8 +145,35 @@ public static string GetExactPathName(string pathName)
return di.Name.ToUpper();
}

/// <summary>
/// Get the path of the file on which to act upon.
/// This can be different depending on where the TGit context menu was used
/// </summary>
/// <returns>File path</returns>
public static async Task<string> GetActiveDocumentFilePath()
{
var windowFrame = await VS.Windows.GetCurrentWindowAsync();
var solutionExplorerIsActive = windowFrame.Guid == new Guid(WindowGuids.SolutionExplorer);

// Context menu in the Solution Explorer
if (solutionExplorerIsActive)
{
var selectedItem = await VS.Solutions.GetActiveItemAsync();

if (selectedItem != null)
{
if (selectedItem.Type == SolutionItemType.Project ||
selectedItem.Type == SolutionItemType.Solution)
{
return Path.GetDirectoryName(selectedItem.FullPath);
}
else if (selectedItem.Type == SolutionItemType.PhysicalFile)
{
return selectedItem.FullPath;
}
}
}

var documentView = await VS.Documents.GetActiveDocumentViewAsync();
return documentView?.FilePath;
}
Expand Down
35 changes: 35 additions & 0 deletions TGit/TGIT.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@
<ButtonText>TGit</ButtonText>
</Strings>
</Menu>

<!--Solution Explorer Context Menu-->
<Menu guid="guidTGitCmdSet" id="TGitContextMenu" priority="0x0200" type="Menu">
<Parent guid="VSMainMenu" id="SolutionNode.SourceControlGroup" />
<Strings>
<ButtonText>TGit</ButtonText>
</Strings>
</Menu>
<Menu guid="guidTGitCmdSet" id="TGitContextMenu" priority="0x0200" type="Menu">
<Parent guid="VSMainMenu" id="ProjectNode.SourceControlGroup" />
<Strings>
<ButtonText>TGit</ButtonText>
</Strings>
</Menu>
<Menu guid="guidTGitCmdSet" id="TGitContextMenu" priority="0x0200" type="Menu">
<Parent guid="VSMainMenu" id="Node.SourceControlGroup" />
<Strings>
<ButtonText>TGit</ButtonText>
</Strings>
</Menu>

<!--GitFlow Menu-->
<Menu guid="guidTGitCmdSet" id="TGitGitFlowMenu" priority="0x0100" type="Menu">
Expand Down Expand Up @@ -144,6 +164,16 @@
<Group guid="guidTGitCmdSet" id="sixthMenuGroup" priority="0x0600">
<Parent guid="guidTGitCmdSet" id="Toolbar"/>
</Group>

<!--Solution Explorer - Folder View - Context Menu-->
<Group guid="guidTGitCmdSet" id="contextMenuGroup" priority="0x0200">
<Parent guid="guidWorkspaceExplorerToolWindowCmdSet" id="idmWSE_ContextMenu" />
</Group>

<!--Solution Explorer - Folder View - Context Menu-->
<Group guid="guidTGitCmdSet" id="contextMenuGroup" priority="0x0600">
<Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_EZDOCWINTAB" />
</Group>
</Groups>

<Buttons>
Expand Down Expand Up @@ -585,6 +615,11 @@
<IDSymbol name="add" value="25" />
</GuidSymbol>

<!-- Solution Explorer folder mode GUIDs and IDs. -->
<GuidSymbol name="guidWorkspaceExplorerToolWindowCmdSet" value="{cfb400f1-5c60-4f3c-856e-180d28def0b7}">
<IDSymbol name="idmWSE_ContextMenu" value="0x0002" />
</GuidSymbol>

<!--Special Context Menus-->
<GuidSymbol name="HTMLContext" value="{78F03954-2FB8-4087-8CE7-59D71710B3BB}">
<IDSymbol name="HTMLContextMenu" value="0x0001"/>
Expand Down
4 changes: 4 additions & 0 deletions TGit/TGit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ internal sealed partial class PackageGuids
public const string guidImagesString = "fec49b6d-c04a-42bd-b021-b8b2e5cfb291";
public static Guid guidImages = new Guid(guidImagesString);

public const string guidWorkspaceExplorerToolWindowCmdSetString = "cfb400f1-5c60-4f3c-856e-180d28def0b7";
public static Guid guidWorkspaceExplorerToolWindowCmdSet = new Guid(guidWorkspaceExplorerToolWindowCmdSetString);

public const string HTMLContextString = "78f03954-2fb8-4087-8ce7-59d71710b3bb";
public static Guid HTMLContext = new Guid(HTMLContextString);

Expand Down Expand Up @@ -60,6 +63,7 @@ internal sealed partial class PackageIds
public const int revgraph = 0x0017;
public const int config = 0x0018;
public const int add = 0x0019;
public const int idmWSE_ContextMenu = 0x0002;
public const int HTMLContextMenu = 0x0001;
public const int CSSContextMenu = 0x0002;
public const int ASPXContextMenu = 0x0035;
Expand Down
6 changes: 3 additions & 3 deletions TGit/TGit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,16 @@
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Community.VisualStudio.Toolkit">
<Version>15.0.76.304</Version>
<PackageReference Include="Community.VisualStudio.Toolkit.15">
<Version>15.0.339</Version>
</PackageReference>
<PackageReference Include="Community.VisualStudio.VSCT">
<Version>16.0.29.6</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools">
<Version>17.0.4207-preview4</Version>
<Version>17.0.5232</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit bea5957

Please sign in to comment.