Skip to content

Commit 2dbf402

Browse files
authored
Merge pull request #174 from sharwell/fix-crash
Avoid crashing if GitDiffMarginCommandHandler is not in the property bag
2 parents b545e64 + a5f6b8b commit 2dbf402

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

GitDiffMargin/ViewModel/EditorDiffViewModel.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,16 @@ public bool ShowPopup
169169
IVsUIShell4 uiShell = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell4;
170170
if (uiShell != null)
171171
{
172-
IOleCommandTarget commandTarget = MarginCore.TextView.Properties.GetProperty<GitDiffMarginCommandHandler>(typeof(GitDiffMarginCommandHandler));
172+
if (MarginCore.TextView.Properties.TryGetProperty<GitDiffMarginCommandHandler>(typeof(GitDiffMarginCommandHandler), out var commandTarget))
173+
{
174+
IVsToolbarTrayHost toolbarTrayHost;
175+
ErrorHandler.ThrowOnFailure(uiShell.CreateToolbarTray(commandTarget, out toolbarTrayHost));
173176

174-
IVsToolbarTrayHost toolbarTrayHost;
175-
ErrorHandler.ThrowOnFailure(uiShell.CreateToolbarTray(commandTarget, out toolbarTrayHost));
177+
Guid toolBarGuid = typeof(GitDiffMarginCommand).GUID;
178+
ErrorHandler.ThrowOnFailure(toolbarTrayHost.AddToolbar(ref toolBarGuid, (int)GitDiffMarginCommand.GitDiffToolbar));
176179

177-
Guid toolBarGuid = typeof(GitDiffMarginCommand).GUID;
178-
ErrorHandler.ThrowOnFailure(toolbarTrayHost.AddToolbar(ref toolBarGuid, (int)GitDiffMarginCommand.GitDiffToolbar));
179-
180-
_toolbarTrayHost = toolbarTrayHost;
180+
_toolbarTrayHost = toolbarTrayHost;
181+
}
181182
}
182183
}
183184
else

0 commit comments

Comments
 (0)