internal static int GetItemControlID(TreeViewItem item, TreeView treeView) { return((item == null ? 0 : item.GetHashCode()) + treeView.GetHashCode()); }
public ObjectTreeViewGroup(ViewGroupManager owner, EditorWindowConfigSource configSource, string stateConfigName, string containerConfigName, string dragId = null) : base(owner) { m_ConfigSource = configSource; if (configSource != null) { if (configSource.FindProperty(stateConfigName) != null) { m_TreeViewState = configSource.GetValue <TreeViewState>(stateConfigName); } if (m_TreeViewState == null) { m_TreeViewState = new TreeViewState(); if (configSource.FindProperty(stateConfigName) != null) { configSource.SetValue(stateConfigName, m_TreeViewState); } configSource.SetConfigDirty(); } m_TreeViewState.SetConfigSource(configSource); if (configSource.FindProperty(containerConfigName) != null) { m_TreeItemContainer = configSource.GetValue <TreeItemContainer>(containerConfigName); } if (m_TreeItemContainer == null) { m_TreeItemContainer = ScriptableObject.CreateInstance <TreeItemContainer>(); m_TreeItemContainer.ConfigSource = configSource; if (configSource.FindProperty(containerConfigName) != null) { configSource.SetValue(containerConfigName, m_TreeItemContainer); } configSource.SetConfigDirty(); } else { m_TreeItemContainer.ConfigSource = configSource; m_TreeItemContainer.UpdateItemsParent(); } } if (m_TreeViewState == null) { m_TreeViewState = new TreeViewState(); } m_TreeView = new TreeView(owner.WindowOwner, m_TreeViewState); dataSource = new ObjectTreeViewDataSource(m_TreeView, m_TreeItemContainer, m_ConfigSource); m_TreeViewGUI = new ObjectTreeViewGUI(m_TreeView); m_TreeViewDragging = new ObjectTreeViewDragging(m_TreeView, dragId != null ? dragId : m_TreeView.GetHashCode().ToString()); DeleteItemsAction += DeleteItems; DuplicateItemsAction += DuplicateItems; m_TreeViewGUI.BeginRenameAction += () => { if (needUndo) { Undo.RegisterCompleteObjectUndo(m_TreeItemContainer, "Rename Item"); } }; m_TreeViewDragging.PrepareDoDrag += () => { if (needUndo) { Undo.RegisterCompleteObjectUndo(m_TreeItemContainer, "Reparent Item"); } }; }
public FolderTreeViewGroup(ViewGroupManager owner, EditorWindowConfigSource configSource, string stateConfigName, string containerConfigName, string dragId = null) : base(owner) { m_ConfigSource = configSource; if (configSource != null) { m_TreeViewState = configSource.GetValue <TreeViewState>(stateConfigName); if (m_TreeViewState == null) { m_TreeViewState = new TreeViewState(); configSource.SetValue(stateConfigName, m_TreeViewState); configSource.SetConfigDirty(); } m_TreeViewState.SetConfigSource(configSource); m_TreeItemContainer = configSource.GetValue <FolderTreeItemContainer>(containerConfigName); if (m_TreeItemContainer == null) { m_TreeItemContainer = ScriptableObject.CreateInstance <FolderTreeItemContainer>(); m_TreeItemContainer.ConfigSource = configSource; configSource.SetValue(containerConfigName, m_TreeItemContainer); configSource.SetConfigDirty(); } else { m_TreeItemContainer.ConfigSource = configSource; m_TreeItemContainer.UpdateItemsParent(); } } if (m_TreeViewState == null) { m_TreeViewState = new TreeViewState(); } m_TreeView = new TreeView(owner.WindowOwner, m_TreeViewState); m_DataSource = new FolderTreeViewDataSource(m_TreeView, m_TreeItemContainer, m_ConfigSource); m_TreeViewGUI = new FolderTreeViewGUI(m_TreeView, m_TreeItemContainer); m_TreeViewDragging = new FolderTreeViewDragging(m_TreeView, dragId != null ? dragId : m_TreeView.GetHashCode().ToString()); DeleteItemsAction += DeleteItems; DuplicateItemsAction += DuplicateItems; m_TreeViewGUI.RenameEndAction += RenameItem; m_TreeViewGUI.BeginRenameAction += () => { m_TreeView.state.renameOverlay.isRenamingFilename = true; }; m_TreeViewDragging.EndDragAction += (hasError) => { if (hasError) { m_TreeItemContainer.UpdateValidItems(); } m_TreeView.data.RefreshData(); m_ConfigSource.SetConfigDirty(); }; }