Example #1
0
        public void RefreshTree()
        {
            if (m_TreeViewDataSource == null)
            {
                return;
            }

            if (m_Selection == null)
            {
                m_Selection = new int[0];
            }

            // get the names of the previous items
            var selected = m_Selection.Select(x => m_TreeViewDataSource.FindItem(x)).Where(t => t != null).Select(c => c.displayName).ToArray();

            // update the source
            m_TreeViewDataSource.UpdateData();

            // find the same items
            var reselected = m_TreeViewDataSource.GetRows().Where(x => selected.Contains(x.displayName)).Select(x => x.id).ToArray();

            if (!reselected.Any())
            {
                if (m_TreeViewDataSource.GetRows().Count > 0)
                {
                    reselected = new[] { m_TreeViewDataSource.GetItem(0).id };
                }
            }

            // update the selection
            OnItemSelectionChanged(reselected);
        }
        public void InitIfNeeded(Rect rect, CurveDataSource dataSource, bool isNewSelection)
        {
            if (Event.current.type != EventType.Layout)
            {
                return;
            }

            m_CurveDataSource = dataSource;
            var clip = dataSource.animationClip;

            List <EditorCurveBinding> allBindings = new List <EditorCurveBinding>();

            allBindings.Add(new EditorCurveBinding {
                propertyName = "Summary"
            });
            if (clip != null)
            {
                allBindings.AddRange(AnimationUtility.GetCurveBindings(clip));
            }

            m_DopeLines.list = allBindings.ToArray();

            if (m_TreeViewState != null)
            {
                if (isNewSelection)
                {
                    RefreshAll();
                }

                return;
            }

            m_TreeViewState = m_TrackGlobalTreeViewState != null ? m_TrackGlobalTreeViewState : new TreeViewState();

            m_TreeView = new TreeViewController(m_Window, m_TreeViewState)
            {
                useExpansionAnimation        = false,
                deselectOnUnhandledMouseDown = true
            };

            m_TreeView.selectionChangedCallback += OnItemSelectionChanged;

            m_TreeViewDataSource = new BindingTreeViewDataSource(m_TreeView, clip, m_CurveDataSource);

            m_TreeViewGUI = new BindingTreeViewGUI(m_TreeView);
            m_TreeView.Init(rect, m_TreeViewDataSource, m_TreeViewGUI, null);

            m_TreeViewDataSource.UpdateData();

            RefreshSelection();
        }