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); }
private void UpdateSelectionItems() { var treeView = m_FolderGridViewGroup.GetFolderGridViewGroup().GetTreeView(); if (treeView.data == null) { return; } var gridViewDataSource = m_FolderGridViewGroup.GetGridViewDataSource(); var itemList = gridViewDataSource.ItemList; itemList.Clear(); if (treeView.state.selectedIDs != null) { foreach (var id in treeView.state.selectedIDs) { var folderTreeItem = treeView.data.FindItem(id) as FolderTreeViewItem; if (folderTreeItem != null && folderTreeItem.hasChildren) { foreach (var child in folderTreeItem.children) { var gridItem = new FolderGridItem(); var childFolderItem = child as FolderTreeViewItem; gridItem.Id = child.id; gridItem.DisplayName = child.displayName; gridItem.Path = childFolderItem.Path; gridItem.ParentId = folderTreeItem.id; gridItem.IsFolder = true; gridItem.IsChildItem = false; itemList.Add(gridItem); } } if (folderTreeItem != null && folderTreeItem.FileList != null) { foreach (var child in folderTreeItem.FileList) { var gridItem = new FileGridItem(); gridItem.Id = child.id; gridItem.DisplayName = child.displayName; gridItem.Path = child.Path; gridItem.ParentId = folderTreeItem.id; gridItem.IsFolder = false; gridItem.IsChildItem = false; itemList.Add(gridItem); } } } } SortGridViewItem(); }
private void GetSearchItems(string searchText, FolderTreeViewItem item, List <GridItem> itemList) { if (item != m_DataContainer.RootItem) { if (item.displayName.ToLower().Contains(searchText)) { var gridItem = new FolderGridItem(); gridItem.Id = item.id; gridItem.DisplayName = item.displayName; gridItem.Path = item.Path; gridItem.ParentId = item.parent.id; gridItem.IsFolder = true; itemList.Add(gridItem); } } if (item.hasChildren) { foreach (var child in item.children) { GetSearchItems(searchText, child as FolderTreeViewItem, itemList); } } if (item.FileList != null) { foreach (var child in item.FileList) { if (child.displayName.ToLower().Contains(searchText)) { var gridItem = new FileGridItem(); gridItem.Id = child.id; gridItem.DisplayName = child.displayName; gridItem.Path = child.Path; gridItem.ParentId = item.id; gridItem.IsFolder = false; itemList.Add(gridItem); } } } }