Esempio n. 1
0
        /// <summary>
        /// Set the one and only selected thumbnail
        /// </summary>
        /// <param name="item"></param>
        public Thumbnail SelectItem(Thumbnail thumb)
        {
            // We won't allow a NULL selection, 'cause we don't want null references being thrown around
            if (thumb != null)
            {
                if (mySelectedThumbnail != null)
                {
                    mySelectedThumbnail.Selected = false;
                }

                mySelectedThumbnail = thumb;

                thumb.Selected = true;

                // Want the image to bind dynamically to something really, but... data binding is confusing
                if (OnThumbnailSelected != null)
                {
                    OnThumbnailSelected(this, thumb);
                }
            }

            return(thumb);
        }
Esempio n. 2
0
        /// <summary>
        /// Remove an item from the palette
        /// </summary>
        /// <param name="thumb"></param>
        public void RemoveThumbnail(Thumbnail thumb)
        {
            int index = myThumbnails.IndexOf(thumb);

            myThumbnails.Remove(thumb);

            if (thumb.CanRemove == false)
            {
                NumUnremovable--;
            }

            if (mySelectedThumbnail == thumb)
            {
                int iNumThumbs = myThumbnails.Count;
                if (iNumThumbs > 0)
                {
                    SelectItem(myThumbnails[Math.Min(index, iNumThumbs - 1)]);
                }
                else
                {
                    mySelectedThumbnail = null;
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Event handler for palette item selected
 /// </summary>
 /// <param name="palette"></param>
 /// <param name="thumb"></param>
 private void event_ThumbnailSelected(Palette palette, Thumbnail thumb)
 {
     PreviewItem = thumb;
 }
Esempio n. 4
0
        public void SelectionLogic(Thumbnail thumb, bool shift, bool ctrl)
        {
            Console.WriteLine(String.Format("Item: {0} Shift: {1} CTRL: {2}", thumb, shift, ctrl));

            // Selection & multi-selection logic... surprisingly complicated, isn't it?  Think this is idiomatic usage of CTRL+SHIFT modifiers now.
            // WPF would probably do all of this for me naturally if I figured out the right way to make Palettes a custom/user control...
            if (shift)
            {
                // if shift key is down, we're range-selecting (deselecting?)
                int index1 = myThumbnails.IndexOf(thumb);
                int index2 = (mySelectedThumbnail == null) ? 0 : myThumbnails.IndexOf(mySelectedThumbnail);
                if (index1 > index2)
                {
                    int t = index1;
                    index1 = index2;
                    index2 = t;
                }
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    // CTRL+SHIFT = additive range selection
                    for (int i = index1; i <= index2; i++)
                    {
                        myThumbnails[i].MultiSelected = true;
                    }
                    SelectItem(thumb);
                }
                else
                {
                    // SHIFT alone = exclusive range selection
                    for (int i = 0; i < myThumbnails.Count; i++)
                    {
                        myThumbnails[i].MultiSelected = (i >= index1 && i <= index2);
                    }

                    if (index1 != index2)
                    {
                        bHasMultiselection = true;
                    }
                    else
                    {
                        SelectItem(thumb);
                        bHasMultiselection = false;
                    }
                }
            }
            else if (ctrl)
            {
                // If CTRL is held down, we're multi-selecting
                if (thumb.MultiSelected == false)
                {
                    if (mySelectedThumbnail != null)
                    {
                        mySelectedThumbnail.MultiSelected = true;
                    }
                    thumb.MultiSelected = true;
                    bHasMultiselection  = true;
                    SelectItem(thumb);
                }
                else
                {
                    thumb.MultiSelected = false;
                }
            }
            else
            {
                foreach (Thumbnail t in myThumbnails)
                {
                    if (t.MultiSelected)
                    {
                        t.MultiSelected = false;
                    }
                }
                bHasMultiselection = false;
                SelectItem(thumb);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Callback event to remove the thumbnail when the underlying collection removes an item
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="item"></param>
        void palette_itemRemoved(BitmapCollection collection, BitmapType item)
        {
            Thumbnail thumb = FindThumbnail(item);

            RemoveThumbnail(thumb);
        }