コード例 #1
0
        /// <summary>
        /// Handle the deletion of a file in the Solution Hierarchy
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnDeleteFile(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;

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

            lock (files)
            {
                HashSet <XSharpLibraryNode> values = null;
                // Ok, now remove ALL nodes for that key
                if (files.TryGetValue(id, out values))
                {
                    foreach (XSharpLibraryNode node in values)
                    {
                        if (node.Freeing(id.ItemID) == 0)
                        {
                            if (node.parent != null)
                            {
                                node.parent.RemoveNode(node);
                            }
                        }
                    }
                }
                // and then remove the key
                files.Remove(id);
            }
            //
        }
コード例 #2
0
        /// <summary>
        /// Called when a new file is added in the Project Hierarchy
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        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;
                }
            }
            CreateUpdateTreeRequest(args.CanonicalName, new XSharpModuleId(hierarchy, args.ItemID));
        }
コード例 #3
0
        /// <summary>
        /// Do a recursive walk on the hierarchy to find all the PRG 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 PRG file, then send the add item event.
                string itemName;
                if ((null != onItemAdded) && IsPrgFile(currentItem, out itemName))
                {
                    HierarchyEventArgs args = new HierarchyEventArgs(currentItem, itemName);
                    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);
                }
            }
        }
コード例 #4
0
        public void OnIdle()
        {
            if (!isDirty)
            {
                return;
            }
            if (null != onFileChanged)
            {
                HierarchyEventArgs args = new HierarchyEventArgs(fileId.ItemID, fileName);
                args.TextBuffer = buffer;
                // Enqueue a Library Request
                //onFileChanged(fileId.Hierarchy, args);
            }

            isDirty = false;
        }
コード例 #5
0
        public int OnItemDeleted(uint itemid)
        {
            Debug.WriteLine("--> OnItemDeleted");
            // Notify that the item is deleted only if it is a PRG file.
            string name;

            if (!IsPrgFile(itemid, out name))
            {
                return(VSConstants.S_OK);
            }
            if (null != onItemDeleted)
            {
                HierarchyEventArgs args = new HierarchyEventArgs(itemid, name);
                onItemDeleted(hierarchy, args);
            }
            return(VSConstants.S_OK);
        }
コード例 #6
0
        public int OnItemAdded(uint itemidParent, uint itemidSiblingPrev, uint itemidAdded)
        {
            // Check if the item is a PRG file.
            Debug.WriteLine("--> OnItemAdded");
            string name;

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

            // This item is a PRG file, so we can notify that it is added to the hierarchy.
            if (null != onItemAdded)
            {
                HierarchyEventArgs args = new HierarchyEventArgs(itemidAdded, name);
                onItemAdded(hierarchy, args);
            }
            return(VSConstants.S_OK);
        }
コード例 #7
0
        public int OnBeforeLastDocumentUnlock(uint docCookie, uint dwRDTLockType, uint dwReadLocksRemaining, uint dwEditLocksRemaining)
        {
#if TEXTCHANGELISTENER
            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);
                OnNewFile(listener.FileID.Hierarchy, args);
            }
#endif
            return(VSConstants.S_OK);
        }