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