示例#1
0
        /// <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
        }
示例#2
0
        /// <summary>
        /// Shows an <see cref="SaveFileDialog"/> allowing the user to enter or select a file to
        /// save.</summary>
        /// <param name="title">
        /// The title bar text for the <see cref="SaveFileDialog"/>.</param>
        /// <param name="filter">
        /// The file type filter for displayed files.</param>
        /// <param name="index">
        /// The index of the initially selected file type filter.</param>
        /// <param name="extension">
        /// The default extension for files entered by the user.</param>
        /// <param name="path">
        /// A <see cref="RootedPath"/> wrapping the absolute file path initially selected in the
        /// dialog.</param>
        /// <param name="directory">
        /// The directory initially shown in the dialog if <paramref name="path"/> is empty.</param>
        /// <returns>
        /// A <see cref="RootedPath"/> wrapping the absolute file path selected by the user, or an
        /// empty path if the user cancelled the dialog.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="path"/> is a null reference.</exception>
        /// <remarks>
        /// The specified <paramref name="path"/> may be empty to indicate that no file should be
        /// initially selected. In this case, the dialog initially shows the specified <paramref
        /// name="directory"/>, which is otherwise ignored.</remarks>

        private static RootedPath SaveDialog(string title, string filter,
                                             int index, string extension, RootedPath path, string directory)
        {
            if (path == null)
            {
                ThrowHelper.ThrowArgumentNullException("path");
            }

            SaveFileDialog dialog = new SaveFileDialog();

            dialog.DefaultExt       = extension;
            dialog.Filter           = filter;
            dialog.FilterIndex      = index;
            dialog.InitialDirectory = directory ?? "";
            dialog.RestoreDirectory = true;
            dialog.Title            = title;
            dialog.ValidateNames    = true;

            // pre-select specified file path, if any
            if (!path.IsEmpty)
            {
                dialog.InitialDirectory = path.DirectoryName;
                dialog.FileName         = path.FileName;
            }

            // allow creation of new files
            dialog.CheckFileExists = false;
            dialog.CheckPathExists = false;

            // return empty path if user cancels
            var owner = System.Windows.Application.Current.MainWindow;

            if (dialog.ShowDialog(owner) != true)
            {
                return(path.Clear());
            }

            // return selected file path
            return(path.Change(dialog.FileName));
        }