Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: experimental/visual_studio_plugin/third_party/Microsoft.VisualStudio.Project/FileDocumentManager.cs

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /// Copyright (c) Microsoft Corporation. All rights reserved.
2
3 using System;
4 using System.Diagnostics;
5 using System.Runtime.InteropServices;
6 using Microsoft.VisualStudio;
7 using Microsoft.VisualStudio.Shell.Interop;
8 using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
9
10 namespace Microsoft.VisualStudio.Project
11 {
12 /// <summary>
13 /// This class handles opening, saving of file items in the hierarchy.
14 /// </summary>
15 [CLSCompliant(false)]
16 public class FileDocumentManager : DocumentManager
17 {
18 #region ctors
19
20 public FileDocumentManager(FileNode node)
21 : base(node)
22 {
23 }
24 #endregion
25
26 #region overriden methods
27
28 /// <summary>
29 /// Open a file using the standard editor
30 /// </summary>
31 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, s ee constants starting with LOGVIEWID_ defined in NativeMethods class</param>
32 /// <param name="docDataExisting">IntPtr to the IUnknown interfa ce of the existing document data object</param>
33 /// <param name="windowFrame">A reference to the window frame th at is mapped to the file</param>
34 /// <param name="windowFrameAction">Determine the UI action on t he document window</param>
35 /// <returns>If the method succeeds, it returns S_OK. If it fail s, it returns an error code.</returns>
36 public override int Open(ref Guid logicalView, IntPtr docDataExi sting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
37 {
38 bool newFile = false;
39 bool openWith = false;
40 return this.Open(newFile, openWith, ref logicalView, doc DataExisting, out windowFrame, windowFrameAction);
41 }
42
43 /// <summary>
44 /// Open a file with a specific editor
45 /// </summary>
46 /// <param name="editorFlags">Specifies actions to take when ope ning a specific editor. Possible editor flags are defined in the enumeration Mic rosoft.VisualStudio.Shell.Interop.__VSOSPEFLAGS</param>
47 /// <param name="editorType">Unique identifier of the editor typ e</param>
48 /// <param name="physicalView">Name of the physical view. If nul l, the environment calls MapLogicalView on the editor factory to determine the p hysical view that corresponds to the logical view. In this case, null does not s pecify the primary view, but rather indicates that you do not know which view co rresponds to the logical view</param>
49 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, s ee constants starting with LOGVIEWID_ defined in NativeMethods class</param>
50 /// <param name="docDataExisting">IntPtr to the IUnknown interfa ce of the existing document data object</param>
51 /// <param name="windowFrame">A reference to the window frame th at is mapped to the file</param>
52 /// <param name="windowFrameAction">Determine the UI action on t he document window</param>
53 /// <returns>If the method succeeds, it returns S_OK. If it fail s, it returns an error code.</returns>
54 public override int OpenWithSpecific(uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataExisting, o ut IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
55 {
56 windowFrame = null;
57 bool newFile = false;
58 bool openWith = false;
59 return this.Open(newFile, openWith, editorFlags, ref edi torType, physicalView, ref logicalView, docDataExisting, out windowFrame, window FrameAction);
60 }
61
62 #endregion
63
64 #region public methods
65 /// <summary>
66 /// Open a file in a document window with a std editor
67 /// </summary>
68 /// <param name="newFile">Open the file as a new file</param>
69 /// <param name="openWith">Use a dialog box to determine which e ditor to use</param>
70 /// <param name="windowFrameAction">Determine the UI action on t he document window</param>
71 /// <returns>If the method succeeds, it returns S_OK. If it fail s, it returns an error code.</returns>
72 public int Open(bool newFile, bool openWith, WindowFrameShowActi on windowFrameAction)
73 {
74 Guid logicalView = Guid.Empty;
75 IVsWindowFrame windowFrame = null;
76 return this.Open(newFile, openWith, logicalView, out win dowFrame, windowFrameAction);
77 }
78
79 /// <summary>
80 /// Open a file in a document window with a std editor
81 /// </summary>
82 /// <param name="newFile">Open the file as a new file</param>
83 /// <param name="openWith">Use a dialog box to determine which e ditor to use</param>
84 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, s ee constants starting with LOGVIEWID_ defined in NativeMethods class</param>
85 /// <param name="frame">A reference to the window frame that is mapped to the file</param>
86 /// <param name="windowFrameAction">Determine the UI action on t he document window</param>
87 /// <returns>If the method succeeds, it returns S_OK. If it fail s, it returns an error code.</returns>
88 public int Open(bool newFile, bool openWith, Guid logicalView, o ut IVsWindowFrame frame, WindowFrameShowAction windowFrameAction)
89 {
90 frame = null;
91 IVsRunningDocumentTable rdt = this.Node.ProjectMgr.Site. GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
92 Debug.Assert(rdt != null, " Could not get running docume nt table from the services exposed by this project");
93 if(rdt == null)
94 {
95 return VSConstants.E_FAIL;
96 }
97
98 // First we see if someone else has opened the requested view of the file.
99 _VSRDTFLAGS flags = _VSRDTFLAGS.RDT_NoLock;
100 uint itemid;
101 IntPtr docData = IntPtr.Zero;
102 IVsHierarchy ivsHierarchy;
103 uint docCookie;
104 string path = this.GetFullPathForDocument();
105 int returnValue = VSConstants.S_OK;
106
107 try
108 {
109 ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocum ent((uint)flags, path, out ivsHierarchy, out itemid, out docData, out docCookie) );
110 ErrorHandler.ThrowOnFailure(this.Open(newFile, o penWith, ref logicalView, docData, out frame, windowFrameAction));
111 }
112 catch(COMException e)
113 {
114 Trace.WriteLine("Exception :" + e.Message);
115 returnValue = e.ErrorCode;
116 }
117 finally
118 {
119 if(docData != IntPtr.Zero)
120 {
121 Marshal.Release(docData);
122 }
123 }
124
125 return returnValue;
126 }
127
128 #endregion
129
130 #region virtual methods
131 /// <summary>
132 /// Open a file in a document window
133 /// </summary>
134 /// <param name="newFile">Open the file as a new file</param>
135 /// <param name="openWith">Use a dialog box to determine which e ditor to use</param>
136 /// <param name="logicalView">In MultiView case determines view to be activated by IVsMultiViewDocumentView. For a list of logical view GUIDS, s ee constants starting with LOGVIEWID_ defined in NativeMethods class</param>
137 /// <param name="docDataExisting">IntPtr to the IUnknown interfa ce of the existing document data object</param>
138 /// <param name="windowFrame">A reference to the window frame th at is mapped to the file</param>
139 /// <param name="windowFrameAction">Determine the UI action on t he document window</param>
140 /// <returns>If the method succeeds, it returns S_OK. If it fail s, it returns an error code.</returns>
141 public virtual int Open(bool newFile, bool openWith, ref Guid lo gicalView, IntPtr docDataExisting, out IVsWindowFrame windowFrame, WindowFrameSh owAction windowFrameAction)
142 {
143 windowFrame = null;
144 Guid editorType = Guid.Empty;
145 return this.Open(newFile, openWith, 0, ref editorType, n ull, ref logicalView, docDataExisting, out windowFrame, windowFrameAction);
146 }
147
148 #endregion
149
150 #region helper methods
151
152 private int Open(bool newFile, bool openWith, uint editorFlags, ref Guid editorType, string physicalView, ref Guid logicalView, IntPtr docDataEx isting, out IVsWindowFrame windowFrame, WindowFrameShowAction windowFrameAction)
153 {
154 windowFrame = null;
155 if(this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed)
156 {
157 return VSConstants.E_FAIL;
158 }
159
160 Debug.Assert(this.Node != null, "No node has been initia lized for the document manager");
161 Debug.Assert(this.Node.ProjectMgr != null, "No project m anager has been initialized for the document manager");
162 Debug.Assert(this.Node is FileNode, "Node is not FileNod e object");
163
164 int returnValue = VSConstants.S_OK;
165 string caption = this.GetOwnerCaption();
166 string fullPath = this.GetFullPathForDocument();
167
168 // Make sure that the file is on disk before we open the editor and display message if not found
169 if(!((FileNode)this.Node).IsFileOnDisk(true))
170 {
171 // Inform clients that we have an invalid item ( wrong icon)
172 this.Node.OnInvalidateItems(this.Node.Parent);
173
174 // Bail since we are not able to open the item
175 // Do not return an error code otherwise an inte rnal error message is shown. The scenario for this operation
176 // normally is already a reaction to a dialog bo x telling that the item has been removed.
177 return VSConstants.S_FALSE;
178 }
179
180 IVsUIShellOpenDocument uiShellOpenDocument = this.Node.P rojectMgr.Site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocum ent;
181 IOleServiceProvider serviceProvider = this.Node.ProjectM gr.Site.GetService(typeof(IOleServiceProvider)) as IOleServiceProvider;
182
183 try
184 {
185 this.Node.ProjectMgr.OnOpenItem(fullPath);
186 int result = VSConstants.E_FAIL;
187
188 if(openWith)
189 {
190 result = uiShellOpenDocument.OpenStandar dEditor((uint)__VSOSEFLAGS.OSE_UseOpenWithDialog, fullPath, ref logicalView, cap tion, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
191 }
192 else
193 {
194 __VSOSEFLAGS openFlags = 0;
195 if(newFile)
196 {
197 openFlags |= __VSOSEFLAGS.OSE_Op enAsNewFile;
198 }
199
200 //NOTE: we MUST pass the IVsProject in p VsUIHierarchy and the itemid
201 // of the node being opened, otherwise t he debugger doesn't work.
202 if(editorType != Guid.Empty)
203 {
204 result = uiShellOpenDocument.Ope nSpecificEditor(editorFlags, fullPath, ref editorType, physicalView, ref logical View, caption, this.Node.ProjectMgr, this.Node.ID, docDataExisting, serviceProvi der, out windowFrame);
205 }
206 else
207 {
208 openFlags |= __VSOSEFLAGS.OSE_Ch ooseBestStdEditor;
209 result = uiShellOpenDocument.Ope nStandardEditor((uint)openFlags, fullPath, ref logicalView, caption, this.Node.P rojectMgr, this.Node.ID, docDataExisting, serviceProvider, out windowFrame);
210 }
211 }
212
213 if(result != VSConstants.S_OK && result != VSCon stants.S_FALSE && result != VSConstants.OLE_E_PROMPTSAVECANCELLED)
214 {
215 ErrorHandler.ThrowOnFailure(result);
216 }
217
218 if(windowFrame != null)
219 {
220 object var;
221
222 if(newFile)
223 {
224 ErrorHandler.ThrowOnFailure(wind owFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out var));
225 IVsPersistDocData persistDocData = (IVsPersistDocData)var;
226 ErrorHandler.ThrowOnFailure(pers istDocData.SetUntitledDocPath(fullPath));
227 }
228
229 var = null;
230 ErrorHandler.ThrowOnFailure(windowFrame. GetProperty((int)__VSFPROPID.VSFPROPID_DocCookie, out var));
231 this.Node.DocCookie = (uint)(int)var;
232
233 if(windowFrameAction == WindowFrameShowA ction.Show)
234 {
235 ErrorHandler.ThrowOnFailure(wind owFrame.Show());
236 }
237 else if(windowFrameAction == WindowFrame ShowAction.ShowNoActivate)
238 {
239 ErrorHandler.ThrowOnFailure(wind owFrame.ShowNoActivate());
240 }
241 else if(windowFrameAction == WindowFrame ShowAction.Hide)
242 {
243 ErrorHandler.ThrowOnFailure(wind owFrame.Hide());
244 }
245 }
246 }
247 catch(COMException e)
248 {
249 Trace.WriteLine("Exception e:" + e.Message);
250 returnValue = e.ErrorCode;
251 CloseWindowFrame(ref windowFrame);
252 }
253
254 return returnValue;
255 }
256
257
258 #endregion
259 }
260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698