public void AddNew()
        {
            //find an available name
            int id = 1;
            {
                var list = _Parent.Project.Actions;
                while (list.Any(a => a.ActionID == "New Action " + id.ToString()))
                {
                    ++id;
                }
            }

            var action = new Pat.Action()
            {
                ActionID = "New Action " + id.ToString(),
            };

            _Parent.Project.Actions.Add(action);

            if (_SelectedItem != null)
            {
                _SelectedItem.IsSelected = false;
                _SelectedItem            = null;
            }

            RefreshList();

            _SelectedItem            = _Items.Last();
            _SelectedItem.IsSelected = true;
            OnSelectChange();
        }
        public void RemoveCurrent()
        {
            if (_SelectedItem != null)
            {
                _Parent.Project.Actions.RemoveAt(_SelectedItem.Index);
                _SelectedItem.IsSelected = false;
                _SelectedItem            = null;

                RefreshList();
            }
        }
        private void ctrl_Click(object sender, EventArgs e)
        {
            var pos = _Control.PointToClient(Control.MousePosition);

            //find the item
            var item = FindItem(pos);

            if (!item.CanSelect)
            {
                return;
            }

            if (_SelectedItem != null)
            {
                _SelectedItem.IsSelected = false;
            }
            _SelectedItem = item;
            if (item != null)
            {
                item.IsSelected = true;
            }
            OnSelectChange();
        }
        private void RefreshList()
        {
            var lastSelectedAction = _SelectedItem == null ? null : _SelectedItem.Object;
            var unsortedItems      = new List <AnimationListItem>();
            var addedCategories    = new HashSet <string>();
            var lastCollapsed      = _Items.Where(i => i.CanCollapse && i.IsCollapsed).Select(i => i.CategoryName).ToArray();

            _Items.Clear();

            var list = _Parent.Project.Actions;

            for (int i = 0; i < list.Count; ++i)
            {
                var a = list[i];
                unsortedItems.Add(CreateItemForAnimation(a, i));
            }

            foreach (var item in unsortedItems)
            {
                var c = item.Object.Category;
                if (c != null && c.Length > 0 && !addedCategories.Contains(c))
                {
                    addedCategories.Add(c);
                    var items = unsortedItems.Where(i => i.Object.Category == c);
                    var ci    = new AnimationListItem(c, "" + items.Count() + " animation(s)", c);
                    _Items.Add(ci);
                    if (lastCollapsed.Contains(ci.CategoryName))
                    {
                        ci.IsCollapsed = true;
                    }
                    else
                    {
                        _Items.AddRange(items);
                    }
                }
            }
            {
                var items = unsortedItems
                            .Where(i => i.Object.Category == null || i.Object.Category.Length == 0);
                var ci = new AnimationListItem("uncategoried", "" + items.Count() + " animation(s)", "");
                _Items.Add(ci);
                if (lastCollapsed.Contains(ci.CategoryName))
                {
                    ci.IsCollapsed = true;
                }
                else
                {
                    _Items.AddRange(items);
                }
            }

            if (_Control != null)
            {
                _Control.Height = _Items.Sum(item => (int)item.Height) + 1;
                _Control.Invalidate();
            }

            _SelectedItem = _Items.FirstOrDefault(i => i.CanSelect && i.Object == lastSelectedAction);
            if (_SelectedItem != null)
            {
                _SelectedItem.IsSelected = true;
            }

            //TODO ensure visible

            if (SelectedChange != null)
            {
                SelectedChange();
            }
        }