Exemplo n.º 1
0
        private void tsmiEditExample_Click(object sender, EventArgs e)
        {
            if (lvExamples.SelectedItems.Count == 0)
            {
                return;
            }

            var exampleViewItem = lvExamples.SelectedItems[0] as ExampleViewItem;

            using (var dialog = new EditExampleForm(exampleViewItem.SubItems[1].Text))
            {
                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                if (string.IsNullOrWhiteSpace(dialog.Example))
                {
                    return;
                }

                exampleViewItem.SubItems[1].Text = dialog.Example;
                WordInfo.Entries[exampleViewItem.EntryIndex].Definitions[exampleViewItem.DefinitionIndex].Examples[exampleViewItem.ExampleIndex] = dialog.Example;
                rtbOutput.Text = dialog.Example;
                ChangeMade     = true;
            }
        }
Exemplo n.º 2
0
        private void tsmiAddExample_Click(object sender, EventArgs e)
        {
            if (lvDefinitions.SelectedItems.Count == 0)
            {
                return;
            }

            var exampleViewItem = new ExampleViewItem();

            lvExamples.Items.Add(exampleViewItem);

            using (var dialog = new EditExampleForm())
            {
                if (dialog.ShowDialog() != DialogResult.OK || string.IsNullOrWhiteSpace(dialog.Example))
                {
                    lvExamples.Items.Remove(exampleViewItem);
                    return;
                }

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

                var examples = dialog.Example.Split(Environment.NewLine.ToCharArray())
                               .Select(x => x.Trim())
                               .Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
                for (int index = 0; index < examples.Length; index++)
                {
                    if (index > 0)
                    {
                        exampleViewItem = new ExampleViewItem();
                        lvExamples.Items.Add(exampleViewItem);
                    }

                    exampleViewItem.EntryIndex      = definitionViewItem.EntryIndex;
                    exampleViewItem.DefinitionIndex = definitionViewItem.DefinitionIndex;

                    if (WordInfo.Entries[exampleViewItem.EntryIndex].Definitions[exampleViewItem.DefinitionIndex].Examples == null)
                    {
                        WordInfo.Entries[exampleViewItem.EntryIndex].Definitions[exampleViewItem.DefinitionIndex].Examples = new List <string>();
                    }
                    exampleViewItem.ExampleIndex = WordInfo.Entries[exampleViewItem.EntryIndex].Definitions[exampleViewItem.DefinitionIndex].Examples.Count;
                    exampleViewItem.Text         = (exampleViewItem.ExampleIndex + 1).ToString();

                    var example = examples[index];
                    exampleViewItem.SubItems.Add(example);
                    WordInfo.Entries[exampleViewItem.EntryIndex].Definitions[exampleViewItem.DefinitionIndex].Examples.Add(example);
                }
                definitionViewItem.WordInfo = WordInfo;
                ChangeMade = true;
            }
        }