예제 #1
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 =
                _provider.GetService(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 (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 extension of the file to see if a listener is required.
                    //
                    string extension = Path.GetExtension(documentMoniker);

                    if (string.Compare(extension, NemerleConstants.FileExtension, StringComparison.OrdinalIgnoreCase) != 0)
                        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 += OnFileChanged;

                    // 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;
        }
예제 #2
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 =
                _provider.GetService(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 (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 extension of the file to see if a listener is required.
                    //
                    string extension = Path.GetExtension(documentMoniker);

                    if (string.Compare(extension, NemerleConstants.FileExtension, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        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 += OnFileChanged;

                    // 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);
        }