private void ImproveAndRefreshBookButtons()
{
ButtonRefreshInfo buttonRefreshInfo;
if (!_buttonsNeedingSlowUpdate.TryDequeue(out buttonRefreshInfo))
return;
var button = buttonRefreshInfo.Button;
var bookInfo = GetBookInfoFromButton(button);
Book.Book book;
try
{
book = _model.GetBookFromBookInfo(bookInfo);
}
catch (Exception error)
{
//skip over the dependency injection layer
if (error.Source == "Autofac" && error.InnerException != null)
error = error.InnerException;
Logger.WriteEvent("There was a problem with the book at " + bookInfo.FolderPath + ". " + error.Message);
if (!_alreadyReportedErrorDuringImproveAndRefreshBookButtons)
{
_alreadyReportedErrorDuringImproveAndRefreshBookButtons = true;
SIL.Reporting.ErrorReport.NotifyUserOfProblem(error, "There was a problem with the book at {0}. \r\n\r\nClick the 'Details' button for more information.\r\n\r\nThis error may effect other books, but this is the only notice you will receive.\r\n\r\nSee 'Help:Show Event Log' for any further errors.", bookInfo.FolderPath);
}
return;
}
//Only go looking for a better title if the book hasn't already been localized when we first showed it.
//The idea is, if we already have a localization mapping for this name, then
// we're not going to get a better title by digging into the document itself and overriding what the localizer
// chose to call it.
// Note: currently (August 2014) the books that will have been localized are are those in the main "templates" section: Basic Book, Calendar, etc.
if (button.Text == ShortenTitleIfNeeded(bookInfo.QuickTitleUserDisplay, button))
{
var bestTitle = book.TitleBestForUserDisplay;
var titleBestForUserDisplay = ShortenTitleIfNeeded(bestTitle, button);
if (titleBestForUserDisplay != button.Text)
{
Debug.WriteLine(button.Text + " --> " + titleBestForUserDisplay);
button.Text = titleBestForUserDisplay;
toolTip1.SetToolTip(button, bestTitle);
}
}
if (buttonRefreshInfo.ThumbnailRefreshNeeded)//!bookInfo.TryGetPremadeThumbnail(out unusedImage))
ScheduleRefreshOfOneThumbnail(book);
}