public void Execute(object parameter) { var metadata = parameter as DocumentMetadata; if (metadata == null) { return; } Window window = null; foreach (var itm in _dte2.Documents) { var document = (Document)itm; var match = _metadataEqualityService.Compare( document.FullName, metadata.FullName); if (match) { var enumerator = document.Windows.GetEnumerator(); if (enumerator.MoveNext()) { window = (Window)enumerator.Current; } break; } } if (window == null) { var item = _projectItemService.FindProjectItem(metadata.FullName); window = item?.Open(); } if (window == null) { _documentMetadataManager.Synchronize(_dte2.Documents, true); } else { window.Activate(); } }
public void Execute(object parameter) { var metadata = parameter as DocumentMetadata; if (metadata == null) { return; } var testFileName = _testFileNameEvaluator .EvaluateTestFileName(metadata.FullName); var projectItem = _projectItemService.FindProjectItem(testFileName); var window = projectItem?.Open(Constants.vsViewKindCode); window?.Activate(); }
/// <summary> /// Updates <see cref="ActiveDocumentMetadata"/> to reflect the documents /// in the method argument. Does not update the value of /// <see cref="DocumentMetadata.ActivatedAt"/> for existing metadata; sets /// as the current time in UTC for new metadata. /// </summary> /// <param name="documents"> /// <see cref="Documents"/> that <see cref="ActiveDocumentMetadata"/> /// should reflect /// </param> /// <param name="setUsageOrder"> /// true to update <see cref="DocumentMetadata.UsageOrder"/> for every /// <see cref="DocumentMetadata"/> in <see cref="ActiveDocumentMetadata"/> /// after Synchronization, false otherwise /// </param> public void Synchronize(Documents documents, bool setUsageOrder) { // DocumentMetadataInfo for each Document in 'documents' var documentsInfoSet = new HashSet <DocumentMetadataInfo>(); // Add documents unique to method parameter collection try { foreach (var obj in documents) { var document = (Document)obj; if (document.ActiveWindow == null) { continue; } var info = new DocumentMetadataInfo { FullName = document.FullName, ProjectDisplayName = document.ProjectItem.ContainingProject.Name, ProjectFullName = document.ProjectItem.ContainingProject.FullName }; documentsInfoSet.Add(info); Add(info); } } catch (COMException) { // COMException is thrown during enumeration of 'documents' // when a project is closed in Visual Studio. Do nothing: this // will result in the active documents metadata collection // being emptied, which is appropriate } // Remove documents not in method parameter collection for (int i = 0; i < _activeDocumentMetadata.Count; i++) { var foundInDocumentInfoSet = documentsInfoSet.Any(info => _metadataEqualityService.Compare( info, _activeDocumentMetadata[i])); if (!foundInDocumentInfoSet) { var removeMetadata = true; if (_activeDocumentMetadata[i].IsPinned) { var exists = _projectItemService.FindProjectItem( _activeDocumentMetadata[i].FullName) != null; if (exists) { _activeDocumentMetadata[i].HasWindow = false; removeMetadata = false; } } if (removeMetadata) { _activeDocumentMetadata.RemoveAt(i); i--; } } } if (setUsageOrder) { _normalizedUsageOrderService.SetUsageOrder( _activeDocumentMetadata, _userPreferences); } ActiveDocumentMetadata.Refresh(); }