Skip to content

Commit 5a1c77e

Browse files
committed
add init repo to the context menu
1 parent d3db053 commit 5a1c77e

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

BasicSccProvider.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace GitScc
3131
[MsVsShell.ProvideOptionPageAttribute(typeof(SccProviderOptions), "Source Control", "Git Source Control Provider Options", 106, 107, false)]
3232
[ProvideToolsOptionsPageVisibility("Source Control", "Git Source Control Provider Options", "C4128D99-0000-41D1-A6C3-704E6C1A3DE2")]
3333
// Register a sample tool window visible only when the provider is active
34-
[MsVsShell.ProvideToolWindow(typeof(SccProviderToolWindow), Style = VsDockStyle.Linked, Orientation = ToolWindowOrientation.Bottom)]
34+
[MsVsShell.ProvideToolWindow(typeof(SccProviderToolWindow), Style = VsDockStyle.Tabbed, Orientation = ToolWindowOrientation.Bottom)]
3535
[MsVsShell.ProvideToolWindowVisibility(typeof(SccProviderToolWindow), "C4128D99-0000-41D1-A6C3-704E6C1A3DE2")]
3636
// Register the source control provider's service (implementing IVsScciProvider interface)
3737
[MsVsShell.ProvideService(typeof(SccProviderService), ServiceName = "Git Source Control Service")]
@@ -91,6 +91,10 @@ protected override void Initialize()
9191
menu = new MenuCommand(new EventHandler(Exec_icmdViewToolWindow), cmd);
9292
mcs.AddCommand(menu);
9393

94+
cmd = new CommandID(GuidList.guidSccProviderCmdSet, CommandId.icmdSccCommandInit);
95+
menu = new MenuCommand(new EventHandler(OnInitCommand), cmd);
96+
mcs.AddCommand(menu);
97+
9498
}
9599

96100
// Register the provider with the source control manager
@@ -153,7 +157,7 @@ int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] p
153157
cmdf |= OLECMDF.OLECMDF_ENABLED;
154158
}
155159
break;
156-
160+
157161
case CommandId.icmdSccCommandUndo:
158162
case CommandId.icmdSccCommandCompare:
159163
if (sccService.CanCompareSelectedFile) cmdf |= OLECMDF.OLECMDF_ENABLED;
@@ -163,13 +167,20 @@ int IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] p
163167
if (sccService.IsSolutionGitControlled) cmdf |= OLECMDF.OLECMDF_ENABLED;
164168
break;
165169

170+
case CommandId.icmdSccCommandInit:
171+
if (!sccService.IsSolutionGitControlled)
172+
cmdf |= OLECMDF.OLECMDF_ENABLED;
173+
else
174+
cmdf |= OLECMDF.OLECMDF_INVISIBLE;
175+
break;
176+
166177
default:
167178
cmdf |= OLECMDF.OLECMDF_ENABLED;
168179
break;
169180
}
170181

171182

172-
prgCmds[0].cmdf = (uint) (cmdf);
183+
prgCmds[0].cmdf = (uint)(cmdf);
173184
return VSConstants.S_OK;
174185
}
175186

@@ -237,6 +248,10 @@ private void Exec_icmdViewToolWindow(object sender, EventArgs e)
237248
}
238249
}
239250

251+
private void OnInitCommand(object sender, EventArgs e)
252+
{
253+
sccService.InitRepo();
254+
}
240255
#endregion
241256

242257
// This function is called by the IVsSccProvider service implementation when the active state of the provider changes
@@ -294,7 +309,7 @@ internal void RunDetatched(string cmd, string arguments)
294309

295310
process.Start();
296311
}
297-
}
312+
}
298313
#endregion
299314

300315
}

GitFileStatusTracker.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ public string CurrentBranch
117117
return this.HasGitRepository ? this.repositoryStatus.Repository.CurrentBranch.Name : "";
118118
}
119119
}
120+
121+
internal void Init()
122+
{
123+
if (!this.HasGitRepository)
124+
{
125+
Repository.Init(this.workingFolder);
126+
}
127+
}
120128
}
121129

122130
public static class HashSetExt

PkgCmd.vsct

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@
7777
</Strings>
7878
</Button>
7979

80+
<Button guid="guidSccProviderCmdSet" id="icmdSccCommandInit" priority="0x0000" type="Button">
81+
<Parent guid="guidSccProviderCmdSet" id="igrpSourceControlCommands"/>
82+
<!--<Icon guid="guidSccProviderImages" id="iconRefresh" /-->
83+
<CommandFlag>DynamicVisibility</CommandFlag>
84+
<CommandFlag>DefaultInvisible</CommandFlag>
85+
<!--<CommandFlag>IconAndText</CommandFlag>-->
86+
<Strings>
87+
<ButtonText>Init Repository</ButtonText>
88+
</Strings>
89+
</Button>
90+
8091
</Buttons>
8192
<Bitmaps>
8293
<Bitmap guid="guidSccProviderImages" href="Resources\Images_32bit.bmp" usedList="iconGitBash, iconGitExt, iconUncheckout, iconCompare, iconRefresh"/>

SccProviderService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,5 +796,14 @@ public bool IsSolutionGitControlled
796796
return _statusTracker.HasGitRepository;
797797
}
798798
}
799+
800+
internal void InitRepo()
801+
{
802+
if (MessageBox.Show("Are you sure you want to create a local repository for this solution?",
803+
"Init Repository", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
804+
{
805+
_statusTracker.Init();
806+
}
807+
}
799808
}
800809
}

0 commit comments

Comments
 (0)