コード例 #1
0
        private void Add(DocumentMetadataInfo info, bool isPinned)
        {
            var metadata = _activeDocumentMetadata.FirstOrDefault(m =>
                                                                  _metadataEqualityService.Compare(info, m));

            var exists = metadata != null;

            if (!exists)
            {
                metadata = _documentMetadataFactory.Create(info);
                _activeDocumentMetadata.Add(metadata);
            }

            metadata.HasWindow = !isPinned || exists;

            if (isPinned)
            {
                TogglePinnedStatus(metadata);
            }

            if (!isPinned || !exists)
            {
                ActiveDocumentMetadata.Refresh();
            }
        }
コード例 #2
0
        /// <summary>
        /// Sets <see cref="DocumentMetadata.IsActive"/> to true and
        /// <see cref="DocumentMetadata.ActivatedAt"/> to the current time in UTC
        /// for the specified file. Sets <see cref="DocumentMetadata.IsActive"/>
        /// to false for all other files
        /// </summary>
        /// <param name="fullName">Full path and name of document file</param>
        public void Activate(string fullName)
        {
            var activatedDocument = _activeDocumentMetadata.FirstOrDefault(m =>
                                                                           m.IsActive)?.FullName;

            if (fullName == activatedDocument)
            {
                return;
            }

            var activated = false;

            foreach (var metadata in _activeDocumentMetadata)
            {
                metadata.IsActive = _metadataEqualityService.Compare(
                    metadata.FullName,
                    fullName);

                if (metadata.IsActive)
                {
                    var utcNow = _timeProvider.UtcNow;
                    metadata.ActivatedAt = utcNow;
                    activated            = true;
                }
            }

            if (activated)
            {
                _normalizedUsageOrderService.SetUsageOrder(
                    _activeDocumentMetadata,
                    _userPreferences);

                ActiveDocumentMetadata.Refresh();
                PinnedDocumentMetadata.Refresh();
            }
        }
コード例 #3
0
        /// <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();
        }
コード例 #4
0
 /// <summary>
 /// Updates the DocumentMetadata filter match information.
 /// </summary>
 private void UpdateFilter()
 {
     PinnedDocumentMetadata.Refresh();
     ActiveDocumentMetadata.Refresh();
 }