/// <summary> /// Removes a <see cref="Page" /> from the <see cref="Story" />. /// </summary> /// <param name="pageToRemove">The instance of the <see cref="Page" /> to remove.</param> private void DeletePage(Page pageToRemove) { // TODO: Prompt before anything actually happens. if (pageToRemove == null) { return; } // Find a suitable replacement page (usually the first page, unless that's the one getting deleted). var replacementPage = _engine.Story.Pages.FirstOrDefault(page => page != pageToRemove); var nukeChoices = replacementPage == null; // Evaluate all Objects and remove Choice references to the deleted page. foreach (var page in _engine.Story.Pages) { foreach (var pageObject in page.Objects.Where(o => o.GetType() == typeof(Choice))) { var obj = (Choice)pageObject; if (obj.Target != pageToRemove) { continue; } // Uh oh, we have a match. If we have a replacement page, use that. Otherwise, delete the choice. // TODO: (No, seriously, prompt before deleting stuff. That's just common courtesy.) if (!nukeChoices) { obj.Target = replacementPage; } else { page.Objects.Remove(obj); } } } // Replace the default first page if necessary. if (_engine.Story.Configuration.FirstPage == pageToRemove) { _engine.Story.Configuration.FirstPage = replacementPage; } // Remove the selected page from the page list. _engine.Story.Pages.Remove(pageToRemove); // Refresh the list. UpdatePageList(); }
private void PageList_OnPageDoubleClicked(object sender, Page e) { var nameEntry = new NameEntry { EnteredName = e.Name, Owner = this }; var result = nameEntry.ShowDialog(); if (!result.HasValue || !result.Value) { return; } e.Name = nameEntry.EnteredName; UpdatePageList(); }
/// <summary> /// Adds a new <see cref="Page" /> to the <see cref="Story" />. /// </summary> /// <param name="pageName">The name of the new <see cref="Page" />.</param> private void AddPage(string pageName) { if (_engine.Story.Pages.Count(p => p.Name == pageName) > 0) { throw new PageAlreadyExistsException(pageName); } var newPage = new Page { Name = pageName }; _engine.Story.Pages.Add(newPage); // If no page was configured in the story configuration, set it now. if (_engine.Story.Configuration.FirstPage == null) { _engine.Story.Configuration.FirstPage = _engine.Story.Pages.First(); } UpdatePageList(); PageList.SelectedPage = newPage; }
private void PageList_OnSelectionChanged(object sender, Page e) { UpdateObjectList(); }