public void Dispose() {
            if ((null != _connectionPoint) && (0 != _connectionCookie)) {
                _connectionPoint.Unadvise(_connectionCookie);
            }
            _connectionCookie = 0;
            _connectionPoint = null;

            _buffer = null;
            _fileId = null;
        }
 public TextLineEventListener(IVsTextLines buffer, string fileName, ModuleId id) {
     _buffer = buffer;
     _fileId = id;
     _fileName = fileName;
     IConnectionPointContainer container = buffer as IConnectionPointContainer;
     if (null != container) {
         Guid eventsGuid = typeof(IVsTextLinesEvents).GUID;
         container.FindConnectionPoint(ref eventsGuid, out _connectionPoint);
         _connectionPoint.Advise(this as IVsTextLinesEvents, out _connectionCookie);
     }
 }
 public LibraryTask(string fileName, ITextBuffer textBuffer, ModuleId moduleId) {
     _fileName = fileName;
     _textBuffer = textBuffer;
     _moduleId = moduleId;
 }
Beispiel #4
0
        public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
        {
            // Check if this document is in the list of the documents.
            if (_documents.ContainsKey(docCookie))
            {
                return(VSConstants.S_OK);
            }
            // Get the information about this document from the RDT.
            IVsRunningDocumentTable rdt = GetPackageService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;

            if (null != rdt)
            {
                // Note that here we don't want to throw in case of error.
                uint         flags;
                uint         readLocks;
                uint         writeLoks;
                string       documentMoniker;
                IVsHierarchy hierarchy;
                uint         itemId;
                IntPtr       unkDocData;
                int          hr = rdt.GetDocumentInfo(docCookie, out flags, out readLocks, out writeLoks,
                                                      out documentMoniker, out hierarchy, out itemId, out unkDocData);
                try {
                    if (Microsoft.VisualStudio.ErrorHandler.Failed(hr) || (IntPtr.Zero == unkDocData))
                    {
                        return(VSConstants.S_OK);
                    }
                    // Check if the herarchy is one of the hierarchies this service is monitoring.
                    if (!_hierarchies.ContainsKey(hierarchy))
                    {
                        // This hierarchy is not monitored, we can exit now.
                        return(VSConstants.S_OK);
                    }

                    // Check the file to see if a listener is required.
                    if (_package.IsRecognizedFile(documentMoniker))
                    {
                        return(VSConstants.S_OK);
                    }

                    // Create the module id for this document.
                    ModuleId docId = new ModuleId(hierarchy, itemId);

                    // Try to get the text buffer.
                    IVsTextLines buffer = Marshal.GetObjectForIUnknown(unkDocData) as IVsTextLines;

                    // Create the listener.
                    TextLineEventListener listener = new TextLineEventListener(buffer, documentMoniker, docId);
                    // Set the event handler for the change event. Note that there is no difference
                    // between the AddFile and FileChanged operation, so we can use the same handler.
                    listener.OnFileChanged += new EventHandler <HierarchyEventArgs>(OnNewFile);
                    // Add the listener to the dictionary, so we will not create it anymore.
                    _documents.Add(docCookie, listener);
                } finally {
                    if (IntPtr.Zero != unkDocData)
                    {
                        Marshal.Release(unkDocData);
                    }
                }
            }
            // Always return success.
            return(VSConstants.S_OK);
        }
        private void CreateModuleTree(LibraryNode current, IScopeNode scope, string namePrefix, ModuleId moduleId)
        {
            if ((null == scope) || (null == scope.NestedScopes))
            {
                return;
            }

            foreach (IScopeNode subItem in scope.NestedScopes)
            {
                LibraryNode newNode       = CreateLibraryNode(current, subItem, namePrefix, moduleId.Hierarchy, moduleId.ItemID);
                string      newNamePrefix = namePrefix;

                current.AddNode(newNode);
                if ((newNode.NodeType & LibraryNodeType.Classes) != LibraryNodeType.None)
                {
                    newNamePrefix = namePrefix + newNode.Name + ".";
                }

                // Now use recursion to get the other types.
                CreateModuleTree(newNode, subItem, newNamePrefix, moduleId);
            }
        }
Beispiel #6
0
 public LibraryTask(string fileName, ITextBuffer textBuffer, ModuleId moduleId)
 {
     _fileName   = fileName;
     _textBuffer = textBuffer;
     _moduleId   = moduleId;
 }
Beispiel #7
0
        private void OnNewFile(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;
            if (null == hierarchy || IsNonMemberItem(hierarchy, args.ItemID)) {
                return;
            }

            ITextBuffer buffer = null;
            if (null != args.TextBuffer) {
                buffer = _adapterFactory.GetDocumentBuffer(args.TextBuffer);
            }

            var id = new ModuleId(hierarchy, args.ItemID);
            OnNewFile(new LibraryTask(args.CanonicalName, buffer, new ModuleId(hierarchy, args.ItemID)));
        }
Beispiel #8
0
 /// <summary>
 /// Does a delete w/o checking if it's a non-meber item, for handling the
 /// transition from member item to non-member item.
 /// </summary>
 private void OnDeleteFile(IVsHierarchy hierarchy, HierarchyEventArgs args)
 {
     ModuleId id = new ModuleId(hierarchy, args.ItemID);
     LibraryNode node = null;
     lock (_files) {
         if (_files.TryGetValue(id, out node)) {
             _files.Remove(id);
             HierarchyInfo parent;
             if (_hierarchies.TryGetValue(hierarchy, out parent)) {
                 parent.ProjectLibraryNode.RemoveNode(node);
             }
         }
     }
     if (null != node) {
         _library.RemoveNode(node);
     }
 }
Beispiel #9
0
 public void UnregisterHierarchy(IVsHierarchy hierarchy)
 {
     if ((null == hierarchy) || !_hierarchies.ContainsKey(hierarchy)) {
         return;
     }
     HierarchyInfo info = _hierarchies[hierarchy];
     if (null != info) {
         info.Listener.Dispose();
     }
     _hierarchies.Remove(hierarchy);
     _library.RemoveNode(info.ProjectLibraryNode);
     if (0 == _hierarchies.Count) {
         UnregisterRDTEvents();
     }
     lock (_files) {
         ModuleId[] keys = new ModuleId[_files.Keys.Count];
         _files.Keys.CopyTo(keys, 0);
         foreach (ModuleId id in keys) {
             if (hierarchy.Equals(id.Hierarchy)) {
                 _library.RemoveNode(_files[id]);
                 _files.Remove(id);
             }
         }
     }
     // Remove the document listeners.
     uint[] docKeys = new uint[_documents.Keys.Count];
     _documents.Keys.CopyTo(docKeys, 0);
     foreach (uint id in docKeys) {
         TextLineEventListener docListener = _documents[id];
         if (hierarchy.Equals(docListener.FileID.Hierarchy)) {
             _documents.Remove(id);
             docListener.Dispose();
         }
     }
 }
Beispiel #10
0
        public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame)
        {
            // Check if this document is in the list of the documents.
            if (_documents.ContainsKey(docCookie)) {
                return VSConstants.S_OK;
            }
            // Get the information about this document from the RDT.
            IVsRunningDocumentTable rdt = GetPackageService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
            if (null != rdt) {
                // Note that here we don't want to throw in case of error.
                uint flags;
                uint readLocks;
                uint writeLoks;
                string documentMoniker;
                IVsHierarchy hierarchy;
                uint itemId;
                IntPtr unkDocData;
                int hr = rdt.GetDocumentInfo(docCookie, out flags, out readLocks, out writeLoks,
                                             out documentMoniker, out hierarchy, out itemId, out unkDocData);
                try {
                    if (Microsoft.VisualStudio.ErrorHandler.Failed(hr) || (IntPtr.Zero == unkDocData)) {
                        return VSConstants.S_OK;
                    }
                    // Check if the herarchy is one of the hierarchies this service is monitoring.
                    if (!_hierarchies.ContainsKey(hierarchy)) {
                        // This hierarchy is not monitored, we can exit now.
                        return VSConstants.S_OK;
                    }

                    // Check the file to see if a listener is required.
                    if (_package.IsRecognizedFile(documentMoniker)) {
                        return VSConstants.S_OK;
                    }

                    // Create the module id for this document.
                    ModuleId docId = new ModuleId(hierarchy, itemId);

                    // Try to get the text buffer.
                    IVsTextLines buffer = Marshal.GetObjectForIUnknown(unkDocData) as IVsTextLines;

                    // Create the listener.
                    TextLineEventListener listener = new TextLineEventListener(buffer, documentMoniker, docId);
                    // Set the event handler for the change event. Note that there is no difference
                    // between the AddFile and FileChanged operation, so we can use the same handler.
                    listener.OnFileChanged += new EventHandler<HierarchyEventArgs>(OnNewFile);
                    // Add the listener to the dictionary, so we will not create it anymore.
                    _documents.Add(docCookie, listener);
                } finally {
                    if (IntPtr.Zero != unkDocData) {
                        Marshal.Release(unkDocData);
                    }
                }
            }
            // Always return success.
            return VSConstants.S_OK;
        }
Beispiel #11
0
 public LibraryTask(string fileName, ITextBuffer textBuffer, ModuleId moduleId)
 {
     this.FileName   = fileName;
     this.TextBuffer = textBuffer;
     this.ModuleId   = moduleId;
 }
Beispiel #12
0
        private void CreateModuleTree(LibraryNode current, IScopeNode scope, string namePrefix, ModuleId moduleId) {
            if ((null == scope) || (null == scope.NestedScopes)) {
                return;
            }

            foreach (IScopeNode subItem in scope.NestedScopes) {                
                LibraryNode newNode = CreateLibraryNode(current, subItem, namePrefix, moduleId.Hierarchy, moduleId.ItemID);
                string newNamePrefix = namePrefix;

                current.AddNode(newNode);
                if ((newNode.NodeType & LibraryNodeType.Classes) != LibraryNodeType.None) {
                    newNamePrefix = namePrefix + newNode.Name + ".";
                }

                // Now use recursion to get the other types.
                CreateModuleTree(newNode, subItem, newNamePrefix, moduleId);
            }
        }