/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Add Image" <see /// cref="Button"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="RoutedEventArgs"/> object containing event data.</param> /// <remarks><para> /// <b>OnImageAdd</b> shows an error message if the "Image File" list view is empty. /// Otherwise, <b>OnImageAdd</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog, /// followed by a <see cref="Dialog.ChangeImage"/> dialog, allowing the user to define a new /// image. The new image copies the properties of the selected image, if any; otherwise, it /// is created with default properties. /// </para><para> /// If the user confirmed both dialogs, <b>OnImageAdd</b> adds the new image to the <see /// cref="ImageListBox"/> and to the current <see cref="ImageSection"/>, and sets the <see /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void OnImageAdd(object sender, RoutedEventArgs args) { args.Handled = true; // abort if there are no image files if (FileList.Items.Count == 0) { MessageBox.Show(MainWindow.Instance, Global.Strings.DialogImageFileNone, Global.Strings.TitleImageFileNone, MessageBoxButton.OK, MessageBoxImage.Information); return; } // ask user for new image ID var images = MasterSection.Instance.Images.Collection; var dialog = new Dialog.ChangeIdentifier("image-id", Global.Strings.TitleImageIdEnter, images.ContainsKey, false); dialog.Owner = MainWindow.Instance; if (dialog.ShowDialog() != true) { return; } // retrieve new image ID string id = String.Intern(dialog.Identifier); // create new image based on selected image, if any var selection = ImageList.SelectedItem as ImageListBoxItem; EntityImage image = (selection == null ? new EntityImage() : (EntityImage)((EntityImage)selection.Content).Clone()); image.Id = id; // let user make changes to new image var imageDialog = new Dialog.ChangeImage(image) { Owner = MainWindow.Instance }; if (imageDialog.ShowDialog() != true) { return; } // add image to section table images.Add(id, image); // update list box and select new item var item = new ImageListBoxItem(image); int index = ImageList.Insert(item); ImageList.SelectAndShow(index); // broadcast data changes EnableListButtons(); SectionTab.DataChanged = true; }
/// <summary> /// Allows the user to change the <see cref="EntityImage"/> associated with the item at the /// specified index in the <see cref="ImageListBox"/>.</summary> /// <param name="index"> /// The index of the <see cref="ImageListBoxItem"/> whose image to change.</param> /// <remarks><para> /// <b>ChangeImage</b> shows an error message if the "Image File" list view is empty. /// Otherwise, <b>ChangeImage</b> displays a <see cref="Dialog.ChangeImage"/> dialog for the /// <see cref="ImageListBoxItem"/> with the specified <paramref name="index"/>. /// </para><para> /// If the user made any changes, <b>ChangeImage</b> propagates them to the current <see /// cref="ImageSection"/>, redisplays all images, and sets the <see /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void ChangeImage(int index) { if (index < 0) { return; } var item = (ImageListBoxItem)ImageList.Items[index]; var image = (EntityImage)item.Content; // abort if there are no image files if (FileList.Items.Count == 0) { MessageBox.Show(MainWindow.Instance, Global.Strings.DialogImageFileNone, Global.Strings.TitleImageFileNone, MessageBoxButton.OK, MessageBoxImage.Information); return; } // show dialog and let user make changes var dialog = new Dialog.ChangeImage(image) { Owner = MainWindow.Instance }; dialog.ShowDialog(); // broadcast data changes, if any if (dialog.DataChanged) { item = new ImageListBoxItem(image); ImageList.Items[index] = item; ImageList.Items.Refresh(); ImageList.SelectAndShow(index); SectionTab.DataChanged = true; } }