-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSolutionEventsHandler.cs
More file actions
137 lines (115 loc) · 4.95 KB
/
SolutionEventsHandler.cs
File metadata and controls
137 lines (115 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* *******************************************************************************************************************
* Application: ClaudeCodeExtension
*
* Autor: Daniel Carvalho Liedke
*
* Copyright © Daniel Carvalho Liedke 2026
* Usage and reproduction in any manner whatsoever without the written permission of Daniel Carvalho Liedke is strictly forbidden.
*
* Purpose: Solution events handler for detecting solution and project changes
*
* *******************************************************************************************************************/
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
namespace ClaudeCodeVS
{
/// <summary>
/// Handles Visual Studio solution events to detect when solutions/projects are opened or closed
/// Triggers terminal restart when the workspace directory changes
/// </summary>
public class SolutionEventsHandler : IVsSolutionEvents
{
#region Fields
/// <summary>
/// Reference to the main control for callback
/// </summary>
private readonly ClaudeCodeControl _control;
#endregion
#region Constructor
/// <summary>
/// Initializes a new instance of the SolutionEventsHandler class
/// </summary>
/// <param name="control">The ClaudeCodeControl instance to notify of changes</param>
public SolutionEventsHandler(ClaudeCodeControl control)
{
_control = control;
}
#endregion
#region Solution Event Handlers
/// <summary>
/// Called after a solution is opened
/// </summary>
/// <param name="pUnkReserved">Reserved for future use</param>
/// <param name="fNewSolution">True if this is a new solution being created</param>
/// <returns>S_OK if successful</returns>
public int OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
{
ThreadHelper.JoinableTaskFactory.Run(async delegate
{
// Add small delay to ensure solution is fully loaded
await Task.Delay(500);
await _control.OnWorkspaceDirectoryChangedAsync(true);
});
return VSConstants.S_OK;
}
/// <summary>
/// Called after a project is opened or added to the solution
/// </summary>
/// <param name="pHierarchy">The project hierarchy</param>
/// <param name="fAdded">True if the project was added to an existing solution</param>
/// <returns>S_OK if successful</returns>
public int OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded)
{
ThreadHelper.JoinableTaskFactory.Run(async delegate
{
// Add small delay to ensure project is fully loaded
await Task.Delay(300);
await _control.OnWorkspaceDirectoryChangedAsync(true);
});
return VSConstants.S_OK;
}
#endregion
#region Unused Event Handlers (Required by Interface)
/// <summary>
/// Called after a solution is closed
/// </summary>
public int OnAfterCloseSolution(object pUnkReserved) => VSConstants.S_OK;
/// <summary>
/// Called after a project is loaded
/// </summary>
public int OnAfterLoadProject(IVsHierarchy pStubHierarchy, IVsHierarchy pRealHierarchy) => VSConstants.S_OK;
/// <summary>
/// Called after a project is unloaded
/// </summary>
public int OnAfterUnloadProject(IVsHierarchy pRealHierarchy, IVsHierarchy pStubHierarchy) => VSConstants.S_OK;
/// <summary>
/// Called before a project is closed
/// </summary>
public int OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved) => VSConstants.S_OK;
/// <summary>
/// Called before a solution is closed
/// </summary>
public int OnBeforeCloseSolution(object pUnkReserved) => VSConstants.S_OK;
/// <summary>
/// Called before a project is unloaded
/// </summary>
public int OnBeforeUnloadProject(IVsHierarchy pRealHierarchy, IVsHierarchy pStubHierarchy) => VSConstants.S_OK;
/// <summary>
/// Called when querying whether a project can be closed
/// </summary>
public int OnQueryCloseProject(IVsHierarchy pHierarchy, int fRemoving, ref int pfCancel) => VSConstants.S_OK;
/// <summary>
/// Called when querying whether a solution can be closed
/// </summary>
public int OnQueryCloseSolution(object pUnkReserved, ref int pfCancel) => VSConstants.S_OK;
/// <summary>
/// Called when querying whether a project can be unloaded
/// </summary>
public int OnQueryUnloadProject(IVsHierarchy pRealHierarchy, ref int pfCancel) => VSConstants.S_OK;
#endregion
}
}