Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Runs the check.
        /// </summary>
        /// <param name="check">The check.</param>
        /// ------------------------------------------------------------------------------------
        public void RunCheck(IScriptureCheck check)
        {
            if (m_bookChecksFailed == null)
            {
                m_bookChecksFailed = new Dictionary <int, Dictionary <Guid, ScrCheckRunResult> >();
            }

            if (m_pendingCheckErrors == null)
            {
                m_pendingCheckErrors = new Dictionary <int, Dictionary <Guid, Dictionary <string, List <ScrScriptureNote> > > >();
            }

            Dictionary <Guid, Dictionary <string, List <ScrScriptureNote> > > pendingErrorsForBook;
            int bookNum = m_bookBeingChecked.CanonicalNum;

            if (!m_pendingCheckErrors.TryGetValue(bookNum, out pendingErrorsForBook))
            {
                pendingErrorsForBook          = new Dictionary <Guid, Dictionary <string, List <ScrScriptureNote> > >();
                m_pendingCheckErrors[bookNum] = pendingErrorsForBook;
            }
            Dictionary <string, List <ScrScriptureNote> > pendingErrorsForCheck =
                new Dictionary <string, List <ScrScriptureNote> >();

            pendingErrorsForBook[check.CheckId] = pendingErrorsForCheck;

            ScrBookAnnotations annotations =
                (ScrBookAnnotations)m_scr.BookAnnotationsOS[bookNum - 1];

            // Find previously created error annotions for the current book and check.
            foreach (ScrScriptureNote ann in annotations.NotesOS)
            {
                BCVRef beginRef = new BCVRef(ann.BeginRef);
                // ENHANCE, use a smarter algorithm to search for the start of the annotations for this book
                if (beginRef.Book == bookNum && ann.AnnotationTypeRA.Guid == check.CheckId)
                {
                    BCVRef    endRef         = new BCVRef(ann.EndRef);
                    StTxtPara quotePara      = (StTxtPara)ann.QuoteOA.ParagraphsOS[0];
                    StTxtPara discussionPara = (StTxtPara)ann.DiscussionOA.ParagraphsOS[0];
                    string    key            = beginRef.AsString + endRef.AsString + quotePara.Contents.Text +
                                               discussionPara.Contents.Text;

                    List <ScrScriptureNote> errors;
                    if (!pendingErrorsForCheck.TryGetValue(key, out errors))
                    {
                        errors = new List <ScrScriptureNote>();
                        pendingErrorsForCheck[key] = errors;
                    }
                    errors.Add(ann);
                }
            }

            if (!m_bookChecksFailed.ContainsKey(bookNum))
            {
                m_bookChecksFailed[bookNum] = new Dictionary <Guid, ScrCheckRunResult>();
            }

            // Before running the check, reset the check result for this book and check.
            // This is like initializing our check result to green bar in an NUnit test.
            // As the check is running, that status may get changed to "Inconsistencies"
            // (red bar) or "IgnoredInconsistencies" (yellow bar).
            m_bookChecksFailed[bookNum][check.CheckId] = ScrCheckRunResult.NoInconsistencies;

            // Create a hash table for this check to tally how many times each unique error is generated.
            if (m_errorCounts != null)
            {
                m_errorCounts.Clear();
                m_errorCounts = null;
            }
            m_errorCounts = new ErrorInventory();

            // Run the Scripture check.
            check.Check(TextTokens(), RecordError);

            // Find a check history record for the check just run.
            // If one cannot be found, then create a new one.
            ScrCheckRun checkRun = null;

            foreach (ScrCheckRun scrChkRun in annotations.ChkHistRecsOC)
            {
                if (scrChkRun.CheckId == check.CheckId)
                {
                    checkRun = scrChkRun;
                    break;
                }
            }

            if (checkRun == null)
            {
                checkRun = new ScrCheckRun();
                annotations.ChkHistRecsOC.Add(checkRun);
                checkRun.CheckId = check.CheckId;
            }

            checkRun.RunDate = DateTime.Now;
            checkRun.Result  = m_bookChecksFailed[bookNum][check.CheckId];

            // Should this be initialized to certain capacity?
            Set <int> obsoleteErrorIds = new Set <int>();

            foreach (List <ScrScriptureNote> obsoleteErrors in pendingErrorsForCheck.Values)
            {
                foreach (ScrScriptureNote obsoleteError in obsoleteErrors)
                {
                    //annotations.NotesOS.Remove(obsoleteError);
                    obsoleteErrorIds.Add(obsoleteError.Hvo);
                }
            }

            CmObject.DeleteObjects(obsoleteErrorIds, m_cache);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Override method to handle launching of a chooser for selecting lexical entries.
        /// </summary>
        protected override void HandleChooser()
        {
            string displayWs = "analysis vernacular";
            string postDialogMessageTrigger = null;

            if (m_configurationNode != null)
            {
                XmlNode node = m_configurationNode.SelectSingleNode("deParams");
                if (node != null)
                {
                    displayWs = XmlUtils.GetAttributeValue(node, "ws", "analysis vernacular").ToLower();
                    postDialogMessageTrigger = XmlUtils.GetAttributeValue(node, "postChangeMessageTrigger", null);
                }
            }
            Set <int>             candidates = m_obj.ReferenceTargetCandidates(m_flid);
            ObjectLabelCollection labels     = new ObjectLabelCollection(m_cache, candidates,
                                                                         m_displayNameProperty, displayWs);

            using (MorphTypeChooser chooser = GetChooser(labels))
            {
                bool      fMadeMorphTypeChange = false;
                ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, m_obj.OwnerHVO);
                chooser.InitializeExtras(m_configurationNode, Mediator);
                chooser.SetObjectAndFlid(m_obj.Hvo, m_flid);
                int hvoType = m_cache.GetObjProperty(m_obj.Hvo, m_flid);
                chooser.MakeSelection(hvoType);
                // LT-4433 changed the Alternate Forms to choose between Stem and Affix automatically
                // when inserting.  Thus, we need the check box in that environment as well.
                //if (m_obj.OwningFlid != (int)LexEntry.LexEntryTags.kflidLexemeForm)
                //    chooser.ShowAllTypesCheckBoxVisible = false;
                if (chooser.ShowDialog() == DialogResult.OK)
                {
                    ObjectLabel selected    = chooser.ChosenOne;
                    int         hvoOriginal = TargetHvo;
                    string      sUndo       = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeUndo", m_ksPath);
                    string      sRedo       = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeRedo", m_ksPath);

                    bool fRemoveComponents = false;
                    if (selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphRoot)) ||
                        selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphBoundRoot)))
                    {
                        // changing to root...not allowed to have complex forms.
                        foreach (LexEntryRef ler in entry.EntryRefsOS)
                        {
                            if (ler.RefType == LexEntryRef.krtComplexForm)
                            {
                                fRemoveComponents = true;
                                // If there are no components we will delete without asking...but must then check for more
                                // complex forms that DO have components.
                                if (ler.ComponentLexemesRS.Count > 0)
                                {
                                    if (MessageBox.Show(FindForm(), DetailControlsStrings.ksRootNoComponentsMessage,
                                                        DetailControlsStrings.ksRootNoComponentsCaption, MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0, FwApp.App.HelpFile,
                                                        HelpNavigator.Topic, "khtRootCannotHaveComponents") != DialogResult.Yes)
                                    {
                                        return;
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    using (new UndoRedoTaskHelper(entry.Cache, sUndo, sRedo))
                    {
                        if (fRemoveComponents)
                        {
                            Set <int> delObjs = new Set <int>();
                            foreach (LexEntryRef ler in entry.EntryRefsOS)
                            {
                                if (ler.RefType == LexEntryRef.krtComplexForm)
                                {
                                    delObjs.Add(ler.Hvo);
                                }
                            }
                            CmObject.DeleteObjects(delObjs, m_cache);
                        }

                        if (IsStemType(hvoOriginal) || m_obj is MoStemAllomorph)
                        {
                            if (IsStemType(selected.Hvo))
                            {
                                TargetHvo = selected.Hvo;
                            }
                            else
                            {
                                //have to switch from stem to affix
                                fMadeMorphTypeChange = ChangeStemToAffix(entry, selected.Hvo, sUndo, sRedo);
                            }
                        }
                        else
                        {
                            // original is affix variety
                            if (IsStemType(selected.Hvo))
                            {
                                //have to switch from affix to stem
                                fMadeMorphTypeChange = ChangeAffixToStem(entry, selected.Hvo, sUndo, sRedo);
                            }
                            else
                            {
                                TargetHvo = selected.Hvo;
                            }
                        }
                        if (selected.Hvo == entry.Cache.GetIdFromGuid(new Guid(MoMorphType.kguidMorphPhrase)))
                        {
                            ILexEntryRef ler = new LexEntryRef();
                            entry.EntryRefsOS.Append(ler);
                            ler.RefType        = LexEntryRef.krtComplexForm;
                            ler.HideMinorEntry = 1;
                            // No automatic propchanged for new objects, need to let the view see it.
                            // At that point our slice will be disposed, so don't do anything after this.
                            entry.Cache.PropChanged(entry.Hvo, (int)LexEntry.LexEntryTags.kflidEntryRefs, 0, 1, 0);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void DeleteObjects()
        {
            CheckDisposed();

            m_fdoCache.BeginUndoTask("make texts", "undo make texts");
            // One text with 4 paras
            SIL.FieldWorks.FDO.Ling.Text text1 = new Text();
            m_fdoCache.LangProject.TextsOC.Add(text1);
            StText body1 = new StText();

            text1.ContentsOA = body1;
            StTxtPara para1A = new StTxtPara();

            body1.ParagraphsOS.Append(para1A);
            StTxtPara para1B = new StTxtPara();

            body1.ParagraphsOS.Append(para1B);
            StTxtPara para1C = new StTxtPara();

            body1.ParagraphsOS.Append(para1C);
            StTxtPara para1D = new StTxtPara();

            body1.ParagraphsOS.Append(para1D);
            para1A.Contents.Text = "Contents of para1A";
            para1B.Contents.Text = "Para 1B stuff";
            para1C.Contents.Text = "Rubbish in 1C";
            para1D.Contents.Text = "Things in 1D";

            // Second text, 2 paras
            SIL.FieldWorks.FDO.Ling.Text text2 = new Text();
            m_fdoCache.LangProject.TextsOC.Add(text2);
            StText body2 = new StText();

            text2.ContentsOA = body2;
            StTxtPara para2A = new StTxtPara();

            body2.ParagraphsOS.Append(para2A);
            StTxtPara para2B = new StTxtPara();

            body2.ParagraphsOS.Append(para2B);
            para2A.Contents.Text = "2A contents";
            para2B.Contents.Text = "2B stuff";

            m_fdoCache.EndUndoTask();

            Set <int> idsToDelete = new Set <int>();

            idsToDelete.Add(para1A.Hvo);
            idsToDelete.Add(para1B.Hvo);
            idsToDelete.Add(para1D.Hvo);
            idsToDelete.Add(para2A.Hvo);
            m_fdoCache.BeginUndoTask("delete paras", "undo delete paras");
            CmObject.DeleteObjects(idsToDelete, m_fdoCache);
            m_fdoCache.EndUndoTask();
            Assert.AreEqual(1, body1.ParagraphsOS.Count, "paras were deleted1");
            Assert.AreEqual(1, body2.ParagraphsOS.Count, "paras were deleted2");
            m_fdoCache.Undo();
            m_fdoCache.VwCacheDaAccessor.ClearAllData();             // as in Refresh.
            Assert.AreEqual(4, body1.ParagraphsOS.Count, "paras were restored1");
            Assert.AreEqual(2, body2.ParagraphsOS.Count, "paras were restored1");
            Assert.AreEqual("Contents of para1A", para1A.Contents.Text, "para 1A contents restored");
            Assert.AreEqual("Things in 1D", para1D.Contents.Text, "para 1D contents restored");
            Assert.AreEqual("2A contents", para2A.Contents.Text, "para 2A contents restored");
            m_fdoCache.Redo();
            m_fdoCache.VwCacheDaAccessor.ClearAllData();             // as in Refresh.
            Assert.AreEqual(1, body1.ParagraphsOS.Count, "paras were deleted1");
            Assert.AreEqual(1, body2.ParagraphsOS.Count, "paras were deleted2");
            m_fdoCache.Undo();
            m_fdoCache.VwCacheDaAccessor.ClearAllData();             // as in Refresh.
            Assert.AreEqual(4, body1.ParagraphsOS.Count, "paras were restored1");
            Assert.AreEqual(2, body2.ParagraphsOS.Count, "paras were restored1");
            Assert.AreEqual("Contents of para1A", para1A.Contents.Text, "para 1A contents restored");
            Assert.AreEqual("Things in 1D", para1D.Contents.Text, "para 1D contents restored");
            Assert.AreEqual("2A contents", para2A.Contents.Text, "para 2A contents restored");
            m_fdoCache.Undo();             // cleans up the last of what we added.
        }