FolderNameEditor.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. //
  2. // System.Windows.Forms.Design.FolderNameEditor.cs
  3. //
  4. // Author:
  5. // Gert Driesen ([email protected])
  6. // (C) 2004 Ximian, Inc. http://www.ximian.com
  7. //
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.ComponentModel;
  30. using System.Drawing.Design;
  31. namespace System.Windows.Forms.Design
  32. {
  33. [MonoTODO]
  34. public class FolderNameEditor : UITypeEditor
  35. {
  36. #region Public Instance Constructors
  37. public FolderNameEditor ()
  38. {
  39. }
  40. #endregion Public Instance Constructors
  41. #region Override implementation of UITypeEditor
  42. public override object EditValue (ITypeDescriptorContext context, IServiceProvider provider, object value)
  43. {
  44. if (folderBrowser == null)
  45. {
  46. folderBrowser = new FolderBrowser ();
  47. InitializeDialog (folderBrowser);
  48. }
  49. if (this.folderBrowser.ShowDialog () != DialogResult.OK)
  50. {
  51. return value;
  52. }
  53. return folderBrowser.DirectoryPath;
  54. }
  55. public override UITypeEditorEditStyle GetEditStyle (ITypeDescriptorContext context)
  56. {
  57. return UITypeEditorEditStyle.Modal;
  58. }
  59. #endregion Override implementation of UITypeEditor
  60. #region Protected Instance Methods
  61. protected virtual void InitializeDialog (FolderBrowser folderBrowser)
  62. {
  63. }
  64. #endregion Protected Instance Methods
  65. #region Private Instance Fields
  66. private FolderBrowser folderBrowser;
  67. #endregion Private Instance Fields
  68. protected enum FolderBrowserFolder
  69. {
  70. Desktop = 0,
  71. Favorites = 6,
  72. MyComputer = 17,
  73. MyDocuments = 5,
  74. MyPictures = 39,
  75. NetAndDialUpConnections = 49,
  76. NetworkNeighborhood = 18,
  77. Printers = 4,
  78. Recent = 8,
  79. SendTo = 9,
  80. StartMenu = 11,
  81. Templates = 21
  82. }
  83. [Flags]
  84. protected enum FolderBrowserStyles
  85. {
  86. BrowseForComputer = 4096,
  87. BrowseForEverything = 16384,
  88. BrowseForPrinter = 8192,
  89. RestrictToDomain = 2,
  90. RestrictToFilesystem = 1,
  91. RestrictToSubfolders = 8,
  92. ShowTextBox = 16
  93. }
  94. protected sealed class FolderBrowser : Component
  95. {
  96. [MonoTODO]
  97. public FolderBrowser ()
  98. {
  99. startLocation = FolderBrowserFolder.Desktop;
  100. publicOptions = FolderBrowserStyles.RestrictToFilesystem;
  101. descriptionText = string.Empty;
  102. directoryPath = string.Empty;
  103. }
  104. #region Public Instance Properties
  105. public string Description
  106. {
  107. get
  108. {
  109. return descriptionText;
  110. }
  111. set
  112. {
  113. descriptionText = (value == null) ? string.Empty : value;
  114. }
  115. }
  116. public string DirectoryPath
  117. {
  118. get
  119. {
  120. return directoryPath;
  121. }
  122. }
  123. public FolderBrowserFolder StartLocation
  124. {
  125. get
  126. {
  127. return startLocation;
  128. }
  129. set
  130. {
  131. startLocation = value;
  132. }
  133. }
  134. public FolderBrowserStyles Style
  135. {
  136. get
  137. {
  138. return publicOptions;
  139. }
  140. set
  141. {
  142. publicOptions = value;
  143. }
  144. }
  145. #endregion Public Instance Properties
  146. #region Public Instance Methods
  147. [MonoTODO]
  148. public DialogResult ShowDialog ()
  149. {
  150. return ShowDialog (null);
  151. }
  152. [MonoTODO]
  153. public DialogResult ShowDialog (IWin32Window owner)
  154. {
  155. throw new NotImplementedException ();
  156. }
  157. #endregion Public Instance Methods
  158. #region Private Instance Fields
  159. private string descriptionText;
  160. private string directoryPath;
  161. private FolderBrowserStyles publicOptions;
  162. private FolderBrowserFolder startLocation;
  163. #endregion Private Instance Fields
  164. }
  165. }
  166. }