Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SolutionEventsListener.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using Microsoft.VisualStudio;
5 using Microsoft.VisualStudio.Shell.Interop;
6 
7 namespace SiliconStudio.Paradox.VisualStudio
8 {
10  {
11  private IVsSolution solution;
12  private uint solutionEventsCookie;
13 
14  public event Action AfterSolutionLoaded;
16  public event Action BeforeSolutionClosed;
17 
18  public event Action<IVsHierarchy> AfterProjectOpened;
19  public event Action<IVsHierarchy> BeforeProjectClosed;
20 
21  public SolutionEventsListener(IServiceProvider serviceProvider)
22  {
23  solution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
24  if (solution != null)
25  {
26  solution.AdviseSolutionEvents(this, out solutionEventsCookie);
27  }
28  }
29 
30  public int OnBeforeOpenSolution(string pszSolutionFilename)
31  {
32  return VSConstants.S_OK;
33  }
34 
36  {
37  return VSConstants.S_OK;
38  }
39 
40  public int OnQueryBackgroundLoadProjectBatch(out bool pfShouldDelayLoadToNextIdle)
41  {
42  pfShouldDelayLoadToNextIdle = false;
43  return VSConstants.S_OK;
44  }
45 
46  public int OnBeforeLoadProjectBatch(bool fIsBackgroundIdleBatch)
47  {
48  return VSConstants.S_OK;
49  }
50 
51  public int OnAfterLoadProjectBatch(bool fIsBackgroundIdleBatch)
52  {
53  return VSConstants.S_OK;
54  }
55 
57  {
58  var afterSolutionBackgroundLoadComplete = AfterSolutionBackgroundLoadComplete;
59  if (afterSolutionBackgroundLoadComplete != null)
60  afterSolutionBackgroundLoadComplete();
61  return VSConstants.S_OK;
62  }
63 
64  #region IVsSolutionEvents Members
65 
66  int IVsSolutionEvents.OnAfterCloseSolution(object pUnkReserved)
67  {
68  return VSConstants.S_OK;
69  }
70 
71  int IVsSolutionEvents.OnAfterLoadProject(IVsHierarchy pStubHierarchy, IVsHierarchy pRealHierarchy)
72  {
73  return VSConstants.S_OK;
74  }
75 
76  int IVsSolutionEvents.OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded)
77  {
78  var afterProjectOpened = AfterProjectOpened;
79  if (afterProjectOpened != null)
80  afterProjectOpened(pHierarchy);
81  return VSConstants.S_OK;
82  }
83 
84  int IVsSolutionEvents.OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
85  {
86  var afterSolutionLoaded = AfterSolutionLoaded;
87  if (afterSolutionLoaded != null)
88  afterSolutionLoaded();
89  return VSConstants.S_OK;
90  }
91 
92  int IVsSolutionEvents.OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved)
93  {
94  var beforeProjectClosed = BeforeProjectClosed;
95  if (beforeProjectClosed != null)
96  beforeProjectClosed(pHierarchy);
97  return VSConstants.S_OK;
98  }
99 
100  int IVsSolutionEvents.OnBeforeCloseSolution(object pUnkReserved)
101  {
102  var beforeSolutionClosed = BeforeSolutionClosed;
103  if (beforeSolutionClosed != null)
104  beforeSolutionClosed();
105  return VSConstants.S_OK;
106  }
107 
108  int IVsSolutionEvents.OnBeforeUnloadProject(IVsHierarchy pRealHierarchy, IVsHierarchy pStubHierarchy)
109  {
110  return VSConstants.S_OK;
111  }
112 
113  int IVsSolutionEvents.OnQueryCloseProject(IVsHierarchy pHierarchy, int fRemoving, ref int pfCancel)
114  {
115  return VSConstants.S_OK;
116  }
117 
118  int IVsSolutionEvents.OnQueryCloseSolution(object pUnkReserved, ref int pfCancel)
119  {
120  return VSConstants.S_OK;
121  }
122 
123  int IVsSolutionEvents.OnQueryUnloadProject(IVsHierarchy pRealHierarchy, ref int pfCancel)
124  {
125  return VSConstants.S_OK;
126  }
127 
128  #endregion
129 
130  #region IDisposable Members
131 
132  public void Dispose()
133  {
134  if (solution != null && solutionEventsCookie != 0)
135  {
136  GC.SuppressFinalize(this);
137  solution.UnadviseSolutionEvents(solutionEventsCookie);
138  AfterSolutionLoaded = null;
139  BeforeSolutionClosed = null;
140  solutionEventsCookie = 0;
141  solution = null;
142  }
143  }
144 
145  #endregion
146  }
147 }
int OnQueryBackgroundLoadProjectBatch(out bool pfShouldDelayLoadToNextIdle)