示例#1
0
        private void OnNewFile(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 (Microsoft.VisualStudio.ErrorHandler.Failed(hr))
                {
                    return;
                }
                hr = args.TextBuffer.GetLineText(0, 0, lastLine, lastIndex, out fileText);
                if (Microsoft.VisualStudio.ErrorHandler.Failed(hr))
                {
                    return;
                }
            }

            CreateParseRequest(args.CanonicalName, fileText, new ModuleId(hierarchy, args.ItemID));
        }
示例#2
0
        /// <summary>
        /// Do a recursive walk on the hierarchy to find all the python files in it.
        /// It will generate an event for every file found.
        /// </summary>
        private void InternalScanHierarchy(uint itemId)
        {
            uint currentItem = itemId;

            while (VSConstants.VSITEMID_NIL != currentItem)
            {
                // If this item is a python file, then send the add item event.
                string itemName;
                if ((null != onItemAdded) && IsSquirrelFile(currentItem, out itemName))
                {
                    HierarchyEventArgs args = new HierarchyEventArgs(currentItem, itemName, sqVersion);
                    onItemAdded(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);
                if (VSConstants.S_OK != hr)
                {
                    currentItem = VSConstants.VSITEMID_NIL;
                }
                else
                {
                    currentItem = GetItemId(sibling);
                }
            }
        }
        public void OnIdle()
        {
            if (!isDirty)
            {
                return;
            }
            if (null != onFileChanged)
            {
                HierarchyEventArgs args = new HierarchyEventArgs(fileId.ItemID, fileName, sqVersion);
                args.TextBuffer = buffer;
                onFileChanged(fileId.Hierarchy, args);
            }

            isDirty = false;
        }
示例#4
0
        public int OnItemDeleted(uint itemid)
        {
            Debug.WriteLine("\n\tOnItemDeleted\n");
            // Notify that the item is deleted only if it is a python file.
            string name;

            if (!IsSquirrelFile(itemid, out name))
            {
                return(VSConstants.S_OK);
            }
            if (null != onItemDeleted)
            {
                HierarchyEventArgs args = new HierarchyEventArgs(itemid, name, sqVersion);
                onItemDeleted(hierarchy, args);
            }
            return(VSConstants.S_OK);
        }
示例#5
0
        public int OnItemAdded(uint itemidParent, uint itemidSiblingPrev, uint itemidAdded)
        {
            // Check if the item is a python file.
            Debug.WriteLine("\n\tOnItemAdded\n");
            string name;

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

            // This item is a python file, so we can notify that it is added to the hierarchy.
            if (null != onItemAdded)
            {
                HierarchyEventArgs args = new HierarchyEventArgs(itemidAdded, name, sqVersion);
                onItemAdded(hierarchy, args);
            }
            return(VSConstants.S_OK);
        }
示例#6
0
        private void OnDeleteFile(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;

            if (null == hierarchy)
            {
                return;
            }
            ModuleId id = new ModuleId(hierarchy, args.ItemID);

            lock (library)
            {
                List <LibraryNode> retlist;
                if (library.Files.TryGetValue(args.CanonicalName, out retlist))
                {
                    library.Release(retlist);
                    library.Files.Remove(args.CanonicalName);
                }
            }
        }