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

Commit 22457e7

Browse files
authored
Merge pull request #4 from Microsoft/dev/priyan/talkpoints
Fixed adding Talkpoint more than once.
2 parents 749cdef + ca0ee35 commit 22457e7

3 files changed

Lines changed: 90 additions & 77 deletions

File tree

src/VisualStudio/CodeTalk/Commands/Commands.cs

Lines changed: 70 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ namespace Microsoft.CodeTalk.Commands
2222
{
2323
public class GetFunctionsCommand : CommandBase
2424
{
25-
ResourceManager rm;
25+
ResourceManager rm;
2626

2727
public GetFunctionsCommand(CommandKeyConfig keys) : base(keys) { }
28-
28+
2929
public override void Execute()
3030
{
31-
rm = new ResourceManager(typeof(Resources));
32-
System.Diagnostics.Debug.WriteLine("Get Functions");
31+
rm = new ResourceManager(typeof(Resources));
32+
System.Diagnostics.Debug.WriteLine("Get Functions");
3333

3434
IEnumerable<ISyntaxEntity> functions = new List<ISyntaxEntity>();
3535
CodeFile codeFile;
@@ -47,8 +47,8 @@ public override void Execute()
4747
}
4848
catch (CodeTalkLanguageServiceException)
4949
{
50-
MessageBox.Show(rm.GetString("CompilationErrorMessage", CultureInfo.CurrentCulture), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK, MessageBoxIcon.Error);
51-
return;
50+
MessageBox.Show(rm.GetString("CompilationErrorMessage", CultureInfo.CurrentCulture), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK, MessageBoxIcon.Error);
51+
return;
5252
}
5353

5454
//Creating a function collector for getting all the functions
@@ -60,8 +60,8 @@ public override void Execute()
6060

6161
if (0 == functions.Count())
6262
{
63-
MessageBox.Show(rm.GetString("NoFunctionsString", CultureInfo.CurrentCulture), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK);
64-
return;
63+
MessageBox.Show(rm.GetString("NoFunctionsString", CultureInfo.CurrentCulture), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK);
64+
return;
6565
}
6666

6767
ToolWindowPane listFunctionsWindow = TalkCodePackage.currentPackage.FindToolWindow(typeof(AccessibilityToolWindow), 0, true);
@@ -72,31 +72,31 @@ public override void Execute()
7272
}
7373

7474
IVsWindowFrame windowFrame = (IVsWindowFrame)listFunctionsWindow.Frame;
75-
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, rm.GetString("FunctionsListTitle", CultureInfo.CurrentCulture));
75+
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, rm.GetString("FunctionsListTitle", CultureInfo.CurrentCulture));
7676

77-
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
77+
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
7878

79-
(listFunctionsWindow as AccessibilityToolWindow).windowControl.SetListView(functions, rm.GetString("FunctionsListTitle", CultureInfo.CurrentCulture));
80-
}
79+
(listFunctionsWindow as AccessibilityToolWindow).windowControl.SetListView(functions, rm.GetString("FunctionsListTitle", CultureInfo.CurrentCulture));
80+
}
8181

8282
public override bool PassControl() => false;
8383
}
8484

8585
public class GetContextCommand : CommandBase
8686
{
87-
ResourceManager rm;
87+
ResourceManager rm;
8888

89-
public GetContextCommand(CommandKeyConfig keys) : base(keys) { }
89+
public GetContextCommand(CommandKeyConfig keys) : base(keys) { }
9090

9191
public override bool PassControl()
9292
{
9393
return false;
9494
}
9595
public override void Execute()
9696
{
97-
rm = new ResourceManager(typeof(Resources));
97+
rm = new ResourceManager(typeof(Resources));
9898

99-
CodeFile codeFile;
99+
CodeFile codeFile;
100100
IList<ISyntaxEntity> contextHierarchy;
101101

102102
//Getting the code text from the active document
@@ -112,8 +112,8 @@ public override void Execute()
112112
}
113113
catch (CodeTalkLanguageServiceException)
114114
{
115-
MessageBox.Show(rm.GetString("CompilationErrorMessage", CultureInfo.CurrentCulture), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK, MessageBoxIcon.Error);
116-
return;
115+
MessageBox.Show(rm.GetString("CompilationErrorMessage", CultureInfo.CurrentCulture), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK, MessageBoxIcon.Error);
116+
return;
117117
}
118118
try
119119
{
@@ -124,8 +124,8 @@ public override void Execute()
124124

125125
if (0 == contextHierarchy.Count)
126126
{
127-
MessageBox.Show(rm.GetString("NoContextString", CultureInfo.CurrentCulture) + " " + currentLineNumber.ToString(), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK);
128-
return;
127+
MessageBox.Show(rm.GetString("NoContextString", CultureInfo.CurrentCulture) + " " + currentLineNumber.ToString(), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK);
128+
return;
129129
}
130130

131131
var entities = contextHierarchy.Reverse().ToList().ConvertAll(x => (ISyntaxEntity)x);
@@ -134,16 +134,16 @@ public override void Execute()
134134

135135
if ((null == listFunctionsWindow) || (null == listFunctionsWindow.Frame))
136136
{
137-
MessageBox.Show("Cannote create tool window", "Cannot create tool window", MessageBoxButtons.OK);
137+
MessageBox.Show("Cannote create tool window", "Cannot create tool window", MessageBoxButtons.OK);
138138
}
139139

140140
IVsWindowFrame windowFrame = (IVsWindowFrame)listFunctionsWindow.Frame;
141-
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, rm.GetString("GetContextTitle", CultureInfo.CurrentCulture));
141+
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, rm.GetString("GetContextTitle", CultureInfo.CurrentCulture));
142142

143-
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
143+
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
144144

145-
(listFunctionsWindow as AccessibilityToolWindow).windowControl.SetListView(entities, rm.GetString("GetContextTitle", CultureInfo.CurrentCulture), false);
146-
}
145+
(listFunctionsWindow as AccessibilityToolWindow).windowControl.SetListView(entities, rm.GetString("GetContextTitle", CultureInfo.CurrentCulture), false);
146+
}
147147
catch (IndexOutOfRangeException)
148148
{
149149
MessageBox.Show("The cursor does not seem to be in code. please move the cursor and try again.", "CodeTalk", MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -165,14 +165,14 @@ public override void Execute()
165165

166166
public class GetErrorsCommand : CommandBase
167167
{
168-
ResourceManager rm;
168+
ResourceManager rm;
169169

170-
public GetErrorsCommand(CommandKeyConfig keys) : base(keys) { }
170+
public GetErrorsCommand(CommandKeyConfig keys) : base(keys) { }
171171

172172
public override void Execute()
173173
{
174-
rm = new ResourceManager(typeof(Resources));
175-
System.Diagnostics.Debug.WriteLine("Get Errors");
174+
rm = new ResourceManager(typeof(Resources));
175+
System.Diagnostics.Debug.WriteLine("Get Errors");
176176

177177
var errors = new List<ISyntaxEntity>();
178178

@@ -190,26 +190,26 @@ public override void Execute()
190190
{
191191
System.Threading.Tasks.Task.Run(() =>
192192
{
193-
MessageBox.Show(rm.GetString("NoErrorsString", CultureInfo.CurrentCulture), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK);
194-
});
193+
MessageBox.Show(rm.GetString("NoErrorsString", CultureInfo.CurrentCulture), rm.GetString("CodeTalkString", CultureInfo.CurrentCulture), MessageBoxButtons.OK);
194+
});
195195
return;
196196
}
197197

198198
ToolWindowPane listFunctionsWindow = TalkCodePackage.currentPackage.FindToolWindow(typeof(AccessibilityToolWindow), 0, true);
199199

200200
if ((null == listFunctionsWindow) || (null == listFunctionsWindow.Frame))
201201
{
202-
MessageBox.Show("Cannote create tool window", "Cannot create tool window", MessageBoxButtons.OK);
203-
}
204-
else
205-
{
206-
IVsWindowFrame windowFrame = (IVsWindowFrame)listFunctionsWindow.Frame;
207-
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, rm.GetString("ErrorListTitle", CultureInfo.CurrentCulture));
202+
MessageBox.Show("Cannote create tool window", "Cannot create tool window", MessageBoxButtons.OK);
203+
}
204+
else
205+
{
206+
IVsWindowFrame windowFrame = (IVsWindowFrame)listFunctionsWindow.Frame;
207+
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, rm.GetString("ErrorListTitle", CultureInfo.CurrentCulture));
208208

209-
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
209+
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
210210

211-
(listFunctionsWindow as AccessibilityToolWindow).windowControl.SetListView(errors, rm.GetString("ErrorListTitle", CultureInfo.CurrentCulture));
212-
}
211+
(listFunctionsWindow as AccessibilityToolWindow).windowControl.SetListView(errors, rm.GetString("ErrorListTitle", CultureInfo.CurrentCulture));
212+
}
213213

214214

215215
}
@@ -219,14 +219,14 @@ public override void Execute()
219219

220220
public class GetSummaryCommand : CommandBase
221221
{
222-
ResourceManager rm;
222+
ResourceManager rm;
223223

224-
public GetSummaryCommand(CommandKeyConfig keys) : base(keys) { }
224+
public GetSummaryCommand(CommandKeyConfig keys) : base(keys) { }
225225

226226
public override void Execute()
227227
{
228-
rm = new ResourceManager(typeof(Resources));
229-
System.Diagnostics.Debug.WriteLine("Get Summary");
228+
rm = new ResourceManager(typeof(Resources));
229+
System.Diagnostics.Debug.WriteLine("Get Summary");
230230

231231
//Getting the code text from the active document
232232
var path = TalkCodePackage.vsOperations.GetActiveDocumentPath();
@@ -244,22 +244,22 @@ public override void Execute()
244244

245245
if ((null == listFunctionsWindow) || (null == listFunctionsWindow.Frame))
246246
{
247-
MessageBox.Show("Cannote create tool window", "Cannot create tool window", MessageBoxButtons.OK);
248-
}
249-
else
250-
{
251-
IVsWindowFrame windowFrame = (IVsWindowFrame)listFunctionsWindow.Frame;
252-
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, rm.GetString("FileSummaryTitle", CultureInfo.CurrentCulture));
253-
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
254-
255-
(listFunctionsWindow as GetSummaryToolWindow).windowControl.SetTreeView(codeFile, rm.GetString("FileSSummaryTitle", CultureInfo.CurrentCulture));
256-
}
247+
MessageBox.Show("Cannote create tool window", "Cannot create tool window", MessageBoxButtons.OK);
248+
}
249+
else
250+
{
251+
IVsWindowFrame windowFrame = (IVsWindowFrame)listFunctionsWindow.Frame;
252+
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, rm.GetString("FileSummaryTitle", CultureInfo.CurrentCulture));
253+
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
254+
255+
(listFunctionsWindow as GetSummaryToolWindow).windowControl.SetTreeView(codeFile, rm.GetString("FileSSummaryTitle", CultureInfo.CurrentCulture));
256+
}
257257

258258
}
259259
catch (CodeTalkLanguageServiceException)
260260
{
261-
MessageBox.Show(rm.GetString("FileProcessError", CultureInfo.CurrentCulture));
262-
}
261+
MessageBox.Show(rm.GetString("FileProcessError", CultureInfo.CurrentCulture));
262+
}
263263
}
264264

265265
public override bool PassControl() => false;
@@ -268,31 +268,30 @@ public override void Execute()
268268

269269
public class CreateBreakpointCommand : CommandBase
270270
{
271-
ResourceManager rm;
271+
ResourceManager rm;
272272

273-
public CreateBreakpointCommand(CommandKeyConfig keys) : base(keys) { }
273+
public CreateBreakpointCommand(CommandKeyConfig keys) : base(keys) { }
274274

275275
public override void Execute()
276276
{
277-
rm = new ResourceManager(typeof(Resources));
278-
Debug.WriteLine("Create Breakpoint");
277+
rm = new ResourceManager(typeof(Resources));
279278

280-
if (TalkCodePackage.vsOperations.RemoveTalkpointIfExists()) { return; }
279+
if (TalkCodePackage.vsOperations.RemoveBreakpointIfExists()) { return; }
281280

282281
ToolWindowPane talkpointWindow = TalkCodePackage.currentPackage.FindToolWindow(typeof(TalkpointToolWindow), 0, true);
283282

284283
if ((null == talkpointWindow) || (null == talkpointWindow.Frame))
285284
{
286-
MessageBox.Show("Cannote create breakpoint window", "Cannot create tool window", MessageBoxButtons.OK);
287-
}
288-
else
289-
{
290-
IVsWindowFrame twindowFrame = (IVsWindowFrame)talkpointWindow.Frame;
291-
twindowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, rm.GetString("TalkPointWindowTitle", CultureInfo.CurrentCulture));
292-
293-
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(twindowFrame.Show());
294-
((talkpointWindow as TalkpointToolWindow).Content as TalkpointToolWindowControl).ClearAll();
295-
}
285+
MessageBox.Show("Cannote create breakpoint window", "Cannot create tool window", MessageBoxButtons.OK);
286+
}
287+
else
288+
{
289+
IVsWindowFrame twindowFrame = (IVsWindowFrame)talkpointWindow.Frame;
290+
twindowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_Caption, rm.GetString("TalkPointWindowTitle", CultureInfo.CurrentCulture));
291+
292+
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(twindowFrame.Show());
293+
((talkpointWindow as TalkpointToolWindow).Content as TalkpointToolWindowControl).ClearAll();
294+
}
296295
}
297296

298297
public override bool PassControl() => false;

src/VisualStudio/CodeTalk/Talkpoints/ExpressionTalkpoint.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public ExpressionTalkpoint(string filePath, CursorPos position, bool doesContinu
1818
public override void Execute()
1919
{
2020
if (string.IsNullOrEmpty(expression)) { return; }
21-
var exp = TalkCodePackage.vsOperations.RunExpressionInDebugger(expression);
22-
if (exp.IsValidValue)
21+
var expResult = TalkCodePackage.vsOperations.RunExpressionInDebugger(expression);
22+
if (!string.IsNullOrEmpty(expResult))
2323
{
24-
TextToSpeech.SpeakText(exp.Value);
24+
TextToSpeech.SpeakText(expResult);
2525
}
2626
}
2727
}

src/VisualStudio/CodeTalk/VSOperations.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,14 @@ public void BreakHandler(dbgEventReason reason, ref dbgExecutionAction execActio
122122

123123
}
124124

125-
public EnvDTE.Expression RunExpressionInDebugger(string expression)
125+
public string RunExpressionInDebugger(string expression)
126126
{
127-
return dte.Debugger.GetExpression(expression);
127+
var exprResult = dte.Debugger.GetExpression(expression);
128+
if (exprResult.IsValidValue)
129+
{
130+
return exprResult.Value;
131+
}
132+
return string.Empty;
128133
}
129134

130135
Talkpoint MatchTalkPoint(Breakpoint breakpoint)
@@ -140,6 +145,7 @@ public void AddTonalTalkPointToCurrentLine(Tones tone, bool doesContinue)
140145
var cursorPos = GetCurrentCursorPosition();
141146
var filePath = GetActiveDocumentPath();
142147
//Toggling Talkpoint
148+
RemoveIfTalkpointsExists(filePath, cursorPos);
143149
if (CheckIfBreakpointExists(filePath, cursorPos))
144150
{
145151
RemoveBreakpoints(filePath, cursorPos);
@@ -161,6 +167,7 @@ public void AddTonalTalkPointToCurrentLine(CustomTone customTone, bool doesConti
161167
var cursorPos = GetCurrentCursorPosition();
162168
var filePath = GetActiveDocumentPath();
163169
//Toggling Talkpoint
170+
RemoveIfTalkpointsExists(filePath, cursorPos);
164171
if (CheckIfBreakpointExists(filePath, cursorPos))
165172
{
166173
RemoveBreakpoints(filePath, cursorPos);
@@ -182,6 +189,7 @@ public void AddTextualTalkpointToCurrentLine(string statement, bool doesContinue
182189
var cursorPos = GetCurrentCursorPosition();
183190
var filePath = GetActiveDocumentPath();
184191
//Toggling Talkpoint
192+
RemoveIfTalkpointsExists(filePath, cursorPos);
185193
if (CheckIfBreakpointExists(filePath, cursorPos))
186194
{
187195
RemoveBreakpoints(filePath, cursorPos);
@@ -203,6 +211,7 @@ public void AddExpressionTalkpointToCurrentLine(string expression, bool doesCont
203211
var cursorPos = GetCurrentCursorPosition();
204212
var filePath = GetActiveDocumentPath();
205213
//Toggling Talkpoint
214+
RemoveIfTalkpointsExists(filePath, cursorPos);
206215
if (CheckIfBreakpointExists(filePath, cursorPos))
207216
{
208217
RemoveBreakpoints(filePath, cursorPos);
@@ -217,7 +226,7 @@ public void AddExpressionTalkpointToCurrentLine(string expression, bool doesCont
217226
}
218227
}
219228

220-
public bool RemoveTalkpointIfExists()
229+
public bool RemoveBreakpointIfExists()
221230
{
222231
var cursorPos = GetCurrentCursorPosition();
223232
var filePath = GetActiveDocumentPath();
@@ -256,6 +265,11 @@ public bool CheckIfBreakpointExists(string filePath, CursorPos position)
256265
return false;
257266
}
258267

268+
public void RemoveIfTalkpointsExists(string filePath, CursorPos position)
269+
{
270+
mTalkPoints.RemoveAll(t => (t.filePath.Equals(filePath) && t.position.lineNumber == position.lineNumber));
271+
}
272+
259273
public void RemoveBreakpoints(string filePath, CursorPos position)
260274
{
261275

0 commit comments

Comments
 (0)