protected override void InitData() { WindowConfigSource = FileConfigSource.CreateFileConfigSource("ViewConfig/TestWindow/config4.txt", true, typeof(FolderTreeViewTestWindowConfig)); m_FolderTreeViewGroup = new FolderTreeViewGroup(m_LayoutGroupMgr, WindowConfigSource, "TreeViewStateConfig", "TreeViewDataContainer"); m_FolderTreeViewGroup.Active = false; m_DataContainer = m_FolderTreeViewGroup.GetDataContainer(); m_DataContainer.ExtNames = ExtNames; m_DataContainer.UpdateValidItems(); m_TreeView = m_FolderTreeViewGroup.GetTreeView(); m_TreeView.useExpansionAnimation = true; m_TreeView.deselectOnUnhandledMouseDown = true; m_TreeView.contextClickItemCallback = ContextClickItemCallback; m_TreeView.contextClickOutsideItemsCallback = ContextClickOutsideItemsCallback; m_LayoutGroupMgr.AddViewGroup(m_FolderTreeViewGroup); m_TipsViewGroup = new TipsViewGroup(m_LayoutGroupMgr); m_TipsViewGroup.Active = false; m_TipsViewGroup.TipStr = "当前根目录路径不存在,请配置根目录路径"; m_TipsViewGroup.DrawAction += () => { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("选择目录")) { var path = EditorUtility.OpenFolderPanel("选择目录", "", ""); if (!string.IsNullOrEmpty(path)) { if (m_DataContainer.RootFolderPath != path) { m_DataContainer.RootFolderPath = path; m_TreeView.state.expandedIDs = new List <int>(); m_TreeView.state.selectedIDs = new List <int>(); m_TreeView.state.lastClickedID = Int32.MinValue; m_TreeView.state.scrollPos = Vector2.zero; if (m_TreeView.data != null) { m_TreeView.data.ReloadData(); } WindowConfigSource.SetConfigDirty(); WindowConfigSource.SaveConfigLazily(); } } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }; m_LayoutGroupMgr.AddViewGroup(m_TipsViewGroup); CheckViewVisible(); }
public FolderGridViewGroup(ViewGroupManager owner, EditorWindowConfigSource configSource, string stateConfigName, string containerConfigName, string dragId = null) : base(owner) { m_ConfigSource = configSource; m_ItemDataSource = new ItemDataSource(); m_SearchBar = new SearchBar(owner); m_SearchBar.UpOrDownArrowPressedAction += SearchBarUpOrDownArrowPressedAction; m_SearchBar.OnTextChangedAction += (str) => UpdateItemsBySearchText(); dragId = dragId != null ? dragId : GetHashCode().ToString(); m_FolderTreeViewGroup = new FolderTreeViewGroup(owner, configSource, stateConfigName, containerConfigName, dragId); m_GridViewDataSource = new GridViewDataSource(); var layout = new GenericGridLayouter(m_GridViewDataSource); var viewHandler = new FolderGridViewHandler(layout.DataSource); viewHandler.TreeViewDragging = m_FolderTreeViewGroup.GetTreeViewDragging(); m_GridView = new GridView(owner, layout, viewHandler); m_GridView.KeyboardCallback += ListAreaKeyboardCallback; m_GridView.ItemExpandedAction += ItemExpandedAction; m_GridView.BeginRenameAction += ItemBeginRenameAction; m_GridView.RenameEndAction += ItemRenameEndAction; m_GridView.ItemDoubleClickAction += ItemDoubleClick; m_GridView.ItemSelectedAction += GridViewItemSelected; m_GridView.ViewHandler.GenericDragId = dragId; m_GridView.GridSizeChangedAction += (size) => { m_BottomBar.Value = size; }; m_BreadcrumbBar = new BreadcrumbBar(owner); m_BreadcrumbBar.ShowFolderContentsAction += (id) => { m_TreeView.SetSelection(new int[] { id }, false); UpdateBreadcrumbBarContents(); UpdateGridViewContent(); }; m_BottomBar = new BottomBar(owner); m_BottomBar.Value = m_GridView.GridSize; m_BottomBar.MinValue = m_GridView.ViewLayouter.LayoutParams.MinGridSize; m_BottomBar.MaxValue = m_GridView.ViewLayouter.LayoutParams.MaxGridSize; m_BottomBar.OnValueChangedAction += (size) => { m_GridView.GridSize = size; }; GridViewDeleteAction += DeleteGridItems; m_TreeView = m_FolderTreeViewGroup.GetTreeView(); m_BreadcrumbBar.FolderTreeView = m_TreeView; m_FolderTreeViewGroup.GetFolderTreeViewGUI().RenameEndAction += (item, name) => { UpdateBreadcrumbBarContents(); }; m_HorizontalSplitLine = new HorizontalSplitLine(m_SplitLineStartPosX, HorizontalSplitLineMinX); m_HorizontalSplitLine.PositionChangedAction += RefreshSplittedSelectedPath; m_HorizontalSplitLine.ConfigSource = configSource; m_ItemDataSource.SetConfigSource(configSource); m_TreeView.selectionChangedCallback += FolderTreeViewSelectionChanged; m_FolderTreeViewGroup.GetTreeViewDragging().EndDragAction += (hasError) => { UpdateGridViewContent(); }; m_FolderTreeViewGroup.DuplicateItemsDone += UpdateGridViewContent; GetDataContainer().UpdateItemChangedAction += () => { UpdateGridViewContent(); CheckBottomBarItemValidity(); UpdateBreadcrumbBarContents(); }; DuplicateItemsAction += DuplicateItemGridView; }