Beispiel #1
0
        private void ClearExampleCustom()
        {
            MultiText customFieldInExample =
                _examples.GetOrCreateProperty <MultiText>("customFieldInExample");

            customFieldInExample["th"] = string.Empty;
            _entry.CleanUpAfterEditting();
        }
        private void EnsureHasOneEntryProperty()
        {
            LexEntry entry = GetCurrentEntry();

            entry.CleanUpAfterEditting();
            Assert.AreEqual(1, entry.Properties.Count);
        }
        private void EnsureHasTwoSenseProperties()
        {
            LexEntry entry = GetCurrentEntry();

            entry.CleanUpAfterEditting();
            //one for definition, one for custom field
            Assert.AreEqual(2, entry.Senses[0].Properties.Count);
        }
Beispiel #4
0
        public void Cleanup_HasBaseform_PropertyIsNotRemoved()
        {
            var target = new LexEntry();

            _entry = new LexEntry();
            _entry.LexicalForm["v"] = "hello";
            _entry.AddRelationTarget(LexEntry.WellKnownProperties.BaseForm, target.GetOrCreateId(true));
            _entry.CleanUpAfterEditting();
            Assert.IsNotNull(_entry.GetProperty <LexRelationCollection>(LexEntry.WellKnownProperties.BaseForm));
        }
Beispiel #5
0
        /// <summary>
        /// Removes the sense (if otherwise empty) and deletes the entry if it has no reason left to live
        /// </summary>
        public void TryToRemoveAssociationWithListWordFromEntry(RecordToken <LexEntry> recordToken)
        {
            // have to iterate through these in reverse order
            // since they might get modified
            LexEntry entry = recordToken.RealObject;

            for (int i = entry.Senses.Count - 1; i >= 0; i--)
            {
                if (entry.Senses[i].Equals(CurrentTemplateSense))
                {
                    entry.Senses.RemoveAt(i);
                }
            }
            entry.CleanUpAfterEditting();
            if (entry.IsEmptyExceptForLexemeFormForPurposesOfDeletion)
            {
                LexEntryRepository.DeleteItem(entry);
            }
            else
            {
                LexEntryRepository.SaveItem(entry);
            }
        }
Beispiel #6
0
        public void PrepareToMoveWordToEditArea(WordDisplay wordDisplay)
        {
            VerifyTaskActivated();
            _savedSensesDuringMoveToEditArea = null;

            if (wordDisplay == null)
            {
                throw new ArgumentNullException();
            }
            // this task was coded to have a list of word-forms, not actual entries.
            //so we have to go searching for possible matches at this point.
            ResultSet <LexEntry> matchingEntries =
                LexEntryRepository.GetEntriesWithMatchingLexicalForm(wordDisplay.Vernacular.Form, FormWritingSystem);

            foreach (RecordToken <LexEntry> recordToken in matchingEntries)
            {
                if (_savedSensesDuringMoveToEditArea == null)
                {
                    _savedSensesDuringMoveToEditArea = new List <LexSense>();
                }
                // have to iterate through these in reverse order since they might get modified
                LexEntry entry = recordToken.RealObject;
                //If we aren't showing the meaning field then we are going let any edits effect all matching Senses
                if (!ShowMeaningField)
                {
                    for (int i = entry.Senses.Count - 1; i >= 0; i--)
                    {
                        LexSense sense           = entry.Senses[i];
                        var      semanticDomains = sense.GetProperty <OptionRefCollection>(_semanticDomainField.FieldName);
                        if (semanticDomains != null)
                        {
                            if (semanticDomains.Contains(CurrentDomainKey))
                            {
                                RememberMeaningOfDissociatedWord(sense);
                                entry.Senses.Remove(sense);
                                //if we don't do this and it has a meaning, we'll fail to delete the word when the user is trying to correct the spelling. (WS-34245)
                            }
                        }
                    }
                }
                //If we are showing the meaning field then we only let edits effect the sense that matches the shown meaning (definition)
                else
                {
                    var firstSenseMatchingSemDomAndMeaning =
                        entry.Senses.
                        Where(s => s.GetProperty <OptionRefCollection>(LexSense.WellKnownProperties.SemanticDomainDdp4) != null).
                        FirstOrDefault(s => s.GetProperty <OptionRefCollection>(LexSense.WellKnownProperties.SemanticDomainDdp4).Contains(CurrentDomainKey) &&
                                       s.Definition.GetBestAlternative(new[] { DefinitionWritingSystem.Id }) == wordDisplay.Meaning);
                    if (firstSenseMatchingSemDomAndMeaning != null)
                    {
                        RememberMeaningOfDissociatedWord(firstSenseMatchingSemDomAndMeaning);
                        entry.Senses.Remove(firstSenseMatchingSemDomAndMeaning);
                    }
                }
                entry.CleanUpAfterEditting();
                if (entry.IsEmptyExceptForLexemeFormForPurposesOfDeletion)
                {
                    LexEntryRepository.DeleteItem(entry);                     // if there are no senses left, get rid of it
                }
                else
                {
                    LexEntryRepository.SaveItem(entry);
                }
            }

            UpdateCurrentWords();
        }