// Check if album name entered is correct private Boolean albumNameCheck(DialogAlbumName dialog) { // Display dialog while a correct name is entered or user quit do { if (dialog.ShowDialog(this) == DialogResult.OK) { // Album name cannot be emtpy and 2 albums can't have the same name if (dialog.getTextBox().Text.Equals("")) { MessageBox.Show("Please enter a name !"); } else if (this.photoViewer.getAlbum(dialog.getTextBox().Text) != null) { MessageBox.Show("An another album have already this name !"); } else { return(true); } } else { return(false); } } while (this.photoViewer.getAlbum(dialog.getTextBox().Text) != null || dialog.getTextBox().Text.Equals("")); return(false); }
// Context menu strip click events (Rename/Delete album) private void lstBxAlbumsContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { this.listboxContextMenu.Hide(); if (e.ClickedItem.ToString().Equals("Rename")) // Display dialog albm name to rename { DialogAlbumName dialog = new DialogAlbumName(); dialog.getTextBox().Text = this.lstBxAlbums.SelectedItem.ToString(); if (albumNameCheck(dialog)) { // Move directory name / change xml content / refresh listbox Directory.Move("albums\\" + this.lstBxAlbums.SelectedItem.ToString(), "albums\\" + dialog.getTextBox().Text); this.photoViewer.getAlbum(this.lstBxAlbums.SelectedItem.ToString()).Name = dialog.getTextBox().Text; this.photoViewer.save(); int index = this.lstBxAlbums.SelectedIndex; lstBxAlbums.Items.RemoveAt(index); lstBxAlbums.Items.Insert(index, dialog.getTextBox().Text); this.lstBxAlbums.SelectedIndex = index; } dialog.Dispose(); } else if (e.ClickedItem.ToString().Equals("Delete")) { this.rmAlbum(); } }
// Click event on button to add album. Display dialog to ask for album name private void buttonAddAlbum_Click(object sender, EventArgs e) { DialogAlbumName dialog = new DialogAlbumName(); if (albumNameCheck(dialog)) { this.lstBxAlbums.Items.Add(dialog.getTextBox().Text); Directory.CreateDirectory("albums\\" + dialog.getTextBox().Text); // Create folder for the album this.photoViewer.addAlbum(dialog.getTextBox().Text, DateTime.Now); this.photoViewer.save(); } dialog.Dispose(); this.lstBxAlbums.Focus(); // Return focus to list box album }