1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2006 Alexander Olk
24 // Alexander Olk alex.olk@googlemail.com
25 // Gert Driesen (drieseng@users.sourceforge.net)
26 // Eric Petit (surfzoid2002@yahoo.fr)
29 // Keyboard shortcuts (DEL, F5, F2)
33 using System.Collections;
34 using System.Collections.Specialized;
35 using System.ComponentModel;
38 using System.Resources;
40 using System.Threading;
43 namespace System.Windows.Forms
46 [DefaultProperty ("FileName")]
47 [DefaultEvent ("FileOk")]
48 public abstract class FileDialog : CommonDialog
50 protected static readonly object EventFileOk = new object ();
51 private static int MaxFileNameItems = 10;
53 internal enum FileDialogType
59 private bool addExtension = true;
60 private bool checkFileExists;
61 private bool checkPathExists = true;
62 private string defaultExt;
63 private bool dereferenceLinks = true;
64 private string[] fileNames;
65 private string filter = "";
66 private int filterIndex = 1;
67 private string initialDirectory;
68 private bool restoreDirectory;
69 private bool showHelp;
71 private bool validateNames = true;
73 private bool auto_upgrade_enable = true;
74 private FileDialogCustomPlacesCollection custom_places;
75 private bool supportMultiDottedExtensions;
76 private bool checkForIllegalChars = true;
79 private Button cancelButton;
80 private ToolBarButton upToolBarButton;
81 private PopupButtonPanel popupButtonPanel;
82 private Button openSaveButton;
83 private Button helpButton;
84 private Label fileTypeLabel;
85 private ToolBarButton menueToolBarButton;
86 private ContextMenu menueToolBarButtonContextMenu;
87 private ToolBar smallButtonToolBar;
88 private DirComboBox dirComboBox;
89 private ComboBox fileNameComboBox;
90 private Label fileNameLabel;
91 private MWFFileView mwfFileView;
92 private MwfFileViewItemComparer file_view_comparer;
93 private Label searchSaveLabel;
94 private ToolBarButton newdirToolBarButton;
95 private ToolBarButton backToolBarButton;
96 private ComboBox fileTypeComboBox;
97 private ImageList imageListTopToolbar;
98 private CheckBox readonlyCheckBox;
100 private bool multiSelect;
102 private string restoreDirectoryString = String.Empty;
104 internal FileDialogType fileDialogType;
106 private bool do_not_call_OnSelectedIndexChangedFileTypeComboBox;
108 private bool showReadOnly;
109 private bool readOnlyChecked;
110 internal bool createPrompt;
111 internal bool overwritePrompt = true;
113 private FileFilter fileFilter;
114 private string[] configFileNames = null;
115 private string lastFolder = String.Empty;
119 private const string filedialog_string = "FileDialog";
120 private const string lastfolder_string = "LastFolder";
121 private const string width_string = "Width";
122 private const string height_string = "Height";
123 private const string filenames_string = "FileNames";
124 private const string x_string = "X";
125 private const string y_string = "Y";
127 private readonly char [] wildcard_chars = new char [] { '*', '?' };
129 private bool disable_form_closed_event;
131 internal FileDialog ()
133 form = new DialogForm (this);
136 Size formConfigSize = Size.Empty;
137 Point formConfigLocation = Point.Empty;
139 object formWidth = MWFConfig.GetValue (filedialog_string, width_string);
141 object formHeight = MWFConfig.GetValue (filedialog_string, height_string);
143 if (formHeight != null && formWidth != null)
144 formConfigSize = new Size ((int)formWidth, (int)formHeight);
146 object formLocationX = MWFConfig.GetValue (filedialog_string, x_string);
147 object formLocationY = MWFConfig.GetValue (filedialog_string, y_string);
149 if (formLocationX != null && formLocationY != null)
150 formConfigLocation = new Point ((int)formLocationX, (int)formLocationY);
152 configFileNames = (string[])MWFConfig.GetValue (filedialog_string, filenames_string);
154 fileTypeComboBox = new ComboBox ();
155 backToolBarButton = new ToolBarButton ();
156 newdirToolBarButton = new ToolBarButton ();
157 searchSaveLabel = new Label ();
158 mwfFileView = new MWFFileView (vfs);
159 fileNameLabel = new Label ();
160 fileNameComboBox = new ComboBox ();
161 dirComboBox = new DirComboBox (vfs);
162 smallButtonToolBar = new ToolBar ();
163 menueToolBarButton = new ToolBarButton ();
164 fileTypeLabel = new Label ();
165 openSaveButton = new Button ();
166 helpButton = new Button ();
167 popupButtonPanel = new PopupButtonPanel ();
168 upToolBarButton = new ToolBarButton ();
169 cancelButton = new Button ();
170 form.CancelButton = cancelButton;
171 imageListTopToolbar = new ImageList ();
172 menueToolBarButtonContextMenu = new ContextMenu ();
173 readonlyCheckBox = new CheckBox ();
175 form.SuspendLayout ();
177 //imageListTopToolbar
178 imageListTopToolbar.ColorDepth = ColorDepth.Depth32Bit;
179 imageListTopToolbar.ImageSize = new Size (16, 16); // 16, 16
180 imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("go-previous.png"));
181 imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("go-top.png"));
182 imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("folder-new.png"));
183 imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("preferences-system-windows.png"));
184 imageListTopToolbar.TransparentColor = Color.Transparent;
187 searchSaveLabel.FlatStyle = FlatStyle.System;
188 searchSaveLabel.Location = new Point (6, 6);
189 searchSaveLabel.Size = new Size (86, 22);
190 searchSaveLabel.TextAlign = ContentAlignment.MiddleRight;
193 dirComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Left) | AnchorStyles.Right)));
194 dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
195 dirComboBox.Location = new Point (99, 6);
196 dirComboBox.Size = new Size (261, 22);
197 dirComboBox.TabIndex = 7;
199 // smallButtonToolBar
200 smallButtonToolBar.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right)));
201 smallButtonToolBar.Appearance = ToolBarAppearance.Flat;
202 smallButtonToolBar.AutoSize = false;
203 smallButtonToolBar.Buttons.AddRange (new ToolBarButton [] {
207 menueToolBarButton});
208 smallButtonToolBar.ButtonSize = new Size (24, 24); // 21, 16
209 smallButtonToolBar.Divider = false;
210 smallButtonToolBar.Dock = DockStyle.None;
211 smallButtonToolBar.DropDownArrows = true;
212 smallButtonToolBar.ImageList = imageListTopToolbar;
213 smallButtonToolBar.Location = new Point (372, 6);
214 smallButtonToolBar.ShowToolTips = true;
215 smallButtonToolBar.Size = new Size (140, 28);
216 smallButtonToolBar.TabIndex = 8;
217 smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
220 popupButtonPanel.Dock = DockStyle.None;
221 popupButtonPanel.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left))));
222 popupButtonPanel.Location = new Point (6, 35);
223 popupButtonPanel.Size = new Size (87, 338);
224 popupButtonPanel.TabIndex = 9;
227 mwfFileView.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
228 mwfFileView.Location = new Point (99, 35);
229 mwfFileView.Size = new Size (450, 283);
230 mwfFileView.MultiSelect = false;
231 mwfFileView.TabIndex = 10;
232 mwfFileView.RegisterSender (dirComboBox);
233 mwfFileView.RegisterSender (popupButtonPanel);
236 fileNameLabel.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
237 fileNameLabel.FlatStyle = FlatStyle.System;
238 fileNameLabel.Location = new Point (101, 326);
239 fileNameLabel.Size = new Size (70, 21);
240 fileNameLabel.Text = "File name:";
241 fileNameLabel.TextAlign = ContentAlignment.MiddleLeft;
244 fileNameComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
245 fileNameComboBox.Location = new Point (195, 326);
246 fileNameComboBox.Size = new Size (246, 22);
247 fileNameComboBox.TabIndex = 1;
248 fileNameComboBox.MaxDropDownItems = MaxFileNameItems;
249 fileNameComboBox.RestoreContextMenu ();
250 UpdateRecentFiles ();
253 fileTypeLabel.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
254 fileTypeLabel.FlatStyle = FlatStyle.System;
255 fileTypeLabel.Location = new Point (101, 355);
256 fileTypeLabel.Size = new Size (90, 21);
257 fileTypeLabel.Text = "Files of type:";
258 fileTypeLabel.TextAlign = ContentAlignment.MiddleLeft;
261 fileTypeComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
262 fileTypeComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
263 fileTypeComboBox.Location = new Point (195, 355);
264 fileTypeComboBox.Size = new Size (246, 22);
265 fileTypeComboBox.TabIndex = 2;
268 backToolBarButton.ImageIndex = 0;
269 backToolBarButton.Enabled = false;
270 backToolBarButton.Style = ToolBarButtonStyle.PushButton;
271 mwfFileView.AddControlToEnableDisableByDirStack (backToolBarButton);
274 upToolBarButton.ImageIndex = 1;
275 upToolBarButton.Style = ToolBarButtonStyle.PushButton;
276 mwfFileView.SetFolderUpToolBarButton (upToolBarButton);
278 // newdirToolBarButton
279 newdirToolBarButton.ImageIndex = 2;
280 newdirToolBarButton.Style = ToolBarButtonStyle.PushButton;
282 // menueToolBarButton
283 menueToolBarButton.ImageIndex = 3;
284 menueToolBarButton.DropDownMenu = menueToolBarButtonContextMenu;
285 menueToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
287 // menueToolBarButtonContextMenu
288 menueToolBarButtonContextMenu.MenuItems.AddRange (mwfFileView.ViewMenuItems);
291 openSaveButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
292 openSaveButton.FlatStyle = FlatStyle.System;
293 openSaveButton.Location = new Point (474, 326);
294 openSaveButton.Size = new Size (75, 23);
295 openSaveButton.TabIndex = 4;
296 openSaveButton.FlatStyle = FlatStyle.System;
299 cancelButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
300 cancelButton.FlatStyle = FlatStyle.System;
301 cancelButton.Location = new Point (474, 353);
302 cancelButton.Size = new Size (75, 23);
303 cancelButton.TabIndex = 5;
304 cancelButton.Text = "Cancel";
305 cancelButton.FlatStyle = FlatStyle.System;
308 helpButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
309 helpButton.FlatStyle = FlatStyle.System;
310 helpButton.Location = new Point (474, 353);
311 helpButton.Size = new Size (75, 23);
312 helpButton.TabIndex = 6;
313 helpButton.Text = "Help";
314 helpButton.FlatStyle = FlatStyle.System;
315 helpButton.Visible = false;
318 readonlyCheckBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
319 readonlyCheckBox.Text = "Open Readonly";
320 readonlyCheckBox.Location = new Point (195, 350);
321 readonlyCheckBox.Size = new Size (245, 21);
322 readonlyCheckBox.TabIndex = 3;
323 readonlyCheckBox.FlatStyle = FlatStyle.System;
324 readonlyCheckBox.Visible = false;
326 form.SizeGripStyle = SizeGripStyle.Show;
327 form.AcceptButton = openSaveButton;
328 form.MaximizeBox = true;
329 form.MinimizeBox = true;
330 form.FormBorderStyle = FormBorderStyle.Sizable;
331 form.ClientSize = new Size (555, 385);
332 form.MinimumSize = form.Size;
334 form.Controls.Add (smallButtonToolBar);
335 form.Controls.Add (cancelButton);
336 form.Controls.Add (openSaveButton);
337 form.Controls.Add (mwfFileView);
338 form.Controls.Add (fileTypeLabel);
339 form.Controls.Add (fileNameLabel);
340 form.Controls.Add (fileTypeComboBox);
341 form.Controls.Add (fileNameComboBox);
342 form.Controls.Add (dirComboBox);
343 form.Controls.Add (searchSaveLabel);
344 form.Controls.Add (popupButtonPanel);
345 form.Controls.Add (helpButton);
346 form.Controls.Add (readonlyCheckBox);
348 form.ResumeLayout (true);
350 if (formConfigSize != Size.Empty) {
351 form.ClientSize = formConfigSize;
354 if (formConfigLocation != Point.Empty) {
355 form.Location = formConfigLocation;
358 openSaveButton.Click += new EventHandler (OnClickOpenSaveButton);
359 cancelButton.Click += new EventHandler (OnClickCancelButton);
360 helpButton.Click += new EventHandler (OnClickHelpButton);
362 smallButtonToolBar.ButtonClick += new ToolBarButtonClickEventHandler (OnClickSmallButtonToolBar);
364 fileTypeComboBox.SelectedIndexChanged += new EventHandler (OnSelectedIndexChangedFileTypeComboBox);
366 mwfFileView.SelectedFileChanged += new EventHandler (OnSelectedFileChangedFileView);
367 mwfFileView.ForceDialogEnd += new EventHandler (OnForceDialogEndFileView);
368 mwfFileView.SelectedFilesChanged += new EventHandler (OnSelectedFilesChangedFileView);
369 mwfFileView.ColumnClick += new ColumnClickEventHandler(OnColumnClickFileView);
371 dirComboBox.DirectoryChanged += new EventHandler (OnDirectoryChangedDirComboBox);
372 popupButtonPanel.DirectoryChanged += new EventHandler (OnDirectoryChangedPopupButtonPanel);
374 readonlyCheckBox.CheckedChanged += new EventHandler (OnCheckCheckChanged);
376 form.FormClosed += new FormClosedEventHandler (OnFileDialogFormClosed);
377 custom_places = new FileDialogCustomPlacesCollection ();
379 form.Closed += new EventHandler (OnFileDialogFormClosed);
384 public bool AddExtension {
390 addExtension = value;
395 [MonoTODO ("Stub, value not respected")]
396 [DefaultValue (true)]
397 public bool AutoUpgradeEnabled {
398 get { return auto_upgrade_enable; }
399 set { auto_upgrade_enable = value; }
403 [DefaultValue(false)]
404 public virtual bool CheckFileExists {
406 return checkFileExists;
410 checkFileExists = value;
415 public bool CheckPathExists {
417 return checkPathExists;
421 checkPathExists = value;
426 [MonoTODO ("Stub, collection not used")]
428 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
429 public FileDialogCustomPlacesCollection CustomPlaces {
430 get { return custom_places; }
435 public string DefaultExt {
437 if (defaultExt == null)
442 if (value != null && value.Length > 0) {
443 // remove leading dot
444 if (value [0] == '.')
445 value = value.Substring (1);
451 // in MS.NET it doesn't make a difference if
452 // DerefenceLinks is true or false
453 // if the selected file is a link FileDialog
454 // always returns the link
456 public bool DereferenceLinks {
458 return dereferenceLinks;
462 dereferenceLinks = value;
467 public string FileName {
469 if (fileNames == null || fileNames.Length == 0)
472 if (fileNames [0].Length == 0)
476 // skip check for illegal characters if the filename was set
477 // through FileDialog API
478 if (!checkForIllegalChars)
479 return fileNames [0];
482 // ensure filename contains only valid characters
483 Path.GetFullPath (fileNames [0]);
484 // but return filename as is
485 return fileNames [0];
491 fileNames = new string [1] { value };
493 fileNames = new string [0];
497 // skip check for illegal characters if the filename was set
498 // through FileDialog API
499 checkForIllegalChars = false;
505 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
506 public string[] FileNames {
508 if (fileNames == null || fileNames.Length == 0) {
509 return new string [0];
512 string[] new_filenames = new string [fileNames.Length];
513 fileNames.CopyTo (new_filenames, 0);
516 // skip check for illegal characters if the filename was set
517 // through FileDialog API
518 if (!checkForIllegalChars)
519 return new_filenames;
522 foreach (string fileName in new_filenames) {
523 // ensure filename contains only valid characters
524 Path.GetFullPath (fileName);
526 return new_filenames;
532 public string Filter {
540 if (fileFilter != null)
541 fileFilter.FilterArrayList.Clear ();
543 if (FileFilter.CheckFilter (value)) {
546 fileFilter = new FileFilter (filter);
548 throw new ArgumentException ("The provided filter string"
549 + " is invalid. The filter string should contain a"
550 + " description of the filter, followed by the "
551 + " vertical bar (|) and the filter pattern. The"
552 + " strings for different filtering options should"
553 + " also be separated by the vertical bar. Example:"
554 + " Text files (*.txt)|*.txt|All files (*.*)|*.*");
562 public int FilterIndex {
572 public string InitialDirectory {
574 if (initialDirectory == null)
576 return initialDirectory;
579 initialDirectory = value;
583 [DefaultValue(false)]
584 public bool RestoreDirectory {
586 return restoreDirectory;
590 restoreDirectory = value;
594 [DefaultValue(false)]
595 public bool ShowHelp {
602 ResizeAndRelocateForHelpOrReadOnly ();
607 [DefaultValue(false)]
608 public bool SupportMultiDottedExtensions {
610 return supportMultiDottedExtensions;
614 supportMultiDottedExtensions = value;
621 public string Title {
632 // this one is a hard one ;)
634 // - up to MAX_PATH characters (windef.h) = 260
635 // - no trailing dots or spaces
638 // NTFS/Posix filename:
639 // - up to 32,768 Unicode characters
640 // - trailing periods or spaces
644 public bool ValidateNames {
646 return validateNames;
650 validateNames = value;
654 public override void Reset ()
657 checkFileExists = false;
658 checkPathExists = true;
660 dereferenceLinks = true;
662 Filter = String.Empty;
664 InitialDirectory = null;
665 restoreDirectory = false;
667 SupportMultiDottedExtensions = false;
671 validateNames = true;
676 public override string ToString ()
678 return String.Format("{0}: Title: {1}, FileName: {2}", base.ToString (), Title, FileName);
681 public event CancelEventHandler FileOk {
682 add { Events.AddHandler (EventFileOk, value); }
683 remove { Events.RemoveHandler (EventFileOk, value); }
686 protected virtual IntPtr Instance {
694 // This is just for internal use with MSs version, so it doesn't need to be implemented
695 // as it can't really be accessed anyways
696 protected int Options {
700 internal virtual string DialogTitle {
706 [MonoTODO ("Not implemented, will throw NotImplementedException")]
707 protected override IntPtr HookProc (IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
709 throw new NotImplementedException ();
712 protected void OnFileOk (CancelEventArgs e)
714 CancelEventHandler fo = (CancelEventHandler) Events [EventFileOk];
719 private void CleanupOnClose ()
721 WriteConfigValues ();
723 Mime.CleanFileCache ();
725 disable_form_closed_event = true;
728 protected override bool RunDialog (IntPtr hWndOwner)
731 form.Text = DialogTitle;
733 // avoid using the FileNames property to skip the invalid characters
735 string fileName = null;
736 if (fileNames != null && fileNames.Length != 0)
737 fileName = fileNames [0];
739 fileName = string.Empty;
745 SetFileAndDirectory (fileName);
746 fileNameComboBox.Select ();
751 internal virtual bool ShowReadOnly {
753 showReadOnly = value;
754 ResizeAndRelocateForHelpOrReadOnly ();
762 internal virtual bool ReadOnlyChecked {
764 readOnlyChecked = value;
765 readonlyCheckBox.Checked = value;
769 return readOnlyChecked;
773 internal bool BMultiSelect {
776 mwfFileView.MultiSelect = value;
784 internal string OpenSaveButtonText {
786 openSaveButton.Text = value;
790 internal string SearchSaveLabel {
792 searchSaveLabel.Text = value;
796 internal string FileTypeLabel {
798 fileTypeLabel.Text = value;
802 internal string CustomFilter {
804 string fname = fileNameComboBox.Text;
805 if (fname.IndexOfAny (wildcard_chars) == -1)
812 private void SelectFilter ()
814 int filter_to_select = (filterIndex - 1);
816 if (mwfFileView.FilterArrayList == null || mwfFileView.FilterArrayList.Count == 0) {
817 filter_to_select = -1;
819 if (filter_to_select < 0 || filter_to_select >= mwfFileView.FilterArrayList.Count)
820 filter_to_select = 0;
823 do_not_call_OnSelectedIndexChangedFileTypeComboBox = true;
824 fileTypeComboBox.BeginUpdate ();
825 fileTypeComboBox.SelectedIndex = filter_to_select;
826 fileTypeComboBox.EndUpdate ();
827 do_not_call_OnSelectedIndexChangedFileTypeComboBox = false;
828 mwfFileView.FilterIndex = filter_to_select + 1;
831 private void SetFileAndDirectory (string fname)
833 if (fname.Length != 0) {
834 bool rooted = Path.IsPathRooted (fname);
836 mwfFileView.ChangeDirectory (null, lastFolder);
837 fileNameComboBox.Text = fname;
839 string dirname = Path.GetDirectoryName (fname);
840 if (dirname != null && dirname.Length > 0 && Directory.Exists (dirname)) {
841 fileNameComboBox.Text = Path.GetFileName (fname);
842 mwfFileView.ChangeDirectory (null, dirname);
844 fileNameComboBox.Text = fname;
845 mwfFileView.ChangeDirectory (null, lastFolder);
849 mwfFileView.ChangeDirectory (null, lastFolder);
850 fileNameComboBox.Text = null;
854 void OnClickOpenSaveButton (object sender, EventArgs e)
857 // for filenames typed or selected by user, enable check for
858 // illegal characters in filename(s)
859 checkForIllegalChars = true;
862 if (fileDialogType == FileDialogType.OpenFileDialog) {
863 ListView.SelectedListViewItemCollection sl = mwfFileView.SelectedItems;
864 if (sl.Count > 0 && sl [0] != null) {
866 FileViewListViewItem item = sl [0] as FileViewListViewItem;
867 FSEntry fsEntry = item.FSEntry;
869 if ((fsEntry.Attributes & FileAttributes.Directory) == FileAttributes.Directory) {
870 mwfFileView.ChangeDirectory (null, fsEntry.FullName, CustomFilter);
874 foreach (FileViewListViewItem item in sl) {
875 FSEntry fsEntry = item.FSEntry;
876 if ((fsEntry.Attributes & FileAttributes.Directory) == FileAttributes.Directory) {
877 mwfFileView.ChangeDirectory (null, fsEntry.FullName, CustomFilter);
885 // Custom filter, typed by the user, ignoring the stored filters
886 if (fileNameComboBox.Text.IndexOfAny (wildcard_chars) != -1) {
887 mwfFileView.UpdateFileView (fileNameComboBox.Text);
891 ArrayList files = new ArrayList ();
892 FileNamesTokenizer tokenizer = new FileNamesTokenizer (
893 fileNameComboBox.Text, multiSelect);
894 tokenizer.GetNextFile ();
895 while (tokenizer.CurrentToken != TokenType.EOF) {
896 string fileName = tokenizer.TokenText;
897 string internalfullfilename;
899 if (!Path.IsPathRooted (fileName)) {
900 // on unix currentRealFolder for "Recently used files" is null,
901 // because recently used files don't get saved as links in a directory
902 // recently used files get saved in a xml file
903 if (mwfFileView.CurrentRealFolder != null)
904 fileName = Path.Combine (mwfFileView.CurrentRealFolder, fileName);
906 if (mwfFileView.CurrentFSEntry != null) {
907 fileName = mwfFileView.CurrentFSEntry.FullName;
911 FileInfo fileInfo = new FileInfo (fileName);
913 if (fileInfo.Exists || fileDialogType == FileDialogType.SaveFileDialog) {
914 internalfullfilename = fileName;
916 DirectoryInfo dirInfo = new DirectoryInfo (fileName);
917 if (dirInfo.Exists) {
918 mwfFileView.ChangeDirectory (null, dirInfo.FullName, CustomFilter);
919 fileNameComboBox.Text = null;
922 internalfullfilename = fileName;
927 string current_extension = Path.GetExtension (fileName);
928 if (current_extension.Length == 0) {
929 string filter_extension = string.Empty;
931 if (AddFilterExtension (internalfullfilename))
932 filter_extension = GetExtension (internalfullfilename);
934 if (filter_extension.Length == 0 && DefaultExt.Length > 0) {
935 filter_extension = "." + DefaultExt;
937 if (checkFileExists) {
938 // ignore DefaultExt if file not exist
939 if (!File.Exists (internalfullfilename + filter_extension))
940 filter_extension = string.Empty;
944 internalfullfilename += filter_extension;
948 if (checkFileExists) {
949 if (!File.Exists (internalfullfilename)) {
950 string message = "\"" + internalfullfilename + "\" does not exist. Please verify that you have entered the correct file name.";
951 MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
956 if (fileDialogType == FileDialogType.SaveFileDialog) {
957 if (overwritePrompt) {
958 if (File.Exists (internalfullfilename)) {
959 string message = "\"" + internalfullfilename + "\" already exists. Do you want to overwrite it?";
960 DialogResult dr = MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
961 if (dr == DialogResult.Cancel)
967 if (!File.Exists (internalfullfilename)) {
968 string message = "\"" + internalfullfilename + "\" does not exist. Do you want to create it?";
969 DialogResult dr = MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
970 if (dr == DialogResult.Cancel)
976 files.Add (internalfullfilename);
977 tokenizer.GetNextFile ();
980 if (files.Count > 0) {
981 fileNames = new string [files.Count];
982 for (int i = 0; i < files.Count; i++) {
983 string fileName = (string) files [i];
984 fileNames [i] = fileName;
985 mwfFileView.WriteRecentlyUsed (fileName);
987 if (!File.Exists (fileName))
988 // ignore files that do not exist
991 if (fileNameComboBox.Items.IndexOf (fileName) == -1)
992 fileNameComboBox.Items.Insert (0, fileName);
995 // remove items above the maximum items that we want to display
996 while (fileNameComboBox.Items.Count > MaxFileNameItems)
997 fileNameComboBox.Items.RemoveAt (MaxFileNameItems);
999 // If a directory is selected, navigate into it
1000 foreach (FileViewListViewItem item in mwfFileView.SelectedItems) {
1001 FSEntry fsEntry = item.FSEntry;
1003 if ((fsEntry.Attributes & FileAttributes.Directory) == FileAttributes.Directory) {
1004 mwfFileView.ChangeDirectory (null, fsEntry.FullName, CustomFilter);
1012 if (checkPathExists && mwfFileView.CurrentRealFolder != null) {
1013 if (!Directory.Exists (mwfFileView.CurrentRealFolder)) {
1014 string message = "\"" + mwfFileView.CurrentRealFolder + "\" does not exist. Please verify that you have entered the correct directory name.";
1015 MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
1017 if (InitialDirectory.Length == 0 || !Directory.Exists (InitialDirectory))
1018 mwfFileView.ChangeDirectory (null, lastFolder, CustomFilter);
1020 mwfFileView.ChangeDirectory (null, InitialDirectory, CustomFilter);
1025 if (restoreDirectory) {
1026 lastFolder = restoreDirectoryString;
1028 lastFolder = mwfFileView.CurrentFolder;
1031 // update value of FilterIndex with user-selected filter
1032 filterIndex = fileTypeComboBox.SelectedIndex + 1;
1034 CancelEventArgs cancelEventArgs = new CancelEventArgs ();
1036 OnFileOk (cancelEventArgs);
1038 if (cancelEventArgs.Cancel)
1042 form.DialogResult = DialogResult.OK;
1045 bool AddFilterExtension (string fileName)
1047 if (fileDialogType == FileDialogType.OpenFileDialog) {
1048 if (DefaultExt.Length == 0)
1051 if (checkFileExists) {
1052 // if CheckFileExists is true, only add filter extension if
1053 // file with DefaultExt does not exist
1054 string fullFileName = fileName + "." + DefaultExt;
1055 return !File.Exists (fullFileName);
1057 // if CheckFileExists is false, only add filter extension
1058 // if specified file does not exist
1059 return !File.Exists (fileName);
1066 string GetExtension (string fileName)
1068 string filter_extension = String.Empty;
1070 if (fileFilter == null || fileTypeComboBox.SelectedIndex == -1)
1071 return filter_extension;
1073 FilterStruct filterstruct = (FilterStruct) fileFilter.FilterArrayList
1074 [fileTypeComboBox.SelectedIndex];
1076 for (int i = 0; i < filterstruct.filters.Count; i++) {
1077 string extension = filterstruct.filters [i];
1079 if (extension.StartsWith ("*"))
1080 extension = extension.Remove (0, 1);
1082 if (extension.IndexOf ('*') != -1)
1086 if (!supportMultiDottedExtensions) {
1088 int lastdot = extension.LastIndexOf('.');
1090 if (extension.LastIndexOf('.', lastdot - 1) != -1) {
1091 extension = extension.Remove(0, lastdot);
1098 if (!checkFileExists) {
1099 filter_extension = extension;
1103 if (fileDialogType == FileDialogType.SaveFileDialog) {
1104 // when DefaultExt is set, only consider first filter
1105 // extension (and do not check if file exists)
1106 if (DefaultExt.Length > 0) {
1107 filter_extension = extension;
1112 // MSDN: If the CheckFileExists property is true,
1113 // the dialog box adds the first extension from the
1114 // current file filter that matches an existing file
1115 string fullfilename = fileName + extension;
1116 if (File.Exists (fullfilename)) {
1117 filter_extension = extension;
1120 if (fileDialogType == FileDialogType.SaveFileDialog) {
1121 // when DefaultExt is set, only consider first filter
1123 if (DefaultExt.Length > 0) {
1124 filter_extension = extension;
1131 return filter_extension;
1134 void OnClickCancelButton (object sender, EventArgs e)
1136 if (restoreDirectory)
1137 mwfFileView.CurrentFolder = restoreDirectoryString;
1141 form.DialogResult = DialogResult.Cancel;
1144 void OnClickHelpButton (object sender, EventArgs e)
1149 void OnClickSmallButtonToolBar (object sender, ToolBarButtonClickEventArgs e)
1151 if (e.Button == upToolBarButton) {
1152 mwfFileView.OneDirUp (CustomFilter);
1154 if (e.Button == backToolBarButton) {
1155 mwfFileView.PopDir (CustomFilter);
1157 if (e.Button == newdirToolBarButton) {
1158 mwfFileView.CreateNewFolder ();
1162 void OnSelectedIndexChangedFileTypeComboBox (object sender, EventArgs e)
1164 if (do_not_call_OnSelectedIndexChangedFileTypeComboBox) {
1165 do_not_call_OnSelectedIndexChangedFileTypeComboBox = false;
1169 UpdateRecentFiles ();
1171 mwfFileView.FilterIndex = fileTypeComboBox.SelectedIndex + 1;
1174 void OnSelectedFileChangedFileView (object sender, EventArgs e)
1176 fileNameComboBox.Text = mwfFileView.CurrentFSEntry.Name;
1179 void OnSelectedFilesChangedFileView (object sender, EventArgs e)
1181 string selectedFiles = mwfFileView.SelectedFilesString;
1182 if (selectedFiles != null && selectedFiles.Length != 0)
1183 fileNameComboBox.Text = selectedFiles;
1186 void OnForceDialogEndFileView (object sender, EventArgs e)
1188 OnClickOpenSaveButton (this, EventArgs.Empty);
1191 void OnDirectoryChangedDirComboBox (object sender, EventArgs e)
1193 mwfFileView.ChangeDirectory (sender, dirComboBox.CurrentFolder, CustomFilter);
1196 void OnDirectoryChangedPopupButtonPanel (object sender, EventArgs e)
1198 mwfFileView.ChangeDirectory (sender, popupButtonPanel.CurrentFolder, CustomFilter);
1201 void OnCheckCheckChanged (object sender, EventArgs e)
1203 ReadOnlyChecked = readonlyCheckBox.Checked;
1207 void OnFileDialogFormClosed (object sender, FormClosedEventArgs e)
1209 HandleFormClosedEvent (sender);
1212 void OnFileDialogFormClosed (object sender, EventArgs e)
1214 HandleFormClosedEvent (sender);
1218 private void OnColumnClickFileView (object sender, ColumnClickEventArgs e)
1220 if (file_view_comparer == null)
1221 file_view_comparer = new MwfFileViewItemComparer (true);
1223 file_view_comparer.ColumnIndex = e.Column;
1224 file_view_comparer.Ascendent = !file_view_comparer.Ascendent;
1226 if (mwfFileView.ListViewItemSorter == null)
1227 mwfFileView.ListViewItemSorter = file_view_comparer;
1229 mwfFileView.Sort ();
1232 void HandleFormClosedEvent (object sender)
1234 if (!disable_form_closed_event)
1235 OnClickCancelButton (sender, EventArgs.Empty);
1237 disable_form_closed_event = false;
1240 private void UpdateFilters ()
1242 if (fileFilter == null)
1243 fileFilter = new FileFilter ();
1245 ArrayList filters = fileFilter.FilterArrayList;
1247 fileTypeComboBox.BeginUpdate ();
1249 fileTypeComboBox.Items.Clear ();
1251 foreach (FilterStruct fs in filters) {
1252 fileTypeComboBox.Items.Add (fs.filterName);
1255 fileTypeComboBox.EndUpdate ();
1257 mwfFileView.FilterArrayList = filters;
1260 private void UpdateRecentFiles ()
1262 fileNameComboBox.Items.Clear ();
1263 if (configFileNames != null) {
1264 foreach (string configFileName in configFileNames) {
1265 if (configFileName == null || configFileName.Trim ().Length == 0)
1267 // add no more than 10 items
1268 if (fileNameComboBox.Items.Count >= MaxFileNameItems)
1270 fileNameComboBox.Items.Add (configFileName);
1275 private void ResizeAndRelocateForHelpOrReadOnly ()
1277 form.SuspendLayout ();
1279 int fx = form.Size.Width - form.MinimumSize.Width;
1280 int fy = form.Size.Height - form.MinimumSize.Height;
1282 if (!ShowHelp && !ShowReadOnly)
1285 mwfFileView.Size = new Size (450 + fx, 254 + fy);
1286 fileNameLabel.Location = new Point (101, 298 + fy);
1287 fileNameComboBox.Location = new Point (195, 298 + fy);
1288 fileTypeLabel.Location = new Point (101, 326 + fy);
1289 fileTypeComboBox.Location = new Point (195, 326 + fy);
1290 openSaveButton.Location = new Point (474 + fx, 298 + fy);
1291 cancelButton.Location = new Point (474 + fx, 324 + fy);
1292 helpButton.Location = new Point (474 + fx, 353 + fy);
1293 readonlyCheckBox.Location = new Point (195, 350 + fy);
1295 helpButton.Visible = ShowHelp;
1296 readonlyCheckBox.Visible = ShowReadOnly;
1298 form.ResumeLayout ();
1301 private void WriteConfigValues ()
1303 MWFConfig.SetValue (filedialog_string, width_string, form.ClientSize.Width);
1304 MWFConfig.SetValue (filedialog_string, height_string, form.ClientSize.Height);
1305 MWFConfig.SetValue (filedialog_string, x_string, form.Location.X);
1306 MWFConfig.SetValue (filedialog_string, y_string, form.Location.Y);
1308 MWFConfig.SetValue (filedialog_string, lastfolder_string, lastFolder);
1310 string[] fileNameCBItems = new string [fileNameComboBox.Items.Count];
1312 fileNameComboBox.Items.CopyTo (fileNameCBItems, 0);
1314 MWFConfig.SetValue (filedialog_string, filenames_string, fileNameCBItems);
1317 private void ReadConfigValues ()
1319 lastFolder = (string)MWFConfig.GetValue (filedialog_string, lastfolder_string);
1321 if (lastFolder != null && lastFolder.IndexOf ("://") == -1) {
1322 if (!Directory.Exists (lastFolder)) {
1323 lastFolder = MWFVFS.DesktopPrefix;
1327 if (InitialDirectory.Length > 0 && Directory.Exists (InitialDirectory))
1328 lastFolder = InitialDirectory;
1330 if (lastFolder == null || lastFolder.Length == 0)
1331 lastFolder = Environment.CurrentDirectory;
1333 if (RestoreDirectory)
1334 restoreDirectoryString = lastFolder;
1337 class FileNamesTokenizer
1339 public FileNamesTokenizer (string text, bool allowMultiple)
1343 _tokenType = TokenType.BOF;
1344 _allowMultiple = allowMultiple;
1347 public TokenType CurrentToken {
1348 get { return _tokenType; }
1351 public string TokenText {
1352 get { return _tokenText; }
1355 public bool AllowMultiple {
1356 get { return _allowMultiple; }
1359 private int ReadChar ()
1361 if (_position < _text.Length) {
1362 return _text [_position++];
1368 private int PeekChar ()
1370 if (_position < _text.Length) {
1371 return _text [_position];
1377 private void SkipWhitespaceAndQuotes ()
1381 while ((ch = PeekChar ()) != -1) {
1382 if ((char) ch != '"' && !char.IsWhiteSpace ((char) ch))
1388 public void GetNextFile ()
1390 if (_tokenType == TokenType.EOF)
1391 throw new Exception ("");
1395 SkipWhitespaceAndQuotes ();
1397 if (PeekChar () == -1) {
1398 _tokenType = TokenType.EOF;
1402 _tokenType = TokenType.FileName;
1403 StringBuilder sb = new StringBuilder ();
1405 while ((ch = PeekChar ()) != -1) {
1406 if ((char) ch == '"') {
1410 int pos = _position;
1412 SkipWhitespaceAndQuotes ();
1413 if (PeekChar () == -1) {
1417 sb.Append ((char) ch);
1419 sb.Append ((char) ReadChar ());
1423 _tokenText = sb.ToString ();
1426 private readonly bool _allowMultiple;
1427 private int _position;
1428 private readonly string _text;
1429 private TokenType _tokenType;
1430 private string _tokenText;
1433 internal enum TokenType
1442 #region PopupButtonPanel
1443 internal class PopupButtonPanel : Control, IUpdateFolder
1446 internal class PopupButton : Control
1448 internal enum PopupButtonState
1451 private Image image = null;
1452 private PopupButtonState popupButtonState = PopupButtonState.Normal;
1453 private StringFormat text_format = new StringFormat();
1454 private Rectangle text_rect = Rectangle.Empty;
1456 public PopupButton ()
1458 text_format.Alignment = StringAlignment.Center;
1459 text_format.LineAlignment = StringAlignment.Near;
1461 SetStyle (ControlStyles.DoubleBuffer, true);
1462 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
1463 SetStyle (ControlStyles.UserPaint, true);
1464 SetStyle (ControlStyles.Selectable, false);
1467 public Image Image {
1478 public PopupButtonState ButtonState {
1480 popupButtonState = value;
1485 return popupButtonState;
1489 #region UIA Framework Members
1490 internal void PerformClick ()
1492 OnClick (EventArgs.Empty);
1496 protected override void OnPaint (PaintEventArgs pe)
1503 private void Draw (PaintEventArgs pe)
1505 Graphics gr = pe.Graphics;
1507 gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
1510 if (image != null) {
1511 int i_x = (ClientSize.Width - image.Width) / 2;
1513 gr.DrawImage (image, i_x, i_y);
1516 if (Text != String.Empty) {
1517 if (text_rect == Rectangle.Empty)
1518 text_rect = new Rectangle (0, Height - 30, Width, Height - 30);
1520 gr.DrawString (Text, Font, Brushes.White, text_rect, text_format);
1523 switch (popupButtonState) {
1524 case PopupButtonState.Up:
1525 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, 0, ClientSize.Width - 1, 0);
1526 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, 0, 0, ClientSize.Height - 1);
1527 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1);
1528 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1);
1531 case PopupButtonState.Down:
1532 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, 0, ClientSize.Width - 1, 0);
1533 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, 0, 0, ClientSize.Height - 1);
1534 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1);
1535 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1);
1540 protected override void OnMouseEnter (EventArgs e)
1542 if (popupButtonState != PopupButtonState.Down)
1543 popupButtonState = PopupButtonState.Up;
1545 PopupButtonPanel panel = Parent as PopupButtonPanel;
1547 if (panel.focusButton != null && panel.focusButton.ButtonState == PopupButtonState.Up) {
1548 panel.focusButton.ButtonState = PopupButtonState.Normal;
1549 panel.SetFocusButton (null);
1552 base.OnMouseEnter (e);
1555 protected override void OnMouseLeave (EventArgs e)
1557 if (popupButtonState == PopupButtonState.Up)
1558 popupButtonState = PopupButtonState.Normal;
1560 base.OnMouseLeave (e);
1563 protected override void OnClick (EventArgs e)
1565 popupButtonState = PopupButtonState.Down;
1572 private PopupButton recentlyusedButton;
1573 private PopupButton desktopButton;
1574 private PopupButton personalButton;
1575 private PopupButton mycomputerButton;
1576 private PopupButton networkButton;
1578 private PopupButton lastPopupButton = null;
1579 private PopupButton focusButton = null;
1581 private string currentPath;
1583 private int currentFocusIndex;
1585 public PopupButtonPanel ()
1589 BackColor = Color.FromArgb (128, 128, 128);
1590 Size = new Size (85, 336);
1591 InternalBorderStyle = BorderStyle.Fixed3D;
1593 recentlyusedButton = new PopupButton ();
1594 desktopButton = new PopupButton ();
1595 personalButton = new PopupButton ();
1596 mycomputerButton = new PopupButton ();
1597 networkButton = new PopupButton ();
1599 recentlyusedButton.Size = new Size (81, 64);
1600 recentlyusedButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 32);
1601 recentlyusedButton.BackColor = BackColor;
1602 recentlyusedButton.ForeColor = Color.Black;
1603 recentlyusedButton.Location = new Point (2, 2);
1604 recentlyusedButton.Text = "Recently\nused";
1605 recentlyusedButton.Click += new EventHandler (OnClickButton);
1607 desktopButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 32);
1608 desktopButton.BackColor = BackColor;
1609 desktopButton.ForeColor = Color.Black;
1610 desktopButton.Size = new Size (81, 64);
1611 desktopButton.Location = new Point (2, 66);
1612 desktopButton.Text = "Desktop";
1613 desktopButton.Click += new EventHandler (OnClickButton);
1615 personalButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 32);
1616 personalButton.BackColor = BackColor;
1617 personalButton.ForeColor = Color.Black;
1618 personalButton.Size = new Size (81, 64);
1619 personalButton.Location = new Point (2, 130);
1620 personalButton.Text = "Personal";
1621 personalButton.Click += new EventHandler (OnClickButton);
1623 mycomputerButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 32);
1624 mycomputerButton.BackColor = BackColor;
1625 mycomputerButton.ForeColor = Color.Black;
1626 mycomputerButton.Size = new Size (81, 64);
1627 mycomputerButton.Location = new Point (2, 194);
1628 mycomputerButton.Text = "My Computer";
1629 mycomputerButton.Click += new EventHandler (OnClickButton);
1631 networkButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 32);
1632 networkButton.BackColor = BackColor;
1633 networkButton.ForeColor = Color.Black;
1634 networkButton.Size = new Size (81, 64);
1635 networkButton.Location = new Point (2, 258);
1636 networkButton.Text = "My Network";
1637 networkButton.Click += new EventHandler (OnClickButton);
1639 Controls.Add (recentlyusedButton);
1640 Controls.Add (desktopButton);
1641 Controls.Add (personalButton);
1642 Controls.Add (mycomputerButton);
1643 Controls.Add (networkButton);
1645 ResumeLayout (false);
1647 KeyDown += new KeyEventHandler (Key_Down);
1649 SetStyle (ControlStyles.StandardClick, false);
1652 void OnClickButton (object sender, EventArgs e)
1654 if (lastPopupButton != null && lastPopupButton != sender as PopupButton)
1655 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1656 lastPopupButton = sender as PopupButton;
1658 if (sender == recentlyusedButton) {
1659 currentPath = MWFVFS.RecentlyUsedPrefix;
1661 if (sender == desktopButton) {
1662 currentPath = MWFVFS.DesktopPrefix;
1664 if (sender == personalButton) {
1665 currentPath = MWFVFS.PersonalPrefix;
1667 if (sender == mycomputerButton) {
1668 currentPath = MWFVFS.MyComputerPrefix;
1670 if (sender == networkButton) {
1671 currentPath = MWFVFS.MyNetworkPrefix;
1674 EventHandler eh = (EventHandler)(Events [PDirectoryChangedEvent]);
1676 eh (this, EventArgs.Empty);
1680 static object UIAFocusedItemChangedEvent = new object ();
1682 internal event EventHandler UIAFocusedItemChanged {
1683 add { Events.AddHandler (UIAFocusedItemChangedEvent, value); }
1684 remove { Events.RemoveHandler (UIAFocusedItemChangedEvent, value); }
1687 internal void OnUIAFocusedItemChanged ()
1689 EventHandler eh = (EventHandler) Events [UIAFocusedItemChangedEvent];
1691 eh (this, EventArgs.Empty);
1694 internal PopupButton UIAFocusButton {
1701 public string CurrentFolder {
1703 string currentPath = value;
1704 if (currentPath == MWFVFS.RecentlyUsedPrefix) {
1705 if (lastPopupButton != recentlyusedButton) {
1706 if (lastPopupButton != null)
1707 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1708 recentlyusedButton.ButtonState = PopupButton.PopupButtonState.Down;
1709 lastPopupButton = recentlyusedButton;
1712 if (currentPath == MWFVFS.DesktopPrefix) {
1713 if (lastPopupButton != desktopButton) {
1714 if (lastPopupButton != null)
1715 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1716 desktopButton.ButtonState = PopupButton.PopupButtonState.Down;
1717 lastPopupButton = desktopButton;
1720 if (currentPath == MWFVFS.PersonalPrefix) {
1721 if (lastPopupButton != personalButton) {
1722 if (lastPopupButton != null)
1723 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1724 personalButton.ButtonState = PopupButton.PopupButtonState.Down;
1725 lastPopupButton = personalButton;
1728 if (currentPath == MWFVFS.MyComputerPrefix) {
1729 if (lastPopupButton != mycomputerButton) {
1730 if (lastPopupButton != null)
1731 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1732 mycomputerButton.ButtonState = PopupButton.PopupButtonState.Down;
1733 lastPopupButton = mycomputerButton;
1736 if (currentPath == MWFVFS.MyNetworkPrefix) {
1737 if (lastPopupButton != networkButton) {
1738 if (lastPopupButton != null)
1739 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1740 networkButton.ButtonState = PopupButton.PopupButtonState.Down;
1741 lastPopupButton = networkButton;
1744 if (lastPopupButton != null) {
1745 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1746 lastPopupButton = null;
1755 protected override void OnGotFocus (EventArgs e)
1757 if (lastPopupButton != recentlyusedButton) {
1758 recentlyusedButton.ButtonState = PopupButton.PopupButtonState.Up;
1759 SetFocusButton (recentlyusedButton);
1761 currentFocusIndex = 0;
1763 base.OnGotFocus (e);
1766 protected override void OnLostFocus (EventArgs e)
1768 if (focusButton != null && focusButton.ButtonState != PopupButton.PopupButtonState.Down)
1769 focusButton.ButtonState = PopupButton.PopupButtonState.Normal;
1770 base.OnLostFocus (e);
1773 protected override bool IsInputKey (Keys key)
1783 return base.IsInputKey (key);
1786 private void Key_Down (object sender, KeyEventArgs e)
1788 bool update_focus = false;
1790 if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Up) {
1791 currentFocusIndex --;
1793 if (currentFocusIndex < 0)
1794 currentFocusIndex = Controls.Count - 1;
1796 update_focus = true;
1798 if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right) {
1799 currentFocusIndex++;
1801 if (currentFocusIndex == Controls.Count)
1802 currentFocusIndex = 0;
1804 update_focus = true;
1806 if (e.KeyCode == Keys.Enter) {
1807 focusButton.ButtonState = PopupButton.PopupButtonState.Down;
1808 OnClickButton (focusButton, EventArgs.Empty);
1812 PopupButton newfocusButton = Controls [currentFocusIndex] as PopupButton;
1813 if (focusButton != null && focusButton.ButtonState != PopupButton.PopupButtonState.Down)
1814 focusButton.ButtonState = PopupButton.PopupButtonState.Normal;
1815 if (newfocusButton.ButtonState != PopupButton.PopupButtonState.Down)
1816 newfocusButton.ButtonState = PopupButton.PopupButtonState.Up;
1817 SetFocusButton (newfocusButton);
1823 static object PDirectoryChangedEvent = new object ();
1825 public event EventHandler DirectoryChanged {
1826 add { Events.AddHandler (PDirectoryChangedEvent, value); }
1827 remove { Events.RemoveHandler (PDirectoryChangedEvent, value); }
1830 internal void SetFocusButton (PopupButton button)
1832 if (button == focusButton)
1835 focusButton = button;
1837 OnUIAFocusedItemChanged ();
1844 internal class DirComboBox : ComboBox, IUpdateFolder
1846 #region DirComboBoxItem
1847 internal class DirComboBoxItem
1849 private int imageIndex;
1850 private string name;
1851 private string path;
1853 private ImageList imageList;
1855 public DirComboBoxItem (ImageList imageList, int imageIndex, string name, string path, int xPos)
1857 this.imageList = imageList;
1858 this.imageIndex = imageIndex;
1864 public int ImageIndex {
1870 public string Name {
1876 public string Path {
1888 public ImageList ImageList {
1898 #region UIA Framework Members
1899 public override string ToString ()
1908 private ImageList imageList = new ImageList();
1910 private string currentPath;
1912 private Stack folderStack = new Stack();
1914 private static readonly int indent = 6;
1916 private DirComboBoxItem recentlyUsedDirComboboxItem;
1917 private DirComboBoxItem desktopDirComboboxItem;
1918 private DirComboBoxItem personalDirComboboxItem;
1919 private DirComboBoxItem myComputerDirComboboxItem;
1920 private DirComboBoxItem networkDirComboboxItem;
1922 private ArrayList myComputerItems = new ArrayList ();
1924 private DirComboBoxItem mainParentDirComboBoxItem = null;
1925 private DirComboBoxItem real_parent = null;
1929 public DirComboBox (MWFVFS vfs)
1935 DrawMode = DrawMode.OwnerDrawFixed;
1937 imageList.ColorDepth = ColorDepth.Depth32Bit;
1938 imageList.ImageSize = new Size (16, 16);
1939 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 16));
1940 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 16));
1941 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 16));
1942 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 16));
1943 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 16));
1944 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.NormalFolder, 16));
1945 imageList.TransparentColor = Color.Transparent;
1947 recentlyUsedDirComboboxItem = new DirComboBoxItem (imageList, 0, "Recently used", MWFVFS.RecentlyUsedPrefix, 0);
1948 desktopDirComboboxItem = new DirComboBoxItem (imageList, 1, "Desktop", MWFVFS.DesktopPrefix, 0);
1949 personalDirComboboxItem = new DirComboBoxItem (imageList, 2, "Personal folder", MWFVFS.PersonalPrefix, indent);
1950 myComputerDirComboboxItem = new DirComboBoxItem (imageList, 3, "My Computer", MWFVFS.MyComputerPrefix, indent);
1951 networkDirComboboxItem = new DirComboBoxItem (imageList, 4, "My Network", MWFVFS.MyNetworkPrefix, indent);
1953 ArrayList al = this.vfs.GetMyComputerContent ();
1955 foreach (FSEntry fsEntry in al) {
1956 myComputerItems.Add (new DirComboBoxItem (MimeIconEngine.LargeIcons, fsEntry.IconIndex, fsEntry.Name, fsEntry.FullName, indent * 2));
1962 mainParentDirComboBoxItem = myComputerDirComboboxItem;
1964 ResumeLayout (false);
1967 public string CurrentFolder {
1969 currentPath = value;
1978 private void CreateComboList ()
1981 DirComboBoxItem selection = null;
1983 if (currentPath == MWFVFS.RecentlyUsedPrefix) {
1984 mainParentDirComboBoxItem = recentlyUsedDirComboboxItem;
1985 selection = recentlyUsedDirComboboxItem;
1986 } else if (currentPath == MWFVFS.DesktopPrefix) {
1987 selection = desktopDirComboboxItem;
1988 mainParentDirComboBoxItem = desktopDirComboboxItem;
1989 } else if (currentPath == MWFVFS.PersonalPrefix) {
1990 selection = personalDirComboboxItem;
1991 mainParentDirComboBoxItem = personalDirComboboxItem;
1992 } else if (currentPath == MWFVFS.MyComputerPrefix) {
1993 selection = myComputerDirComboboxItem;
1994 mainParentDirComboBoxItem = myComputerDirComboboxItem;
1995 } else if (currentPath == MWFVFS.MyNetworkPrefix) {
1996 selection = networkDirComboboxItem;
1997 mainParentDirComboBoxItem = networkDirComboboxItem;
1999 foreach (DirComboBoxItem dci in myComputerItems) {
2000 if (dci.Path == currentPath) {
2001 mainParentDirComboBoxItem = selection = dci;
2011 Items.Add (recentlyUsedDirComboboxItem);
2012 Items.Add (desktopDirComboboxItem);
2013 Items.Add (personalDirComboboxItem);
2014 Items.Add (myComputerDirComboboxItem);
2015 Items.AddRange (myComputerItems);
2016 Items.Add (networkDirComboboxItem);
2018 if (selection == null)
2019 real_parent = CreateFolderStack ();
2021 if (real_parent != null) {
2022 int local_indent = 0;
2024 if (real_parent == desktopDirComboboxItem)
2027 if (real_parent == personalDirComboboxItem || real_parent == networkDirComboboxItem)
2032 selection = AppendToParent (local_indent, real_parent);
2037 if (selection != null)
2038 SelectedItem = selection;
2041 private DirComboBoxItem CreateFolderStack ()
2043 folderStack.Clear ();
2045 DirectoryInfo di = new DirectoryInfo (currentPath);
2047 folderStack.Push (di);
2049 bool ignoreCase = !XplatUI.RunningOnUnix;
2051 while (di.Parent != null) {
2054 if (mainParentDirComboBoxItem != personalDirComboboxItem && string.Compare (di.FullName, ThemeEngine.Current.Places (UIIcon.PlacesDesktop), ignoreCase) == 0)
2055 return desktopDirComboboxItem;
2057 if (mainParentDirComboBoxItem == personalDirComboboxItem) {
2058 if (string.Compare (di.FullName, ThemeEngine.Current.Places (UIIcon.PlacesPersonal), ignoreCase) == 0)
2059 return personalDirComboboxItem;
2061 foreach (DirComboBoxItem dci in myComputerItems) {
2062 if (string.Compare (dci.Path, di.FullName, ignoreCase) == 0) {
2067 folderStack.Push (di);
2073 private DirComboBoxItem AppendToParent (int nr_indents, DirComboBoxItem parentDirComboBoxItem)
2075 DirComboBoxItem selection = null;
2077 int index = Items.IndexOf (parentDirComboBoxItem) + 1;
2079 int xPos = indent * nr_indents;
2081 while (folderStack.Count != 0) {
2082 DirectoryInfo dii = folderStack.Pop () as DirectoryInfo;
2084 DirComboBoxItem dci = new DirComboBoxItem (imageList, 5, dii.Name, dii.FullName, xPos);
2086 Items.Insert (index, dci);
2095 protected override void OnDrawItem (DrawItemEventArgs e)
2100 DirComboBoxItem dcbi = Items [e.Index] as DirComboBoxItem;
2102 Bitmap bmp = new Bitmap (e.Bounds.Width, e.Bounds.Height, e.Graphics);
2103 Graphics gr = Graphics.FromImage (bmp);
2105 Color backColor = e.BackColor;
2106 Color foreColor = e.ForeColor;
2108 int xPos = dcbi.XPos;
2110 if ((e.State & DrawItemState.ComboBoxEdit) != 0)
2113 gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (backColor),
2114 new Rectangle (0, 0, bmp.Width, bmp.Height));
2116 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected &&
2117 (!DroppedDown || (e.State & DrawItemState.ComboBoxEdit) != DrawItemState.ComboBoxEdit)) {
2118 foreColor = ThemeEngine.Current.ColorHighlightText;
2120 int w = (int) gr.MeasureString (dcbi.Name, e.Font).Width;
2122 gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ThemeEngine.Current.ColorHighlight),
2123 new Rectangle (xPos + 23, 1, w + 3, e.Bounds.Height - 2));
2124 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
2125 ControlPaint.DrawFocusRectangle (gr, new Rectangle (xPos + 22, 0, w + 5,
2126 e.Bounds.Height), foreColor, ThemeEngine.Current.ColorHighlight);
2130 gr.DrawString (dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush (foreColor), new Point (24 + xPos, (bmp.Height - e.Font.Height) / 2));
2131 gr.DrawImage (dcbi.ImageList.Images [dcbi.ImageIndex], new Rectangle (new Point (xPos + 2, 0), new Size (16, 16)));
2133 e.Graphics.DrawImage (bmp, e.Bounds.X, e.Bounds.Y);
2138 protected override void OnSelectedIndexChanged (EventArgs e)
2140 if (Items.Count > 0) {
2141 DirComboBoxItem dcbi = Items [SelectedIndex] as DirComboBoxItem;
2143 currentPath = dcbi.Path;
2147 protected override void OnSelectionChangeCommitted (EventArgs e)
2149 EventHandler eh = (EventHandler)(Events [CDirectoryChangedEvent]);
2151 eh (this, EventArgs.Empty);
2154 static object CDirectoryChangedEvent = new object ();
2156 public event EventHandler DirectoryChanged {
2157 add { Events.AddHandler (CDirectoryChangedEvent, value); }
2158 remove { Events.RemoveHandler (CDirectoryChangedEvent, value); }
2163 #region FilterStruct
2164 internal struct FilterStruct
2166 public string filterName;
2167 public StringCollection filters;
2169 public FilterStruct (string filterName, string filter)
2171 this.filterName = filterName;
2173 filters = new StringCollection ();
2175 SplitFilters (filter);
2178 private void SplitFilters (string filter)
2180 string[] split = filter.Split (new char [] {';'});
2181 foreach (string s in split) {
2182 filters.Add (s.Trim ());
2189 internal class FileFilter
2191 private ArrayList filterArrayList = new ArrayList();
2193 private string filter;
2195 public FileFilter ()
2198 public FileFilter (string filter) : base ()
2200 this.filter = filter;
2205 public static bool CheckFilter (string val)
2207 if (val.Length == 0)
2210 string[] filters = val.Split (new char [] {'|'});
2212 if ((filters.Length % 2) != 0)
2218 public ArrayList FilterArrayList {
2220 filterArrayList = value;
2224 return filterArrayList;
2228 public string Filter {
2240 private void SplitFilter ()
2242 filterArrayList.Clear ();
2244 if (filter.Length == 0)
2247 string[] filters = filter.Split (new char [] {'|'});
2249 for (int i = 0; i < filters.Length; i += 2) {
2250 FilterStruct filterStruct = new FilterStruct (filters [i], filters [i + 1]);
2252 filterArrayList.Add (filterStruct);
2260 internal class MWFFileView : ListView
2262 private ArrayList filterArrayList;
2264 private bool showHiddenFiles = false;
2266 private string selectedFilesString;
2268 private int filterIndex = 1;
2270 private ToolTip toolTip;
2271 private int oldItemIndexForToolTip = -1;
2273 private ContextMenu contextMenu;
2275 private MenuItem menuItemView;
2276 private MenuItem menuItemNew;
2278 private MenuItem smallIconMenutItem;
2279 private MenuItem tilesMenutItem;
2280 private MenuItem largeIconMenutItem;
2281 private MenuItem listMenutItem;
2282 private MenuItem detailsMenutItem;
2284 private MenuItem newFolderMenuItem;
2285 private MenuItem showHiddenFilesMenuItem;
2287 private int previousCheckedMenuItemIndex;
2289 private ArrayList viewMenuItemClones = new ArrayList ();
2291 private FSEntry currentFSEntry = null;
2293 private string currentFolder;
2294 private string currentRealFolder;
2295 private FSEntry currentFolderFSEntry;
2297 // store DirectoryInfo for a back button for example
2298 private Stack directoryStack = new Stack();
2300 // list of controls(components to enable or disable depending on current directoryStack.Count
2301 private ArrayList dirStackControlsOrComponents = new ArrayList ();
2303 private ToolBarButton folderUpToolBarButton;
2305 private ArrayList registered_senders = new ArrayList ();
2307 private bool should_push = true;
2311 private View old_view;
2313 private int old_menuitem_index;
2314 private bool do_update_view = false;
2316 private ColumnHeader [] columns;
2318 public MWFFileView (MWFVFS vfs)
2321 this.vfs.RegisterUpdateDelegate (new MWFVFS.UpdateDelegate (RealFileViewUpdate), this);
2325 contextMenu = new ContextMenu ();
2327 toolTip = new ToolTip ();
2328 toolTip.InitialDelay = 300;
2329 toolTip.ReshowDelay = 0;
2334 menuItemView = new MenuItem ("View");
2336 smallIconMenutItem = new MenuItem ("Small Icon", new EventHandler (OnClickViewMenuSubItem));
2337 smallIconMenutItem.RadioCheck = true;
2338 menuItemView.MenuItems.Add (smallIconMenutItem);
2340 tilesMenutItem = new MenuItem ("Tiles", new EventHandler (OnClickViewMenuSubItem));
2341 tilesMenutItem.RadioCheck = true;
2342 menuItemView.MenuItems.Add (tilesMenutItem);
2344 largeIconMenutItem = new MenuItem ("Large Icon", new EventHandler (OnClickViewMenuSubItem));
2345 largeIconMenutItem.RadioCheck = true;
2346 menuItemView.MenuItems.Add (largeIconMenutItem);
2348 listMenutItem = new MenuItem ("List", new EventHandler (OnClickViewMenuSubItem));
2349 listMenutItem.RadioCheck = true;
2350 listMenutItem.Checked = true;
2351 menuItemView.MenuItems.Add (listMenutItem);
2352 previousCheckedMenuItemIndex = listMenutItem.Index;
2354 detailsMenutItem = new MenuItem ("Details", new EventHandler (OnClickViewMenuSubItem));
2355 detailsMenutItem.RadioCheck = true;
2356 menuItemView.MenuItems.Add (detailsMenutItem);
2358 contextMenu.MenuItems.Add (menuItemView);
2360 contextMenu.MenuItems.Add (new MenuItem ("-"));
2363 menuItemNew = new MenuItem ("New");
2365 newFolderMenuItem = new MenuItem ("New Folder", new EventHandler (OnClickNewFolderMenuItem));
2366 menuItemNew.MenuItems.Add (newFolderMenuItem);
2368 contextMenu.MenuItems.Add (menuItemNew);
2370 contextMenu.MenuItems.Add (new MenuItem ("-"));
2372 // Show hidden files menu item
2373 showHiddenFilesMenuItem = new MenuItem ("Show hidden files", new EventHandler (OnClickContextMenu));
2374 showHiddenFilesMenuItem.Checked = showHiddenFiles;
2375 contextMenu.MenuItems.Add (showHiddenFilesMenuItem);
2379 SmallImageList = MimeIconEngine.SmallIcons;
2380 LargeImageList = MimeIconEngine.LargeIcons;
2382 View = old_view = View.List;
2385 ContextMenu = contextMenu;
2387 // Create columns, but only add them when view changes to Details
2388 columns = new ColumnHeader [4];
2389 columns [0] = CreateColumnHeader (" Name", 170, HorizontalAlignment.Left);
2390 columns [1] = CreateColumnHeader ("Size ", 80, HorizontalAlignment.Right);
2391 columns [2] = CreateColumnHeader (" Type", 100, HorizontalAlignment.Left);
2392 columns [3] = CreateColumnHeader (" Last Access", 150, HorizontalAlignment.Left);
2394 AllowColumnReorder = true;
2396 ResumeLayout (false);
2398 KeyDown += new KeyEventHandler (MWF_KeyDown);
2401 ColumnHeader CreateColumnHeader (string text, int width, HorizontalAlignment alignment)
2403 ColumnHeader col = new ColumnHeader ();
2406 col.TextAlign = alignment;
2411 public string CurrentFolder {
2413 return currentFolder;
2416 currentFolder = value;
2420 public string CurrentRealFolder {
2422 return currentRealFolder;
2426 public FSEntry CurrentFSEntry {
2428 return currentFSEntry;
2432 public MenuItem[] ViewMenuItems {
2434 MenuItem[] menuItemClones = new MenuItem [] {
2435 smallIconMenutItem.CloneMenu (),
2436 tilesMenutItem.CloneMenu (),
2437 largeIconMenutItem.CloneMenu (),
2438 listMenutItem.CloneMenu (),
2439 detailsMenutItem.CloneMenu ()
2442 viewMenuItemClones.Add (menuItemClones);
2444 return menuItemClones;
2448 public ArrayList FilterArrayList {
2450 filterArrayList = value;
2454 return filterArrayList;
2458 public bool ShowHiddenFiles {
2460 showHiddenFiles = value;
2464 return showHiddenFiles;
2468 public int FilterIndex {
2470 filterIndex = value;
2480 public string SelectedFilesString {
2482 selectedFilesString = value;
2486 return selectedFilesString;
2490 public void PushDir ()
2492 if (currentFolder != null)
2493 directoryStack.Push (currentFolder);
2495 EnableOrDisableDirstackObjects ();
2498 public void PopDir ()
2503 public void PopDir (string filter)
2505 if (directoryStack.Count == 0)
2508 string new_folder = directoryStack.Pop () as string;
2510 EnableOrDisableDirstackObjects ();
2512 should_push = false;
2514 ChangeDirectory (null, new_folder, filter);
2517 public void RegisterSender (IUpdateFolder iud)
2519 registered_senders.Add (iud);
2522 public void CreateNewFolder ()
2524 if (currentFolder == MWFVFS.MyComputerPrefix ||
2525 currentFolder == MWFVFS.RecentlyUsedPrefix)
2528 FSEntry fsEntry = new FSEntry ();
2529 fsEntry.Attributes = FileAttributes.Directory;
2530 fsEntry.FileType = FSEntry.FSEntryType.Directory;
2531 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
2532 fsEntry.LastAccessTime = DateTime.Now;
2534 // FIXME: when ListView.LabelEdit is available use it
2535 // listViewItem.BeginEdit();
2537 TextEntryDialog ted = new TextEntryDialog ();
2538 ted.IconPictureBoxImage = MimeIconEngine.LargeIcons.Images.GetImage (fsEntry.IconIndex);
2540 string folder = String.Empty;
2542 if (currentFolderFSEntry.RealName != null)
2543 folder = currentFolderFSEntry.RealName;
2545 folder = currentFolder;
2547 string tmp_filename = "New Folder";
2549 if (Directory.Exists (Path.Combine (folder, tmp_filename))) {
2552 if (XplatUI.RunningOnUnix) {
2553 tmp_filename = tmp_filename + "-" + i;
2555 tmp_filename = tmp_filename + " (" + i + ")";
2558 while (Directory.Exists (Path.Combine (folder, tmp_filename))) {
2560 if (XplatUI.RunningOnUnix) {
2561 tmp_filename = "New Folder" + "-" + i;
2563 tmp_filename = "New Folder" + " (" + i + ")";
2568 ted.FileName = tmp_filename;
2570 if (ted.ShowDialog () == DialogResult.OK) {
2571 string new_folder = Path.Combine (folder, ted.FileName);
2573 if (vfs.CreateFolder (new_folder)) {
2574 fsEntry.FullName = new_folder;
2575 fsEntry.Name = ted.FileName;
2577 FileViewListViewItem listViewItem = new FileViewListViewItem (fsEntry);
2580 Items.Add (listViewItem);
2583 listViewItem.EnsureVisible ();
2588 public void SetSelectedIndexTo (string fname)
2590 foreach (FileViewListViewItem item in Items) {
2591 if (item.Text == fname) {
2593 SelectedItems.Clear ();
2594 item.Selected = true;
2601 public void OneDirUp ()
2606 public void OneDirUp (string filter)
2608 string parent_folder = vfs.GetParent ();
2609 if (parent_folder != null)
2610 ChangeDirectory (null, parent_folder, filter);
2613 public void ChangeDirectory (object sender, string folder)
2615 ChangeDirectory (sender, folder, null);
2618 public void ChangeDirectory (object sender, string folder, string filter)
2620 if (folder == MWFVFS.DesktopPrefix || folder == MWFVFS.RecentlyUsedPrefix)
2621 folderUpToolBarButton.Enabled = false;
2623 folderUpToolBarButton.Enabled = true;
2625 foreach (IUpdateFolder iuf in registered_senders) {
2626 iuf.CurrentFolder = folder;
2634 currentFolderFSEntry = vfs.ChangeDirectory (folder);
2636 currentFolder = folder;
2638 if (currentFolder.IndexOf ("://") != -1)
2639 currentRealFolder = currentFolderFSEntry.RealName;
2641 currentRealFolder = currentFolder;
2646 SelectedItems.Clear ();
2648 if (folder == MWFVFS.RecentlyUsedPrefix) {
2650 View = View.Details;
2651 old_menuitem_index = previousCheckedMenuItemIndex;
2652 UpdateMenuItems (detailsMenutItem);
2653 do_update_view = true;
2655 if (View != old_view && do_update_view) {
2656 UpdateMenuItems (menuItemView.MenuItems [old_menuitem_index]);
2658 do_update_view = false;
2663 UpdateFileView (filter);
2664 } catch (Exception e) {
2667 MessageBox.Show (e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
2671 public void UpdateFileView ()
2673 UpdateFileView (null);
2676 public void UpdateFileView (string custom_filter)
2678 if (custom_filter != null) {
2679 StringCollection custom_filters = new StringCollection ();
2680 custom_filters.Add (custom_filter);
2682 vfs.GetFolderContent (custom_filters);
2683 } else if (filterArrayList != null && filterArrayList.Count != 0) {
2684 FilterStruct fs = (FilterStruct)filterArrayList [filterIndex - 1];
2686 vfs.GetFolderContent (fs.filters);
2688 vfs.GetFolderContent ();
2691 public void RealFileViewUpdate (ArrayList directoriesArrayList, ArrayList fileArrayList)
2696 SelectedItems.Clear ();
2698 foreach (FSEntry directoryFSEntry in directoriesArrayList) {
2699 if (!ShowHiddenFiles)
2700 if (directoryFSEntry.Name.StartsWith (".") || (directoryFSEntry.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
2703 FileViewListViewItem listViewItem = new FileViewListViewItem (directoryFSEntry);
2705 Items.Add (listViewItem);
2708 StringCollection collection = new StringCollection ();
2710 foreach (FSEntry fsEntry in fileArrayList) {
2712 // remove duplicates. that can happen when you read recently used files for example
2713 if (collection.Contains (fsEntry.Name)) {
2715 string fileName = fsEntry.Name;
2717 if (collection.Contains (fileName)) {
2720 while (collection.Contains (fileName + "(" + i + ")")) {
2724 fileName = fileName + "(" + i + ")";
2727 fsEntry.Name = fileName;
2730 collection.Add (fsEntry.Name);
2732 DoOneFSEntry (fsEntry);
2737 collection.Clear ();
2740 directoriesArrayList.Clear ();
2741 fileArrayList.Clear ();
2744 public void AddControlToEnableDisableByDirStack (object control)
2746 dirStackControlsOrComponents.Add (control);
2749 public void SetFolderUpToolBarButton (ToolBarButton tb)
2751 folderUpToolBarButton = tb;
2754 public void WriteRecentlyUsed (string fullfilename)
2756 vfs.WriteRecentlyUsedFiles (fullfilename);
2759 private void EnableOrDisableDirstackObjects ()
2761 foreach (object o in dirStackControlsOrComponents) {
2763 Control c = o as Control;
2764 c.Enabled = (directoryStack.Count > 1);
2766 if (o is ToolBarButton) {
2767 ToolBarButton t = o as ToolBarButton;
2768 t.Enabled = (directoryStack.Count > 0);
2773 private void DoOneFSEntry (FSEntry fsEntry)
2775 if (!ShowHiddenFiles)
2776 if (fsEntry.Name.StartsWith (".") || (fsEntry.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
2779 FileViewListViewItem listViewItem = new FileViewListViewItem (fsEntry);
2781 Items.Add (listViewItem);
2784 private void MWF_KeyDown (object sender, KeyEventArgs e)
2786 if (e.KeyCode == Keys.Back) {
2788 } else if (e.Control && e.KeyCode == Keys.A && MultiSelect) {
2789 foreach (ListViewItem lvi in Items)
2790 lvi.Selected = true;
2795 #region UIA Framework Members
2796 internal void PerformClick ()
2798 OnClick (EventArgs.Empty);
2801 internal void PerformDoubleClick ()
2803 OnDoubleClick (EventArgs.Empty);
2807 protected override void OnClick (EventArgs e)
2810 if (SelectedItems.Count > 0) {
2811 FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
2813 FSEntry fsEntry = listViewItem.FSEntry;
2815 if (fsEntry.FileType == FSEntry.FSEntryType.File) {
2816 currentFSEntry = fsEntry;
2818 EventHandler eh = (EventHandler)(Events [MSelectedFileChangedEvent]);
2820 eh (this, EventArgs.Empty);
2828 protected override void OnDoubleClick (EventArgs e)
2830 if (SelectedItems.Count > 0) {
2831 FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
2833 FSEntry fsEntry = listViewItem.FSEntry;
2835 if ((fsEntry.Attributes & FileAttributes.Directory) == FileAttributes.Directory) {
2837 ChangeDirectory (null, fsEntry.FullName);
2839 EventHandler eh = (EventHandler)(Events [MDirectoryChangedEvent]);
2841 eh (this, EventArgs.Empty);
2843 currentFSEntry = fsEntry;
2845 EventHandler eh = (EventHandler)(Events [MSelectedFileChangedEvent]);
2847 eh (this, EventArgs.Empty);
2849 eh = (EventHandler)(Events [MForceDialogEndEvent]);
2851 eh (this, EventArgs.Empty);
2857 base.OnDoubleClick (e);
2860 protected override void OnSelectedIndexChanged (EventArgs e)
2862 if (SelectedItems.Count > 0) {
2863 selectedFilesString = String.Empty;
2865 if (SelectedItems.Count == 1) {
2866 FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
2868 FSEntry fsEntry = listViewItem.FSEntry;
2870 if ((fsEntry.Attributes & FileAttributes.Directory) != FileAttributes.Directory)
2871 selectedFilesString = SelectedItems [0].Text;
2873 foreach (FileViewListViewItem lvi in SelectedItems) {
2874 FSEntry fsEntry = lvi.FSEntry;
2876 if ((fsEntry.Attributes & FileAttributes.Directory) != FileAttributes.Directory)
2877 selectedFilesString = selectedFilesString + "\"" + lvi.Text + "\" ";
2881 EventHandler eh = (EventHandler)(Events [MSelectedFilesChangedEvent]);
2883 eh (this, EventArgs.Empty);
2886 base.OnSelectedIndexChanged (e);
2889 protected override void OnMouseMove (MouseEventArgs e)
2891 FileViewListViewItem item = GetItemAt (e.X, e.Y) as FileViewListViewItem;
2894 int currentItemIndex = item.Index;
2896 if (currentItemIndex != oldItemIndexForToolTip) {
2897 oldItemIndexForToolTip = currentItemIndex;
2899 if (toolTip != null && toolTip.Active)
2900 toolTip.Active = false;
2902 FSEntry fsEntry = item.FSEntry;
2904 string output = String.Empty;
2906 if (fsEntry.FileType == FSEntry.FSEntryType.Directory)
2907 output = "Directory: " + fsEntry.FullName;
2908 else if (fsEntry.FileType == FSEntry.FSEntryType.Device)
2909 output = "Device: "+ fsEntry.FullName;
2910 else if (fsEntry.FileType == FSEntry.FSEntryType.Network)
2911 output = "Network: " + fsEntry.FullName;
2913 output = "File: " + fsEntry.FullName;
2915 toolTip.SetToolTip (this, output);
2917 toolTip.Active = true;
2920 toolTip.Active = false;
2922 base.OnMouseMove (e);
2925 void OnClickContextMenu (object sender, EventArgs e)
2927 MenuItem senderMenuItem = sender as MenuItem;
2929 if (senderMenuItem == showHiddenFilesMenuItem) {
2930 senderMenuItem.Checked = !senderMenuItem.Checked;
2931 showHiddenFiles = senderMenuItem.Checked;
2936 void OnClickViewMenuSubItem (object sender, EventArgs e)
2938 MenuItem senderMenuItem = (MenuItem)sender;
2940 UpdateMenuItems (senderMenuItem);
2942 // update me - call BeginUpdate/EndUpdate to avoid flicker when columns change
2945 switch (senderMenuItem.Index) {
2947 View = View.SmallIcon;
2953 View = View.LargeIcon;
2957 View = View.LargeIcon;
2963 View = View.Details;
2969 if (View == View.Details)
2970 Columns.AddRange (columns);
2972 ListViewItemSorter = null;
2979 protected override void OnBeforeLabelEdit (LabelEditEventArgs e)
2981 FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
2982 FSEntry fsEntry = listViewItem.FSEntry;
2984 // only allow editing of files or directories
2985 if (fsEntry.FileType != FSEntry.FSEntryType.Directory &&
2986 fsEntry.FileType != FSEntry.FSEntryType.File)
2987 e.CancelEdit = true;
2989 base.OnBeforeLabelEdit (e);
2992 protected override void OnAfterLabelEdit (LabelEditEventArgs e)
2994 base.OnAfterLabelEdit (e);
2996 // no changes were made
2997 if (e.Label == null || Items [e.Item].Text == e.Label)
3000 FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
3001 FSEntry fsEntry = listViewItem.FSEntry;
3003 string folder = (currentFolderFSEntry.RealName != null) ?
3004 currentFolderFSEntry.RealName : currentFolder;
3006 switch (fsEntry.FileType) {
3007 case FSEntry.FSEntryType.Directory:
3008 string sourceDir = (fsEntry.RealName != null) ? fsEntry.RealName : fsEntry.FullName;
3009 string destDir = Path.Combine (folder, e.Label);
3010 if (!vfs.MoveFolder (sourceDir, destDir)) {
3011 e.CancelEdit = true;
3013 if (fsEntry.RealName != null)
3014 fsEntry.RealName = destDir;
3016 fsEntry.FullName = destDir;
3019 case FSEntry.FSEntryType.File:
3020 string sourceFile = (fsEntry.RealName != null) ? fsEntry.RealName : fsEntry.FullName;
3021 string destFile = Path.Combine (folder, e.Label);
3022 if (!vfs.MoveFile (sourceFile, destFile)) {
3023 e.CancelEdit = true;
3025 if (fsEntry.RealName != null)
3026 fsEntry.RealName = destFile;
3028 fsEntry.FullName = destFile;
3034 private void UpdateMenuItems (MenuItem senderMenuItem)
3036 menuItemView.MenuItems [previousCheckedMenuItemIndex].Checked = false;
3037 menuItemView.MenuItems [senderMenuItem.Index].Checked = true;
3039 foreach (MenuItem[] items in viewMenuItemClones) {
3040 items [previousCheckedMenuItemIndex].Checked = false;
3041 items [senderMenuItem.Index].Checked = true;
3044 previousCheckedMenuItemIndex = senderMenuItem.Index;
3047 void OnClickNewFolderMenuItem (object sender, EventArgs e)
3052 static object MSelectedFileChangedEvent = new object ();
3053 static object MSelectedFilesChangedEvent = new object ();
3054 static object MDirectoryChangedEvent = new object ();
3055 static object MForceDialogEndEvent = new object ();
3057 public event EventHandler SelectedFileChanged {
3058 add { Events.AddHandler (MSelectedFileChangedEvent, value); }
3059 remove { Events.RemoveHandler (MSelectedFileChangedEvent, value); }
3062 public event EventHandler SelectedFilesChanged {
3063 add { Events.AddHandler (MSelectedFilesChangedEvent, value); }
3064 remove { Events.RemoveHandler (MSelectedFilesChangedEvent, value); }
3067 public event EventHandler DirectoryChanged {
3068 add { Events.AddHandler (MDirectoryChangedEvent, value); }
3069 remove { Events.RemoveHandler (MDirectoryChangedEvent, value); }
3072 public event EventHandler ForceDialogEnd {
3073 add { Events.AddHandler (MForceDialogEndEvent, value); }
3074 remove { Events.RemoveHandler (MForceDialogEndEvent, value); }
3079 #region FileListViewItem
3080 internal class FileViewListViewItem : ListViewItem
3082 private FSEntry fsEntry;
3084 public FileViewListViewItem (FSEntry fsEntry)
3086 this.fsEntry = fsEntry;
3088 ImageIndex = fsEntry.IconIndex;
3090 Text = fsEntry.Name;
3092 switch (fsEntry.FileType) {
3093 case FSEntry.FSEntryType.Directory:
3094 SubItems.Add (String.Empty);
3095 SubItems.Add ("Directory");
3096 SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
3098 case FSEntry.FSEntryType.File:
3101 if (fsEntry.FileSize > 1024)
3102 fileLen = fsEntry.FileSize / 1024;
3103 } catch (Exception) {
3107 SubItems.Add (fileLen.ToString () + " KB");
3108 SubItems.Add ("File");
3109 SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
3111 case FSEntry.FSEntryType.Device:
3112 SubItems.Add (String.Empty);
3113 SubItems.Add ("Device");
3114 SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
3116 case FSEntry.FSEntryType.RemovableDevice:
3117 SubItems.Add (String.Empty);
3118 SubItems.Add ("RemovableDevice");
3119 SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
3126 public FSEntry FSEntry {
3139 #region MwfFileViewItemComparer
3140 class MwfFileViewItemComparer : IComparer
3145 public MwfFileViewItemComparer (bool asc)
3150 public int ColumnIndex {
3152 return column_index;
3155 column_index = value;
3159 public bool Ascendent {
3168 public int Compare (object a, object b)
3170 ListViewItem item_a = (ListViewItem)a;
3171 ListViewItem item_b = (ListViewItem)b;
3175 retval = String.Compare (item_a.SubItems [column_index].Text,
3176 item_b.SubItems [column_index].Text);
3178 retval = String.Compare (item_b.SubItems [column_index].Text,
3179 item_a.SubItems [column_index].Text);
3186 #region IUpdateFolder
3187 internal interface IUpdateFolder
3189 string CurrentFolder {get; set;}
3193 #region TextEntryDialog
3194 // FIXME: When ListView.LabelEdit is implemented remove me
3195 internal class TextEntryDialog : Form
3197 private Label label1;
3198 private Button okButton;
3199 private TextBox newNameTextBox;
3200 private PictureBox iconPictureBox;
3201 private Button cancelButton;
3202 private GroupBox groupBox1;
3204 public TextEntryDialog ()
3206 groupBox1 = new GroupBox ();
3207 cancelButton = new Button ();
3208 iconPictureBox = new PictureBox ();
3209 newNameTextBox = new TextBox ();
3210 okButton = new Button ();
3211 label1 = new Label ();
3212 groupBox1.SuspendLayout ();
3216 groupBox1.Controls.Add (newNameTextBox);
3217 groupBox1.Controls.Add (label1);
3218 groupBox1.Controls.Add (iconPictureBox);
3219 groupBox1.Location = new Point (8, 8);
3220 groupBox1.Size = new Size (232, 160);
3221 groupBox1.TabIndex = 5;
3222 groupBox1.TabStop = false;
3223 groupBox1.Text = "New Name";
3226 cancelButton.DialogResult = DialogResult.Cancel;
3227 cancelButton.Location = new Point (168, 176);
3228 cancelButton.TabIndex = 4;
3229 cancelButton.Text = "Cancel";
3232 iconPictureBox.BorderStyle = BorderStyle.Fixed3D;
3233 iconPictureBox.Location = new Point (86, 24);
3234 iconPictureBox.Size = new Size (60, 60);
3235 iconPictureBox.TabIndex = 3;
3236 iconPictureBox.TabStop = false;
3237 iconPictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
3240 newNameTextBox.Location = new Point (16, 128);
3241 newNameTextBox.Size = new Size (200, 20);
3242 newNameTextBox.TabIndex = 5;
3243 newNameTextBox.Text = String.Empty;
3246 okButton.DialogResult = DialogResult.OK;
3247 okButton.Location = new Point (80, 176);
3248 okButton.TabIndex = 3;
3249 okButton.Text = "OK";
3252 label1.Location = new Point (16, 96);
3253 label1.Size = new Size (200, 23);
3254 label1.TabIndex = 4;
3255 label1.Text = "Enter Name:";
3256 label1.TextAlign = ContentAlignment.MiddleCenter;
3259 AcceptButton = okButton;
3260 AutoScaleBaseSize = new Size (5, 13);
3261 CancelButton = cancelButton;
3262 ClientSize = new Size (248, 205);
3263 Controls.Add (groupBox1);
3264 Controls.Add (cancelButton);
3265 Controls.Add (okButton);
3266 FormBorderStyle = FormBorderStyle.FixedDialog;
3267 Text = "New Folder or File";
3268 groupBox1.ResumeLayout (false);
3269 ResumeLayout (false);
3271 newNameTextBox.Select ();
3274 public Image IconPictureBoxImage {
3276 iconPictureBox.Image = value;
3280 public string FileName {
3282 return newNameTextBox.Text;
3285 newNameTextBox.Text = value;
3292 internal class MWFVFS
3294 private FileSystem fileSystem;
3296 public static readonly string DesktopPrefix = "Desktop://";
3297 public static readonly string PersonalPrefix = "Personal://";
3298 public static readonly string MyComputerPrefix = "MyComputer://";
3299 public static readonly string RecentlyUsedPrefix = "RecentlyUsed://";
3300 public static readonly string MyNetworkPrefix = "MyNetwork://";
3301 public static readonly string MyComputerPersonalPrefix = "MyComputerPersonal://";
3303 public static Hashtable MyComputerDevicesPrefix = new Hashtable ();
3305 public delegate void UpdateDelegate (ArrayList folders, ArrayList files);
3306 private UpdateDelegate updateDelegate;
3307 private Control calling_control;
3309 private ThreadStart get_folder_content_thread_start;
3310 private Thread worker;
3311 private WorkerThread workerThread = null;
3312 private StringCollection the_filters;
3316 if (XplatUI.RunningOnUnix) {
3317 fileSystem = new UnixFileSystem ();
3319 fileSystem = new WinFileSystem ();
3323 public FSEntry ChangeDirectory (string folder)
3325 return fileSystem.ChangeDirectory (folder);
3328 public void GetFolderContent ()
3330 GetFolderContent (null);
3333 public void GetFolderContent (StringCollection filters)
3335 the_filters = filters;
3337 if (workerThread != null) {
3338 workerThread.Stop ();
3339 workerThread = null;
3342 // Added next line to ensure the control is created before BeginInvoke is called on it
3343 calling_control.CreateControl();
3344 workerThread = new WorkerThread (fileSystem, the_filters, updateDelegate, calling_control);
3346 get_folder_content_thread_start = new ThreadStart (workerThread.GetFolderContentThread);
3347 worker = new Thread (get_folder_content_thread_start);
3348 worker.IsBackground = true;
3352 internal class WorkerThread
3354 private FileSystem fileSystem;
3355 private StringCollection the_filters;
3356 private UpdateDelegate updateDelegate;
3357 private Control calling_control;
3358 private readonly object lockobject = new object ();
3359 private bool stopped = false;
3361 public WorkerThread (FileSystem fileSystem, StringCollection the_filters, UpdateDelegate updateDelegate, Control calling_control)
3363 this.fileSystem = fileSystem;
3364 this.the_filters = the_filters;
3365 this.updateDelegate = updateDelegate;
3366 this.calling_control = calling_control;
3369 public void GetFolderContentThread()
3374 fileSystem.GetFolderContent (the_filters, out folders, out files);
3379 if (updateDelegate != null) {
3381 object[] objectArray = new object[2];
3383 objectArray[0] = folders;
3384 objectArray[1] = files;
3386 calling_control.BeginInvoke (updateDelegate, objectArray);
3399 public ArrayList GetFoldersOnly ()
3401 return fileSystem.GetFoldersOnly ();
3404 public void WriteRecentlyUsedFiles (string filename)
3406 fileSystem.WriteRecentlyUsedFiles (filename);
3409 public ArrayList GetRecentlyUsedFiles ()
3411 return fileSystem.GetRecentlyUsedFiles ();
3414 public ArrayList GetMyComputerContent ()
3416 return fileSystem.GetMyComputerContent ();
3419 public ArrayList GetMyNetworkContent ()
3421 return fileSystem.GetMyNetworkContent ();
3424 public bool CreateFolder (string new_folder)
3427 if (Directory.Exists (new_folder)) {
3428 string message = "Folder \"" + new_folder + "\" already exists.";
3429 MessageBox.Show (message, new_folder, MessageBoxButtons.OK,
3430 MessageBoxIcon.Error);
3433 Directory.CreateDirectory (new_folder);
3434 } catch (Exception e) {
3435 MessageBox.Show (e.Message, new_folder, MessageBoxButtons.OK, MessageBoxIcon.Error);
3442 public bool MoveFolder (string sourceDirName, string destDirName)
3445 if (Directory.Exists (destDirName)) {
3446 string message = "Cannot rename " + Path.GetFileName (sourceDirName)
3447 + ": A folder with the name you specified already exists."
3448 + " Specify a different folder name.";
3449 MessageBox.Show (message, "Error Renaming Folder", MessageBoxButtons.OK,
3450 MessageBoxIcon.Error);
3453 Directory.Move (sourceDirName, destDirName);
3454 } catch (Exception e) {
3455 MessageBox.Show (e.Message, "Error Renaming Folder",
3456 MessageBoxButtons.OK, MessageBoxIcon.Error);
3463 public bool MoveFile (string sourceFileName, string destFileName)
3466 if (File.Exists (destFileName)) {
3467 string message = "Cannot rename " + Path.GetFileName (sourceFileName)
3468 + ": A file with the name you specified already exists."
3469 + " Specify a different file name.";
3470 MessageBox.Show (message, "Error Renaming File",
3471 MessageBoxButtons.OK, MessageBoxIcon.Error);
3474 File.Move (sourceFileName, destFileName);
3475 } catch (Exception e) {
3476 MessageBox.Show (e.Message, "Error Renaming File",
3477 MessageBoxButtons.OK, MessageBoxIcon.Error);
3484 public string GetParent ()
3486 return fileSystem.GetParent ();
3489 public void RegisterUpdateDelegate(UpdateDelegate updateDelegate, Control control)
3491 this.updateDelegate = updateDelegate;
3492 calling_control = control;
3498 internal abstract class FileSystem
3500 protected string currentTopFolder = String.Empty;
3501 protected FSEntry currentFolderFSEntry = null;
3502 protected FSEntry currentTopFolderFSEntry = null;
3503 private FileInfoComparer fileInfoComparer = new FileInfoComparer ();
3504 private FSEntryComparer fsEntryComparer = new FSEntryComparer ();
3506 public FSEntry ChangeDirectory (string folder)
3508 if (folder == MWFVFS.DesktopPrefix) {
3509 currentTopFolder = MWFVFS.DesktopPrefix;
3510 currentTopFolderFSEntry = currentFolderFSEntry = GetDesktopFSEntry ();
3512 if (folder == MWFVFS.PersonalPrefix) {
3513 currentTopFolder = MWFVFS.PersonalPrefix;
3514 currentTopFolderFSEntry = currentFolderFSEntry = GetPersonalFSEntry ();
3516 if (folder == MWFVFS.MyComputerPersonalPrefix) {
3517 currentTopFolder = MWFVFS.MyComputerPersonalPrefix;
3518 currentTopFolderFSEntry = currentFolderFSEntry = GetMyComputerPersonalFSEntry ();
3520 if (folder == MWFVFS.RecentlyUsedPrefix) {
3521 currentTopFolder = MWFVFS.RecentlyUsedPrefix;
3522 currentTopFolderFSEntry = currentFolderFSEntry = GetRecentlyUsedFSEntry ();
3524 if (folder == MWFVFS.MyComputerPrefix) {
3525 currentTopFolder = MWFVFS.MyComputerPrefix;
3526 currentTopFolderFSEntry = currentFolderFSEntry = GetMyComputerFSEntry ();
3528 if (folder == MWFVFS.MyNetworkPrefix) {
3529 currentTopFolder = MWFVFS.MyNetworkPrefix;
3530 currentTopFolderFSEntry = currentFolderFSEntry = GetMyNetworkFSEntry ();
3534 foreach (DictionaryEntry entry in MWFVFS.MyComputerDevicesPrefix) {
3535 FSEntry fsEntry = entry.Value as FSEntry;
3536 if (folder == fsEntry.FullName) {
3537 currentTopFolder = entry.Key as string;
3538 currentTopFolderFSEntry = currentFolderFSEntry = fsEntry;
3545 currentFolderFSEntry = GetDirectoryFSEntry (new DirectoryInfo (folder), currentTopFolderFSEntry);
3549 return currentFolderFSEntry;
3552 public string GetParent ()
3554 return currentFolderFSEntry.Parent;
3557 // directories_out and files_out contain FSEntry objects
3558 public void GetFolderContent (StringCollection filters, out ArrayList directories_out, out ArrayList files_out)
3560 directories_out = new ArrayList ();
3561 files_out = new ArrayList ();
3563 if (currentFolderFSEntry.FullName == MWFVFS.DesktopPrefix) {
3564 FSEntry personalFSEntry = GetPersonalFSEntry ();
3566 directories_out.Add (personalFSEntry);
3568 FSEntry myComputerFSEntry = GetMyComputerFSEntry ();
3570 directories_out.Add (myComputerFSEntry);
3572 FSEntry myNetworkFSEntry = GetMyNetworkFSEntry ();
3574 directories_out.Add (myNetworkFSEntry);
3576 ArrayList d_out = null;
3577 ArrayList f_out = null;
3578 GetNormalFolderContent (ThemeEngine.Current.Places (UIIcon.PlacesDesktop), filters, out d_out, out f_out);
3579 directories_out.AddRange (d_out);
3580 files_out.AddRange (f_out);
3583 if (currentFolderFSEntry.FullName == MWFVFS.RecentlyUsedPrefix) {
3584 files_out = GetRecentlyUsedFiles ();
3586 if (currentFolderFSEntry.FullName == MWFVFS.MyComputerPrefix) {
3587 directories_out.AddRange (GetMyComputerContent ());
3589 if (currentFolderFSEntry.FullName == MWFVFS.PersonalPrefix || currentFolderFSEntry.FullName == MWFVFS.MyComputerPersonalPrefix) {
3590 ArrayList d_out = null;
3591 ArrayList f_out = null;
3592 GetNormalFolderContent (ThemeEngine.Current.Places (UIIcon.PlacesPersonal), filters, out d_out, out f_out);
3593 directories_out.AddRange (d_out);
3594 files_out.AddRange (f_out);
3596 if (currentFolderFSEntry.FullName == MWFVFS.MyNetworkPrefix) {
3597 directories_out.AddRange (GetMyNetworkContent ());
3599 GetNormalFolderContent (currentFolderFSEntry.FullName, filters, out directories_out, out files_out);
3603 public ArrayList GetFoldersOnly ()
3605 ArrayList directories_out = new ArrayList ();
3607 if (currentFolderFSEntry.FullName == MWFVFS.DesktopPrefix) {
3608 FSEntry personalFSEntry = GetPersonalFSEntry ();
3610 directories_out.Add (personalFSEntry);
3612 FSEntry myComputerFSEntry = GetMyComputerFSEntry ();
3614 directories_out.Add (myComputerFSEntry);
3616 FSEntry myNetworkFSEntry = GetMyNetworkFSEntry ();
3618 directories_out.Add (myNetworkFSEntry);
3620 ArrayList d_out = GetNormalFolders (ThemeEngine.Current.Places (UIIcon.PlacesDesktop));
3621 directories_out.AddRange (d_out);
3624 if (currentFolderFSEntry.FullName == MWFVFS.RecentlyUsedPrefix) {
3625 //files_out = GetRecentlyUsedFiles ();
3627 if (currentFolderFSEntry.FullName == MWFVFS.MyComputerPrefix) {
3628 directories_out.AddRange (GetMyComputerContent ());
3630 if (currentFolderFSEntry.FullName == MWFVFS.PersonalPrefix || currentFolderFSEntry.FullName == MWFVFS.MyComputerPersonalPrefix) {
3631 ArrayList d_out = GetNormalFolders (ThemeEngine.Current.Places (UIIcon.PlacesPersonal));
3632 directories_out.AddRange (d_out);
3634 if (currentFolderFSEntry.FullName == MWFVFS.MyNetworkPrefix) {
3635 directories_out.AddRange (GetMyNetworkContent ());
3637 directories_out = GetNormalFolders (currentFolderFSEntry.FullName);
3639 return directories_out;
3642 protected void GetNormalFolderContent (string from_folder, StringCollection filters, out ArrayList directories_out, out ArrayList files_out)
3644 DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
3646 directories_out = new ArrayList ();
3648 DirectoryInfo[] dirs = null;
3651 dirs = dirinfo.GetDirectories ();
3652 } catch (Exception) {}
3655 for (int i = 0; i < dirs.Length; i++) {
3656 directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
3659 directories_out.Sort (fsEntryComparer);
3661 files_out = new ArrayList ();
3663 ArrayList files = new ArrayList ();
3666 if (filters == null) {
3667 files.AddRange (dirinfo.GetFiles ());
3669 foreach (string s in filters)
3670 files.AddRange (dirinfo.GetFiles (s));
3672 files.Sort (fileInfoComparer);
3674 } catch (Exception) {}
3676 for (int i = 0; i < files.Count; i++) {
3677 FSEntry fs = GetFileFSEntry (files [i] as FileInfo);
3683 protected ArrayList GetNormalFolders (string from_folder)
3685 DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
3687 ArrayList directories_out = new ArrayList ();
3689 DirectoryInfo[] dirs = null;
3692 dirs = dirinfo.GetDirectories ();
3693 } catch (Exception) {}
3696 for (int i = 0; i < dirs.Length; i++) {
3697 directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
3700 return directories_out;
3703 protected virtual FSEntry GetDirectoryFSEntry (DirectoryInfo dirinfo, FSEntry topFolderFSEntry)
3705 FSEntry fs = new FSEntry ();
3707 fs.Attributes = dirinfo.Attributes;
3708 fs.FullName = dirinfo.FullName;
3709 fs.Name = dirinfo.Name;
3710 fs.MainTopNode = topFolderFSEntry;
3711 fs.FileType = FSEntry.FSEntryType.Directory;
3712 fs.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
3713 fs.LastAccessTime = dirinfo.LastAccessTime;
3718 protected virtual FSEntry GetFileFSEntry (FileInfo fileinfo)
3720 // *sigh* FileInfo gives us no usable information for links to directories
3722 if ((fileinfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
3725 FSEntry fs = new FSEntry ();
3727 fs.Attributes = fileinfo.Attributes;
3728 fs.FullName = fileinfo.FullName;
3729 fs.Name = fileinfo.Name;
3730 fs.FileType = FSEntry.FSEntryType.File;
3731 fs.IconIndex = MimeIconEngine.GetIconIndexForFile (fileinfo.FullName);
3732 fs.FileSize = fileinfo.Length;
3733 fs.LastAccessTime = fileinfo.LastAccessTime;
3738 internal class FileInfoComparer : IComparer
3740 public int Compare (object fileInfo1, object fileInfo2)
3742 return String.Compare (((FileInfo)fileInfo1).Name, ((FileInfo)fileInfo2).Name);
3746 internal class FSEntryComparer : IComparer
3748 public int Compare (object fileInfo1, object fileInfo2)
3750 return String.Compare (((FSEntry)fileInfo1).Name, ((FSEntry)fileInfo2).Name);
3754 protected abstract FSEntry GetDesktopFSEntry ();
3756 protected abstract FSEntry GetRecentlyUsedFSEntry ();
3758 protected abstract FSEntry GetPersonalFSEntry ();
3760 protected abstract FSEntry GetMyComputerPersonalFSEntry ();
3762 protected abstract FSEntry GetMyComputerFSEntry ();
3764 protected abstract FSEntry GetMyNetworkFSEntry ();
3766 public abstract void WriteRecentlyUsedFiles (string fileToAdd);
3768 public abstract ArrayList GetRecentlyUsedFiles ();
3770 public abstract ArrayList GetMyComputerContent ();
3772 public abstract ArrayList GetMyNetworkContent ();
3776 #region UnixFileSystem
3777 internal class UnixFileSystem : FileSystem
3779 private MasterMount masterMount = new MasterMount ();
3780 private FSEntry desktopFSEntry = null;
3781 private FSEntry recentlyusedFSEntry = null;
3782 private FSEntry personalFSEntry = null;
3783 private FSEntry mycomputerpersonalFSEntry = null;
3784 private FSEntry mycomputerFSEntry = null;
3785 private FSEntry mynetworkFSEntry = null;
3787 private string personal_folder;
3788 private string recently_used_path;
3789 private string full_kde_recent_document_dir;
3791 public UnixFileSystem ()
3793 personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
3794 recently_used_path = Path.Combine (personal_folder, ".recently-used");
3796 full_kde_recent_document_dir = personal_folder + "/.kde/share/apps/RecentDocuments";
3798 desktopFSEntry = new FSEntry ();
3800 desktopFSEntry.Attributes = FileAttributes.Directory;
3801 desktopFSEntry.FullName = MWFVFS.DesktopPrefix;
3802 desktopFSEntry.Name = "Desktop";
3803 desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
3804 desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
3805 desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
3806 desktopFSEntry.LastAccessTime = DateTime.Now;
3808 recentlyusedFSEntry = new FSEntry ();
3810 recentlyusedFSEntry.Attributes = FileAttributes.Directory;
3811 recentlyusedFSEntry.FullName = MWFVFS.RecentlyUsedPrefix;
3812 recentlyusedFSEntry.Name = "Recently Used";
3813 recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directory;
3814 recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
3815 recentlyusedFSEntry.LastAccessTime = DateTime.Now;
3817 personalFSEntry = new FSEntry ();
3819 personalFSEntry.Attributes = FileAttributes.Directory;
3820 personalFSEntry.FullName = MWFVFS.PersonalPrefix;
3821 personalFSEntry.Name = "Personal";
3822 personalFSEntry.MainTopNode = GetDesktopFSEntry ();
3823 personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
3824 personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
3825 personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
3826 personalFSEntry.LastAccessTime = DateTime.Now;
3828 mycomputerpersonalFSEntry = new FSEntry ();
3830 mycomputerpersonalFSEntry.Attributes = FileAttributes.Directory;
3831 mycomputerpersonalFSEntry.FullName = MWFVFS.MyComputerPersonalPrefix;
3832 mycomputerpersonalFSEntry.Name = "Personal";
3833 mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
3834 mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
3835 mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
3836 mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
3837 mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
3839 mycomputerFSEntry = new FSEntry ();
3841 mycomputerFSEntry.Attributes = FileAttributes.Directory;
3842 mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
3843 mycomputerFSEntry.Name = "My Computer";
3844 mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
3845 mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
3846 mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
3847 mycomputerFSEntry.LastAccessTime = DateTime.Now;
3849 mynetworkFSEntry = new FSEntry ();
3851 mynetworkFSEntry.Attributes = FileAttributes.Directory;
3852 mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
3853 mynetworkFSEntry.Name = "My Network";
3854 mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
3855 mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
3856 mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
3857 mynetworkFSEntry.LastAccessTime = DateTime.Now;
3860 public override void WriteRecentlyUsedFiles (string fileToAdd)
3862 if (File.Exists (recently_used_path) && new FileInfo (recently_used_path).Length > 0) {
3863 XmlDocument xml_doc = new XmlDocument ();
3864 xml_doc.Load (recently_used_path);
3866 XmlNode grand_parent_node = xml_doc.SelectSingleNode ("RecentFiles");
3868 if (grand_parent_node != null) {
3869 // create a new element
3870 XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
3872 XmlElement new_child = xml_doc.CreateElement ("URI");
3873 UriBuilder ub = new UriBuilder ();
3874 ub.Path = fileToAdd;
3877 XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
3878 new_child.AppendChild (new_text_child);
3880 new_recent_item_node.AppendChild (new_child);
3882 new_child = xml_doc.CreateElement ("Mime-Type");
3883 new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (fileToAdd));
3884 new_child.AppendChild (new_text_child);
3886 new_recent_item_node.AppendChild (new_child);
3888 new_child = xml_doc.CreateElement ("Timestamp");
3889 long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
3890 new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
3891 new_child.AppendChild (new_text_child);
3893 new_recent_item_node.AppendChild (new_child);
3895 new_child = xml_doc.CreateElement ("Groups");
3897 new_recent_item_node.AppendChild (new_child);
3899 // now search the nodes in grand_parent_node for another instance of the new uri and if found remove it
3900 // so that the new node is the first one
3901 foreach (XmlNode n in grand_parent_node.ChildNodes) {
3902 XmlNode uri_node = n.SelectSingleNode ("URI");
3903 if (uri_node != null) {
3904 XmlNode uri_node_child = uri_node.FirstChild;
3905 if (uri_node_child is XmlText)
3906 if (ub.ToString () == ((XmlText)uri_node_child).Data) {
3907 grand_parent_node.RemoveChild (n);
3913 // prepend the new recent item to the grand parent node list
3914 grand_parent_node.PrependChild (new_recent_item_node);
3916 // limit the # of RecentItems to 10
3917 if (grand_parent_node.ChildNodes.Count > 10) {
3918 while (grand_parent_node.ChildNodes.Count > 10)
3919 grand_parent_node.RemoveChild (grand_parent_node.LastChild);
3923 xml_doc.Save (recently_used_path);
3924 } catch (Exception) {
3928 XmlDocument xml_doc = new XmlDocument ();
3929 xml_doc.AppendChild (xml_doc.CreateXmlDeclaration ("1.0", String.Empty, String.Empty));
3931 XmlElement recentFiles_element = xml_doc.CreateElement ("RecentFiles");
3933 XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
3935 XmlElement new_child = xml_doc.CreateElement ("URI");
3936 UriBuilder ub = new UriBuilder ();
3937 ub.Path = fileToAdd;
3940 XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
3941 new_child.AppendChild (new_text_child);
3943 new_recent_item_node.AppendChild (new_child);
3945 new_child = xml_doc.CreateElement ("Mime-Type");
3946 new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (fileToAdd));
3947 new_child.AppendChild (new_text_child);
3949 new_recent_item_node.AppendChild (new_child);
3951 new_child = xml_doc.CreateElement ("Timestamp");
3952 long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
3953 new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
3954 new_child.AppendChild (new_text_child);
3956 new_recent_item_node.AppendChild (new_child);
3958 new_child = xml_doc.CreateElement ("Groups");
3960 new_recent_item_node.AppendChild (new_child);
3962 recentFiles_element.AppendChild (new_recent_item_node);
3964 xml_doc.AppendChild (recentFiles_element);
3967 xml_doc.Save (recently_used_path);
3968 } catch (Exception) {
3973 // return an ArrayList with FSEntry objects
3974 public override ArrayList GetRecentlyUsedFiles ()
3976 // check for GNOME and KDE
3978 ArrayList files_al = new ArrayList ();
3981 if (File.Exists (recently_used_path)) {
3983 XmlTextReader xtr = new XmlTextReader (recently_used_path);
3984 while (xtr.Read ()) {
3985 if (xtr.NodeType == XmlNodeType.Element && xtr.Name.ToUpper () == "URI") {
3987 Uri uri = new Uri (xtr.Value);
3988 if (!files_al.Contains (uri.LocalPath))
3989 if (File.Exists (uri.LocalPath)) {
3990 FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
3997 } catch (Exception) {
4003 if (Directory.Exists (full_kde_recent_document_dir)) {
4004 string[] files = Directory.GetFiles (full_kde_recent_document_dir, "*.desktop");
4006 foreach (string file_name in files) {
4007 StreamReader sr = new StreamReader (file_name);
4009 string line = sr.ReadLine ();
4011 while (line != null) {
4012 line = line.Trim ();
4014 if (line.StartsWith ("URL=")) {
4015 line = line.Replace ("URL=", String.Empty);
4016 line = line.Replace ("$HOME", personal_folder);
4018 Uri uri = new Uri (line);
4019 if (!files_al.Contains (uri.LocalPath))
4020 if (File.Exists (uri.LocalPath)) {
4021 FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
4028 line = sr.ReadLine ();
4039 // return an ArrayList with FSEntry objects
4040 public override ArrayList GetMyComputerContent ()
4042 ArrayList my_computer_content_arraylist = new ArrayList ();
4044 if (masterMount.ProcMountAvailable) {
4045 masterMount.GetMounts ();
4047 foreach (MasterMount.Mount mount in masterMount.Block_devices) {
4048 FSEntry fsEntry = new FSEntry ();
4049 fsEntry.FileType = FSEntry.FSEntryType.Device;
4051 fsEntry.FullName = mount.mount_point;
4053 fsEntry.Name = "HDD (" + mount.fsType + ", " + mount.device_short + ")";
4055 fsEntry.FsType = mount.fsType;
4056 fsEntry.DeviceShort = mount.device_short;
4058 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
4060 fsEntry.Attributes = FileAttributes.Directory;
4062 fsEntry.MainTopNode = GetMyComputerFSEntry ();
4064 my_computer_content_arraylist.Add (fsEntry);
4066 if (!MWFVFS.MyComputerDevicesPrefix.Contains (fsEntry.FullName + "://"))
4067 MWFVFS.MyComputerDevicesPrefix.Add (fsEntry.FullName + "://", fsEntry);
4070 foreach (MasterMount.Mount mount in masterMount.Removable_devices) {
4071 FSEntry fsEntry = new FSEntry ();
4072 fsEntry.FileType = FSEntry.FSEntryType.RemovableDevice;
4074 fsEntry.FullName = mount.mount_point;
4076 bool is_dvd_cdrom = mount.fsType == MasterMount.FsTypes.usbfs ? false : true;
4077 string type_name = is_dvd_cdrom ? "DVD/CD-Rom" : "USB";
4078 string mime_type = is_dvd_cdrom ? "cdrom/cdrom" : "removable/removable";
4080 fsEntry.Name = type_name +" (" + mount.device_short + ")";
4082 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType (mime_type);
4084 fsEntry.FsType = mount.fsType;
4085 fsEntry.DeviceShort = mount.device_short;
4087 fsEntry.Attributes = FileAttributes.Directory;
4089 fsEntry.MainTopNode = GetMyComputerFSEntry ();
4091 my_computer_content_arraylist.Add (fsEntry);
4093 string contain_string = fsEntry.FullName + "://";
4094 if (!MWFVFS.MyComputerDevicesPrefix.Contains (contain_string))
4095 MWFVFS.MyComputerDevicesPrefix.Add (contain_string, fsEntry);
4099 my_computer_content_arraylist.Add (GetMyComputerPersonalFSEntry ());
4101 return my_computer_content_arraylist;
4104 public override ArrayList GetMyNetworkContent ()
4106 ArrayList fsEntries = new ArrayList ();
4108 foreach (MasterMount.Mount mount in masterMount.Network_devices) {
4109 FSEntry fsEntry = new FSEntry ();
4110 fsEntry.FileType = FSEntry.FSEntryType.Network;
4112 fsEntry.FullName = mount.mount_point;
4114 fsEntry.FsType = mount.fsType;
4115 fsEntry.DeviceShort = mount.device_short;
4117 fsEntry.Name = "Network (" + mount.fsType + ", " + mount.device_short + ")";
4119 switch (mount.fsType) {
4120 case MasterMount.FsTypes.nfs:
4121 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("nfs/nfs");
4123 case MasterMount.FsTypes.smbfs:
4124 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("smb/smb");
4126 case MasterMount.FsTypes.ncpfs:
4127 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
4129 case MasterMount.FsTypes.cifs:
4130 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
4136 fsEntry.Attributes = FileAttributes.Directory;
4138 fsEntry.MainTopNode = GetMyNetworkFSEntry ();
4140 fsEntries.Add (fsEntry);
4145 protected override FSEntry GetDesktopFSEntry ()
4147 return desktopFSEntry;
4150 protected override FSEntry GetRecentlyUsedFSEntry ()
4152 return recentlyusedFSEntry;
4155 protected override FSEntry GetPersonalFSEntry ()
4157 return personalFSEntry;
4160 protected override FSEntry GetMyComputerPersonalFSEntry ()
4162 return mycomputerpersonalFSEntry;
4165 protected override FSEntry GetMyComputerFSEntry ()
4167 return mycomputerFSEntry;
4170 protected override FSEntry GetMyNetworkFSEntry ()
4172 return mynetworkFSEntry;
4177 #region WinFileSystem
4178 internal class WinFileSystem : FileSystem
4180 private FSEntry desktopFSEntry = null;
4181 private FSEntry recentlyusedFSEntry = null;
4182 private FSEntry personalFSEntry = null;
4183 private FSEntry mycomputerpersonalFSEntry = null;
4184 private FSEntry mycomputerFSEntry = null;
4185 private FSEntry mynetworkFSEntry = null;
4187 public WinFileSystem ()
4189 desktopFSEntry = new FSEntry ();
4191 desktopFSEntry.Attributes = FileAttributes.Directory;
4192 desktopFSEntry.FullName = MWFVFS.DesktopPrefix;
4193 desktopFSEntry.Name = "Desktop";
4194 desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
4195 desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
4196 desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
4197 desktopFSEntry.LastAccessTime = DateTime.Now;
4199 recentlyusedFSEntry = new FSEntry ();
4201 recentlyusedFSEntry.Attributes = FileAttributes.Directory;
4202 recentlyusedFSEntry.FullName = MWFVFS.RecentlyUsedPrefix;
4203 recentlyusedFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments);
4204 recentlyusedFSEntry.Name = "Recently Used";
4205 recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directory;
4206 recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
4207 recentlyusedFSEntry.LastAccessTime = DateTime.Now;
4209 personalFSEntry = new FSEntry ();
4211 personalFSEntry.Attributes = FileAttributes.Directory;
4212 personalFSEntry.FullName = MWFVFS.PersonalPrefix;
4213 personalFSEntry.Name = "Personal";
4214 personalFSEntry.MainTopNode = GetDesktopFSEntry ();
4215 personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
4216 personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
4217 personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
4218 personalFSEntry.LastAccessTime = DateTime.Now;
4220 mycomputerpersonalFSEntry = new FSEntry ();
4222 mycomputerpersonalFSEntry.Attributes = FileAttributes.Directory;
4223 mycomputerpersonalFSEntry.FullName = MWFVFS.MyComputerPersonalPrefix;
4224 mycomputerpersonalFSEntry.Name = "Personal";
4225 mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
4226 mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
4227 mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
4228 mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
4229 mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
4231 mycomputerFSEntry = new FSEntry ();
4233 mycomputerFSEntry.Attributes = FileAttributes.Directory;
4234 mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
4235 mycomputerFSEntry.Name = "My Computer";
4236 mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
4237 mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
4238 mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
4239 mycomputerFSEntry.LastAccessTime = DateTime.Now;
4241 mynetworkFSEntry = new FSEntry ();
4243 mynetworkFSEntry.Attributes = FileAttributes.Directory;
4244 mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
4245 mynetworkFSEntry.Name = "My Network";
4246 mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
4247 mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
4248 mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
4249 mynetworkFSEntry.LastAccessTime = DateTime.Now;
4252 public override void WriteRecentlyUsedFiles (string fileToAdd)
4254 // TODO: Implement this method
4255 // use SHAddToRecentDocs ?
4258 public override ArrayList GetRecentlyUsedFiles ()
4260 ArrayList al = new ArrayList ();
4262 DirectoryInfo di = new DirectoryInfo (recentlyusedFSEntry.RealName);
4264 FileInfo[] fileinfos = di.GetFiles ();
4266 foreach (FileInfo fi in fileinfos) {
4267 FSEntry fs = GetFileFSEntry (fi);
4275 public override ArrayList GetMyComputerContent ()
4277 string[] logical_drives = Directory.GetLogicalDrives ();
4279 ArrayList my_computer_content_arraylist = new ArrayList ();
4281 foreach (string drive in logical_drives) {
4282 FSEntry fsEntry = new FSEntry ();
4283 fsEntry.FileType = FSEntry.FSEntryType.Device;
4285 fsEntry.FullName = drive;
4287 fsEntry.Name = drive;
4289 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
4291 fsEntry.Attributes = FileAttributes.Directory;
4293 fsEntry.MainTopNode = GetMyComputerFSEntry ();
4295 my_computer_content_arraylist.Add (fsEntry);
4297 string contain_string = fsEntry.FullName + "://";
4298 if (!MWFVFS.MyComputerDevicesPrefix.Contains (contain_string))
4299 MWFVFS.MyComputerDevicesPrefix.Add (contain_string, fsEntry);
4302 my_computer_content_arraylist.Add (GetMyComputerPersonalFSEntry ());
4304 return my_computer_content_arraylist;
4307 public override ArrayList GetMyNetworkContent ()
4309 // TODO: Implement this method
4310 return new ArrayList ();
4312 protected override FSEntry GetDesktopFSEntry ()
4314 return desktopFSEntry;
4317 protected override FSEntry GetRecentlyUsedFSEntry ()
4319 return recentlyusedFSEntry;
4322 protected override FSEntry GetPersonalFSEntry ()
4324 return personalFSEntry;
4327 protected override FSEntry GetMyComputerPersonalFSEntry ()
4329 return mycomputerpersonalFSEntry;
4332 protected override FSEntry GetMyComputerFSEntry ()
4334 return mycomputerFSEntry;
4337 protected override FSEntry GetMyNetworkFSEntry ()
4339 return mynetworkFSEntry;
4345 internal class FSEntry
4347 public enum FSEntryType
4359 private MasterMount.FsTypes fsType;
4360 private string device_short;
4361 private string fullName;
4362 private string name;
4363 private string realName = null;
4364 private FileAttributes attributes = FileAttributes.Normal;
4365 private long fileSize;
4366 private FSEntryType fileType;
4367 private DateTime lastAccessTime;
4368 private FSEntry mainTopNode = null;
4370 private int iconIndex;
4372 private string parent;
4374 public MasterMount.FsTypes FsType {
4384 public string DeviceShort {
4386 device_short = value;
4390 return device_short;
4394 public string FullName {
4404 public string Name {
4414 public string RealName {
4424 public FileAttributes Attributes {
4434 public long FileSize {
4444 public FSEntryType FileType {
4454 public DateTime LastAccessTime {
4456 lastAccessTime = value;
4460 return lastAccessTime;
4464 public int IconIndex {
4474 public FSEntry MainTopNode {
4476 mainTopNode = value;
4484 public string Parent {
4490 parent = GetParent ();
4496 private string GetParent ()
4498 if (fullName == MWFVFS.PersonalPrefix) {
4499 return MWFVFS.DesktopPrefix;
4501 if (fullName == MWFVFS.MyComputerPersonalPrefix) {
4502 return MWFVFS.MyComputerPrefix;
4504 if (fullName == MWFVFS.MyComputerPrefix) {
4505 return MWFVFS.DesktopPrefix;
4507 if (fullName == MWFVFS.MyNetworkPrefix) {
4508 return MWFVFS.DesktopPrefix;
4510 if (fullName == MWFVFS.DesktopPrefix) {
4513 if (fullName == MWFVFS.RecentlyUsedPrefix) {
4516 foreach (DictionaryEntry entry in MWFVFS.MyComputerDevicesPrefix) {
4517 FSEntry fsEntry = entry.Value as FSEntry;
4518 if (fullName == fsEntry.FullName) {
4519 return fsEntry.MainTopNode.FullName;
4523 DirectoryInfo dirInfo = new DirectoryInfo (fullName);
4525 DirectoryInfo dirInfoParent = dirInfo.Parent;
4527 if (dirInfoParent != null) {
4528 FSEntry fsEntry = MWFVFS.MyComputerDevicesPrefix [dirInfoParent.FullName + "://"] as FSEntry;
4530 if (fsEntry != null) {
4531 return fsEntry.FullName;
4534 if (mainTopNode != null) {
4535 if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesDesktop) &&
4536 mainTopNode.FullName == MWFVFS.DesktopPrefix) {
4537 return mainTopNode.FullName;
4539 if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal) &&
4540 mainTopNode.FullName == MWFVFS.PersonalPrefix) {
4541 return mainTopNode.FullName;
4543 if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal) &&
4544 mainTopNode.FullName == MWFVFS.MyComputerPersonalPrefix) {
4545 return mainTopNode.FullName;
4549 return dirInfoParent.FullName;
4559 // Alexsantas little *nix helper
4560 internal class MasterMount
4563 internal enum FsTypes
4587 internal struct Mount
4589 public string device_or_filesystem;
4590 public string device_short;
4591 public string mount_point;
4592 public FsTypes fsType;
4595 bool proc_mount_available = false;
4597 ArrayList block_devices = new ArrayList ();
4598 ArrayList network_devices = new ArrayList ();
4599 ArrayList removable_devices = new ArrayList ();
4601 private MountComparer mountComparer = new MountComparer ();
4603 public MasterMount ()
4605 // maybe check if the current user can access /proc/mounts
4606 if (XplatUI.RunningOnUnix)
4607 if (File.Exists ("/proc/mounts"))
4608 proc_mount_available = true;
4611 public ArrayList Block_devices {
4613 return block_devices;
4617 public ArrayList Network_devices {
4619 return network_devices;
4623 public ArrayList Removable_devices {
4625 return removable_devices;
4629 public bool ProcMountAvailable {
4631 return proc_mount_available;
4635 public void GetMounts ()
4637 if (!proc_mount_available)
4640 block_devices.Clear ();
4641 network_devices.Clear ();
4642 removable_devices.Clear ();
4645 StreamReader sr = new StreamReader ("/proc/mounts");
4647 string line = sr.ReadLine ();
4649 ArrayList lines = new ArrayList ();
4650 while (line != null) {
4651 if (lines.IndexOf (line) == -1) { // Avoid duplicates
4652 ProcessProcMountLine (line);
4655 line = sr.ReadLine ();
4660 block_devices.Sort (mountComparer);
4661 network_devices.Sort (mountComparer);
4662 removable_devices.Sort (mountComparer);
4668 private void ProcessProcMountLine (string line)
4670 string[] split = line.Split (new char [] {' '});
4672 if (split != null && split.Length > 0) {
4673 Mount mount = new Mount ();
4675 if (split [0].StartsWith ("/dev/"))
4676 mount.device_short = split [0].Replace ("/dev/", String.Empty);
4678 mount.device_short = split [0];
4680 mount.device_or_filesystem = split [0];
4681 mount.mount_point = split [1];
4683 // TODO: other removable devices, floppy
4687 if (split [2] == "nfs") {
4688 mount.fsType = FsTypes.nfs;
4689 network_devices.Add (mount);
4690 } else if (split [2] == "smbfs") {
4691 mount.fsType = FsTypes.smbfs;
4692 network_devices.Add (mount);
4693 } else if (split [2] == "cifs") {
4694 mount.fsType = FsTypes.cifs;
4695 network_devices.Add (mount);
4696 } else if (split [2] == "ncpfs") {
4697 mount.fsType = FsTypes.ncpfs;
4698 network_devices.Add (mount);
4700 } else if (split [2] == "iso9660") { //cdrom
4701 mount.fsType = FsTypes.iso9660;
4702 removable_devices.Add (mount);
4703 } else if (split [2] == "usbfs") { //usb ? not tested
4704 mount.fsType = FsTypes.usbfs;
4705 removable_devices.Add (mount);
4707 } else if (split [0].StartsWith ("/")) { //block devices
4708 if (split [1].StartsWith ("/dev/")) // root static, do not add
4711 if (split [2] == "ext2")
4712 mount.fsType = FsTypes.ext2;
4713 else if (split [2] == "ext3")
4714 mount.fsType = FsTypes.ext3;
4715 else if (split [2] == "reiserfs")
4716 mount.fsType = FsTypes.reiserfs;
4717 else if (split [2] == "xfs")
4718 mount.fsType = FsTypes.xfs;
4719 else if (split [2] == "vfat")
4720 mount.fsType = FsTypes.vfat;
4721 else if (split [2] == "ntfs")
4722 mount.fsType = FsTypes.ntfs;
4723 else if (split [2] == "msdos")
4724 mount.fsType = FsTypes.msdos;
4725 else if (split [2] == "umsdos")
4726 mount.fsType = FsTypes.umsdos;
4727 else if (split [2] == "hpfs")
4728 mount.fsType = FsTypes.hpfs;
4729 else if (split [2] == "minix")
4730 mount.fsType = FsTypes.minix;
4731 else if (split [2] == "jfs")
4732 mount.fsType = FsTypes.jfs;
4734 block_devices.Add (mount);
4739 public class MountComparer : IComparer
4741 public int Compare (object mount1, object mount2)
4743 return String.Compare (((Mount)mount1).device_short, ((Mount)mount2).device_short);
4750 // easy to use class to store and read internal MWF config settings.
4751 // the config values are stored in the users home dir as a hidden xml file called "mwf_config".
4752 // currently supports int, string, byte, color and arrays (including byte arrays)
4753 // don't forget, when you read a value you still have to cast this value.
4756 // MWFConfig.SetValue ("SomeClass", "What", value);
4757 // object o = MWFConfig.GetValue ("SomeClass", "What");
4761 // string[] configFileNames = (string[])MWFConfig.GetValue ("FileDialog", "FileNames");
4762 // MWFConfig.SetValue ("FileDialog", "LastFolder", "/home/user");
4764 internal class MWFConfig
4766 private static MWFConfigInstance Instance = new MWFConfigInstance ();
4768 private static object lock_object = new object();
4770 public static object GetValue (string class_name, string value_name)
4772 lock (lock_object) {
4773 return Instance.GetValue (class_name, value_name);
4777 public static void SetValue (string class_name, string value_name, object value)
4779 lock (lock_object) {
4780 Instance.SetValue (class_name, value_name, value);
4784 public static void Flush ()
4786 lock (lock_object) {
4791 public static void RemoveClass (string class_name)
4793 lock (lock_object) {
4794 Instance.RemoveClass (class_name);
4798 public static void RemoveClassValue (string class_name, string value_name)
4800 lock (lock_object) {
4801 Instance.RemoveClassValue (class_name, value_name);
4805 public static void RemoveAllClassValues (string class_name)
4807 lock (lock_object) {
4808 Instance.RemoveAllClassValues (class_name);
4812 internal class MWFConfigInstance
4814 Hashtable classes_hashtable = new Hashtable ();
4815 static string full_file_name;
4816 static string default_file_name;
4817 readonly string configName = "MWFConfig";
4819 static MWFConfigInstance ()
4821 string b = "mwf_config";
4822 string dir = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
4824 if (XplatUI.RunningOnUnix) {
4825 dir = Path.Combine (dir, ".mono");
4827 Directory.CreateDirectory (dir);
4831 default_file_name = Path.Combine (dir, b);
4832 full_file_name = default_file_name;
4835 public MWFConfigInstance ()
4837 Open (default_file_name);
4841 public MWFConfigInstance (string filename)
4843 string path = Path.GetDirectoryName (filename);
4844 if (path == null || path == String.Empty) {
4845 path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
4847 full_file_name = Path.Combine (path, filename);
4849 full_file_name = filename;
4851 Open (full_file_name);
4854 ~MWFConfigInstance ()
4859 public object GetValue (string class_name, string value_name)
4861 ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
4863 if (class_entry != null)
4864 return class_entry.GetValue (value_name);
4869 public void SetValue (string class_name, string value_name, object value)
4871 ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
4873 if (class_entry == null) {
4874 class_entry = new ClassEntry ();
4875 class_entry.ClassName = class_name;
4876 classes_hashtable [class_name] = class_entry;
4879 class_entry.SetValue (value_name, value);
4882 private void Open (string filename)
4885 XmlTextReader xtr = new XmlTextReader (filename);
4890 } catch (Exception) {
4894 public void Flush ()
4897 XmlTextWriter xtw = new XmlTextWriter (full_file_name, null);
4898 xtw.Formatting = Formatting.Indented;
4904 if (!XplatUI.RunningOnUnix)
4905 File.SetAttributes (full_file_name, FileAttributes.Hidden);
4906 } catch (Exception){
4910 public void RemoveClass (string class_name)
4912 ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
4914 if (class_entry != null) {
4915 class_entry.RemoveAllClassValues ();
4917 classes_hashtable.Remove (class_name);
4921 public void RemoveClassValue (string class_name, string value_name)
4923 ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
4925 if (class_entry != null) {
4926 class_entry.RemoveClassValue (value_name);
4930 public void RemoveAllClassValues (string class_name)
4932 ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
4934 if (class_entry != null) {
4935 class_entry.RemoveAllClassValues ();
4939 private void ReadConfig (XmlTextReader xtr)
4941 if (!CheckForMWFConfig (xtr))
4944 while (xtr.Read ()) {
4945 switch (xtr.NodeType) {
4946 case XmlNodeType.Element:
4947 ClassEntry class_entry = classes_hashtable [xtr.Name] as ClassEntry;
4949 if (class_entry == null) {
4950 class_entry = new ClassEntry ();
4951 class_entry.ClassName = xtr.Name;
4952 classes_hashtable [xtr.Name] = class_entry;
4955 class_entry.ReadXml (xtr);
4961 private bool CheckForMWFConfig (XmlTextReader xtr)
4964 if (xtr.NodeType == XmlNodeType.Element) {
4965 if (xtr.Name == configName)
4973 private void WriteConfig (XmlTextWriter xtw)
4975 if (classes_hashtable.Count == 0)
4978 xtw.WriteStartElement (configName);
4979 foreach (DictionaryEntry entry in classes_hashtable) {
4980 ClassEntry class_entry = entry.Value as ClassEntry;
4982 class_entry.WriteXml (xtw);
4984 xtw.WriteEndElement ();
4987 internal class ClassEntry
4989 private Hashtable classvalues_hashtable = new Hashtable ();
4990 private string className;
4992 public string ClassName {
5002 public void SetValue (string value_name, object value)
5004 ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
5006 if (class_value == null) {
5007 class_value = new ClassValue ();
5008 class_value.Name = value_name;
5009 classvalues_hashtable [value_name] = class_value;
5012 class_value.SetValue (value);
5015 public object GetValue (string value_name)
5017 ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
5019 if (class_value == null) {
5023 return class_value.GetValue ();
5026 public void RemoveAllClassValues ()
5028 classvalues_hashtable.Clear ();
5031 public void RemoveClassValue (string value_name)
5033 ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
5035 if (class_value != null) {
5036 classvalues_hashtable.Remove (value_name);
5040 public void ReadXml (XmlTextReader xtr)
5042 while (xtr.Read ()) {
5043 switch (xtr.NodeType) {
5044 case XmlNodeType.Element:
5045 string name = xtr.GetAttribute ("name");
5047 ClassValue class_value = classvalues_hashtable [name] as ClassValue;
5049 if (class_value == null) {
5050 class_value = new ClassValue ();
5051 class_value.Name = name;
5052 classvalues_hashtable [name] = class_value;
5055 class_value.ReadXml (xtr);
5058 case XmlNodeType.EndElement:
5064 public void WriteXml (XmlTextWriter xtw)
5066 if (classvalues_hashtable.Count == 0)
5069 xtw.WriteStartElement (className);
5071 foreach (DictionaryEntry entry in classvalues_hashtable) {
5072 ClassValue class_value = entry.Value as ClassValue;
5074 class_value.WriteXml (xtw);
5077 xtw.WriteEndElement ();
5081 internal class ClassValue
5083 private object value;
5084 private string name;
5086 public string Name {
5096 public void SetValue (object value)
5100 public object GetValue ()
5105 public void ReadXml (XmlTextReader xtr)
5108 string single_value;
5110 type = xtr.GetAttribute ("type");
5112 if (type == "byte_array" || type.IndexOf ("-array") == -1) {
5113 single_value = xtr.ReadString ();
5115 if (type == "string") {
5116 value = single_value;
5118 if (type == "int") {
5119 value = Int32.Parse (single_value);
5121 if (type == "byte") {
5122 value = Byte.Parse (single_value);
5124 if (type == "color") {
5125 int color = Int32.Parse (single_value);
5126 value = Color.FromArgb (color);
5128 if (type == "byte-array") {
5129 byte[] b_array = Convert.FromBase64String (single_value);
5133 ReadXmlArrayValues (xtr, type);
5137 private void ReadXmlArrayValues (XmlTextReader xtr, string type)
5139 ArrayList al = new ArrayList ();
5141 while (xtr.Read ()) {
5142 switch (xtr.NodeType) {
5143 case XmlNodeType.Element:
5144 string single_value = xtr.ReadString ();
5146 if (type == "int-array") {
5147 int int_val = Int32.Parse (single_value);
5150 if (type == "string-array") {
5151 string str_val = single_value;
5156 case XmlNodeType.EndElement:
5157 if (xtr.Name == "value") {
5158 if (type == "int-array") {
5159 value = al.ToArray (typeof(int));
5161 if (type == "string-array") {
5162 value = al.ToArray (typeof(string));
5171 public void WriteXml (XmlTextWriter xtw)
5173 xtw.WriteStartElement ("value");
5174 xtw.WriteAttributeString ("name", name);
5175 if (value is Array) {
5176 WriteArrayContent (xtw);
5178 WriteSingleContent (xtw);
5180 xtw.WriteEndElement ();
5183 private void WriteSingleContent (XmlTextWriter xtw)
5185 string type_string = String.Empty;
5187 if (value is string)
5188 type_string = "string";
5191 type_string = "int";
5194 type_string = "byte";
5197 type_string = "color";
5199 xtw.WriteAttributeString ("type", type_string);
5202 xtw.WriteString (((Color)value).ToArgb ().ToString ());
5204 xtw.WriteString (value.ToString ());
5207 private void WriteArrayContent (XmlTextWriter xtw)
5209 string type_string = String.Empty;
5210 string type_name = String.Empty;
5212 if (value is string[]) {
5213 type_string = "string-array";
5214 type_name = "string";
5216 if (value is int[]) {
5217 type_string = "int-array";
5220 if (value is byte[]) {
5221 type_string = "byte-array";
5225 xtw.WriteAttributeString ("type", type_string);
5227 if (type_string != "byte-array") {
5228 Array array = value as Array;
5230 foreach (object o in array) {
5231 xtw.WriteStartElement (type_name);
5232 xtw.WriteString (o.ToString ());
5233 xtw.WriteEndElement ();
5236 byte[] b_array = value as byte [];
5238 xtw.WriteString (Convert.ToBase64String (b_array, 0, b_array.Length));