private void _listView_MouseUp(object sender, MouseEventArgs e)
        {
//            if (_mouseDownLocation == default(Point))
//            {
//                _currentTarget = null;
//                _currentDraggingItem = null;
//                return;
//            }
//
//		    var mouseDownLocation = _mouseDownLocation;
//		    _mouseDownLocation = default(Point);

            Capture = false;
            Debug.WriteLine("MouseUp");
            _intentionallyChangingSelection = false;

            if (Control.MouseButtons == MouseButtons.Left)
            {
                return;
            }

            Cursor = Cursors.Default;

            bool notPointingAtOriginalLocation = _listView.GetItemAt(e.X, e.Y) != _currentDraggingItem;

//		    var horizontalMovement = Math.Abs(mouseDownLocation.X - e.X);
//            var verticalMovement = Math.Abs(mouseDownLocation.Y - e.Y);
//		    bool sufficientDistance = horizontalMovement > _thumbnailImageList.ImageSize.Width
//                || verticalMovement > _thumbnailImageList.ImageSize.Height;

            if (notPointingAtOriginalLocation && RelocatePageEvent != null && _currentDraggingItem != null)
            {
                Debug.WriteLine("Re-ordering");
                if (_currentTarget == null ||
                    _currentTarget == _currentDraggingItem)                             //should never happen, but to be safe
                {
                    _currentTarget       = null;
                    _currentDraggingItem = null;
                    return;
                }

                RelocatePageEvent.Raise(new RelocatePageInfo((IPage)_currentDraggingItem.Tag, _currentTarget.Index - _numberofEmptyListItemsAtStart));

                _listView.BeginUpdate();
                _listView.Items.Remove(_currentDraggingItem);
                _listView.Items.Insert(_currentTarget.Index, _currentDraggingItem);
                _listView.EndUpdate();
                _currentTarget       = null;
                _currentDraggingItem = null;

                UpdateThumbnailCaptions();
                _listView.Invalidate();
            }
            else
            {
                _currentTarget       = null;
                _currentDraggingItem = null;
            }
        }
        private void GridReordered(string s)
        {
            var newSeq = new List <IPage>();
            var keys   = s.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var key in keys)
            {
                IPage page;
                if (_pageMap.TryGetValue(key, out page))
                {
                    newSeq.Add(page);
                }
            }
            Debug.Assert(newSeq.Count == _pages.Count);
            // Now, which one moved?
            int firstDiff = 0;

            while (firstDiff < _pages.Count && _pages[firstDiff] == newSeq[firstDiff])
            {
                firstDiff++;
            }
            int limDiff = _pages.Count;

            while (limDiff > firstDiff && _pages[limDiff - 1] == newSeq[limDiff - 1])
            {
                limDiff--;
            }
            if (firstDiff == limDiff)
            {
                return;                 // spurious notification somehow? Nothing changed.
            }
            // We have the subsequence that altered.
            // Is the change legal?
            for (int i = firstDiff; i < limDiff; i++)
            {
                if (!_pages[i].CanRelocate)
                {
                    var msg = LocalizationManager.GetString("EditTab.PageList.CantMoveXMatter",
                                                            "That change is not allowed. Front matter and back matter pages must remain where they are.");
                    //previously had a caption that didn't add value, just more translation work
                    if (_pages[i].Book.LockedDown)
                    {
                        msg = LocalizationManager.GetString("PageList.CantMoveWhenTranslating",
                                                            "Pages can not be re-ordered when you are translating a book.");
                        msg = msg + System.Environment.NewLine + EditingView.GetInstructionsForUnlockingBook();
                    }
                    MessageBox.Show(msg);
                    UpdateItems(_pages);                     // reset to old state
                    return;
                }
            }
            // There are two possibilities: the user dragged the item that used to be at the start to the end,
            // or the item that used to be the end to the start.
            IPage movedPage;
            int   newPageIndex;

            if (_pages[firstDiff] == newSeq[limDiff - 1])
            {
                // Move forward
                movedPage    = _pages[firstDiff];
                newPageIndex = limDiff - 1;
            }
            else
            {
                Debug.Assert(_pages[limDiff - 1] == newSeq[firstDiff]);                 // moved last page forwards
                movedPage    = _pages[limDiff - 1];
                newPageIndex = firstDiff;
            }
            var relocatePageInfo = new RelocatePageInfo(movedPage, newPageIndex);

            RelocatePageEvent.Raise(relocatePageInfo);
            if (relocatePageInfo.Cancel)
            {
                UpdateItems(_pages);
            }
            else
            {
                _pages = newSeq;
                UpdatePageNumbers();
                // This is only needed if left and right pages are styled differently.
                // Unfortunately gecko does not re-apply the styles when things are re-ordered!
                UpdateItems(_pages);
            }
        }