Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/BloomExe/Collection/BookCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,19 @@ public void UpdateBookInfo(BookInfo info)
_bookInfos.Insert(newIndex, info);
NotifyCollectionChanged();
}

public void AddBookInfo(BookInfo bookInfo)
{
_bookInfos.Add(bookInfo);
NotifyCollectionChanged();
}
private void AddBookInfoInternalNoSideEffects(BookInfo bookInfo)
{
// Note BL-12890 it's actually the norm, when we add a book, that the new book will already be there
// by the time we officially add it.
if (_bookInfos.FindIndex(i => i.Id == bookInfo.Id) < 0)
_bookInfos.Add(bookInfo);
}

public void AddBookInfo(BookInfo bookInfo)
{
AddBookInfoInternalNoSideEffects(bookInfo);
NotifyCollectionChanged();
}

/// <summary>
/// Insert a book into the appropriate place. If there is already a book with the same FolderPath, replace it.
Expand All @@ -331,13 +338,13 @@ public void InsertBookInfo(BookInfo bookInfo)
if (compare > 0)
{
_bookInfos.Insert(i, bookInfo);
return;
}
}
_bookInfos.Add(bookInfo);
}
return;
}
}
AddBookInfoInternalNoSideEffects(bookInfo);
}

private bool BackupFileExists(string folderPath)
private bool BackupFileExists(string folderPath)
{
var bakFiles = Directory.GetFiles(folderPath, BookStorage.BackupFilename);
return bakFiles.Length == 1 && RobustFile.Exists(bakFiles[0]);
Expand Down
11 changes: 7 additions & 4 deletions src/BloomExe/CollectionTab/CollectionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,15 @@ private void CreateFromSourceBook(Book.Book sourceBook)
// (We can't fix this by reordering things, because there will also be problems if we attempt
// to select an item before it is present in the collection to select.)
// We know this is a new book object, so there's no point in using EnsureUpToDate.
// When we later select it, that code uses EnsureUpToDate and will not do it again.
newBook.BringBookUpToDate(new NullProgress(), false);
// When we later select it, that code uses EnsureUpToDate and will not do it again.
newBook.BringBookUpToDate(new NullProgress(), false);

TheOneEditableCollection.AddBookInfo(newBook.BookInfo);
// You'd think this was needed, but it's not. The book is already in the collection due to
// the BringBookUpToDate side effects. However, I'm too chicken to rely on that, so instead
// I made AddBookInfo() avoid adding a duplicate (BL-12890)
TheOneEditableCollection.AddBookInfo(newBook.BookInfo);

if (_bookSelection != null)
if (_bookSelection != null)
{
Book.Book.SourceToReportForNextRename = Path.GetFileName(sourceBook.FolderPath);
_bookSelection.SelectBook(newBook, aboutToEdit: true);
Expand Down