Bloom.Edit.EditingModel.DeletePage C# (CSharp) Method

DeletePage() private method

private DeletePage ( IPage page ) : void
page IPage
return void
        internal void DeletePage(IPage page)
        {
            // This can only be called on the UI thread in response to a user button click.
            // If that ever changed we might need to arrange locking for access to _inProcessOfSaving and _tasksToDoAfterSaving.
            Debug.Assert(!_view.InvokeRequired);
            if (_inProcessOfSaving && page == _pageSelection.CurrentSelection)
            {
                // Somehow (BL-431) it's possible that a Save is still in progress when we start executing a delete page.
                // If this happens, to prevent crashes we need to let the Save complete before we go ahead with the delete.
                _tasksToDoAfterSaving.Add(OnDeletePage);
                return;
            }
            try
            {
                try
                {
                    // BL-4035 Save any style changes to the book before deleting the page.
                    SaveNow();
                }
                catch(Exception saveError)
                {
                    // we don't want to prevent deleting a problematic page, so just show a toast
                    NonFatalProblem.Report(ModalIf.Alpha, PassiveIf.All, "Error during pre-delete save", exception: saveError);
                }

                _inProcessOfDeleting = true;
                _domForCurrentPage = null; //prevent us trying to save it later, as the page selection changes
                _currentlyDisplayedBook.DeletePage(page);
                //_view.UpdatePageList(false);  DeletePage calls this via pageListChangedEvent.  See BL-3632 for trouble this causes.
                Logger.WriteEvent("Delete Page");
                Analytics.Track("Delete Page");
            }
            catch (Exception error)
            {
                ErrorReport.NotifyUserOfProblem(error,
                    "Could not delete that page. Try quiting Bloom, run it again, and then attempt to delete the page again. And please click 'details' below and report this to us.");
            }
            finally
            {
                _inProcessOfDeleting = false;
            }
        }

Usage Example

Example #1
0
        public PageListView(PageSelection pageSelection,  RelocatePageEvent relocatePageEvent, EditingModel model,
			HtmlThumbNailer thumbnailProvider, NavigationIsolator isolator, ControlKeyEvent controlKeyEvent)
        {
            _pageSelection = pageSelection;
            _model = model;
            this.Font= SystemFonts.MessageBoxFont;
            InitializeComponent();

            _thumbNailList.Thumbnailer = thumbnailProvider;
            _thumbNailList.CanSelect = true;
            _thumbNailList.PreferPageNumbers = true;
            _thumbNailList.KeepShowingSelection = true;
            _thumbNailList.RelocatePageEvent = relocatePageEvent;
            _thumbNailList.PageSelectedChanged+=new EventHandler(OnPageSelectedChanged);
            _thumbNailList.Isolator = isolator;
            _thumbNailList.ControlKeyEvent = controlKeyEvent;
            // First action determines whether the menu item is enabled, second performs it.
            var menuItems = new List<WebThumbNailList.MenuItemSpec>();
            menuItems.Add(
                new WebThumbNailList.MenuItemSpec() {
                    Label = LocalizationManager.GetString("EditTab.DuplicatePageButton", "Duplicate Page"), // same ID as button in toolbar));
                    EnableFunction = (page) => page != null && !page.Required && !_model.CurrentBook.LockedDown,
                    ExecuteCommand = (page) => _model.DuplicatePage(page)});
            menuItems.Add(
                new WebThumbNailList.MenuItemSpec() {
                    Label = LocalizationManager.GetString("EditTab.DeletePageButton", "Remove Page"),  // same ID as button in toolbar));
                    EnableFunction = (page) => page != null && !page.Required && !_model.CurrentBook.LockedDown,
                    ExecuteCommand = (page) =>
                    {
                        if (ConfirmRemovePageDialog.Confirm())
                            _model.DeletePage(page);
                    }});
            menuItems.Add(
                new WebThumbNailList.MenuItemSpec() {
                    Label = LocalizationManager.GetString("EditTab.ChooseLayoutButton", "Choose Different Layout"),
                    EnableFunction = (page) => page != null && !page.Required && !_model.CurrentBook.LockedDown,
                    ExecuteCommand = (page) => _model.ChangePageLayout(page)});
            // This adds the desired menu items to the Gecko context menu that happens when we right-click
            _thumbNailList.ContextMenuProvider = args =>
            {
                var page = _thumbNailList.GetPageContaining(args.TargetNode);
                if (page == null)
                    return true; // no page-related commands if we didn't click on one.
                if(page != _pageSelection.CurrentSelection)
                {
                    return true; //it's too dangerous to let users do thing to a page they aren't seeing
                }
                foreach (var item in menuItems)
                {
                    var menuItem = new MenuItem(item.Label, (sender, eventArgs) => item.ExecuteCommand(page));
                    args.ContextMenu.MenuItems.Add(menuItem);
                    menuItem.Enabled = item.EnableFunction(page);
                }
                return true;
            };
            // This sets up the context menu items that will be shown when the user clicks the
            // arrow in the thumbnail list.
            _thumbNailList.ContextMenuItems = menuItems;
        }
All Usage Examples Of Bloom.Edit.EditingModel::DeletePage