private void AddOneBook(BookInfo bookInfo, FlowLayoutPanel flowLayoutPanel, BookCollection collection)
{
string title = bookInfo.QuickTitleUserDisplay;
if (collection.IsFactoryInstalled)
title = LocalizationManager.GetDynamicString("Bloom", "TemplateBooks.BookName." + title, title);
var button = new Button
{
Size = new Size(ButtonWidth, ButtonHeight),
Font = bookInfo.IsEditable ? _editableBookFont : _collectionBookFont,
TextImageRelation = TextImageRelation.ImageAboveText,
ImageAlign = ContentAlignment.TopCenter,
TextAlign = ContentAlignment.BottomCenter,
FlatStyle = FlatStyle.Flat,
ForeColor = Palette.TextAgainstDarkBackground,
UseMnemonic = false, //otherwise, it tries to interpret '&' as a shortcut
ContextMenuStrip = _bookContextMenu,
AutoSize = false,
Tag = new BookButtonInfo(bookInfo, collection, collection == _model.TheOneEditableCollection)
};
button.MouseDown += OnClickBook; //we need this for right-click menu selection, which needs to 1st select the book
//doesn't work: item.DoubleClick += (sender,arg)=>_model.DoubleClickedBook();
button.Text = ShortenTitleIfNeeded(title, button);
button.FlatAppearance.BorderSize = 1;
button.FlatAppearance.BorderColor = BackColor;
toolTip1.SetToolTip(button, title);
Image thumbnail = Resources.PagePlaceHolder;
_bookThumbnails.Images.Add(bookInfo.Id, thumbnail);
button.ImageIndex = _bookThumbnails.Images.Count - 1;
flowLayoutPanel.Controls.Add(button); // important to add it before RefreshOneThumbnail; uses parent flow to decide whether primary
// Can't use this test until after we add button (uses parent info)
if (!IsUsableBook(button))
button.ForeColor = Palette.DisabledTextAgainstDarkBackColor;
Image img;
var refreshThumbnail = false;
//review: we could do this at idle time, too:
if (bookInfo.TryGetPremadeThumbnail(out img))
{
RefreshOneThumbnail(bookInfo, img);
}
else
{
//show this one for now, in the background someone will do the slow work of getting us a better one
RefreshOneThumbnail(bookInfo,Resources.placeHolderBookThumbnail);
refreshThumbnail = true;
}
_buttonsNeedingSlowUpdate.Enqueue(new ButtonRefreshInfo(button, refreshThumbnail));
}