Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit e4c8162

Browse files
committed
Stub of "Get Link" feature
Quick stub of the VS file apis required for a potential "Get Link" feature - gets the current file name and line number to build a github url of it for sharing.
1 parent d9a1a90 commit e4c8162

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<Compile Include="Helpers\NotificationAwareObject.cs" />
112112
<Compile Include="Services\Connection.cs" />
113113
<Compile Include="Services\GitService.cs" />
114+
<Compile Include="Services\IActiveDocument.cs" />
114115
<Compile Include="Services\IGitService.cs" />
115116
<Compile Include="Services\ITeamExplorerServiceHolder.cs" />
116117
<Compile Include="Services\Logger.cs" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace GitHub.VisualStudio
2+
{
3+
public interface IActiveDocument
4+
{
5+
string Name { get; }
6+
int Line { get; }
7+
}
8+
}

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
<Compile Include="Helpers\Browser.cs" />
223223
<Compile Include="Helpers\Colors.cs" />
224224
<Compile Include="Helpers\Constants.cs" />
225+
<Compile Include="Services\ActiveDocument.cs" />
225226
<Compile Include="Services\ConnectionManager.cs" />
226227
<Compile Include="Services\Program.cs" />
227228
<Compile Include="Services\SharedResources.cs" />

src/GitHub.VisualStudio/GitHub.VisualStudio.vsct

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@
119119
<ButtonText></ButtonText>
120120
</Strings>
121121
</Button>
122+
123+
<Button guid="guidContextMenuSet" id="getLinkCommand" priority="0x0100" type="Button">
124+
<Parent guid="guidContextMenuSet" id="idContextMenuGroup"/>
125+
<Strings>
126+
<ButtonText>Get Link</ButtonText>
127+
</Strings>
128+
</Button>
129+
122130
</Buttons>
123131

124132
</Commands>
@@ -178,6 +186,7 @@
178186

179187
<GuidSymbol name="guidContextMenuSet" value="{31057D08-8C3C-4C5B-9F91-8682EA08EC27}">
180188
<IDSymbol name="idContextMenuGroup" value="0x1010" />
189+
<IDSymbol name="getLinkCommand" value="0x100" />
181190
</GuidSymbol>
182191

183192
<GuidSymbol name="GUID_XAML_EDITOR" value="{4C87B692-1202-46AA-B64C-EF01FAEC53DA}">

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public GitHubPackage(IServiceProvider serviceProvider)
4545

4646
}
4747

48+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions")]
49+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals")]
4850
protected override void Initialize()
4951
{
5052

@@ -58,6 +60,15 @@ protected override void Initialize()
5860
var windowFrame = (IVsWindowFrame)window.Frame;
5961
ErrorHandler.ThrowOnFailure(windowFrame.Show());
6062
});
63+
64+
ServiceProvider.AddTopLevelMenuItem(GuidList.guidContextMenuSet, PkgCmdIDList.getLinkCommand, (s, e) =>
65+
{
66+
var ap = ServiceProvider.GetExportedValue<IActiveDocument>();
67+
var name = ap.Name;
68+
var line = ap.Line;
69+
System.Windows.Forms.MessageBox.Show(name + " : " + line);
70+
71+
});
6172
base.Initialize();
6273
}
6374

src/GitHub.VisualStudio/PkgCmdID.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ static class PkgCmdIDList
1111
public const int forwardCommand = 0x301;
1212
public const int refreshCommand = 0x302;
1313
public const int pullRequestCommand = 0x310;
14+
public const int getLinkCommand = 0x100;
1415
};
1516
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Microsoft.VisualStudio;
2+
using Microsoft.VisualStudio.Shell;
3+
using Microsoft.VisualStudio.TextManager.Interop;
4+
using System;
5+
using System.ComponentModel.Composition;
6+
using System.Diagnostics;
7+
8+
namespace GitHub.VisualStudio
9+
{
10+
[Export(typeof(IActiveDocument))]
11+
[PartCreationPolicy(CreationPolicy.NonShared)]
12+
class ActiveDocument : IActiveDocument
13+
{
14+
public string Name { get; private set; }
15+
public int Line { get; private set; }
16+
public int Column { get; private set; }
17+
18+
[ImportingConstructor]
19+
public ActiveDocument([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
20+
{
21+
Line = Column = -1;
22+
Name = Services.Dte2?.ActiveDocument?.FullName;
23+
var textManager = serviceProvider.GetService(typeof(SVsTextManager)) as IVsTextManager;
24+
Debug.Assert(textManager != null, "No SVsTextManager service available");
25+
if (textManager == null)
26+
return;
27+
IVsTextView view;
28+
int line, col;
29+
if (ErrorHandler.Succeeded(textManager.GetActiveView(0, null, out view)) &&
30+
ErrorHandler.Succeeded(view.GetCaretPos(out line, out col)))
31+
{
32+
Line = line;
33+
Column = col;
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)