Ejemplo n.º 1
0
        private void tsmiAddDefinition_Click(object sender, EventArgs e)
        {
            var definitionViewItem = new DefinitionViewItem();

            lvDefinitions.Items.Add(definitionViewItem);

            using (var dialog = new EditWordDefinitionForm(WordInfo.Entries.Count, tbInputWord.Text))
            {
                if (dialog.ShowDialog() != DialogResult.OK || string.IsNullOrWhiteSpace(dialog.Definition))
                {
                    RemoveDefinitionViewItem(definitionViewItem);
                    return;
                }

                ProcessEditWordDefinitionDialog(dialog);

                var definition = new CambridgeWordInfo.Block()
                {
                    Definition = dialog.Definition
                };
                WordInfo.Entries[dialog.EntryIndex].Definitions.Add(definition);
                WordInfo.Entries[dialog.EntryIndex].Label = dialog.Label;

                definitionViewItem.EntryIndex      = dialog.EntryIndex;
                definitionViewItem.DefinitionIndex = WordInfo.Entries[dialog.EntryIndex].Definitions.Count - 1;
                definitionViewItem.Tag             = lvDefinitions.Items.Count - 1;
                definitionViewItem.WordInfo        = WordInfo;
                ChangeMade = true;
            }
        }
Ejemplo n.º 2
0
        private void tsmiEditDefinition_Click(object sender, EventArgs e)
        {
            if (lvDefinitions.SelectedItems.Count == 0)
            {
                return;
            }

            var definitionViewItem = lvDefinitions.SelectedItems[0] as DefinitionViewItem;

            using (var dialog = new EditWordDefinitionForm(WordInfo.Entries.Count, definitionViewItem.SubItems[0].Text, definitionViewItem.SubItems[1].Text, definitionViewItem.SubItems[3].Text))
            {
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                if (string.IsNullOrWhiteSpace(dialog.Definition))
                {
                    RemoveDefinitionViewItem(definitionViewItem);
                    return;
                }

                WordInfo.Entries[definitionViewItem.EntryIndex].ActualWord = dialog.Word;
                WordInfo.Entries[definitionViewItem.EntryIndex].Label      = dialog.Label;
                WordInfo.Entries[definitionViewItem.EntryIndex].Definitions[definitionViewItem.DefinitionIndex].Definition = dialog.Definition;

                definitionViewItem.Text             = dialog.Word;
                definitionViewItem.SubItems[1].Text = dialog.Label;
                definitionViewItem.SubItems[3].Text = dialog.Definition;
                definitionViewItem.WordInfo.Entries[definitionViewItem.EntryIndex].Definitions[definitionViewItem.DefinitionIndex].Definition = dialog.Definition;
                ChangeMade = true;
            }
        }
Ejemplo n.º 3
0
        private void ProcessEditWordDefinitionDialog(EditWordDefinitionForm dialog)
        {
            CambridgeWordInfo.Entry entry;
            if (WordInfo.Entries.Count != 0 && WordInfo.Entries.Count >= dialog.EntryIndex + 1)
            {
                entry = WordInfo.Entries[dialog.EntryIndex];
                if (entry.ActualWord == dialog.Word && entry.Label == dialog.Label)
                {
                    return;
                }
            }

            entry             = new CambridgeWordInfo.Entry();
            entry.ActualWord  = dialog.Word;
            entry.Definitions = new List <CambridgeWordInfo.Block>();
            entry.Label       = dialog.Label;
            WordInfo.Entries.Add(entry);
        }