Example #1
0
        /// <summary>
        /// Called when a project is loaded
        /// </summary>
        /// <param name="hierarchy"></param>
        public void RegisterHierarchy(IVsHierarchy hierarchy, XProject Prj, XSharpProjectNode ProjectNode)
        {
            // No Hierarchy or... Hierarchy already registered ?
            var optionsPage = XSharpProjectPackage.Instance.GetIntellisenseOptionsPage();

            // disable classview for now
            if (optionsPage.DisableClassViewObjectView)// || true)
            {
                return;
            }

            if ((null == hierarchy) || hierarchies.ContainsKey(hierarchy))
            {
                return;
            }
            //
            if (0 == objectManagerCookie)
            {
                IVsObjectManager2 objManager = provider.GetService(typeof(SVsObjectManager)) as IVsObjectManager2;
                if (null == objManager)
                {
                    return;
                }
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    objManager.RegisterSimpleLibrary(library, out objectManagerCookie));
            }
            // The project is the Root of the Library
            XSharpLibraryProject prjNode = new XSharpLibraryProject(Prj, hierarchy);

            library.AddNode(prjNode);

            //this._defaultNameSpace = prjNode.DefaultNameSpace;
            //Define Callback
            ProjectNode.ProjectModel.FileWalkComplete    = new XProject.OnFileWalkComplete(OnFileWalkComplete);
            ProjectNode.ProjectModel.ProjectWalkComplete = new XProject.OnProjectWalkComplete(OnProjectWalkComplete);

            // Attach a listener to the Project/Hierarchy,so any change is raising an event
            HierarchyListener listener = new HierarchyListener(hierarchy);

            //listener.OnAddItem += new EventHandler<HierarchyEventArgs>(OnNewFile);
            listener.OnDeleteItem += new EventHandler <HierarchyEventArgs>(OnDeleteFile);
            listener.StartListening();
            hierarchies.Add(hierarchy, listener);
            // and ask for any change in the files that are opened in Source editor.
            RegisterForRDTEvents();
        }
Example #2
0
        public void UnregisterHierarchy(IVsHierarchy hierarchy)
        {
            if ((null == hierarchy) || !hierarchies.ContainsKey(hierarchy))
            {
                return;
            }
            // Retrieve the listener for that Tree/Hierarchy
            HierarchyListener listener = hierarchies[hierarchy];

            if (null != listener)
            {
                listener.Dispose();
            }
            hierarchies.Remove(hierarchy);
            if (0 == hierarchies.Count)
            {
                UnregisterRDTEvents();
            }
            // Now remove all nodes
            // for all files
            lock (files)
            {
                XSharpModuleId[] keys = new XSharpModuleId[files.Keys.Count];
                // Get all Keys (ModuleId)
                files.Keys.CopyTo(keys, 0);
                foreach (XSharpModuleId id in keys)
                {
                    // The file is owned by the Hierarchy ?
                    if (hierarchy.Equals(id.Hierarchy))
                    {
                        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.parent != null)
                                {
                                    node.parent.RemoveNode(node);
                                }
                            }
                        }
                        // and then remove the key
                        files.Remove(id);
                    }
                }
            }
            //
            LibraryNode prjNode = this.library.SearchHierarchy(hierarchy);

            if (prjNode is XSharpLibraryProject)
            {
                library.RemoveNode(prjNode);
            }
#if TEXTCHANGELISTENER
            // Remove the document listeners.
            uint[] docKeys = new uint[documents.Keys.Count];
            documents.Keys.CopyTo(docKeys, 0);
            foreach (uint id in docKeys)
            {
                TextLineEventListener docListener = documents[id];
                if (hierarchy.Equals(docListener.FileID.Hierarchy))
                {
                    documents.Remove(id);
                    docListener.Dispose();
                }
            }
#endif
        }