PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/WPF Dialogs/Dialogs/DeleteDialog.xaml.cs

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