private void LoadSourceCollectionButtons()
{
if (!_model.ShowSourceCollections)
{
_sourceBooksFlow.Visible = false;
string lockNotice = LocalizationManager.GetString("CollectionTab.BookSourcesLockNotice",
"This collection is locked, so new books cannot be added/removed.");
var lockNoticeLabel = new Label()
{
Text = lockNotice,
Size = new Size(_primaryCollectionFlow.Width - 20, 15),
ForeColor = Palette.TextAgainstDarkBackground,
Padding = new Padding(10, 0, 0, 0)
};
_primaryCollectionFlow.Controls.Add(lockNoticeLabel);
return;
}
var collections = _model.GetBookCollections();
//without this guy, the FLowLayoutPanel uses the height of a button, on *the next row*, for the height of this row!
var invisibleHackPartner = new Label() {Text = "", Width = 0};
_sourceBooksFlow.SuspendLayout();
_sourceBooksFlow.Controls.Clear();
var bookSourcesHeader = new ListHeader() { ForeColor = Palette.TextAgainstDarkBackground, Width = 450 };
string shellSourceHeading = LocalizationManager.GetString("CollectionTab.SourcesForNewShellsHeading",
"Sources For New Shells");
string bookSourceHeading = LocalizationManager.GetString("CollectionTab.BookSourceHeading",
"Sources For New Books");
bookSourcesHeader.Label.Text = _model.IsShellProject ? shellSourceHeading : bookSourceHeading;
// Don't truncate the heading: see https://jira.sil.org/browse/BL-250.
if (bookSourcesHeader.Width < bookSourcesHeader.Label.Width)
bookSourcesHeader.Width = bookSourcesHeader.Label.Width;
invisibleHackPartner = new Label() {Text = "", Width = 0};
_sourceBooksFlow.Controls.Add(invisibleHackPartner);
_sourceBooksFlow.Controls.Add(bookSourcesHeader);
_sourceBooksFlow.SetFlowBreak(bookSourcesHeader, true);
foreach (BookCollection collection in collections.Skip(1))
{
if (_sourceBooksFlow.Controls.Count > 0)
_sourceBooksFlow.SetFlowBreak(_sourceBooksFlow.Controls[_sourceBooksFlow.Controls.Count - 1], true);
int indexForHeader = _sourceBooksFlow.Controls.Count;
if (LoadOneCollection(collection, _sourceBooksFlow))
{
//without this guy, the FLowLayoutPanel uses the height of a button, on *the next row*, for the height of this row!
invisibleHackPartner = new Label() {Text = "", Width = 0};
_sourceBooksFlow.Controls.Add(invisibleHackPartner);
_sourceBooksFlow.Controls.SetChildIndex(invisibleHackPartner, indexForHeader);
//We showed at least one book, so now go back and insert the header
var collectionHeader = new Label()
{
Text = L10NSharp.LocalizationManager.GetDynamicString("Bloom", "CollectionTab." + collection.Name, collection.Name),
Size = new Size(_sourceBooksFlow.Width - 20, 20),
ForeColor = Palette.TextAgainstDarkBackground,
Padding = new Padding(10, 0, 0, 0)
};
collectionHeader.Margin = new Padding(0, 10, 0, 0);
collectionHeader.Font = _headerFont;
_sourceBooksFlow.Controls.Add(collectionHeader);
_sourceBooksFlow.Controls.SetChildIndex(collectionHeader, indexForHeader + 1);
_sourceBooksFlow.SetFlowBreak(collectionHeader, true);
}
}
AddFinalLinks();
_sourceBooksFlow.ResumeLayout();
}