/// <devdoc> /// Look at the list of projects and files and for each file that is part of this /// project, set the MkDocument on the event argument and trigger the event. /// </devdoc> private void GenerateEvents( IVsProject[] projects, int[] firstFiles, string[] mkDocuments, EventHandler <ProjectDocumentsChangeEventArgs> eventToGenerate, ProjectDocumentsChangeEventArgs e) { if (eventToGenerate == null) { return; // no event = nothing to do } if (projects == null || firstFiles == null || mkDocuments == null) { throw new ArgumentNullException(); } if (projects.Length != firstFiles.Length) { throw new ArgumentException(); } // First find out which range of the array (if any) include the files that belong to this project int first = -1; int last = mkDocuments.Length - 1; // default to the last document for (int i = 0; i < projects.Length; ++i) { if (first > -1) { // We get here if there is 1 or more project(s) after ours in the list last = firstFiles[i] - 1; break; } if (Object.ReferenceEquals(projects[i], this)) { first = firstFiles[i]; } } if (last >= mkDocuments.Length) { throw new ArgumentException(); } // See if we have any documents if (first < 0) { return; // Nothing that belongs to this project } // For each file, generate the event for (int i = first; i <= last; ++i) { try { e.MkDocument = mkDocuments[i]; eventToGenerate(this, e); } catch (Exception error) { Debug.Fail(error.Message); } } }
/// <devdoc> /// Look at the list of projects and files and for each file that is part of this /// project, set the MkDocument on the event argument and trigger the event. /// </devdoc> private void GenerateEvents( IVsProject[] projects, int[] firstFiles, string[] mkDocuments, EventHandler<ProjectDocumentsChangeEventArgs> eventToGenerate, ProjectDocumentsChangeEventArgs e) { if (eventToGenerate == null) return; // no event = nothing to do if (projects == null || firstFiles == null || mkDocuments == null) throw new ArgumentNullException(); if (projects.Length != firstFiles.Length) throw new ArgumentException(); // First find out which range of the array (if any) include the files that belong to this project int first = -1; int last = mkDocuments.Length - 1; // default to the last document for (int i = 0; i < projects.Length; ++i) { if (first > -1) { // We get here if there is 1 or more project(s) after ours in the list last = firstFiles[i] - 1; break; } if (Object.ReferenceEquals(projects[i], this)) first = firstFiles[i]; } if (last >= mkDocuments.Length) throw new ArgumentException(); // See if we have any documents if (first < 0) return; // Nothing that belongs to this project // For each file, generate the event for (int i = first; i <= last; ++i) { try { e.MkDocument = mkDocuments[i]; eventToGenerate(this, e); } catch(Exception error) { Debug.Fail(error.Message); } } }
/// <summary> /// File has been added. /// Maybe we need to update it's type. /// </summary> private void OnFileAdded(object sender, ProjectDocumentsChangeEventArgs e) { var mkDocument = e.MkDocument; uint itemId; if (!ErrorHandler.Succeeded(ParseCanonicalName(e.MkDocument, out itemId))) return; if (!File.Exists(mkDocument)) return; string itemType; var frameworkFolder = GetFrameworkFolder(); if (!ItemTypeDetector.TryDetectItemType(mkDocument, frameworkFolder, out itemType)) return; // Found item type, set it var pItem = _innerVsHierarchy.GetProjectItemFromHierarchy(itemId); pItem.Properties.Item("ItemType").Value = itemType; }