/// <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> /// Handles the <see cref="ButtonBase.Click"/> event for the "Add Faction" <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>OnFactionAdd</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog, followed by /// a <see cref="Dialog.ChangeFaction"/> dialog, allowing the user to define a new faction. /// The new faction copies the properties of the first selected item in the "Faction" list /// view, if any; otherwise, it is created with default properties. /// </para><para> /// If the user confirmed both dialogs, <b>OnFactionAdd</b> adds the new faction to the /// "Faction" list view and to the current <see cref="FactionSection"/>, and sets the <see /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void OnFactionAdd(object sender, RoutedEventArgs args) { args.Handled = true; // ask user for new faction ID var factions = MasterSection.Instance.Factions.Collection; var dialog = new Dialog.ChangeIdentifier("faction-id", Global.Strings.TitleFactionIdEnter, factions.ContainsKey, false); dialog.Owner = MainWindow.Instance; if (dialog.ShowDialog() != true) { return; } // retrieve new faction ID string id = String.Intern(dialog.Identifier); // create new faction based on selected faction, if any FactionClass faction, selection = FactionList.SelectedItem as FactionClass; if (selection == null) { faction = new FactionClass(id); // add default defeat condition (site loss) faction.DefeatConditions.Add(new Condition()); } else { faction = (FactionClass)selection.Clone(); faction.Id = id; } // let user make changes to new faction var factionDialog = new Dialog.ChangeFaction(faction) { Owner = MainWindow.Instance }; if (factionDialog.ShowDialog() != true) { return; } // add faction to section table factions.Add(id, faction); // update list view and select new item FactionList.Items.Refresh(); FactionList.SelectAndShow(faction); // broadcast data changes EnableListButtons(); SectionTab.DataChanged = true; }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Add Variable" <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>OnVariableAdd</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog, followed /// by a <see cref="Dialog.ChangeVariable"/> dialog, allowing the user to define a new /// variable. The new variable copies the properties of the first selected item in the /// "Variable" list view, if any; otherwise, it is created with default properties. /// </para><para> /// If the user confirmed both dialogs, <b>OnVariableAdd</b> adds the new variable to the /// "Variable" list view and to the <see cref="CurrentVariables"/> collection, and sets the /// <see cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void OnVariableAdd(object sender, RoutedEventArgs args) { args.Handled = true; // ask user for new variable ID var variables = CurrentVariables; var dialog = new Dialog.ChangeIdentifier(CurrentDefaultId, Global.Strings.TitleVariableIdEnter, variables.ContainsKey, false); dialog.Owner = MainWindow.Instance; if (dialog.ShowDialog() != true) { return; } // retrieve new variable ID string id = String.Intern(dialog.Identifier); // create new variable based on selected variable, if any VariableClass variable, selection = VariableList.SelectedItem as VariableClass; if (selection == null) { variable = VariableClass.Create(id, CurrentCategory); } else { variable = (VariableClass)selection.Clone(); variable.Id = id; } // let user make changes to new variable var variableDialog = new Dialog.ChangeVariable(variable) { Owner = MainWindow.Instance }; if (variableDialog.ShowDialog() != true) { return; } // add variable to section table variables.Add(id, variable); // update list view and select new item VariableList.Items.Refresh(); VariableList.SelectAndShow(variable); // broadcast data changes EnableListButtons(); SectionTab.DataChanged = true; }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Add File" <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>OnFileAdd</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog, followed by an /// <see cref="FileDialogs.OpenImageDialog"/>, allowing the user to define a new image file. /// </para><para> /// If the user confirmed both dialogs, <b>OnFileAdd</b> adds the new image file to the /// "Image File" list view and to the current <see cref="ImageSection"/>, redisplays all /// images, and sets the <see cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void OnFileAdd(object sender, RoutedEventArgs args) { args.Handled = true; // ask user for new image file ID var files = MasterSection.Instance.Images.ImageFiles; var dialog = new Dialog.ChangeIdentifier("file-id", Global.Strings.TitleImageFileIdEnter, files.ContainsKey, false); dialog.Owner = MainWindow.Instance; if (dialog.ShowDialog() != true) { return; } // retrieve new image file ID string id = String.Intern(dialog.Identifier); // ask user to select an existing image file RootedPath path = FileDialogs.OpenImageDialog(null); // return immediately if user cancelled if (path.IsEmpty) { return; } // construct new image file ImageFile file = new ImageFile(id, path.AbsolutePath); // try to load image file from disk if (!LoadImageFile(file, MasterSection.Instance.Images.MaskColor)) { return; } // add image file to section table files.Add(id, file); // update list view and select new item FileList.Items.Refresh(); FileList.SelectAndShow(file); // broadcast data changes ImageList.Redraw(); EnableListButtons(); SectionTab.DataChanged = true; }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Change ID" <see /// cref="Button"/> that is associated with the <see cref="ImageListBox"/>.</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>OnImageId</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog for the /// selected item in the <see cref="ImageListBox"/>. /// </para><para> /// If the user made any changes, <b>OnImageId</b> propagates them to the current <see /// cref="ImageSection"/>, redisplays all images, and sets the <see /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void OnImageId(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected image, if any int index = ImageList.SelectedIndex; if (index < 0) { return; } var item = (ImageListBoxItem)ImageList.SelectedItem; var image = (EntityImage)item.Content; // let user enter new image ID var images = MasterSection.Instance.Images.Collection; var dialog = new Dialog.ChangeIdentifier(image.Id, Global.Strings.TitleImageIdChange, images.ContainsKey, true); dialog.Owner = MainWindow.Instance; if (dialog.ShowDialog() != true) { return; } // retrieve new image ID string id = String.Intern(dialog.Identifier); // change existing ID references if (!SectionTabItem.ProcessAllIdentifiers(images, image.Id, id)) { return; } // change item in Image list ImageList.Items.RemoveAt(index); item = new ImageListBoxItem(image); index = ImageList.Insert(item); ImageList.Items.Refresh(); ImageList.SelectAndShow(index); // broadcast data changes SectionTab.DataChanged = true; }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Change ID" <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>OnEntityId</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog for the first /// selected item in the "Entity" list view. /// </para><para> /// If the user made any changes, <b>OnEntityId</b> propagates them to the <see /// cref="CurrentEntities"/> collection and sets the <see /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void OnEntityId(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected entity, if any EntityClass entity = EntityList.SelectedItem as EntityClass; if (entity == null) { return; } // let user enter new entity ID var entities = CurrentEntities; var dialog = new Dialog.ChangeIdentifier(entity.Id, Global.Strings.TitleEntityIdChange, entities.ContainsKey, true); dialog.Owner = MainWindow.Instance; if (dialog.ShowDialog() != true) { return; } // retrieve new faction ID string id = String.Intern(dialog.Identifier); // change existing ID references if (!SectionTabItem.ProcessAllIdentifiers(entities, entity.Id, id)) { return; } // broadcast data changes EntityList.Items.Refresh(); SectionTab.DataChanged = true; }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Change ID" <see /// cref="Button"/> that is associated with the "Image File" list view.</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>OnFileId</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog for the first /// selected item in the "Image File" list view. /// </para><para> /// If the user made any changes, <b>OnFileId</b> propagates them to the current <see /// cref="ImageSection"/>, redisplays all images, and sets the <see /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void OnFileId(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected image file, if any ImageFile file = FileList.SelectedItem as ImageFile; if (file == null) { return; } // let user enter new image file ID var files = MasterSection.Instance.Images.ImageFiles; var dialog = new Dialog.ChangeIdentifier(file.Id, Global.Strings.TitleImageIdChange, files.ContainsKey, true); dialog.Owner = MainWindow.Instance; if (dialog.ShowDialog() != true) { return; } // retrieve new image file ID string id = String.Intern(dialog.Identifier); // change existing ID references if (!SectionTabItem.ProcessAllIdentifiers(files, file.Id, id)) { return; } // broadcast data changes FileList.Items.Refresh(); SectionTab.DataChanged = true; }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Change ID" <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>OnFactionId</b> displays a <see cref="Dialog.ChangeIdentifier"/> dialog for the first /// selected item in the "Faction" list view. /// </para><para> /// If the user made any changes, <b>OnFactionId</b> propagates them to the current <see /// cref="FactionSection"/> and sets the <see cref="SectionTabItem.DataChanged"/> flag. /// </para></remarks> private void OnFactionId(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected faction, if any FactionClass faction = FactionList.SelectedItem as FactionClass; if (faction == null) { return; } // let user enter new faction ID var factions = MasterSection.Instance.Factions.Collection; var dialog = new Dialog.ChangeIdentifier(faction.Id, Global.Strings.TitleFactionIdChange, factions.ContainsKey, true); dialog.Owner = MainWindow.Instance; if (dialog.ShowDialog() != true) { return; } // retrieve new faction ID string id = String.Intern(dialog.Identifier); // change existing ID references if (!SectionTabItem.ProcessAllIdentifiers(factions, faction.Id, id)) { return; } // broadcast data changes FactionList.Items.Refresh(); SectionTab.DataChanged = true; }
/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Add Entity" <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>OnEntityAdd</b> shows an error message if the <see cref="ImageSection"/> does not /// currently define any images. Otherwise, <b>OnEntityAdd</b> displays a <see /// cref="Dialog.ChangeIdentifier"/> dialog, followed by a <see cref="Dialog.ChangeEntity"/> /// dialog, allowing the user to define a new entity. The new entity copies the properties /// of the first selected item in the "Entity" list view, if any; otherwise, it is created /// with default properties. /// </para><para> /// If the user confirmed both dialogs, <b>OnEntityAdd</b> adds the new entity to the /// "Entity" list view and to the <see cref="CurrentEntities"/> collection, and sets the /// <see cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void OnEntityAdd(object sender, RoutedEventArgs args) { args.Handled = true; // abort if there are no images if (MasterSection.Instance.Images.Collection.Count == 0) { MessageBox.Show(MainWindow.Instance, Global.Strings.DialogImageNone, Global.Strings.TitleImageNone, MessageBoxButton.OK, MessageBoxImage.Information); return; } // ask user for new entity ID var entities = CurrentEntities; var dialog = new Dialog.ChangeIdentifier(CurrentDefaultId, Global.Strings.TitleEntityIdEnter, entities.ContainsKey, false); dialog.Owner = MainWindow.Instance; if (dialog.ShowDialog() != true) { return; } // retrieve new entity ID string id = String.Intern(dialog.Identifier); // create new entity based on selected entity, if any EntityClass entity, selection = EntityList.SelectedItem as EntityClass; if (selection == null) { entity = EntityClass.Create(id, CurrentCategory); } else { entity = (EntityClass)selection.Clone(); entity.Id = id; } // let user make changes to new entity var entityDialog = new Dialog.ChangeEntity(entity) { Owner = MainWindow.Instance }; if (entityDialog.ShowDialog() != true) { return; } // add entity to section table entities.Add(id, entity); // update list view and select new item EntityList.Items.Refresh(); EntityList.SelectAndShow(entity); // broadcast data changes EnableListButtons(); SectionTab.DataChanged = true; }