MakeUndoRedoLabels() 공개 정적인 메소드

Function to create appropriate labels for Undo tasks, with the action names coming from the stid.
public static MakeUndoRedoLabels ( string stid, string &stUndo, string &stRedo ) : void
stid string String resource id
stUndo string Returns string for Undo task
stRedo string Returns string for Redo task
리턴 void
예제 #1
0
        /// ------------------------------------------------------------------------------------
        /// <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;
                        }
                    }
                }
        }
예제 #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// When really, truly done with all merging etc, collapse all the things we can Undo
        /// for the import into a single Undo Item.
        /// </summary>
        /// <returns>True if some actions were collapsed, false otherwise</returns>
        /// ------------------------------------------------------------------------------------
        public bool CollapseAllUndoActions()
        {
            string undo;
            string redo;

            TeResourceHelper.MakeUndoRedoLabels("kstidImport", out undo, out redo);
            return(m_cache.DomainDataByFlid.GetActionHandler().CollapseToMark(m_hMark, undo, redo));
        }
예제 #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// When really, truly done with all merging etc, collapse all the things we can Undo
        /// for the import into a single Undo Item.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void CollapseAllUndoActions()
        {
            string undo;
            string redo;

            TeResourceHelper.MakeUndoRedoLabels("kstidImport", out undo, out redo);
            m_cache.ActionHandlerAccessor.CollapseToMark(m_hMark, undo, redo);
        }
예제 #5
0
        /// ------------------------------------------------------------------------------------
        /// <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(DataAccess))
            {
                return(true);                //discard this event
            }
            if (!ValidFootnoteSelection)
            {
                return(true);
            }

            string undo;
            string redo;

            TeResourceHelper.MakeUndoRedoLabels("kstidUndoDelFootnote", out undo, out redo);
            using (new UndoTaskHelper(this, undo, redo, false))
                using (new DataUpdateMonitor(this, RootBox.DataAccess, this, "DeleteFootnote"))
                {
                    SelectionHelper helper  = SelectionHelper.Create(this);
                    int             fnLevel = helper.GetLevelForTag((int)ScrBook.ScrBookTags.kflidFootnotes);

                    if (helper.Selection.IsRange)
                    {
                        DeleteFootnoteRange(helper);
                    }
                    else
                    {
                        // There's no range selection, so delete only one footnote
                        ScrFootnote footnote = new ScrFootnote(m_fdoCache, helper.LevelInfo[fnLevel].hvo);
                        ScrFootnote.DeleteFootnoteAndMarker(footnote);
                    }

                    if (RootBox.Height <= 0)
                    {
                        DraftView.Focus();
                    }
                    else
                    {
                        int     iBook     = helper.LevelInfo[fnLevel + 1].ihvo;
                        ScrBook book      = m_bookFilter.GetBook(iBook);
                        int     iFootnote = helper.LevelInfo[fnLevel].ihvo;

                        // If the last footnote in the book was deleted find a footnote to move to
                        if (iFootnote >= book.FootnotesOS.Count)
                        {
                            FindNearestFootnote(ref iBook, ref iFootnote);
                        }

                        FootnoteEditingHelper.ScrollToFootnote(iBook, iFootnote, 0);
                    }
                }

            return(true);
        }
예제 #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handle the OK button click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        private void m_btnOK_Click(object sender, EventArgs e)
        {
            using (new WaitCursor(this))
            {
                string undo, redo;
                TeResourceHelper.MakeUndoRedoLabels("kstidUndoRedoScriptureProperties",
                                                    out undo, out redo);

                UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(undo, redo,
                                                                m_cache.ServiceLocator.GetInstance <IActionHandler>(), () =>
                {
                    ProcessScriptNumberSettings();
                    ProcessRefFormattingSettings();
                    ProcessVersificationSettings();
                    ProcessFootnoteSettings();
                });
            }
        }
예제 #7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Shows the category chooser dialog to let the user set the category for the
        /// specified annotation.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void SetAnnotationCategory(ScrScriptureNote 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 UndoTaskHelper(this, sUndo, sRedo, true))
                using (new WaitCursor(this))
                    using (CategoryChooserDlg dlg =
                               new CategoryChooserDlg(m_scr.NoteCategoriesOA, ann.CategoriesRS.HvoArray))
                    {
                        if (dlg.ShowDialog(ParentForm) == DialogResult.OK &&
                            !dlg.GetPossibilities(ann.CategoriesRS))
                        {
                            ann.DateModified = DateTime.Now;
                        }
                    }
        }
예제 #8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Updates the updateTime on the specified note. This method deletes the mark in the
        /// undo stack. If fStartNewMark is true then a new mark is created.
        /// </summary>
        /// <param name="noteHvo">The hvo of the note to be updated, or 0 to ignore</param>
        /// ------------------------------------------------------------------------------------
        public void SetNoteUpdateTime(int noteHvo)
        {
            CheckDisposed();

            IActionHandler handler = m_fdoCache.ActionHandlerAccessor;

            if (m_fIgnoreTmStmpUpdate || handler == null || handler.CurrentDepth > 0 ||
                handler.TopMarkHandle == 0)
            {
                return;
            }

            if (!handler.get_TasksSinceMark(true))
            {
                handler.DiscardToMark(0);
            }
            else
            {
                // Can happen... just continue on
                if (noteHvo != 0 && m_fdoCache.IsValidObject(noteHvo))
                {
                    ScrScriptureNote ann = new ScrScriptureNote(m_fdoCache, noteHvo);
                    ann.DateModified = DateTime.Now;
                    m_fdoCache.PropChanged(null, PropChangeType.kpctNotifyAll, noteHvo,
                                           (int)CmAnnotation.CmAnnotationTags.kflidDateModified, 0, 1, 1);
                }

                string sUndo;
                string sRedo;
                TeResourceHelper.MakeUndoRedoLabels("kstidDiffDlgUndoRedoEditNote",
                                                    out sUndo, out sRedo);
                handler.CollapseToMark(0, sUndo, sRedo);
                // If no tasks since the mark actually change the data, they should all get
                // deleted when we collapse.
            }
        }
예제 #9
0
        /// ------------------------------------------------------------------------------------
        /// <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;
                }
        }
예제 #10
0
        /// ------------------------------------------------------------------------------------
        /// <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;
                }
            }
        }
예제 #11
0
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
예제 #12
0
        /// ------------------------------------------------------------------------------------
        /// <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;
                    }
                }
        }