File tree Expand file tree Collapse file tree
VisualStudioDiscordRPC.Shared Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,9 +5,11 @@ public static class LocalizationKeys
55 public const string Project = "project" ;
66 public const string File = "file" ;
77 public const string Solution = "solution" ;
8+ public const string Branch = "branch" ;
89
910 public const string NoActiveProject = "noActiveProject" ;
1011 public const string NoActiveFile = "noActiveFile" ;
1112 public const string NoActiveSolution = "noActiveSolution" ;
13+ public const string NoActiveBranch = "noActiveBranch" ;
1214 }
1315}
Original file line number Diff line number Diff line change 1+ using System ;
2+ using VisualStudioDiscordRPC . Shared . Observers ;
3+ using VisualStudioDiscordRPC . Shared . Services ;
4+
5+ namespace VisualStudioDiscordRPC . Shared . Plugs . TextPlugs
6+ {
7+ public class GitBranchTextPlug : BaseTextPlug
8+ {
9+ private readonly LocalizationService _localizationService ;
10+ private readonly GitObserver _gitObserver ;
11+
12+ private string _branchName ;
13+
14+ public GitBranchTextPlug ( GitObserver gitObserver , LocalizationService localizationService )
15+ {
16+ _gitObserver = gitObserver ;
17+ _localizationService = localizationService ;
18+
19+ _branchName = gitObserver . BranchName ;
20+ }
21+
22+ public override void Enable ( )
23+ {
24+ _gitObserver . BranchNameChanged += OnBranchNameChanged ;
25+ }
26+
27+ public override void Disable ( )
28+ {
29+ _gitObserver . BranchNameChanged -= OnBranchNameChanged ;
30+ }
31+
32+ private void OnBranchNameChanged ( string newBranchName )
33+ {
34+ _branchName = newBranchName ;
35+ Update ( ) ;
36+ }
37+
38+ protected override string GetData ( )
39+ {
40+ if ( string . IsNullOrEmpty ( _branchName ) )
41+ {
42+ return _localizationService . Localize ( LocalizationKeys . NoActiveBranch ) ;
43+ }
44+
45+ return $ "{ _localizationService . Localize ( LocalizationKeys . Branch ) } { _branchName } ";
46+ }
47+ }
48+ }
Original file line number Diff line number Diff line change @@ -157,13 +157,15 @@ private void LoadTextPlugs()
157157 private void LoadBuiltInTextPlugs ( )
158158 {
159159 var localizationService = ServiceRepository . Default . GetService < LocalizationService > ( ) ;
160+ var gitObserver = ServiceRepository . Default . GetService < GitObserver > ( ) ;
160161
161162 _plugs . AddRange ( new BaseTextPlug [ ]
162163 {
163164 new NoneTextPlug ( ) ,
164165 new FileNameTextPlug ( _vsObserver , localizationService ) ,
165166 new ProjectNameTextPlug ( _vsObserver , localizationService ) ,
166167 new SolutionNameTextPlug ( _vsObserver , localizationService ) ,
168+ new GitBranchTextPlug ( gitObserver , localizationService ) ,
167169 new VisualStudioVersionTextPlug ( _vsObserver . DTE )
168170 } ) ;
169171 }
Original file line number Diff line number Diff line change 2424 <Compile Include =" $(MSBuildThisFileDirectory)DiscordRpcController.cs" />
2525 <Compile Include =" $(MSBuildThisFileDirectory)IStringCollectionProvider.cs" />
2626 <Compile Include =" $(MSBuildThisFileDirectory)LocalizationKeys.cs" />
27+ <Compile Include =" $(MSBuildThisFileDirectory)Plugs\TextPlugs\GitBranchTextPlug.cs" />
2728 <Compile Include =" $(MSBuildThisFileDirectory)Utils\MigrationHelper.cs" />
2829 <Compile Include =" $(MSBuildThisFileDirectory)Utils\StringHelper.cs" />
2930 <Compile Include =" $(MSBuildThisFileDirectory)Variables\DebugModeVariable.cs" />
117118 </Compile >
118119 <Compile Include =" $(MSBuildThisFileDirectory)VisualStudioDiscordRPCPackage.cs" />
119120 </ItemGroup >
120- <ItemGroup >
121- <Folder Include =" $(MSBuildThisFileDirectory)Plugs\" />
122- </ItemGroup >
123121 <ItemGroup >
124122 <Page Include =" $(MSBuildThisFileDirectory)Views\CustomTextPlugsEditor.xaml" >
125123 <SubType >Designer</SubType >
You can’t perform that action at this time.
0 commit comments