Example #1
0
        internal void DeleteWord()
        {
            Debug.Assert(CurrentIndex >= 0);
            if (CurrentIndex == -1)
            {
                return;
            }
            if (!_btnDeleteWord.Focused)
            {
                // if we use a hot key, it may not have received the focus
                // but we assume it has the focus when we do our selection change event
                _btnDeleteWord.Focus();
            }

            _logger.WriteConciseHistoricalEvent("Deleted '{0}'", CurrentEntry.GetSimpleFormForLogging());
            CurrentEntry.IsBeingDeleted = true;
            // If the record hasn't been saved (newly created), then setting _recordsListBox.SelectedIndex
            // can have a side-effect of reordering _records.  So we need to record the current id, not just
            // the current index.
            var idToDelete = _records[CurrentIndex].Id;

            _recordsListBox.SelectedIndex = _records.Count == CurrentIndex + 1 ? CurrentIndex - 1 : CurrentIndex + 1;
            _lexEntryRepository.DeleteItem(idToDelete);
            LoadRecords();
            UpdateListViewIfGecko();

            _entryViewControl.SelectOnCorrectControl();
        }
Example #2
0
        public void GetAllEntriesSortedByHeadWord_DeleteAfterFirstCall_EntryIsDeletedInResultSet()
        {
            LexEntry entrytoBeDeleted = CreateEntryWithLexicalFormBeforeFirstQuery("de", "word 0");

            _repository.GetAllEntriesSortedByHeadword(WritingSystemDefinition.Parse("de"));

            _repository.DeleteItem(entrytoBeDeleted);

            ResultSet <LexEntry> results = _repository.GetAllEntriesSortedByHeadword(WritingSystemDefinition.Parse("de"));

            Assert.AreEqual(0, results.Count);
        }
        public void DeleteEntry_ByEntry_TriggersAfterEntryDeleted()
        {
            using (TemporaryFolder f = new TemporaryFolder("eventTests"))
            {
                using (LexEntryRepository r = new LexEntryRepository(f.GetPathForNewTempFile(true)))
                {
                    r.AfterEntryDeleted += OnEvent;

                    LexEntry entry = r.CreateItem();
                    r.SaveItem(entry);

                    r.DeleteItem(entry);
                    Assert.IsTrue(_gotEventCall);
                }
            }
        }
Example #4
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);
            }
        }
Example #5
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();
        }