public int OnBeforeLastDocumentUnlock(
            uint docCookie,
            uint dwRDTLockType,
            uint dwReadLocksRemaining,
            uint dwEditLocksRemaining)
        {
            if ((0 != dwEditLocksRemaining) || (0 != dwReadLocksRemaining))
            {
                return(VSConstants.S_OK);
            }

            TextLineEventListener listener;

            if (!_documents.TryGetValue(docCookie, out listener) || (null == listener))
            {
                return(VSConstants.S_OK);
            }

            using (listener)
            {
                _documents.Remove(docCookie);

                // Now make sure that the information about this file are up to date
                // (e.g. it is possible that Class View shows something strange if the
                // file was closed without saving the changes).
                //
                HierarchyEventArgs args = new HierarchyEventArgs(listener.FileID.ItemID, listener.FileName);

                OnFileChanged(listener.FileID.Hierarchy, args);
            }
            return(VSConstants.S_OK);
        }
Beispiel #2
0
        public int OnItemAdded(uint itemidParent, uint itemidSiblingPrev, uint itemidAdded)
        {
            // Check if the item is a nemerle file.
            //

            string itemName;
            string parentName;
            string siblingName;

            _hierarchy.GetCanonicalName(itemidAdded, out itemName);
            _hierarchy.GetCanonicalName(itemidParent, out parentName);
            _hierarchy.GetCanonicalName(itemidSiblingPrev, out siblingName);

            Debug.WriteLine(string.Format("\tOnItemsAdded {0} to {1} next to {2} \n", Path.GetFileName(itemName),
                                          Path.GetFileName(parentName),
                                          Path.GetFileName(siblingName)));

            string name;

            if (!IsNemerleFile(itemidAdded, out name))
            {
                return(VSConstants.S_OK);
            }

            // This item is a nemerle file, so we can notify that it is added to the hierarchy.
            //
            if (ItemAdded != null)
            {
                HierarchyEventArgs args = new HierarchyEventArgs(itemidAdded, name);
                ItemAdded(_hierarchy, args);
            }

            return(VSConstants.S_OK);
        }
        private void FileDeleted(object sender, HierarchyEventArgs ergs)
        {
            Debug.Assert(ergs.TextBuffer == null);

            string path = ergs.FileName;

            RemoveSource(path);
        }
Beispiel #4
0
        /// <summary>
        /// Do a recursive walk on the hierarchy to find all the nemerle files in
        /// it. It will generate an event for every file found.
        /// </summary>
        void InternalScanHierarchy(uint itemId)
        {
            uint currentItem = itemId;

            while (VSConstants.VSITEMID_NIL != currentItem)
            {
                // If this item is a nemerle file, then send the add item event.
                string itemName;

                if (ItemAdded != null && IsNemerleFile(currentItem, out itemName))
                {
                    HierarchyEventArgs args = new HierarchyEventArgs(currentItem, itemName);
                    ItemAdded(_hierarchy, args);
                }

                // NOTE: At the moment we skip the nested hierarchies, so here  we
                // look for the  children of this node. Before looking at the children
                // we have to make sure that the enumeration has not side effects to
                // avoid unexpected behavior.
                //
                object propertyValue;
                bool   canScanSubitems = true;
                int    hr = _hierarchy.GetProperty(
                    currentItem, (int)__VSHPROPID.VSHPROPID_HasEnumerationSideEffects, out propertyValue);

                if ((VSConstants.S_OK == hr) && (propertyValue is bool))
                {
                    canScanSubitems = !(bool)propertyValue;
                }

                // If it is allow to look at the sub-items of the current one, lets do it.
                //
                if (canScanSubitems)
                {
                    object child;

                    hr = _hierarchy.GetProperty(currentItem, (int)__VSHPROPID.VSHPROPID_FirstChild, out child);

                    if (VSConstants.S_OK == hr)
                    {
                        // There is a sub-item, call this same function on it.
                        InternalScanHierarchy(GetItemId(child));
                    }
                }

                // Move the current item to its first visible sibling.
                //
                object sibling;

                hr = _hierarchy.GetProperty(currentItem, (int)__VSHPROPID.VSHPROPID_NextSibling, out sibling);

                currentItem = VSConstants.S_OK != hr? VSConstants.VSITEMID_NIL: GetItemId(sibling);
            }
        }
        private void FileAdded(object sender, HierarchyEventArgs ergs)
        {
            Debug.Assert(ergs.TextBuffer == null);

            IVsHierarchy hierarchy = (IVsHierarchy)sender;
            NemerleFileNodeProperties nodeProps = GetNodeProperties(hierarchy, ergs.ItemID);

            if (nodeProps.BuildAction != BuildAction.Compile)
            {
                return;
            }

            string path = ergs.FileName;

            AddSource(path);
        }
Beispiel #6
0
        public void OnIdle()
        {
            if (!_isDirty)
            {
                return;
            }

            if (_onFileChanged != null)
            {
                HierarchyEventArgs args = new HierarchyEventArgs(_fileId.ItemID, _fileName);

                args.TextBuffer = _buffer;

                _onFileChanged(_fileId.Hierarchy, args);
            }

            _isDirty = false;
        }
Beispiel #7
0
        public int OnItemDeleted(uint itemid)
        {
            Debug.WriteLine("\n\tOnItemDeleted\n");

            // Notify that the item is deleted only if it is a nemerle file.
            //
            string name;

            if (!IsNemerleFile(itemid, out name))
            {
                return(VSConstants.S_OK);
            }

            if (ItemDeleted != null)
            {
                HierarchyEventArgs args = new HierarchyEventArgs(itemid, name);
                ItemDeleted(_hierarchy, args);
            }

            return(VSConstants.S_OK);
        }
        void OnFileChanged(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;

            if (null == hierarchy)
            {
                return;
            }

            string fileText = null;

            if (null != args.TextBuffer)
            {
                int lastLine;
                int lastIndex;
                int hr = args.TextBuffer.GetLastLineIndex(out lastLine, out lastIndex);

                if (ErrorHandler.Failed(hr))
                {
                    return;
                }

                hr = args.TextBuffer.GetLineText(0, 0, lastLine, lastIndex, out fileText);

                if (ErrorHandler.Failed(hr))
                {
                    return;
                }

                var projectInfo = ProjectInfo.FindProject(hierarchy);
                if (null != projectInfo)
                {
                    int fileIndex = Nemerle.Compiler.Location.GetFileIndex(args.FileName);
                    projectInfo.Engine.NotifySourceChanged(new StringSource(fileIndex, fileText));
                }
            }

            CreateParseRequest(args.FileName, fileText, new ModuleID(hierarchy, args.ItemID));
        }
        void OnDeleteFile(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;

            if (null == hierarchy)
            {
                return;
            }

            ModuleID    id = new ModuleID(hierarchy, args.ItemID);
            LibraryNode node;

            lock (_files)
                if (_files.TryGetValue(id, out node))
                {
                    _files.Remove(id);
                }

            if (null != node)
            {
                _library.RemoveNode(node);
            }
        }
        void OnFileChanged(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;

            if (null == hierarchy)
                return;

            string fileText = null;

            if (null != args.TextBuffer)
            {
                int lastLine;
                int lastIndex;
                int hr = args.TextBuffer.GetLastLineIndex(out lastLine, out lastIndex);

                if (ErrorHandler.Failed(hr))
                    return;

                hr = args.TextBuffer.GetLineText(0, 0, lastLine, lastIndex, out fileText);

                if (ErrorHandler.Failed(hr))
                    return;

                var projectInfo = ProjectInfo.FindProject(hierarchy);
                if (null != projectInfo)
                {
                    int fileIndex = Nemerle.Compiler.Location.GetFileIndex(args.FileName);
                    projectInfo.Engine.NotifySourceChanged(new StringSource(fileIndex, fileText));
                }
            }

            CreateParseRequest(args.FileName, fileText, new ModuleID(hierarchy, args.ItemID));
        }
        void OnDeleteFile(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;

            if (null == hierarchy)
                return;

            ModuleID	id = new ModuleID(hierarchy, args.ItemID);
            LibraryNode node;

            lock (_files)
                if (_files.TryGetValue(id, out node))
                    _files.Remove(id);

            if (null != node)
                _library.RemoveNode(node);
        }
        public int OnBeforeLastDocumentUnlock(
            uint docCookie,
            uint dwRDTLockType,
            uint dwReadLocksRemaining,
            uint dwEditLocksRemaining)
        {
            if ((0 != dwEditLocksRemaining) || (0 != dwReadLocksRemaining))
                return VSConstants.S_OK;

            TextLineEventListener listener;

            if (!_documents.TryGetValue(docCookie, out listener) || (null == listener))
                return VSConstants.S_OK;

            using (listener)
            {
                _documents.Remove(docCookie);

                // Now make sure that the information about this file are up to date
                // (e.g. it is possible that Class View shows something strange if the
                // file was closed without saving the changes).
                //
                HierarchyEventArgs args = new HierarchyEventArgs(listener.FileID.ItemID, listener.FileName);

                OnFileChanged(listener.FileID.Hierarchy, args);
            }
            return VSConstants.S_OK;
        }
        public void OnIdle()
        {
            if (!_isDirty)
                return;

            if (_onFileChanged != null)
            {
                HierarchyEventArgs args = new HierarchyEventArgs(_fileId.ItemID, _fileName);

                args.TextBuffer = _buffer;

                _onFileChanged(_fileId.Hierarchy, args);
            }

            _isDirty = false;
        }