Skip to content

Commit 278fcae

Browse files
committed
Adds support for a button to explicitly set the robot project
1 parent 2f7b0a6 commit 278fcae

File tree

3 files changed

+123
-4
lines changed

3 files changed

+123
-4
lines changed

FRC-Extension/Buttons/DeployDebugButton.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ public override void QueryCallback(object sender, EventArgs e)
125125
{
126126
if (project.Globals.VariableExists["RobotProject"])
127127
{
128+
if (project.Globals["RobotProject"].ToString() != "yes")
129+
{
130+
continue;
131+
}
128132
var vsproject = project.Object as VSLangProj.VSProject;
129133

130134
if (vsproject != null)

FRC-Extension/Buttons/SetMainRobotButton.cs

Lines changed: 118 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Runtime.InteropServices;
56
using System.Text;
67
using System.Threading.Tasks;
78
using EnvDTE;
@@ -24,14 +25,128 @@ public override void QueryCallback(object sender, EventArgs e)
2425
var menuCommand = sender as OleMenuCommand;
2526
if (menuCommand != null)
2627
{
27-
menuCommand.Visible = false;
28-
menuCommand.Enabled = false;
28+
if (GetSelectedProject() != null)
29+
{
30+
menuCommand.Visible = true;
31+
menuCommand.Enabled = true;
32+
}
33+
else
34+
{
35+
menuCommand.Visible = false;
36+
menuCommand.Enabled = false;
37+
}
2938
}
3039
}
3140

41+
public Project GetSelectedProject()
42+
{
43+
IntPtr hierarchyPointer = IntPtr.Zero;
44+
IntPtr selectionContainerPointer = IntPtr.Zero;
45+
46+
try
47+
{
48+
49+
50+
Object selectedObject = null;
51+
IVsMultiItemSelect multiItemSelect;
52+
uint projectItemId;
53+
54+
IVsMonitorSelection monitorSelection =
55+
(IVsMonitorSelection)Package.GetGlobalService(
56+
typeof(SVsShellMonitorSelection));
57+
58+
monitorSelection.GetCurrentSelection(out hierarchyPointer,
59+
out projectItemId,
60+
out multiItemSelect,
61+
out selectionContainerPointer);
62+
63+
IVsHierarchy selectedHierarchy = Marshal.GetTypedObjectForIUnknown(
64+
hierarchyPointer,
65+
typeof(IVsHierarchy)) as IVsHierarchy;
66+
67+
if (selectedHierarchy != null)
68+
{
69+
if (ErrorHandler.Failed(selectedHierarchy.GetProperty(
70+
projectItemId,
71+
(int)__VSHPROPID.VSHPROPID_ExtObject,
72+
out selectedObject)))
73+
{
74+
return null;
75+
}
76+
}
77+
78+
Project project = selectedObject as Project;
79+
80+
var vsproject = project?.Object as VSProject;
81+
82+
if (vsproject != null)
83+
{
84+
//If we are an assembly, and its named WPILib, enable the deploy
85+
if (
86+
(from Reference reference in vsproject.References
87+
where reference.SourceProject == null
88+
select reference.Name).Any(name => name.Contains("WPILib")))
89+
{
90+
return project;
91+
}
92+
}
93+
94+
return null;
95+
}
96+
finally
97+
{
98+
if (selectionContainerPointer != IntPtr.Zero)
99+
{
100+
Marshal.Release(selectionContainerPointer);
101+
}
102+
103+
if (hierarchyPointer != IntPtr.Zero)
104+
{
105+
Marshal.Release(hierarchyPointer);
106+
}
107+
}
108+
}
109+
110+
32111
public override void ButtonCallback(object sender, EventArgs e)
33112
{
34-
OutputWriter.Instance.WriteLine("Set Pressed");
113+
Project project = GetSelectedProject();
114+
115+
if (project == null)
116+
{
117+
return;
118+
}
119+
120+
ClearAllProjectsInSolution();
121+
122+
project.Globals["RobotProject"] = "yes";
123+
project.Globals.VariablePersists["RobotProject"] = true;
124+
project.Save();
125+
}
126+
127+
private void ClearAllProjectsInSolution()
128+
{
129+
var dte = m_package.PublicGetService(typeof(DTE)) as DTE;
130+
var sb = dte?.Solution;
131+
if (sb == null)
132+
{
133+
return;
134+
}
135+
136+
137+
foreach (Project p in sb.Projects)
138+
{
139+
var globals = p.Globals;
140+
if (globals == null)
141+
{
142+
continue;
143+
}
144+
if (globals.VariableExists["RobotProject"])
145+
{
146+
globals["RobotProject"] = "no";
147+
}
148+
p.Save();
149+
}
35150
}
36151
}
37152
}

FRC-Extension/FRC-Extension.vsct

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<CommandFlag>DynamicVisibility</CommandFlag>
9090
<CommandFlag>DefaultInvisible</CommandFlag>
9191
<Strings>
92-
<ButtonText>Set Main Robot Project</ButtonText>
92+
<ButtonText>Set As Main Robot Project</ButtonText>
9393
<CommandName>cmdidSetRobotProject</CommandName>
9494
</Strings>
9595
</Button>

0 commit comments

Comments
 (0)