public void InsertPageAfter(IPage pageBefore, IPage templatePage)
{
Guard.Against(Type != BookType.Publication, "Tried to edit a non-editable book.");
ClearPagesCache();
if(templatePage.Book !=null) // will be null in some unit tests that are unconcerned with stylesheets
HtmlDom.AddStylesheetFromAnotherBook(templatePage.Book.OurHtmlDom, OurHtmlDom);
XmlDocument dom = OurHtmlDom.RawDom;
var templatePageDiv = templatePage.GetDivNodeForThisPage();
var newPageDiv = dom.ImportNode(templatePageDiv, true) as XmlElement;
BookStarter.SetupIdAndLineage(templatePageDiv, newPageDiv);
BookStarter.SetupPage(newPageDiv, _collectionSettings, _bookData.MultilingualContentLanguage2, _bookData.MultilingualContentLanguage3);//, LockedExceptForTranslation);
SizeAndOrientation.UpdatePageSizeAndOrientationClasses(newPageDiv, GetLayout());
newPageDiv.RemoveAttribute("title"); //titles are just for templates [Review: that's not true for front matter pages, but at the moment you can't insert those, so this is ok]C:\dev\Bloom\src\BloomExe\StyleSheetService.cs
var elementOfPageBefore = FindPageDiv(pageBefore);
elementOfPageBefore.ParentNode.InsertAfter(newPageDiv, elementOfPageBefore);
BuildPageCache();
var newPage = GetPages().First(p=>p.GetDivNodeForThisPage() == newPageDiv);
Guard.AgainstNull(newPage,"could not find the page we just added");
//_pageSelection.SelectPage(CreatePageDecriptor(newPageDiv, "should not show", _collectionSettings.Language1Iso639Code));
// If copied page references images, copy them.
foreach (var pathFromBook in BookStorage.GetImagePathsRelativeToBook(newPageDiv))
{
var path = Path.Combine(FolderPath, pathFromBook);
if (!RobustFile.Exists(path))
{
var fileName = Path.GetFileName(path);
var sourcePath = Path.Combine(templatePage.Book.FolderPath, fileName);
if (RobustFile.Exists(sourcePath))
RobustFile.Copy(sourcePath, path);
}
}
//similarly, if the page has stylesheet files we don't have, copy them
foreach(string sheetName in templatePage.Book.OurHtmlDom.GetTemplateStyleSheets())
{
var destinationPath = Path.Combine(FolderPath, sheetName);
if (!File.Exists(destinationPath))
{
var sourcePath = Path.Combine(templatePage.Book.FolderPath, sheetName);
if (File.Exists(sourcePath))
File.Copy(sourcePath, destinationPath);
}
}
Save();
if (_pageListChangedEvent != null)
_pageListChangedEvent.Raise(null);
_pageSelection.SelectPage(newPage);
InvokeContentsChanged(null);
}