Esempio n. 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">
        /// An <see cref="EventArgs"/> or <see cref="RoutedEventArgs"/> object containing event
        /// data.</param>
        /// <remarks><para>
        /// <b>OnPathBrowse</b> automatically calls <see cref="Load"/> if the user specifies an
        /// existing file, and <see cref="Save"/> if the user specifies a non-existent file.
        /// </para><para>
        /// <b>OnPathBrowse</b> does nothing if the user cancels the dialog, or enters an empty path
        /// or the current <see cref="Path"/>.</para></remarks>

        private void OnPathBrowse(object sender, EventArgs args)
        {
            RoutedEventArgs routedArgs = args as RoutedEventArgs;

            if (routedArgs != null)
            {
                routedArgs.Handled = true;
            }

            // ask user to enter an existing or new file
            RootedPath path = FileDialogs.OpenSectionDialog(Section, Path, true);

            // quit if user cancelled or entered old path
            if (path == null || path.IsEmpty || path.Equals(this._path))
            {
                return;
            }

            // save to or load from new path
            if (!File.Exists(path.AbsolutePath))
            {
                Save(path.AbsolutePath);
            }
            else
            {
                // ask for confirmation to load file
                if (MainWindow.Instance.ClearData(Section))
                {
                    Load(path.AbsolutePath);
                }
            }
        }
Esempio n. 2
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
        }
Esempio n. 3
0
        public void Equals()
        {
            Assert.IsTrue(RootedPath.Equals(null, null));

            RootedPath path = new RootedPath(@"C:\Windows", "win.ini");

            Assert.AreEqual(new RootedPath(@"C:\Windows"), new RootedPath(@"C:\Windows"));
            Assert.AreEqual(path, new RootedPath(@"C:\Windows", "win.ini"));

            Assert.AreNotEqual(path, null);
            Assert.AreNotEqual(path, new RootedPath(@"C:\Temp", "win.ini"));
            Assert.AreNotEqual(path, new RootedPath(@"C:\Windows", "system.ini"));
            Assert.AreNotEqual(path, new RootedPath(@"C:\", @"Windows\win.ini"));
        }