Ejemplo n.º 1
0
        /// <summary>
        /// Handles the delete event, checking to see if this is a project item.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnDeleteFile(object sender, HierarchyEventArgs args)
        {
            var hierarchy = sender as IVsHierarchy;
            if (null == hierarchy || IsNonMemberItem(hierarchy, args.ItemID))
            {
                return;
            }

            OnDeleteFile(hierarchy, args);
        }
Ejemplo n.º 2
0
            public int OnItemDeleted(uint itemid)
            {
                // Notify that the item is deleted only if it is my language file.
                if (!IsAnalyzableSource(itemid, out var name))
                {
                    return(VSConstants.S_OK);
                }
                var args = new HierarchyEventArgs(itemid, name);

                this._manager.OnDeleteFile(this._hierarchy, args);
                return(VSConstants.S_OK);
            }
Ejemplo n.º 3
0
            public int OnItemAdded(uint itemidParent, uint itemidSiblingPrev, uint itemidAdded)
            {
                // Check if the item is my language file.
                if (!IsAnalyzableSource(itemidAdded, out var name))
                {
                    return(VSConstants.S_OK);
                }

                // This item is a my language file, so we can notify that it is added to the hierarchy.
                var args = new HierarchyEventArgs(itemidAdded, name);

                this._manager.OnNewFile(this._hierarchy, args);
                return(VSConstants.S_OK);
            }
Ejemplo n.º 4
0
            /// <summary>
            /// Do a recursive walk on the hierarchy to find all this language 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 my language file, then send the add item event.
                    string itemName;
                    if (IsAnalyzableSource(currentItem, out itemName))
                    {
                        HierarchyEventArgs args = new HierarchyEventArgs(currentItem, itemName);
                        _manager.OnNewFile(_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);
                    }
                }
            }
        /// <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);
                }
            }
            if (null != node)
            {
                _library.RemoveNode(node);
            }
        }
Ejemplo n.º 6
0
        private void IsNonMemberItemChanged(object sender, HierarchyEventArgs args)
        {
            var hierarchy = sender as IVsHierarchy;
            if (null == hierarchy)
            {
                return;
            }

            if (!IsNonMemberItem(hierarchy, args.ItemID))
            {
                OnNewFile(hierarchy, args);
            }
            else
            {
                OnDeleteFile(hierarchy, args);
            }
        }
Ejemplo n.º 7
0
        private void OnNewFile(object sender, HierarchyEventArgs args)
        {
            var hierarchy = sender as IVsHierarchy;
            if (null == hierarchy || IsNonMemberItem(hierarchy, args.ItemID))
            {
                return;
            }

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

            var id = new ModuleId(hierarchy, args.ItemID);
            OnNewFile(new LibraryTask(args.CanonicalName, buffer, new ModuleId(hierarchy, args.ItemID)));
        }
Ejemplo n.º 8
0
        public void OnIdle()
        {
            if (!_isDirty)
            {
                return;
            }
            var onFileChanged = OnFileChanged;

            if (null != onFileChanged)
            {
                HierarchyEventArgs args = new HierarchyEventArgs(_fileId.ItemID, _fileName);
                args.TextBuffer = _buffer;
                onFileChanged(_fileId.Hierarchy, args);
            }

            _isDirty = false;
        }
Ejemplo n.º 9
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)
 {
     var id = new ModuleId(hierarchy, args.ItemID);
     LibraryNode node = null;
     lock (this._files)
     {
         if (this._files.TryGetValue(id, out node))
         {
             this._files.Remove(id);
             if (this._hierarchies.TryGetValue(hierarchy, out var parent))
             {
                 parent.ProjectLibraryNode.RemoveNode(node);
             }
         }
     }
     if (null != node)
     {
         this._library.RemoveNode(node);
     }
 }
Ejemplo n.º 10
0
 public int OnBeforeLastDocumentUnlock(uint docCookie, uint dwRDTLockType, uint dwReadLocksRemaining, uint dwEditLocksRemaining)
 {
     if ((0 != dwEditLocksRemaining) || (0 != dwReadLocksRemaining))
     {
         return VSConstants.S_OK;
     }
     if (!this._documents.TryGetValue(docCookie, out var listener) || (null == listener))
     {
         return VSConstants.S_OK;
     }
     using (listener)
     {
         this._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).
         var args = new HierarchyEventArgs(listener.FileID.ItemId, listener.FileName);
         OnNewFile(listener.FileID.Hierarchy, args);
     }
     return VSConstants.S_OK;
 }
Ejemplo n.º 11
0
        private void IsNonMemberItemChanged(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;
            if (null == hierarchy) {
                return;
            }

            if (!IsNonMemberItem(hierarchy, args.ItemID)) {
                OnNewFile(hierarchy, args);
            } else {
                OnDeleteFile(hierarchy, args);
            }
        }
Ejemplo n.º 12
0
            /// <summary>
            /// Do a recursive walk on the hierarchy to find all this language 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 my language file, then send the add item event.
                    string itemName;
                    if (IsAnalyzableSource(currentItem, out itemName)) {
                        HierarchyEventArgs args = new HierarchyEventArgs(currentItem, itemName);
                        _manager.OnNewFile(_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);
                    }
                }
            }
Ejemplo n.º 13
0
 public int OnItemDeleted(uint itemid) {
     // Notify that the item is deleted only if it is my language file.
     string name;
     if (!IsAnalyzableSource(itemid, out name)) {
         return VSConstants.S_OK;
     }
     HierarchyEventArgs args = new HierarchyEventArgs(itemid, name);
     _manager.OnDeleteFile(_hierarchy, args);
     return VSConstants.S_OK;
 }
Ejemplo n.º 14
0
            public int OnItemAdded(uint itemidParent, uint itemidSiblingPrev, uint itemidAdded) {
                // Check if the item is my language file.
                string name;
                if (!IsAnalyzableSource(itemidAdded, out name)) {
                    return VSConstants.S_OK;
                }

                // This item is a my language file, so we can notify that it is added to the hierarchy.
                HierarchyEventArgs args = new HierarchyEventArgs(itemidAdded, name);
                _manager.OnNewFile(_hierarchy, args);
                return VSConstants.S_OK;
            }
Ejemplo n.º 15
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)));
        }
Ejemplo n.º 16
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);
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Handles the delete event, checking to see if this is a project item.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void OnDeleteFile(object sender, HierarchyEventArgs args)
        {
            IVsHierarchy hierarchy = sender as IVsHierarchy;
            if (null == hierarchy || IsNonMemberItem(hierarchy, args.ItemID)) {
                return;
            }

            OnDeleteFile(hierarchy, args);
        }
Ejemplo n.º 18
0
 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);
         OnNewFile(listener.FileID.Hierarchy, args);
     }
     return VSConstants.S_OK;
 }
Ejemplo n.º 19
0
        public void OnIdle() {
            if (!_isDirty) {
                return;
            }
            var onFileChanged = OnFileChanged;
            if (null != onFileChanged) {
                HierarchyEventArgs args = new HierarchyEventArgs(_fileId.ItemID, _fileName);
                args.TextBuffer = _buffer;
                onFileChanged(_fileId.Hierarchy, args);
            }

            _isDirty = false;
        }