private async Task EditStashTabAsync(StashBookmarkViewModel bookmarkVm)
        {
            var bookmark = bookmarkVm.Bookmark;
            var vm       = new TabPickerViewModel
            {
                Color = bookmark.Color,
                Name  = bookmark.Name
            };
            var result = await _dialogCoordinator.EditStashTabAsync(this, vm);

            switch (result)
            {
            case TabPickerResult.Delete:
                Bookmarks.Remove(bookmarkVm);
                _persistentData.StashBookmarks.Remove(bookmark);
                break;

            case TabPickerResult.DeleteIncludingItems:
                var confirmationResult = await _dialogCoordinator.ShowQuestionAsync(this,
                                                                                    L10n.Message(
                                                                                        "This will delete all items between this and the next bookmark and can not be undone.\nDo you want to continue?"),
                                                                                    title : L10n.Message("Delete items"));

                if (confirmationResult == MessageBoxResult.Yes)
                {
                    DeleteBookmarkAndItems(bookmarkVm);
                }
                break;

            case TabPickerResult.Affirmative:
                bookmark.Name  = vm.Name;
                bookmark.Color = vm.Color;
                break;
            }
        }
        public void AddStashTab(StashBookmark stashBookmark)
        {
            var vm    = new StashBookmarkViewModel(stashBookmark);
            var index = FindTabIndex(vm);

            Bookmarks.Insert(index, vm);
            _persistentData.StashBookmarks.Insert(index, stashBookmark);
        }
        private void DeleteBookmarkAndItems(StashBookmarkViewModel bm)
        {
            BeginUpdate();

            var from = bm.Bookmark.Position;
            var to   =
                Bookmarks.Where(b => b.Bookmark.Position > from)
                .Select(b => b.Bookmark.Position)
                .DefaultIfEmpty(LastOccupiedRow + 1)
                .Min();
            var diff = to - from;

            foreach (var item in Items.ToList())
            {
                var y = item.Item.Y;
                if (y >= from && y < to)
                {
                    Items.Remove(item);
                }
                else if (y >= to)
                {
                    item.Item.Y -= diff;
                }
            }

            Bookmarks.Remove(bm);
            _persistentData.StashBookmarks.Remove(bm.Bookmark);
            foreach (var bookmark in Bookmarks.ToList())
            {
                if (bookmark.Bookmark.Position >= to)
                {
                    bookmark.Bookmark.Position -= diff;
                }
            }

            EndUpdate();
        }
 private void ScrollToStashTab(StashBookmarkViewModel bookmark)
 {
     ScrollBarValue = bookmark.Bookmark.Position;
 }
        private int FindTabIndex(StashBookmarkViewModel bookmark)
        {
            var position = bookmark.Bookmark.Position;

            return(Bookmarks.Where(b => b != bookmark).TakeWhile(b => b.Bookmark.Position <= position).Count());
        }