Exemplo n.º 1
0
        private void DeleteNoteBT_Click(object sender, EventArgs e)
        {
            if (Current_Note != null)
            {
                DialogResult delete;

                delete = MessageBox.Show("Are you sure you want to delete \"" + Current_Note.Name + "\"?", "Delete Note", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (delete == DialogResult.Yes)
                {
                    Deleting_Item = true;
                    Note_Changes.Remove(Current_Note.Name);
                    NotesLV.Items.Remove(Current_Note);
                    Deleting_Item = false;

                    NotesLV.SelectedItems.Clear();

                    try
                    {
                        NotesLV.Items[0].Selected = true;
                    }

                    catch
                    {
                    }

                    NotesLV.Select();

                    try
                    {
                        Current_Note = NotesLV.SelectedItems[0];
                    }

                    catch
                    {
                        Current_Note = null;
                        NoteTitleTB.Clear();
                        NoteBodyTB.Clear();
                        NoteTitleTB.Enabled = false;
                        NoteBodyTB.Enabled  = false;
                    }

                    Previous_Note = null;

                    try
                    {
                        Current_Note.Font = BoldFont;
                        NoteTitleTB.Text  = Current_Note.Name;
                    }

                    catch
                    {
                    }

                    try
                    {
                        NoteBodyTB.Text = Note_Changes[Current_Note.Name];
                    }

                    catch
                    {
                    }
                }
            }

            if (NotesLV.Items.Count == 0)
            {
                DeleteNoteBT.Visible = false;
            }
        }
Exemplo n.º 2
0
        private void Selection_Changed_Selection_Changed_EventHandler(object sender, EventArgs e)
        {
            if (Selection_Changed.Selection_Changed)
            {
                if (_lock)
                {
                }

                else if (!_lock)
                {
                    _lock = true;

                    // Going from selected to deselected
                    // Happens when selecting another item after an already selected one or selecting nothing after a selected item
                    if (Current_Count == 0 && Previous_Count == 1)
                    {
                        DeleteNoteBT.Visible = false;

                        if (!string.IsNullOrEmpty(NoteTitleTB.Text) && !string.IsNullOrWhiteSpace(NoteTitleTB.Text))
                        {
                            if (NoteTitleTB.Text != Current_Note.Name)
                            {
                                if (!Duplicate_Note(NoteTitleTB.Text))
                                {
                                    Note_Changes.Remove(Current_Note.Name);
                                    Note_Changes.Add(NoteTitleTB.Text, NoteBodyTB.Text);
                                    Current_Note.Name = NoteTitleTB.Text;
                                    Current_Note.Text = NoteTitleTB.Text;
                                }

                                else
                                {
                                    MessageBox.Show("Duplicate note titles are not allowed.", "Duplicate Note Title", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    Note_Changes[Current_Note.Name] = NoteBodyTB.Text;
                                }
                            }

                            else
                            {
                                Note_Changes[Current_Note.Name] = NoteBodyTB.Text;
                            }
                        }

                        // Cant differentiate easily so just assume a safe general case of the following
                        // Set the previous to current and the current to null
                        if (Previous_Note != null)
                        {
                            Previous_Note.Font = RegularFont;
                        }

                        if (Current_Note != null)
                        {
                            Current_Note.Font = RegularFont;
                        }

                        Previous_Note = Current_Note;
                        Current_Note  = null;

                        NoteTitleTB.Clear();
                        NoteTitleTB.Enabled = false;
                        NoteBodyTB.Clear();
                        NoteBodyTB.Enabled = false;
                    }

                    // Going from deselected to selected
                    // Happens when selecting another item after the last item is deselected or going from nothing to selecting an item.
                    else if (Current_Count == 1 && Previous_Count == 0)
                    {
                        DeleteNoteBT.Visible = true;

                        // Cant differentiate easily so just assume a safe general case of the following
                        // Set the previous to null and the current to the selected item

                        if (Previous_Note != null)
                        {
                            Previous_Note.Font = RegularFont;
                        }

                        Previous_Note = null;

                        Current_Note      = NotesLV.SelectedItems[0];
                        Current_Note.Font = BoldFont;

                        NoteTitleTB.Text    = Current_Note.Name;
                        NoteTitleTB.Enabled = true;

                        try
                        {
                            NoteBodyTB.Text = Note_Changes[Current_Note.Name];
                        }
                        catch
                        {
                        }

                        NoteBodyTB.Enabled = true;
                    }

                    _lock = false;
                }
            }
        }