Ejemplo n.º 1
0
        void FileTabManager_FileCollectionChanged(object sender, NotifyFileCollectionChangedEventArgs e)
        {
            switch (e.Type)
            {
            case NotifyFileCollectionType.Clear:
            case NotifyFileCollectionType.Remove:
                var existing = new HashSet <ModuleId>(fileTabManager.FileTreeView.GetAllModuleNodes().Select(a => moduleIdProvider.Create(a.DnSpyFile.ModuleDef)));
                var removed  = new HashSet <ModuleId>(e.Files.Select(a => moduleIdProvider.Create(a.ModuleDef)));
                existing.Remove(new ModuleId());
                removed.Remove(new ModuleId());
                object orbArg = null;
                if (OnRemoveBreakpoints != null)
                {
                    orbArg = OnRemoveBreakpoints(orbArg);
                }
                foreach (var ilbp in GetILCodeBreakpoints())
                {
                    // Don't auto-remove BPs in dynamic modules since they have no disk file. The
                    // user must delete these him/herself.
                    if (ilbp.MethodToken.Module.IsDynamic)
                    {
                        continue;
                    }

                    // If the file is still in the TV, don't delete anything. This can happen if
                    // we've loaded an in-memory module and the node just got removed.
                    if (existing.Contains(ilbp.MethodToken.Module))
                    {
                        continue;
                    }

                    if (removed.Contains(ilbp.MethodToken.Module))
                    {
                        Remove(ilbp);
                    }
                }
                OnRemoveBreakpoints?.Invoke(orbArg);
                break;

            case NotifyFileCollectionType.Add:
                break;
            }
        }
Ejemplo n.º 2
0
        void FileManager_CollectionChanged(object sender, NotifyFileCollectionChangedEventArgs e)
        {
            switch (e.Type)
            {
            case NotifyFileCollectionType.Clear:
                ClearAll();
                break;

            case NotifyFileCollectionType.Add:
                AnalyzerTreeNodeData.HandleAssemblyListChanged(TreeView.Root, Array.Empty <IDnSpyFile>(), e.Files);
                break;

            case NotifyFileCollectionType.Remove:
                AnalyzerTreeNodeData.HandleAssemblyListChanged(TreeView.Root, e.Files, Array.Empty <IDnSpyFile>());
                break;

            default:
                break;
            }
        }
Ejemplo n.º 3
0
        void FileManager_CollectionChanged(object sender, NotifyFileCollectionChangedEventArgs e)
        {
            switch (e.Type)
            {
            case NotifyFileCollectionType.Clear:
            case NotifyFileCollectionType.Remove:
                var existing = new HashSet <SerializedDnModule>(fileTabManager.FileTreeView.GetAllModuleNodes().Select(a => a.DnSpyFile.ToSerializedDnModule()));
                var removed  = new HashSet <SerializedDnModule>(e.Files.Select(a => a.ToSerializedDnModule()));
                existing.Remove(new SerializedDnModule());
                removed.Remove(new SerializedDnModule());
                foreach (var ilbp in ILCodeBreakpoints)
                {
                    // Don't auto-remove BPs in dynamic modules since they have no disk file. The
                    // user must delete these him/herself.
                    if (ilbp.SerializedDnToken.Module.IsDynamic)
                    {
                        continue;
                    }

                    // If the file is still in the TV, don't delete anything. This can happen if
                    // we've loaded an in-memory module and the node just got removed.
                    if (existing.Contains(ilbp.SerializedDnToken.Module))
                    {
                        continue;
                    }

                    if (removed.Contains(ilbp.SerializedDnToken.Module))
                    {
                        Remove(ilbp);
                    }
                }
                break;

            case NotifyFileCollectionType.Add:
                break;
            }
        }
Ejemplo n.º 4
0
        public void Remove(IEnumerable <IDnSpyFile> files)
        {
            var removedFiles = new List <IDnSpyFile>();

            lock (lockObj) {
                var dict = new Dictionary <IDnSpyFile, int>();
                int i    = 0;
                foreach (var n in this.files)
                {
                    dict[n] = i++;
                }
                var list = new List <Tuple <IDnSpyFile, int> >(files.Select(a => {
                    int j;
                    bool b = dict.TryGetValue(a, out j);
                    Debug.Assert(b);
                    return(Tuple.Create(a, b ? j : -1));
                }));
                list.Sort((a, b) => b.Item2.CompareTo(a.Item2));
                foreach (var t in list)
                {
                    if (t.Item2 < 0)
                    {
                        continue;
                    }
                    Debug.Assert((uint)t.Item2 < (uint)this.files.Count);
                    Debug.Assert(this.files[t.Item2] == t.Item1);
                    this.files.RemoveAt(t.Item2);
                    removedFiles.Add(t.Item1);
                }
            }

            if (removedFiles.Count > 0)
            {
                CallCollectionChanged(NotifyFileCollectionChangedEventArgs.CreateRemove(removedFiles.ToArray(), null));
            }
        }
Ejemplo n.º 5
0
        void FileManager_CollectionChanged(object sender, NotifyFileCollectionChangedEventArgs e)
        {
            switch (e.Type)
            {
            case NotifyFileCollectionType.Add:
                IDnSpyFileNode newNode;

                var addFileInfo = e.Data as AddFileInfo;
                int index;
                if (addFileInfo != null)
                {
                    newNode = addFileInfo.DnSpyFileNode;
                    index   = addFileInfo.Index;
                    if (newNode.TreeNode == null)
                    {
                        TreeView.Create(newNode);
                    }
                }
                else
                {
                    newNode = CreateNode(null, e.Files[0]);
                    TreeView.Create(newNode);
                    index = TreeView.Root.Children.Count;
                }

                if ((uint)index >= (uint)TreeView.Root.Children.Count)
                {
                    index = TreeView.Root.Children.Count;
                }
                TreeView.Root.Children.Insert(index, newNode.TreeNode);
                CallCollectionChanged(NotifyFileTreeViewCollectionChangedEventArgs.CreateAdd(newNode));
                break;

            case NotifyFileCollectionType.Remove:
                var dict  = new Dictionary <IDnSpyFileNode, int>();
                var dict2 = new Dictionary <IDnSpyFile, IDnSpyFileNode>();
                int i     = 0;
                foreach (var n in TopNodes)
                {
                    dict[n]            = i++;
                    dict2[n.DnSpyFile] = n;
                }
                var list = new List <Tuple <IDnSpyFileNode, int> >(e.Files.Select(a => {
                    IDnSpyFileNode node;
                    bool b = dict2.TryGetValue(a, out node);
                    Debug.Assert(b);
                    int j = -1;
                    b     = b && dict.TryGetValue(node, out j);
                    Debug.Assert(b);
                    return(Tuple.Create(node, b ? j : -1));
                }));
                list.Sort((a, b) => b.Item2.CompareTo(a.Item2));
                var removed = new List <IDnSpyFileNode>();
                foreach (var t in list)
                {
                    if (t.Item2 < 0)
                    {
                        continue;
                    }
                    Debug.Assert((uint)t.Item2 < (uint)TreeView.Root.Children.Count);
                    Debug.Assert(TreeView.Root.Children[t.Item2].Data == t.Item1);
                    TreeView.Root.Children.RemoveAt(t.Item2);
                    removed.Add(t.Item1);
                }
                DisableMemoryMappedIO(list.Select(a => a.Item1).ToArray());
                CallCollectionChanged(NotifyFileTreeViewCollectionChangedEventArgs.CreateRemove(removed.ToArray()));
                break;

            case NotifyFileCollectionType.Clear:
                var oldNodes = TreeView.Root.Children.Select(a => (IDnSpyFileNode)a.Data).ToArray();
                TreeView.Root.Children.Clear();
                DisableMemoryMappedIO(oldNodes);
                CallCollectionChanged(NotifyFileTreeViewCollectionChangedEventArgs.CreateClear(oldNodes));
                break;

            default:
                Debug.Fail(string.Format("Unknown event type: {0}", e.Type));
                break;
            }
        }
Ejemplo n.º 6
0
 void CallCollectionChanged2(NotifyFileCollectionChangedEventArgs eventArgs) =>
 CollectionChanged?.Invoke(this, eventArgs);
Ejemplo n.º 7
0
 void FileManager_CollectionChanged(object sender, NotifyFileCollectionChangedEventArgs e)
 {
     CallFileCollectionChanged(e);
 }