Beispiel #1
0
        private void DeleteItem(FolderTreeViewItem item)
        {
            if (item.IsFolder)
            {
                if (Directory.Exists(item.Path))
                {
                    EditorFileUtility.DeleteToTrash(item.Path);
                }

                if (item.parent != null)
                {
                    item.parent.children.Remove(item);
                }
            }
            else
            {
                if (File.Exists(item.Path))
                {
                    EditorFileUtility.DeleteToTrash(item.Path);
                }

                if (item.parent != null)
                {
                    (item.parent as FolderTreeViewItem).FileList.Remove(item);
                }
            }
        }
Beispiel #2
0
        private void DuplicateItems()
        {
            if (m_TreeView.state.selectedIDs != null &&
                m_TreeView.state.selectedIDs.Count > 0)
            {
                List <int> idList = new List <int>();
                try
                {
                    m_TreeView.EndNameEditing(true);
                    foreach (var id in m_TreeView.state.selectedIDs)
                    {
                        if (id == m_TreeView.data.root.id)
                        {
                            continue;
                        }

                        var item    = m_TreeView.data.FindItem(id);
                        var newItem = JsonReader.Deserialize(JsonWriter.Serialize(item, new JsonWriterSettings()
                        {
                            MaxDepth = Int32.MaxValue
                        }), true) as FolderTreeViewItem;
                        var newPath = EditorFileUtility.GetNewFolder(newItem.Path);

                        FileUtil.CopyFileOrDirectory(newItem.Path, newPath);
                        newItem.id = m_TreeItemContainer.GetAutoID();
                        idList.Add(newItem.id);
                        newItem.Path        = newPath;
                        newItem.displayName = new DirectoryInfo(newPath).Name;
                        item.parent.AddChild(newItem);

                        newItem.FileList = null;
                        newItem.children = null;

                        var comparator = new AlphanumComparator.AlphanumComparator();
                        item.parent.children.Sort((viewItem, treeViewItem) =>
                        {
                            return(comparator.Compare(viewItem.displayName, treeViewItem.displayName));
                        });
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("复制item出错:" + e);
                }
                finally
                {
                    m_TreeItemContainer.UpdateValidItems();
                    m_TreeView.SetSelection(idList.ToArray(), true);
                    m_TreeView.data.RefreshData();
                    SetDirty();

                    if (DuplicateItemsDone != null)
                    {
                        DuplicateItemsDone();
                    }
                }
            }
        }
Beispiel #3
0
        private void CreateTxtFile(FolderTreeViewItem parentItem = null)
        {
            var dataContainer = m_FolderGridViewGroup.GetDataContainer();
            var gridView      = m_FolderGridViewGroup.GetGridView();

            if (parentItem == null)
            {
                if (!m_TreeView.isSearching)
                {
                    parentItem = m_TreeView.data.FindItem(m_TreeView.state.selectedIDs[0]) as FolderTreeViewItem;
                }
                else
                {
                    parentItem = m_TreeView.data.root as FolderTreeViewItem;
                }
            }

            var folderItem = new FileGridItem();

            folderItem.IsFolder = false;
            folderItem.ParentId = parentItem.id;
            folderItem.Id       = dataContainer.GetAutoID();
            var newPath = EditorFileUtility.GetNewFile(parentItem.Path, "New Txt", "txt");

            folderItem.Path = newPath;
            var fi = new System.IO.FileInfo(newPath);

            File.Create(newPath).Close();
            folderItem.DisplayName = Path.GetFileNameWithoutExtension(fi.Name);

            //添加到TreeView
            var child = new FolderTreeViewItem();

            child.Path        = fi.FullName.Replace("/", "\\");;
            child.IsFolder    = false;
            child.id          = folderItem.Id;
            child.displayName = folderItem.DisplayName;
            child.parent      = parentItem;
            child.SetConfigSource(m_WindowConfigSource);

            if (parentItem.FileList == null)
            {
                parentItem.FileList = new List <FolderTreeViewItem>();
            }
            parentItem.FileList.Add(child);

            m_FolderGridViewGroup.GetGridViewDataSource().ItemList.Add(folderItem);

            SortGridViewItem();

            m_FolderGridViewGroup.IsCreatingItem = true;
            gridView.SetSelection(new[] { folderItem.Id }, false);
            gridView.BeginRename(0);
        }
Beispiel #4
0
        private void CreateFolder(FolderTreeViewItem parentItem = null)
        {
            var dataContainer = m_FolderGridViewGroup.GetDataContainer();
            var gridView      = m_FolderGridViewGroup.GetGridView();

            if (parentItem == null)
            {
                if (!m_TreeView.isSearching)
                {
                    parentItem = m_TreeView.data.FindItem(m_TreeView.state.selectedIDs[0]) as FolderTreeViewItem;
                }
                else
                {
                    parentItem = m_TreeView.data.root as FolderTreeViewItem;
                }
            }

            var folderItem = new FolderGridItem();

            folderItem.IsFolder = true;
            folderItem.ParentId = parentItem.id;
            folderItem.Id       = dataContainer.GetAutoID();
            var newPath = EditorFileUtility.CreateNewFolder(parentItem.Path, "New Folder");

            folderItem.Path = newPath;
            var di = new DirectoryInfo(newPath);

            folderItem.DisplayName = di.Name;

            //重命名完成后添加到TreeView中
            m_FolderGridViewGroup.RenameEndWhenCreatingAction  = null;
            m_FolderGridViewGroup.RenameEndWhenCreatingAction += () =>
            {
                //添加到TreeView
                var child = new FolderTreeViewItem();
                child.Path        = di.FullName.Replace("/", "\\");;
                child.IsFolder    = true;
                child.id          = folderItem.Id;
                child.displayName = di.Name;
                child.parent      = parentItem;
                child.SetConfigSource(m_WindowConfigSource);
                parentItem.AddChild(child);
            };

            m_FolderGridViewGroup.GetGridViewDataSource().ItemList.Add(folderItem);

            SortGridViewItem();

            m_FolderGridViewGroup.IsCreatingItem = true;
            gridView.SetSelection(new[] { folderItem.Id }, false);
            gridView.BeginRename(0);
        }
Beispiel #5
0
        public bool Rename(string newName)
        {
            var result  = false;
            var newPath = EditorFileUtility.RenameFileOrDirectory(Path, newName, out result).Replace("/", "\\");

            if (!result)
            {
                return(result);
            }
            RenameChildren(Path, newPath);
            Path = newPath;
            return(true);
        }
        private void DuplicateItemGridView()
        {
            var selectedIdList = m_GridView.GetSelection();

            if (selectedIdList.Length == 0)
            {
                return;
            }

            List <int> idList = new List <int>();

            try
            {
                m_TreeView.EndNameEditing(true);
                m_GridView.EndRename(false);
                foreach (var id in selectedIdList)
                {
                    var item = m_GridViewDataSource.GetItemByIndex(m_GridViewDataSource.GetItemIndexByItemId(id)) as FolderGridItem;
                    FolderTreeViewItem treeItem       = null;
                    FolderTreeViewItem parentTreeItem = null;
                    if (item.IsFolder)
                    {
                        treeItem       = m_TreeView.FindItem(item.Id) as FolderTreeViewItem;
                        parentTreeItem = treeItem.parent as FolderTreeViewItem;
                    }
                    else
                    {
                        parentTreeItem = m_TreeView.FindItem(item.ParentId) as FolderTreeViewItem;
                        foreach (var child in parentTreeItem.FileList)
                        {
                            if (child.id == item.Id)
                            {
                                treeItem = child;
                                break;
                            }
                        }
                    }

                    if (item.IsFolder)
                    {
                        var newPath = EditorFileUtility.GetNewFolder(item.Path);
                        FileUtil.CopyFileOrDirectory(item.Path, newPath);
                        var newItem = JsonReader.Deserialize(JsonWriter.Serialize(treeItem, new JsonWriterSettings()
                        {
                            MaxDepth = Int32.MaxValue
                        }), true) as FolderTreeViewItem;

                        newItem.id       = m_FolderTreeViewGroup.GetDataContainer().GetAutoID();
                        newItem.FileList = null;
                        newItem.children = null;
                        idList.Add(newItem.id);

                        newItem.Path        = newPath;
                        newItem.displayName = new DirectoryInfo(newPath).Name;

                        var newGridItem = JsonReader.Deserialize(JsonWriter.Serialize(item, new JsonWriterSettings()
                        {
                            MaxDepth = Int32.MaxValue
                        }), item.GetType(), true) as FolderGridItem;
                        newGridItem.Id          = newItem.id;
                        newGridItem.Path        = newItem.Path;
                        newGridItem.DisplayName = newItem.displayName;
                        m_GridViewDataSource.ItemList.Add(newGridItem);

                        parentTreeItem.AddChild(newItem);
                        var comparator = new AlphanumComparator.AlphanumComparator();
                        parentTreeItem.children.Sort((viewItem, treeViewItem) =>
                        {
                            return(comparator.Compare(viewItem.displayName, treeViewItem.displayName));
                        });
                    }
                    else
                    {
                        var newPath = EditorFileUtility.GetNewFile(item.Path);
                        FileUtil.CopyFileOrDirectory(item.Path, newPath);
                        var newItem = JsonReader.Deserialize(JsonWriter.Serialize(treeItem, new JsonWriterSettings()
                        {
                            MaxDepth = Int32.MaxValue
                        }), true) as FolderTreeViewItem;
                        newItem.id = m_FolderTreeViewGroup.GetDataContainer().GetAutoID();
                        idList.Add(newItem.id);
                        newItem.Path        = newPath;
                        newItem.displayName = Path.GetFileNameWithoutExtension(newPath);
                        parentTreeItem.FileList.Add(newItem);

                        var newGridItem = JsonReader.Deserialize(JsonWriter.Serialize(item, new JsonWriterSettings()
                        {
                            MaxDepth = Int32.MaxValue
                        }), item.GetType(), true) as FolderGridItem;
                        newGridItem.Id          = newItem.id;
                        newGridItem.Path        = newItem.Path;
                        newGridItem.DisplayName = newItem.displayName;
                        m_GridViewDataSource.ItemList.Add(newGridItem);
                    }
                }

                m_GridView.SetSelection(idList.ToArray(), false);
            }
            catch (Exception e)
            {
                Debug.LogError("复制item出错:" + e);
            }
            finally
            {
                m_FolderTreeViewGroup.GetDataContainer().UpdateValidItems();
                m_TreeView.data.RefreshData();
                UpdateGridViewContent();
                if (m_ConfigSource != null)
                {
                    m_ConfigSource.SetConfigDirty();
                }
            }
        }