/// ------------------------------------------------------------------------------------ /// <summary> /// Deletes a footnote /// </summary> /// <param name="args"></param> /// <returns><c>true</c> if we handle this</returns> /// ------------------------------------------------------------------------------------ protected bool OnDeleteFootnote(object args) { if (DataUpdateMonitor.IsUpdateInProgress() || !ValidFootnoteSelection) { return(true); //discard this event } string undo; string redo; TeResourceHelper.MakeUndoRedoLabels("kstidUndoDelFootnote", out undo, out redo); using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(this, undo, redo)) using (new DataUpdateMonitor(this, "DeleteFootnote")) { // Put code to do work in separate method for testing DeleteFootnoteAux(); undoTaskHelper.RollBack = false; } // If there are no more footnotes, then give focus back to the main draft view if (RootBox.Height <= 0 && DraftView != null) { DraftView.Focus(); } return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Shows the category chooser dialog to let the user set the category for the /// specified annotation. /// </summary> /// ------------------------------------------------------------------------------------ private void SetAnnotationCategory(IScrScriptureNote ann) { if (ann == null) { return; // Not much we can do } m_rootb.DestroySelection(); string sUndo, sRedo; TeResourceHelper.MakeUndoRedoLabels("kstidSetAnnotationCategory", out sUndo, out sRedo); using (new WaitCursor(this)) using (CategoryChooserDlg dlg = new CategoryChooserDlg(m_scr.NoteCategoriesOA, ann.CategoriesRS.ToHvoArray(), m_helpTopicProvider, TheMainWnd.App)) { if (dlg.ShowDialog(ParentForm) == DialogResult.OK) { using (UndoTaskHelper undoHelper = new UndoTaskHelper(this, sUndo, sRedo)) { dlg.GetPossibilities(ann.CategoriesRS); ann.DateModified = DateTime.Now; undoHelper.RollBack = false; } } } }
private void m_btnInsert_Click(object sender, System.EventArgs e) { IVwSelection sel = m_view.RootBox.Selection; if (sel == null) { return; } string undo; string redo; ResourceHelper.MakeUndoRedoLabels("kstidUndoRedoInsertRelatedWord", out undo, out redo); using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(m_cache.MainCacheAccessor, m_view.RootBox.Site != null ? m_view.RootBox.Site : null, undo, redo, true)) { ITsString tss; sel.GetSelectionString(out tss, ""); m_sel.ReplaceWithTsString(tss); // TE-5754: The selection is not the installed selection so the commits that happen // as part of the data monitoring process are not committed to the database. We have // to perform an explicit commit on the selection. m_sel.Commit(); } }
private void m_btnInsert_Click(object sender, System.EventArgs e) { IVwSelection sel = m_view.RootBox.Selection; if (sel == null) { return; } string undo; string redo; ResourceHelper.MakeUndoRedoLabels("kstidUndoRedoInsertRelatedWord", out undo, out redo); using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor, m_view.RootBox.Site, undo, redo)) { ITsString tss; sel.GetSelectionString(out tss, ""); m_sel.ReplaceWithTsString(tss); undoTaskHelper.RollBack = false; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Click event of the m_btnCopyToCurr control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event /// data.</param> /// ------------------------------------------------------------------------------------ private void m_btnCopyToCurr_Click(object sender, EventArgs e) { // If nothing or a complete archive is selected, do nothing. TreeNode node = m_treeArchives.SelectedNode; if (node == null || !(node.Tag is IScrBook)) { return; } IScrBook savedBook = (IScrBook)node.Tag; IScrBook originalBook = (IScrBook)m_scr.FindBook(savedBook.CanonicalNum); TreeNode parentNode = node.Parent; IScrDraft archive = (IScrDraft)parentNode.Tag; OverwriteType typeOfOverwrite = OverwriteType.FullNoDataLoss; List <IScrSection> sectionsToRemove = null; if (originalBook != null) { string sDetails; HashSet <int> missingBtWs; typeOfOverwrite = originalBook.DetermineOverwritability(savedBook, out sDetails, out sectionsToRemove, out missingBtWs); if (typeOfOverwrite == OverwriteType.DataLoss) { // There will be data loss if the user overwrites so we don't allow them // to continue. ImportedBooks.ReportDataLoss(originalBook, ScrDraftType.SavedVersion, this, sDetails); return; } if (missingBtWs != null && !ImportedBooks.ConfirmBtOverwrite(originalBook, ScrDraftType.SavedVersion, sectionsToRemove, missingBtWs, this)) { // The user might lose back translation(s) if they proceed and they decided // against it. return; } } string stUndo; string stRedo; TeResourceHelper.MakeUndoRedoLabels("kstidOverwriteCurrentWithSaved", out stUndo, out stRedo); using (new WaitCursor(this)) using (UndoTaskHelper undoHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor, null, stUndo, stRedo)) { if (typeOfOverwrite == OverwriteType.Partial) { // Perform an automerge of the original book and the saved version. using (BookMerger merger = new BookMerger(m_cache, m_styleSheet, savedBook)) { using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this, m_cache.ThreadHelper)) { progress.Title = DlgResources.ResourceString("kstidOverwriteCaption"); progress.RunTask(merger.DoPartialOverwrite, sectionsToRemove); } if (!merger.AutoMerged) { throw new ContinuableErrorException("Partial Overwrite was not successful."); } } } else { // FWNX-677 - caused by mono-calgary patch bug-614850_Modal_614850_v6.patch List <Form> disabled_forms = new List <Form>(); if (MiscUtils.IsUnix) { lock (Application.OpenForms) { foreach (Form form in Application.OpenForms) { if (form.Enabled == false) { disabled_forms.Add(form); } } } foreach (Form form in disabled_forms) { form.Enabled = true; } } if (originalBook != null) { if (m_cache.ActionHandlerAccessor != null) { // When Undoing, we need to first resurrect the deleted book, then // put it back in the book filter...so we need a RIFF in the sequence // BEFORE the delete. ReplaceInFilterFixer fixer1 = new ReplaceInFilterFixer(originalBook, null, m_app); m_cache.ActionHandlerAccessor.AddAction(fixer1); } m_scr.ScriptureBooksOS.Remove(originalBook); } IScrBook newBook = m_scr.CopyBookToCurrent(savedBook); ReplaceInFilterFixer fixer = new ReplaceInFilterFixer(null, newBook, m_app); fixer.Redo(); if (m_cache.ActionHandlerAccessor != null) { m_cache.ActionHandlerAccessor.AddAction(fixer); } // FWNX-677 - caused by mono-calgary patch bug-614850_Modal_614850_v6.patch if (MiscUtils.IsUnix) { foreach (Form form in disabled_forms) { form.Enabled = false; } disabled_forms.Clear(); } } undoHelper.RollBack = false; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle the Delete button. Either delete an archive or a book within the archive /// depending on the selected item. /// </summary> /// ------------------------------------------------------------------------------------ protected void m_btnDelete_Click(object sender, System.EventArgs e) { using (new WaitCursor(this)) { // Figure out what is selected (book or archive) TreeNode node = m_treeArchives.SelectedNode; if (node == null) { return; } // If the tree node is a book and it is the only book in the archive then // switch the node to the parent (archive) node to delete it instead. if (node.Parent != null && node.Parent.Nodes.Count == 1) { node = node.Parent; } string stUndo; string stRedo; // If the tree node is a book, then delete the book from the archive. if (node.Tag is IScrBook) { IScrBook book = (IScrBook)node.Tag; TreeNode parentNode = node.Parent; IScrDraft archive = (IScrDraft)parentNode.Tag; if (archive.Protected) { MessageBox.Show(this, TeResourceHelper.GetResourceString("kstidCannotDeleteBookFromProtectedVersion"), TeResourceHelper.GetResourceString("kstidProtectedVersionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Delete the book from the saved version TeResourceHelper.MakeUndoRedoLabels("kstidUndoDeleteArchiveBook", out stUndo, out stRedo); using (UndoTaskHelper undoHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor, null, stUndo, stRedo)) { archive.BooksOS.Remove(book); undoHelper.RollBack = false; } // Delete the node from the tree parentNode.Nodes.Remove(node); } // If the tree node is an archive then delete the entire archive else if (node.Tag is IScrDraft) { IScrDraft archive = (IScrDraft)node.Tag; if (archive.Protected) { MessageBox.Show(this, TeResourceHelper.GetResourceString("kstidCannotDeleteProtectedVersion"), TeResourceHelper.GetResourceString("kstidProtectedVersionCaption"), MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Delete the ScrDraft object from the scripture TeResourceHelper.MakeUndoRedoLabels("kstidUndoDeleteArchive", out stUndo, out stRedo); using (UndoTaskHelper undoHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor, null, stUndo, stRedo)) { m_scr.ArchivedDraftsOC.Remove(archive); undoHelper.RollBack = false; } // Delete the archive node from the tree m_treeArchives.Nodes.Remove(node); } // If the last thing was deleted from the tree, disable the action buttons. if (m_treeArchives.Nodes.Count == 0) { m_btnDelete.Enabled = false; m_btnCopyToCurr.Enabled = false; m_btnDiff.Enabled = false; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Inserts a note referencing the currently selected paragraph. /// </summary> /// <param name="noteType">Type of note</param> /// <param name="startRef">reference at beginning of selection</param> /// <param name="endRef">reference at end of selection</param> /// <param name="topObj">The object where quoted text begins.</param> /// <param name="bottomObj">The object where quoted text ends.</param> /// <param name="wsSelector">The writing system selector.</param> /// <param name="startOffset">The starting character offset.</param> /// <param name="endOffset">The ending character offset.</param> /// <param name="tssQuote">The text of the quote.</param> /// <returns>The inserted note</returns> /// ------------------------------------------------------------------------------------ public virtual IScrScriptureNote InsertNote(ICmAnnotationDefn noteType, BCVRef startRef, BCVRef endRef, CmObject topObj, CmObject bottomObj, int wsSelector, int startOffset, int endOffset, ITsString tssQuote) { CheckDisposed(); TeNotesVc notesVc = CurrentNotesVc; IScrScriptureNote annotation; string sUndo, sRedo; int iPos; ScrBookAnnotations annotations = (ScrBookAnnotations)m_scr.BookAnnotationsOS[startRef.Book - 1]; TeResourceHelper.MakeUndoRedoLabels("kstidInsertAnnotation", out sUndo, out sRedo); string sType = noteType.Name.UserDefaultWritingSystem; sUndo = string.Format(sUndo, sType); sRedo = string.Format(sRedo, sType); using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(m_cache.MainCacheAccessor, Control as IVwRootSite, sUndo, sRedo, false)) { try { StTxtParaBldr quoteParaBldr = new StTxtParaBldr(m_cache); quoteParaBldr.ParaProps = StyleUtils.ParaStyleTextProps(ScrStyleNames.Remark); quoteParaBldr.StringBuilder.ReplaceTsString(0, 0, tssQuote); annotation = annotations.InsertNote(startRef, endRef, topObj, bottomObj, noteType.Guid, wsSelector, startOffset, endOffset, quoteParaBldr, null, null, null, out iPos); if (notesVc != null) { // tell the VC that the newly inserted item should be expanded. That will cause // the view to be updated to show the new note. notesVc.ExpandItem(annotation.Hvo); notesVc.ExpandItem(annotation.DiscussionOAHvo); } } catch { undoTaskHelper.EndUndoTask = false; FwApp.App.RefreshAllViews(m_cache); throw; } } if (Control != null) { Control.Focus(); } // Make a selection in the discussion so the user can start to type if (notesVc != null && notesVc.NotesSequenceHandler != null) { // Get the corresponding index in the virtual property. iPos = notesVc.NotesSequenceHandler.GetVirtualIndex(annotations.Hvo, iPos); } IVwRootSite rootSite = Control as IVwRootSite; MakeSelectionInNote(notesVc, startRef.Book - 1, iPos, rootSite, true); // REVIEW: Do we need to create a synch record? return(annotation); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Click event of the m_btnCopyToCurr control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event /// data.</param> /// ------------------------------------------------------------------------------------ private void m_btnCopyToCurr_Click(object sender, EventArgs e) { // If nothing or a complete archive is selected, do nothing. TreeNode node = m_treeArchives.SelectedNode; if (node == null || !(node.Tag is ScrBook)) { return; } ScrBook savedBook = node.Tag as ScrBook; ScrBook originalBook = (ScrBook)m_scr.FindBook(savedBook.CanonicalNum); TreeNode parentNode = node.Parent; ScrDraft archive = parentNode.Tag as ScrDraft; OverwriteType typeOfOverwrite = OverwriteType.FullNoDataLoss; List <IScrSection> sectionsToRemove = null; if (originalBook != null) { string sDetails; List <int> missingBtWs; typeOfOverwrite = originalBook.DetermineOverwritability(savedBook, out sDetails, out sectionsToRemove, out missingBtWs); if (typeOfOverwrite == OverwriteType.DataLoss) { // There will be data loss if the user overwrites so we don't allow them // to continue. ImportedBooks.ReportDataLoss(originalBook, ScrDraftType.SavedVersion, this, sDetails); return; } if (missingBtWs != null && !ImportedBooks.ConfirmBtOverwrite(originalBook, ScrDraftType.SavedVersion, sectionsToRemove, missingBtWs, this)) { // The user might lose back translation(s) if they proceed and they decided // against it. return; } } string stUndo; string stRedo; TeResourceHelper.MakeUndoRedoLabels("kstidOverwriteCurrentWithSaved", out stUndo, out stRedo); using (new WaitCursor(this)) using (UndoTaskHelper helper = new UndoTaskHelper(m_cache.MainCacheAccessor, null, stUndo, stRedo, true)) { try { if (typeOfOverwrite == OverwriteType.Partial) { // Perform an automerge of the original book and the saved version. using (BookMerger merger = new BookMerger(m_cache, m_styleSheet, savedBook)) { using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this)) { progress.Title = DlgResources.ResourceString("kstidOverwriteCaption"); progress.RunTask(true, new BackgroundTaskInvoker(merger.DoPartialOverwrite), sectionsToRemove); } if (!merger.AutoMerged) { throw new Exception("Partial Overwrite was not successful."); } } } else { if (originalBook != null) { if (m_cache.ActionHandlerAccessor != null) { // When Undoing, we need to first resurrect the deleted book, then // put it back in the book filter...so we need a RIFF in the sequence // BEFORE the delete. ReplaceInFilterFixer fixer1 = new ReplaceInFilterFixer(originalBook.Hvo, 0, m_cache); m_cache.ActionHandlerAccessor.AddAction(fixer1); } originalBook.DeleteUnderlyingObject(); } int hvoNew = (m_scr as Scripture).CopyBookToCurrent(savedBook); ReplaceInFilterFixer fixer = new ReplaceInFilterFixer(0, hvoNew, m_cache); fixer.Redo(false); if (m_cache.ActionHandlerAccessor != null) { m_cache.ActionHandlerAccessor.AddAction(fixer); } } } catch { helper.EndUndoTask = false; throw; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Shows the Format Apply Style dialog. Apply the results to the selection of the active /// view if the user clicks OK. /// </summary> /// <param name="paraStyleName">Name of the para style.</param> /// <param name="charStyleName">Name of the char style.</param> /// <param name="maxStyleLevel">The maximum style level that will be shown in this /// dialog. (apps that do not use style levels in their stylesheets can pass 0)</param> /// ------------------------------------------------------------------------------------ public void ShowApplyStyleDialog(string paraStyleName, string charStyleName, int maxStyleLevel) { SimpleRootSite rootsite = (ActiveView as SimpleRootSite); try { if (rootsite != null) { rootsite.ShowRangeSelAfterLostFocus = true; } IVwSelection sel = EditingHelper.CurrentSelection.Selection; if (paraStyleName == null && charStyleName == null) { // If the caller didn't know the default style, try to figure it out from // the selection. GetStyleNames(rootsite, sel, ref paraStyleName, ref charStyleName); } int hvoRoot, frag; IVwViewConstructor vc; IVwStylesheet ss; ActiveView.CastAsIVwRootSite().RootBox.GetRootObject(out hvoRoot, out vc, out frag, out ss); using (FwApplyStyleDlg applyStyleDlg = new FwApplyStyleDlg(ActiveView.CastAsIVwRootSite(), Cache, ActiveStyleSheet.RootObjectHvo, StyleSheetOwningFlid, ActiveStyleSheet.GetDefaultBasedOnStyleName(), maxStyleLevel, paraStyleName, charStyleName, hvoRoot, m_app, m_app)) { if (FwEditingHelper != null) { if (FwEditingHelper.ApplicableStyleContexts != null) { applyStyleDlg.ApplicableStyleContexts = FwEditingHelper.ApplicableStyleContexts; } } else if (m_app != null) { // Window doesn't have an editing helper, go with whole-app default if (m_app.DefaultStyleContexts != null) { applyStyleDlg.ApplicableStyleContexts = m_app.DefaultStyleContexts; } } applyStyleDlg.AllowSelectStyleTypes = m_callbacks.ShowTEStylesComboInStylesDialog; applyStyleDlg.CanApplyCharacterStyle = sel.CanFormatChar; applyStyleDlg.CanApplyParagraphStyle = sel.CanFormatPara; if (applyStyleDlg.ShowDialog(m_callbacks) == DialogResult.OK) { string sUndo, sRedo; ResourceHelper.MakeUndoRedoLabels("kstidUndoApplyStyle", out sUndo, out sRedo); using (UndoTaskHelper helper = new UndoTaskHelper(Cache.ActionHandlerAccessor, ActiveView.CastAsIVwRootSite(), sUndo, sRedo)) { EditingHelper.ApplyStyle(applyStyleDlg.StyleChosen); helper.RollBack = false; } } } } finally { if (rootsite != null) { rootsite.ShowRangeSelAfterLostFocus = false; } } }