示例#1
0
        public static HistoryItem FromDataRow(HistoryList list, DataRow row)
        {
            if (row == null)
            {
                throw new ArgumentNullException(nameof(row));
            }

            var ret = new HistoryItem(list);

            ret._location       = row.GetString("path");
            ret._locationOnDisk = row.GetString("path");
            ret._rating         = row.GetInt("rating");

            var bytes = row.GetBytes("thumb");

            if (bytes != null)
            {
                ret._thumbnail = new CompressedImage(bytes);
            }

            return(ret);
        }
示例#2
0
        public HistoryItem AddHistory(HistoryItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            _items.Insert(0, item);

            while (_items.Count > _maxHistory)
            {
                var removeItem = _items[_items.Count - 1];
                if (removeItem == _selectedItem)
                {
                    _selectedItem = null;
                }
                _items.RemoveAt(_items.Count - 1);
            }

            UpdateLayout();
            Invalidate();
            return(item);
        }
示例#3
0
        private void SelectItem(HistoryItem item)
        {
            var oldSel = _selectedItem;

            _selectedItem = item;

            if (!EnsureVisible(_selectedItem))
            {
                if (oldSel != null)
                {
                    var rect = oldSel.Bounds;
                    rect.Offset(0, -_scroll);
                    Invalidate(rect);
                }

                if (_selectedItem != null)
                {
                    var rect = _selectedItem.Bounds;
                    rect.Offset(0, -_scroll);
                    Invalidate(rect);
                }
            }
        }
示例#4
0
        private void HistoryList_MouseHover(object sender, EventArgs e)
        {
            try
            {
                var cursorPos = this.PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y));

                if (_imageToolTip != null)
                {
                    HistoryItem hi = HitTest(cursorPos);
                    if (hi != null)
                    {
                        _imageToolTip.SetToolTip(this, hi.Location);
                    }
                    else
                    {
                        _imageToolTip.SetToolTip(this, string.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                this.ShowError(ex);
            }
        }
示例#5
0
 public DeleteItemRequestedEventArgs(HistoryItem item)
 {
     Item = item;
 }
示例#6
0
 public ItemActivatedEventArgs(HistoryItem item)
 {
     Item = item;
 }
示例#7
0
        private void HistoryList_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                switch (e.KeyCode)
                {
                case Keys.Left:
                {
                    var index = GetItemIndex(_selectedItem);
                    if (index > 0)
                    {
                        SelectItem(GetItemByIndex(index - 1));
                    }
                }
                break;

                case Keys.Right:
                {
                    var index = GetItemIndex(_selectedItem) + 1;
                    if (index >= _items.Count)
                    {
                        index = _items.Count - 1;
                    }
                    SelectItem(GetItemByIndex(index));
                }
                break;

                case Keys.Up:
                    if (_selectedItem == null)
                    {
                        SelectItem(GetItemByIndex(0));
                    }
                    else
                    {
                        var pt = _selectedItem.Bounds.Center();
                        pt.Y -= _selectedItem.Bounds.Height;

                        var found = false;
                        foreach (var item in _items)
                        {
                            if (item.Bounds.Contains(pt))
                            {
                                SelectItem(item);
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            SelectItem(GetItemByIndex(0));
                        }
                    }
                    break;

                case Keys.Down:
                    if (_selectedItem == null)
                    {
                        SelectItem(GetItemByIndex(0));
                    }
                    else
                    {
                        var pt = _selectedItem.Bounds.Center();
                        pt.Y += _selectedItem.Bounds.Height;

                        var found = false;
                        foreach (var item in _items)
                        {
                            if (item.Bounds.Contains(pt))
                            {
                                SelectItem(item);
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            HistoryItem selItem = null;
                            foreach (var item in _items)
                            {
                                if (item.Bounds.Top < pt.Y && item.Bounds.Bottom > pt.Y)
                                {
                                    selItem = item;
                                }
                            }
                            if (selItem != null)
                            {
                                SelectItem(selItem);
                            }
                        }
                    }
                    break;

                case Keys.Delete:
                    if (_selectedItem != null)
                    {
                        FireDeleteItemRequested(_selectedItem);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                this.ShowError(ex);
            }
        }