PageRenderTime 121ms CodeModel.GetById 65ms app.highlight 51ms RepoModel.GetById 1ms app.codeStats 1ms

/WPF Dialogs/Dialogs/DeleteDialog.xaml.cs

#
C# | 126 lines | 90 code | 10 blank | 26 comment | 3 complexity | ba6a30ae7bf6fdfa821669ef1a55e93f MD5 | raw file
  1using System;
  2using System.Collections.Generic;
  3using System.IO;
  4using System.Linq;
  5using System.Text;
  6using System.Windows;
  7using System.Windows.Controls;
  8using System.Windows.Data;
  9using System.Windows.Documents;
 10using System.Windows.Input;
 11using System.Windows.Media;
 12using System.Windows.Media.Imaging;
 13using System.Windows.Shapes;
 14
 15using WPF_Dialogs.Custom_Controls;
 16
 17namespace WPF_Dialogs.Dialogs
 18{
 19    /// <summary>
 20    /// Interaction logic for Delete.xaml
 21    /// </summary>
 22    public partial class DeleteDialog : Window, IDialog
 23    {
 24        /// <summary>
 25        /// Gets or sets the dialog result value, which is the value that is returned from the <see cref="M:System.Windows.Window.ShowDialog"/> method.
 26        /// </summary>
 27        /// <value></value>
 28        /// <returns>A <see cref="T:System.Nullable`1"/> value of type <see cref="T:System.Boolean"/>. The default is false.</returns>
 29        /// <exception cref="T:System.InvalidOperationException">
 30        /// 	<see cref="P:System.Windows.Window.DialogResult"/> is set before a window is opened by calling <see cref="M:System.Windows.Window.ShowDialog"/>, or a window opened by calling <see cref="M:System.Windows.Window.Show"/>.</exception>
 31        public new EDialogResult DialogResult { set; get; }
 32        /// <summary>
 33        /// Gets or sets a value indicating whether the new object should be a folder or a file. DEFAULT: True
 34        /// </summary>
 35        /// <value><c>true</c> if the new object should be a folder; otherwise, <c>false</c>.</value>
 36        public bool IsFolder { get; set; }
 37        private string name;
 38
 39        public DeleteDialog(string name)
 40        {
 41            InitializeComponent();
 42            this.buttonCancel.Focus();
 43            this.IsFolder = true;
 44            this.name = name;
 45        }
 46
 47        #region public functions
 48        public EDialogResult showDialog()
 49        {
 50            this.ShowDialog();
 51            return this.DialogResult;
 52        }
 53        #endregion
 54
 55        #region public Properties
 56        /// <summary>
 57        /// Sets the content of the label text.
 58        /// </summary>
 59        /// <value>The content of the label text.</value>
 60        public object LabelTextContent
 61        {
 62            set
 63            {
 64                this.labelText.Content = value;
 65            }
 66        }
 67
 68        /// <summary>
 69        /// Sets the content of the button OK.
 70        /// </summary>
 71        /// <value>The content of the button OK.</value>
 72        public object ButtonOKContent
 73        {
 74            set
 75            {
 76                this.buttonOK.Content = value;
 77            }
 78        }
 79
 80        /// <summary>
 81        /// Sets the content of the button cancel.
 82        /// </summary>
 83        /// <value>The content of the button cancel.</value>
 84        public object ButtonCancelContent
 85        {
 86            set
 87            {
 88                this.buttonCancel.Content = value;
 89            }
 90        }
 91        #endregion
 92
 93        #region private functions
 94        private void DialogButton_clicked(object sender, RoutedEventArgs e)
 95        {
 96            DialogButton db = e.OriginalSource as DialogButton;
 97            this.DialogResult = db.DialogResult;
 98            if (this.DialogResult == EDialogResult.OK)
 99                delete();
100            this.Close();
101        }
102
103        private new bool? ShowDialog()
104        {
105            return base.ShowDialog();
106        }
107
108        private void delete()
109        {
110            try
111            {
112                if (IsFolder)
113                    Directory.Delete(name);
114                else
115                {
116                    File.Delete(name);
117                }
118            }
119            catch (IOException ex)
120            {
121                throw ex;
122            }
123        }
124        #endregion
125    }
126}