Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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;
            }
        }