/// <summary> /// Handles the <see cref="ButtonBase.Click"/> event for the "Browse…" <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> /// <b>OnPathBrowse</b> shows an <see cref="FileDialogs.OpenImageDialog"/> allowing the user /// to select a new <see cref="OverlayImage.Path"/>, and sets the <see cref="DataChanged"/> /// flag if the user selects a valid new file path.</remarks> private void OnPathBrowse(object sender, RoutedEventArgs args) { args.Handled = true; // ask user to enter an existing image RootedPath path = FileDialogs.OpenImageDialog(this._overlay.Path); // quit if user cancelled, or entered old or invalid path if (path == null || path.IsEmpty || path.Equals(this._overlay.Path) || !File.Exists(path.AbsolutePath)) { return; } // disable dialog while image loads IsEnabled = false; Dispatcher.DoEvents(); // try loading overlay image this._overlay.Path = path.AbsolutePath; if (!AreasTabContent.MapView.ShowOverlay(this, this._editing)) { path.Clear(); } // broadcast data changes ShowImagePath(); ShowImageSize(); DataChanged = true; IsEnabled = true; // reenable dialog }
/// <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 Path" <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>OnFileChange</b> displays an <see cref="FileDialogs.OpenImageDialog"/> for the first /// selected item in the "Image File" list view. /// </para><para> /// If the user made any changes, <b>OnFileChange</b> propagates them to the current <see /// cref="ImageSection"/>, redisplays all class images, and sets the <see /// cref="SectionTabItem.DataChanged"/> flag.</para></remarks> private void OnFileChange(object sender, RoutedEventArgs args) { args.Handled = true; // retrieve selected image, if any ImageFile file = FileList.SelectedItem as ImageFile; if (file == null) { return; } // ask user to select an existing image file RootedPath path = FileDialogs.OpenImageDialog(file.Path); // return immediately if user cancelled if (path.IsEmpty) { return; } // construct new image file object ImageFile newFile = new ImageFile(file.Id, path.AbsolutePath); // try to load image file from disk var imageSection = MasterSection.Instance.Images; if (!LoadImageFile(newFile, imageSection.MaskColor)) { return; } // replace image file in scenario file.Unload(); Debug.Assert(file.Id == newFile.Id); imageSection.ImageFiles[newFile.Id] = newFile; // broadcast data changes FileList.Items.Refresh(); ImageList.Redraw(); SectionTab.DataChanged = true; }