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 {
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.Width);
1304 MWFConfig.SetValue (filedialog_string, height_string, form.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.focusButton = 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);
1679 public string CurrentFolder {
1681 string currentPath = value;
1682 if (currentPath == MWFVFS.RecentlyUsedPrefix) {
1683 if (lastPopupButton != recentlyusedButton) {
1684 if (lastPopupButton != null)
1685 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1686 recentlyusedButton.ButtonState = PopupButton.PopupButtonState.Down;
1687 lastPopupButton = recentlyusedButton;
1690 if (currentPath == MWFVFS.DesktopPrefix) {
1691 if (lastPopupButton != desktopButton) {
1692 if (lastPopupButton != null)
1693 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1694 desktopButton.ButtonState = PopupButton.PopupButtonState.Down;
1695 lastPopupButton = desktopButton;
1698 if (currentPath == MWFVFS.PersonalPrefix) {
1699 if (lastPopupButton != personalButton) {
1700 if (lastPopupButton != null)
1701 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1702 personalButton.ButtonState = PopupButton.PopupButtonState.Down;
1703 lastPopupButton = personalButton;
1706 if (currentPath == MWFVFS.MyComputerPrefix) {
1707 if (lastPopupButton != mycomputerButton) {
1708 if (lastPopupButton != null)
1709 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1710 mycomputerButton.ButtonState = PopupButton.PopupButtonState.Down;
1711 lastPopupButton = mycomputerButton;
1714 if (currentPath == MWFVFS.MyNetworkPrefix) {
1715 if (lastPopupButton != networkButton) {
1716 if (lastPopupButton != null)
1717 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1718 networkButton.ButtonState = PopupButton.PopupButtonState.Down;
1719 lastPopupButton = networkButton;
1722 if (lastPopupButton != null) {
1723 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1724 lastPopupButton = null;
1733 protected override void OnGotFocus (EventArgs e)
1735 if (lastPopupButton != recentlyusedButton) {
1736 recentlyusedButton.ButtonState = PopupButton.PopupButtonState.Up;
1737 focusButton = recentlyusedButton;
1739 currentFocusIndex = 0;
1741 base.OnGotFocus (e);
1744 protected override void OnLostFocus (EventArgs e)
1746 if (focusButton != null && focusButton.ButtonState != PopupButton.PopupButtonState.Down)
1747 focusButton.ButtonState = PopupButton.PopupButtonState.Normal;
1748 base.OnLostFocus (e);
1751 protected override bool IsInputKey (Keys key)
1761 return base.IsInputKey (key);
1764 private void Key_Down (object sender, KeyEventArgs e)
1766 bool update_focus = false;
1768 if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Up) {
1769 currentFocusIndex --;
1771 if (currentFocusIndex < 0)
1772 currentFocusIndex = Controls.Count - 1;
1774 update_focus = true;
1776 if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right) {
1777 currentFocusIndex++;
1779 if (currentFocusIndex == Controls.Count)
1780 currentFocusIndex = 0;
1782 update_focus = true;
1784 if (e.KeyCode == Keys.Enter) {
1785 focusButton.ButtonState = PopupButton.PopupButtonState.Down;
1786 OnClickButton (focusButton, EventArgs.Empty);
1790 PopupButton newfocusButton = Controls [currentFocusIndex] as PopupButton;
1791 if (focusButton != null && focusButton.ButtonState != PopupButton.PopupButtonState.Down)
1792 focusButton.ButtonState = PopupButton.PopupButtonState.Normal;
1793 if (newfocusButton.ButtonState != PopupButton.PopupButtonState.Down)
1794 newfocusButton.ButtonState = PopupButton.PopupButtonState.Up;
1795 focusButton = newfocusButton;
1801 static object PDirectoryChangedEvent = new object ();
1803 public event EventHandler DirectoryChanged {
1804 add { Events.AddHandler (PDirectoryChangedEvent, value); }
1805 remove { Events.RemoveHandler (PDirectoryChangedEvent, value); }
1811 internal class DirComboBox : ComboBox, IUpdateFolder
1813 #region DirComboBoxItem
1814 internal class DirComboBoxItem
1816 private int imageIndex;
1817 private string name;
1818 private string path;
1820 private ImageList imageList;
1822 public DirComboBoxItem (ImageList imageList, int imageIndex, string name, string path, int xPos)
1824 this.imageList = imageList;
1825 this.imageIndex = imageIndex;
1831 public int ImageIndex {
1837 public string Name {
1843 public string Path {
1855 public ImageList ImageList {
1865 #region UIA Framework Members
1866 public override string ToString ()
1875 private ImageList imageList = new ImageList();
1877 private string currentPath;
1879 private Stack folderStack = new Stack();
1881 private static readonly int indent = 6;
1883 private DirComboBoxItem recentlyUsedDirComboboxItem;
1884 private DirComboBoxItem desktopDirComboboxItem;
1885 private DirComboBoxItem personalDirComboboxItem;
1886 private DirComboBoxItem myComputerDirComboboxItem;
1887 private DirComboBoxItem networkDirComboboxItem;
1889 private ArrayList myComputerItems = new ArrayList ();
1891 private DirComboBoxItem mainParentDirComboBoxItem = null;
1892 private DirComboBoxItem real_parent = null;
1896 public DirComboBox (MWFVFS vfs)
1902 DrawMode = DrawMode.OwnerDrawFixed;
1904 imageList.ColorDepth = ColorDepth.Depth32Bit;
1905 imageList.ImageSize = new Size (16, 16);
1906 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 16));
1907 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 16));
1908 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 16));
1909 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 16));
1910 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 16));
1911 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.NormalFolder, 16));
1912 imageList.TransparentColor = Color.Transparent;
1914 recentlyUsedDirComboboxItem = new DirComboBoxItem (imageList, 0, "Recently used", MWFVFS.RecentlyUsedPrefix, 0);
1915 desktopDirComboboxItem = new DirComboBoxItem (imageList, 1, "Desktop", MWFVFS.DesktopPrefix, 0);
1916 personalDirComboboxItem = new DirComboBoxItem (imageList, 2, "Personal folder", MWFVFS.PersonalPrefix, indent);
1917 myComputerDirComboboxItem = new DirComboBoxItem (imageList, 3, "My Computer", MWFVFS.MyComputerPrefix, indent);
1918 networkDirComboboxItem = new DirComboBoxItem (imageList, 4, "My Network", MWFVFS.MyNetworkPrefix, indent);
1920 ArrayList al = this.vfs.GetMyComputerContent ();
1922 foreach (FSEntry fsEntry in al) {
1923 myComputerItems.Add (new DirComboBoxItem (MimeIconEngine.LargeIcons, fsEntry.IconIndex, fsEntry.Name, fsEntry.FullName, indent * 2));
1929 mainParentDirComboBoxItem = myComputerDirComboboxItem;
1931 ResumeLayout (false);
1934 public string CurrentFolder {
1936 currentPath = value;
1945 private void CreateComboList ()
1948 DirComboBoxItem selection = null;
1950 if (currentPath == MWFVFS.RecentlyUsedPrefix) {
1951 mainParentDirComboBoxItem = recentlyUsedDirComboboxItem;
1952 selection = recentlyUsedDirComboboxItem;
1953 } else if (currentPath == MWFVFS.DesktopPrefix) {
1954 selection = desktopDirComboboxItem;
1955 mainParentDirComboBoxItem = desktopDirComboboxItem;
1956 } else if (currentPath == MWFVFS.PersonalPrefix) {
1957 selection = personalDirComboboxItem;
1958 mainParentDirComboBoxItem = personalDirComboboxItem;
1959 } else if (currentPath == MWFVFS.MyComputerPrefix) {
1960 selection = myComputerDirComboboxItem;
1961 mainParentDirComboBoxItem = myComputerDirComboboxItem;
1962 } else if (currentPath == MWFVFS.MyNetworkPrefix) {
1963 selection = networkDirComboboxItem;
1964 mainParentDirComboBoxItem = networkDirComboboxItem;
1966 foreach (DirComboBoxItem dci in myComputerItems) {
1967 if (dci.Path == currentPath) {
1968 mainParentDirComboBoxItem = selection = dci;
1978 Items.Add (recentlyUsedDirComboboxItem);
1979 Items.Add (desktopDirComboboxItem);
1980 Items.Add (personalDirComboboxItem);
1981 Items.Add (myComputerDirComboboxItem);
1982 Items.AddRange (myComputerItems);
1983 Items.Add (networkDirComboboxItem);
1985 if (selection == null)
1986 real_parent = CreateFolderStack ();
1988 if (real_parent != null) {
1989 int local_indent = 0;
1991 if (real_parent == desktopDirComboboxItem)
1994 if (real_parent == personalDirComboboxItem || real_parent == networkDirComboboxItem)
1999 selection = AppendToParent (local_indent, real_parent);
2004 if (selection != null)
2005 SelectedItem = selection;
2008 private DirComboBoxItem CreateFolderStack ()
2010 folderStack.Clear ();
2012 DirectoryInfo di = new DirectoryInfo (currentPath);
2014 folderStack.Push (di);
2016 bool ignoreCase = !XplatUI.RunningOnUnix;
2018 while (di.Parent != null) {
2021 if (mainParentDirComboBoxItem != personalDirComboboxItem && string.Compare (di.FullName, ThemeEngine.Current.Places (UIIcon.PlacesDesktop), ignoreCase) == 0)
2022 return desktopDirComboboxItem;
2024 if (mainParentDirComboBoxItem == personalDirComboboxItem) {
2025 if (string.Compare (di.FullName, ThemeEngine.Current.Places (UIIcon.PlacesPersonal), ignoreCase) == 0)
2026 return personalDirComboboxItem;
2028 foreach (DirComboBoxItem dci in myComputerItems) {
2029 if (string.Compare (dci.Path, di.FullName, ignoreCase) == 0) {
2034 folderStack.Push (di);
2040 private DirComboBoxItem AppendToParent (int nr_indents, DirComboBoxItem parentDirComboBoxItem)
2042 DirComboBoxItem selection = null;
2044 int index = Items.IndexOf (parentDirComboBoxItem) + 1;
2046 int xPos = indent * nr_indents;
2048 while (folderStack.Count != 0) {
2049 DirectoryInfo dii = folderStack.Pop () as DirectoryInfo;
2051 DirComboBoxItem dci = new DirComboBoxItem (imageList, 5, dii.Name, dii.FullName, xPos);
2053 Items.Insert (index, dci);
2062 protected override void OnDrawItem (DrawItemEventArgs e)
2067 DirComboBoxItem dcbi = Items [e.Index] as DirComboBoxItem;
2069 Bitmap bmp = new Bitmap (e.Bounds.Width, e.Bounds.Height, e.Graphics);
2070 Graphics gr = Graphics.FromImage (bmp);
2072 Color backColor = e.BackColor;
2073 Color foreColor = e.ForeColor;
2075 int xPos = dcbi.XPos;
2077 if ((e.State & DrawItemState.ComboBoxEdit) != 0)
2080 gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (backColor),
2081 new Rectangle (0, 0, bmp.Width, bmp.Height));
2083 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected &&
2084 (!DroppedDown || (e.State & DrawItemState.ComboBoxEdit) != DrawItemState.ComboBoxEdit)) {
2085 foreColor = ThemeEngine.Current.ColorHighlightText;
2087 int w = (int) gr.MeasureString (dcbi.Name, e.Font).Width;
2089 gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ThemeEngine.Current.ColorHighlight),
2090 new Rectangle (xPos + 23, 1, w + 3, e.Bounds.Height - 2));
2091 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
2092 ControlPaint.DrawFocusRectangle (gr, new Rectangle (xPos + 22, 0, w + 5,
2093 e.Bounds.Height), foreColor, ThemeEngine.Current.ColorHighlight);
2097 gr.DrawString (dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush (foreColor), new Point (24 + xPos, (bmp.Height - e.Font.Height) / 2));
2098 gr.DrawImage (dcbi.ImageList.Images [dcbi.ImageIndex], new Rectangle (new Point (xPos + 2, 0), new Size (16, 16)));
2100 e.Graphics.DrawImage (bmp, e.Bounds.X, e.Bounds.Y);
2105 protected override void OnSelectedIndexChanged (EventArgs e)
2107 if (Items.Count > 0) {
2108 DirComboBoxItem dcbi = Items [SelectedIndex] as DirComboBoxItem;
2110 currentPath = dcbi.Path;
2114 protected override void OnSelectionChangeCommitted (EventArgs e)
2116 EventHandler eh = (EventHandler)(Events [CDirectoryChangedEvent]);
2118 eh (this, EventArgs.Empty);
2121 static object CDirectoryChangedEvent = new object ();
2123 public event EventHandler DirectoryChanged {
2124 add { Events.AddHandler (CDirectoryChangedEvent, value); }
2125 remove { Events.RemoveHandler (CDirectoryChangedEvent, value); }
2130 #region FilterStruct
2131 internal struct FilterStruct
2133 public string filterName;
2134 public StringCollection filters;
2136 public FilterStruct (string filterName, string filter)
2138 this.filterName = filterName;
2140 filters = new StringCollection ();
2142 SplitFilters (filter);
2145 private void SplitFilters (string filter)
2147 string[] split = filter.Split (new char [] {';'});
2148 foreach (string s in split) {
2149 filters.Add (s.Trim ());
2156 internal class FileFilter
2158 private ArrayList filterArrayList = new ArrayList();
2160 private string filter;
2162 public FileFilter ()
2165 public FileFilter (string filter) : base ()
2167 this.filter = filter;
2172 public static bool CheckFilter (string val)
2174 if (val.Length == 0)
2177 string[] filters = val.Split (new char [] {'|'});
2179 if ((filters.Length % 2) != 0)
2185 public ArrayList FilterArrayList {
2187 filterArrayList = value;
2191 return filterArrayList;
2195 public string Filter {
2207 private void SplitFilter ()
2209 filterArrayList.Clear ();
2211 if (filter.Length == 0)
2214 string[] filters = filter.Split (new char [] {'|'});
2216 for (int i = 0; i < filters.Length; i += 2) {
2217 FilterStruct filterStruct = new FilterStruct (filters [i], filters [i + 1]);
2219 filterArrayList.Add (filterStruct);
2227 internal class MWFFileView : ListView
2229 private ArrayList filterArrayList;
2231 private bool showHiddenFiles = false;
2233 private string selectedFilesString;
2235 private int filterIndex = 1;
2237 private ToolTip toolTip;
2238 private int oldItemIndexForToolTip = -1;
2240 private ContextMenu contextMenu;
2242 private MenuItem menuItemView;
2243 private MenuItem menuItemNew;
2245 private MenuItem smallIconMenutItem;
2246 private MenuItem tilesMenutItem;
2247 private MenuItem largeIconMenutItem;
2248 private MenuItem listMenutItem;
2249 private MenuItem detailsMenutItem;
2251 private MenuItem newFolderMenuItem;
2252 private MenuItem showHiddenFilesMenuItem;
2254 private int previousCheckedMenuItemIndex;
2256 private ArrayList viewMenuItemClones = new ArrayList ();
2258 private FSEntry currentFSEntry = null;
2260 private string currentFolder;
2261 private string currentRealFolder;
2262 private FSEntry currentFolderFSEntry;
2264 // store DirectoryInfo for a back button for example
2265 private Stack directoryStack = new Stack();
2267 // list of controls(components to enable or disable depending on current directoryStack.Count
2268 private ArrayList dirStackControlsOrComponents = new ArrayList ();
2270 private ToolBarButton folderUpToolBarButton;
2272 private ArrayList registered_senders = new ArrayList ();
2274 private bool should_push = true;
2278 private View old_view;
2280 private int old_menuitem_index;
2281 private bool do_update_view = false;
2283 private ColumnHeader [] columns;
2285 public MWFFileView (MWFVFS vfs)
2288 this.vfs.RegisterUpdateDelegate (new MWFVFS.UpdateDelegate (RealFileViewUpdate), this);
2292 contextMenu = new ContextMenu ();
2294 toolTip = new ToolTip ();
2295 toolTip.InitialDelay = 300;
2296 toolTip.ReshowDelay = 0;
2301 menuItemView = new MenuItem ("View");
2303 smallIconMenutItem = new MenuItem ("Small Icon", new EventHandler (OnClickViewMenuSubItem));
2304 smallIconMenutItem.RadioCheck = true;
2305 menuItemView.MenuItems.Add (smallIconMenutItem);
2307 tilesMenutItem = new MenuItem ("Tiles", new EventHandler (OnClickViewMenuSubItem));
2308 tilesMenutItem.RadioCheck = true;
2309 menuItemView.MenuItems.Add (tilesMenutItem);
2311 largeIconMenutItem = new MenuItem ("Large Icon", new EventHandler (OnClickViewMenuSubItem));
2312 largeIconMenutItem.RadioCheck = true;
2313 menuItemView.MenuItems.Add (largeIconMenutItem);
2315 listMenutItem = new MenuItem ("List", new EventHandler (OnClickViewMenuSubItem));
2316 listMenutItem.RadioCheck = true;
2317 listMenutItem.Checked = true;
2318 menuItemView.MenuItems.Add (listMenutItem);
2319 previousCheckedMenuItemIndex = listMenutItem.Index;
2321 detailsMenutItem = new MenuItem ("Details", new EventHandler (OnClickViewMenuSubItem));
2322 detailsMenutItem.RadioCheck = true;
2323 menuItemView.MenuItems.Add (detailsMenutItem);
2325 contextMenu.MenuItems.Add (menuItemView);
2327 contextMenu.MenuItems.Add (new MenuItem ("-"));
2330 menuItemNew = new MenuItem ("New");
2332 newFolderMenuItem = new MenuItem ("New Folder", new EventHandler (OnClickNewFolderMenuItem));
2333 menuItemNew.MenuItems.Add (newFolderMenuItem);
2335 contextMenu.MenuItems.Add (menuItemNew);
2337 contextMenu.MenuItems.Add (new MenuItem ("-"));
2339 // Show hidden files menu item
2340 showHiddenFilesMenuItem = new MenuItem ("Show hidden files", new EventHandler (OnClickContextMenu));
2341 showHiddenFilesMenuItem.Checked = showHiddenFiles;
2342 contextMenu.MenuItems.Add (showHiddenFilesMenuItem);
2346 SmallImageList = MimeIconEngine.SmallIcons;
2347 LargeImageList = MimeIconEngine.LargeIcons;
2349 View = old_view = View.List;
2352 ContextMenu = contextMenu;
2354 // Create columns, but only add them when view changes to Details
2355 columns = new ColumnHeader [4];
2356 columns [0] = CreateColumnHeader (" Name", 170, HorizontalAlignment.Left);
2357 columns [1] = CreateColumnHeader ("Size ", 80, HorizontalAlignment.Right);
2358 columns [2] = CreateColumnHeader (" Type", 100, HorizontalAlignment.Left);
2359 columns [3] = CreateColumnHeader (" Last Access", 150, HorizontalAlignment.Left);
2361 AllowColumnReorder = true;
2363 ResumeLayout (false);
2365 KeyDown += new KeyEventHandler (MWF_KeyDown);
2368 ColumnHeader CreateColumnHeader (string text, int width, HorizontalAlignment alignment)
2370 ColumnHeader col = new ColumnHeader ();
2373 col.TextAlign = alignment;
2378 public string CurrentFolder {
2380 return currentFolder;
2383 currentFolder = value;
2387 public string CurrentRealFolder {
2389 return currentRealFolder;
2393 public FSEntry CurrentFSEntry {
2395 return currentFSEntry;
2399 public MenuItem[] ViewMenuItems {
2401 MenuItem[] menuItemClones = new MenuItem [] {
2402 smallIconMenutItem.CloneMenu (),
2403 tilesMenutItem.CloneMenu (),
2404 largeIconMenutItem.CloneMenu (),
2405 listMenutItem.CloneMenu (),
2406 detailsMenutItem.CloneMenu ()
2409 viewMenuItemClones.Add (menuItemClones);
2411 return menuItemClones;
2415 public ArrayList FilterArrayList {
2417 filterArrayList = value;
2421 return filterArrayList;
2425 public bool ShowHiddenFiles {
2427 showHiddenFiles = value;
2431 return showHiddenFiles;
2435 public int FilterIndex {
2437 filterIndex = value;
2447 public string SelectedFilesString {
2449 selectedFilesString = value;
2453 return selectedFilesString;
2457 public void PushDir ()
2459 if (currentFolder != null)
2460 directoryStack.Push (currentFolder);
2462 EnableOrDisableDirstackObjects ();
2465 public void PopDir ()
2470 public void PopDir (string filter)
2472 if (directoryStack.Count == 0)
2475 string new_folder = directoryStack.Pop () as string;
2477 EnableOrDisableDirstackObjects ();
2479 should_push = false;
2481 ChangeDirectory (null, new_folder, filter);
2484 public void RegisterSender (IUpdateFolder iud)
2486 registered_senders.Add (iud);
2489 public void CreateNewFolder ()
2491 if (currentFolder == MWFVFS.MyComputerPrefix ||
2492 currentFolder == MWFVFS.RecentlyUsedPrefix)
2495 FSEntry fsEntry = new FSEntry ();
2496 fsEntry.Attributes = FileAttributes.Directory;
2497 fsEntry.FileType = FSEntry.FSEntryType.Directory;
2498 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
2499 fsEntry.LastAccessTime = DateTime.Now;
2501 // FIXME: when ListView.LabelEdit is available use it
2502 // listViewItem.BeginEdit();
2504 TextEntryDialog ted = new TextEntryDialog ();
2505 ted.IconPictureBoxImage = MimeIconEngine.LargeIcons.Images.GetImage (fsEntry.IconIndex);
2507 string folder = String.Empty;
2509 if (currentFolderFSEntry.RealName != null)
2510 folder = currentFolderFSEntry.RealName;
2512 folder = currentFolder;
2514 string tmp_filename = "New Folder";
2516 if (Directory.Exists (Path.Combine (folder, tmp_filename))) {
2519 if (XplatUI.RunningOnUnix) {
2520 tmp_filename = tmp_filename + "-" + i;
2522 tmp_filename = tmp_filename + " (" + i + ")";
2525 while (Directory.Exists (Path.Combine (folder, tmp_filename))) {
2527 if (XplatUI.RunningOnUnix) {
2528 tmp_filename = "New Folder" + "-" + i;
2530 tmp_filename = "New Folder" + " (" + i + ")";
2535 ted.FileName = tmp_filename;
2537 if (ted.ShowDialog () == DialogResult.OK) {
2538 string new_folder = Path.Combine (folder, ted.FileName);
2540 if (vfs.CreateFolder (new_folder)) {
2541 fsEntry.FullName = new_folder;
2542 fsEntry.Name = ted.FileName;
2544 FileViewListViewItem listViewItem = new FileViewListViewItem (fsEntry);
2547 Items.Add (listViewItem);
2550 listViewItem.EnsureVisible ();
2555 public void SetSelectedIndexTo (string fname)
2557 foreach (FileViewListViewItem item in Items) {
2558 if (item.Text == fname) {
2560 SelectedItems.Clear ();
2561 item.Selected = true;
2568 public void OneDirUp ()
2573 public void OneDirUp (string filter)
2575 string parent_folder = vfs.GetParent ();
2576 if (parent_folder != null)
2577 ChangeDirectory (null, parent_folder, filter);
2580 public void ChangeDirectory (object sender, string folder)
2582 ChangeDirectory (sender, folder, null);
2585 public void ChangeDirectory (object sender, string folder, string filter)
2587 if (folder == MWFVFS.DesktopPrefix || folder == MWFVFS.RecentlyUsedPrefix)
2588 folderUpToolBarButton.Enabled = false;
2590 folderUpToolBarButton.Enabled = true;
2592 foreach (IUpdateFolder iuf in registered_senders) {
2593 iuf.CurrentFolder = folder;
2601 currentFolderFSEntry = vfs.ChangeDirectory (folder);
2603 currentFolder = folder;
2605 if (currentFolder.IndexOf ("://") != -1)
2606 currentRealFolder = currentFolderFSEntry.RealName;
2608 currentRealFolder = currentFolder;
2613 SelectedItems.Clear ();
2615 if (folder == MWFVFS.RecentlyUsedPrefix) {
2617 View = View.Details;
2618 old_menuitem_index = previousCheckedMenuItemIndex;
2619 UpdateMenuItems (detailsMenutItem);
2620 do_update_view = true;
2622 if (View != old_view && do_update_view) {
2623 UpdateMenuItems (menuItemView.MenuItems [old_menuitem_index]);
2625 do_update_view = false;
2630 UpdateFileView (filter);
2631 } catch (Exception e) {
2634 MessageBox.Show (e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
2638 public void UpdateFileView ()
2640 UpdateFileView (null);
2643 public void UpdateFileView (string custom_filter)
2645 if (custom_filter != null) {
2646 StringCollection custom_filters = new StringCollection ();
2647 custom_filters.Add (custom_filter);
2649 vfs.GetFolderContent (custom_filters);
2650 } else if (filterArrayList != null && filterArrayList.Count != 0) {
2651 FilterStruct fs = (FilterStruct)filterArrayList [filterIndex - 1];
2653 vfs.GetFolderContent (fs.filters);
2655 vfs.GetFolderContent ();
2658 public void RealFileViewUpdate (ArrayList directoriesArrayList, ArrayList fileArrayList)
2663 SelectedItems.Clear ();
2665 foreach (FSEntry directoryFSEntry in directoriesArrayList) {
2666 if (!ShowHiddenFiles)
2667 if (directoryFSEntry.Name.StartsWith (".") || (directoryFSEntry.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
2670 FileViewListViewItem listViewItem = new FileViewListViewItem (directoryFSEntry);
2672 Items.Add (listViewItem);
2675 StringCollection collection = new StringCollection ();
2677 foreach (FSEntry fsEntry in fileArrayList) {
2679 // remove duplicates. that can happen when you read recently used files for example
2680 if (collection.Contains (fsEntry.Name)) {
2682 string fileName = fsEntry.Name;
2684 if (collection.Contains (fileName)) {
2687 while (collection.Contains (fileName + "(" + i + ")")) {
2691 fileName = fileName + "(" + i + ")";
2694 fsEntry.Name = fileName;
2697 collection.Add (fsEntry.Name);
2699 DoOneFSEntry (fsEntry);
2704 collection.Clear ();
2707 directoriesArrayList.Clear ();
2708 fileArrayList.Clear ();
2711 public void AddControlToEnableDisableByDirStack (object control)
2713 dirStackControlsOrComponents.Add (control);
2716 public void SetFolderUpToolBarButton (ToolBarButton tb)
2718 folderUpToolBarButton = tb;
2721 public void WriteRecentlyUsed (string fullfilename)
2723 vfs.WriteRecentlyUsedFiles (fullfilename);
2726 private void EnableOrDisableDirstackObjects ()
2728 foreach (object o in dirStackControlsOrComponents) {
2730 Control c = o as Control;
2731 c.Enabled = (directoryStack.Count > 1);
2733 if (o is ToolBarButton) {
2734 ToolBarButton t = o as ToolBarButton;
2735 t.Enabled = (directoryStack.Count > 0);
2740 private void DoOneFSEntry (FSEntry fsEntry)
2742 if (!ShowHiddenFiles)
2743 if (fsEntry.Name.StartsWith (".") || (fsEntry.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
2746 FileViewListViewItem listViewItem = new FileViewListViewItem (fsEntry);
2748 Items.Add (listViewItem);
2751 private void MWF_KeyDown (object sender, KeyEventArgs e)
2753 if (e.KeyCode == Keys.Back) {
2755 } else if (e.Control && e.KeyCode == Keys.A && MultiSelect) {
2756 foreach (ListViewItem lvi in Items)
2757 lvi.Selected = true;
2761 protected override void OnClick (EventArgs e)
2764 if (SelectedItems.Count > 0) {
2765 FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
2767 FSEntry fsEntry = listViewItem.FSEntry;
2769 if (fsEntry.FileType == FSEntry.FSEntryType.File) {
2770 currentFSEntry = fsEntry;
2772 EventHandler eh = (EventHandler)(Events [MSelectedFileChangedEvent]);
2774 eh (this, EventArgs.Empty);
2782 protected override void OnDoubleClick (EventArgs e)
2784 if (SelectedItems.Count > 0) {
2785 FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
2787 FSEntry fsEntry = listViewItem.FSEntry;
2789 if ((fsEntry.Attributes & FileAttributes.Directory) == FileAttributes.Directory) {
2791 ChangeDirectory (null, fsEntry.FullName);
2793 EventHandler eh = (EventHandler)(Events [MDirectoryChangedEvent]);
2795 eh (this, EventArgs.Empty);
2797 currentFSEntry = fsEntry;
2799 EventHandler eh = (EventHandler)(Events [MSelectedFileChangedEvent]);
2801 eh (this, EventArgs.Empty);
2803 eh = (EventHandler)(Events [MForceDialogEndEvent]);
2805 eh (this, EventArgs.Empty);
2811 base.OnDoubleClick (e);
2814 protected override void OnSelectedIndexChanged (EventArgs e)
2816 if (SelectedItems.Count > 0) {
2817 selectedFilesString = String.Empty;
2819 if (SelectedItems.Count == 1) {
2820 FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
2822 FSEntry fsEntry = listViewItem.FSEntry;
2824 if ((fsEntry.Attributes & FileAttributes.Directory) != FileAttributes.Directory)
2825 selectedFilesString = SelectedItems [0].Text;
2827 foreach (FileViewListViewItem lvi in SelectedItems) {
2828 FSEntry fsEntry = lvi.FSEntry;
2830 if ((fsEntry.Attributes & FileAttributes.Directory) != FileAttributes.Directory)
2831 selectedFilesString = selectedFilesString + "\"" + lvi.Text + "\" ";
2835 EventHandler eh = (EventHandler)(Events [MSelectedFilesChangedEvent]);
2837 eh (this, EventArgs.Empty);
2840 base.OnSelectedIndexChanged (e);
2843 protected override void OnMouseMove (MouseEventArgs e)
2845 FileViewListViewItem item = GetItemAt (e.X, e.Y) as FileViewListViewItem;
2848 int currentItemIndex = item.Index;
2850 if (currentItemIndex != oldItemIndexForToolTip) {
2851 oldItemIndexForToolTip = currentItemIndex;
2853 if (toolTip != null && toolTip.Active)
2854 toolTip.Active = false;
2856 FSEntry fsEntry = item.FSEntry;
2858 string output = String.Empty;
2860 if (fsEntry.FileType == FSEntry.FSEntryType.Directory)
2861 output = "Directory: " + fsEntry.FullName;
2862 else if (fsEntry.FileType == FSEntry.FSEntryType.Device)
2863 output = "Device: "+ fsEntry.FullName;
2864 else if (fsEntry.FileType == FSEntry.FSEntryType.Network)
2865 output = "Network: " + fsEntry.FullName;
2867 output = "File: " + fsEntry.FullName;
2869 toolTip.SetToolTip (this, output);
2871 toolTip.Active = true;
2874 toolTip.Active = false;
2876 base.OnMouseMove (e);
2879 void OnClickContextMenu (object sender, EventArgs e)
2881 MenuItem senderMenuItem = sender as MenuItem;
2883 if (senderMenuItem == showHiddenFilesMenuItem) {
2884 senderMenuItem.Checked = !senderMenuItem.Checked;
2885 showHiddenFiles = senderMenuItem.Checked;
2890 void OnClickViewMenuSubItem (object sender, EventArgs e)
2892 MenuItem senderMenuItem = (MenuItem)sender;
2894 UpdateMenuItems (senderMenuItem);
2896 // update me - call BeginUpdate/EndUpdate to avoid flicker when columns change
2899 switch (senderMenuItem.Index) {
2901 View = View.SmallIcon;
2907 View = View.LargeIcon;
2911 View = View.LargeIcon;
2917 View = View.Details;
2923 if (View == View.Details)
2924 Columns.AddRange (columns);
2926 ListViewItemSorter = null;
2933 protected override void OnBeforeLabelEdit (LabelEditEventArgs e)
2935 FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
2936 FSEntry fsEntry = listViewItem.FSEntry;
2938 // only allow editing of files or directories
2939 if (fsEntry.FileType != FSEntry.FSEntryType.Directory &&
2940 fsEntry.FileType != FSEntry.FSEntryType.File)
2941 e.CancelEdit = true;
2943 base.OnBeforeLabelEdit (e);
2946 protected override void OnAfterLabelEdit (LabelEditEventArgs e)
2948 base.OnAfterLabelEdit (e);
2950 // no changes were made
2951 if (e.Label == null || Items [e.Item].Text == e.Label)
2954 FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
2955 FSEntry fsEntry = listViewItem.FSEntry;
2957 string folder = (currentFolderFSEntry.RealName != null) ?
2958 currentFolderFSEntry.RealName : currentFolder;
2960 switch (fsEntry.FileType) {
2961 case FSEntry.FSEntryType.Directory:
2962 string sourceDir = (fsEntry.RealName != null) ? fsEntry.RealName : fsEntry.FullName;
2963 string destDir = Path.Combine (folder, e.Label);
2964 if (!vfs.MoveFolder (sourceDir, destDir)) {
2965 e.CancelEdit = true;
2967 if (fsEntry.RealName != null)
2968 fsEntry.RealName = destDir;
2970 fsEntry.FullName = destDir;
2973 case FSEntry.FSEntryType.File:
2974 string sourceFile = (fsEntry.RealName != null) ? fsEntry.RealName : fsEntry.FullName;
2975 string destFile = Path.Combine (folder, e.Label);
2976 if (!vfs.MoveFile (sourceFile, destFile)) {
2977 e.CancelEdit = true;
2979 if (fsEntry.RealName != null)
2980 fsEntry.RealName = destFile;
2982 fsEntry.FullName = destFile;
2988 private void UpdateMenuItems (MenuItem senderMenuItem)
2990 menuItemView.MenuItems [previousCheckedMenuItemIndex].Checked = false;
2991 menuItemView.MenuItems [senderMenuItem.Index].Checked = true;
2993 foreach (MenuItem[] items in viewMenuItemClones) {
2994 items [previousCheckedMenuItemIndex].Checked = false;
2995 items [senderMenuItem.Index].Checked = true;
2998 previousCheckedMenuItemIndex = senderMenuItem.Index;
3001 void OnClickNewFolderMenuItem (object sender, EventArgs e)
3006 static object MSelectedFileChangedEvent = new object ();
3007 static object MSelectedFilesChangedEvent = new object ();
3008 static object MDirectoryChangedEvent = new object ();
3009 static object MForceDialogEndEvent = new object ();
3011 public event EventHandler SelectedFileChanged {
3012 add { Events.AddHandler (MSelectedFileChangedEvent, value); }
3013 remove { Events.RemoveHandler (MSelectedFileChangedEvent, value); }
3016 public event EventHandler SelectedFilesChanged {
3017 add { Events.AddHandler (MSelectedFilesChangedEvent, value); }
3018 remove { Events.RemoveHandler (MSelectedFilesChangedEvent, value); }
3021 public event EventHandler DirectoryChanged {
3022 add { Events.AddHandler (MDirectoryChangedEvent, value); }
3023 remove { Events.RemoveHandler (MDirectoryChangedEvent, value); }
3026 public event EventHandler ForceDialogEnd {
3027 add { Events.AddHandler (MForceDialogEndEvent, value); }
3028 remove { Events.RemoveHandler (MForceDialogEndEvent, value); }
3033 #region FileListViewItem
3034 internal class FileViewListViewItem : ListViewItem
3036 private FSEntry fsEntry;
3038 public FileViewListViewItem (FSEntry fsEntry)
3040 this.fsEntry = fsEntry;
3042 ImageIndex = fsEntry.IconIndex;
3044 Text = fsEntry.Name;
3046 switch (fsEntry.FileType) {
3047 case FSEntry.FSEntryType.Directory:
3048 SubItems.Add (String.Empty);
3049 SubItems.Add ("Directory");
3050 SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
3052 case FSEntry.FSEntryType.File:
3055 if (fsEntry.FileSize > 1024)
3056 fileLen = fsEntry.FileSize / 1024;
3057 } catch (Exception) {
3061 SubItems.Add (fileLen.ToString () + " KB");
3062 SubItems.Add ("File");
3063 SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
3065 case FSEntry.FSEntryType.Device:
3066 SubItems.Add (String.Empty);
3067 SubItems.Add ("Device");
3068 SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
3070 case FSEntry.FSEntryType.RemovableDevice:
3071 SubItems.Add (String.Empty);
3072 SubItems.Add ("RemovableDevice");
3073 SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
3080 public FSEntry FSEntry {
3093 #region MwfFileViewItemComparer
3094 class MwfFileViewItemComparer : IComparer
3099 public MwfFileViewItemComparer (bool asc)
3104 public int ColumnIndex {
3106 return column_index;
3109 column_index = value;
3113 public bool Ascendent {
3122 public int Compare (object a, object b)
3124 ListViewItem item_a = (ListViewItem)a;
3125 ListViewItem item_b = (ListViewItem)b;
3129 retval = String.Compare (item_a.SubItems [column_index].Text,
3130 item_b.SubItems [column_index].Text);
3132 retval = String.Compare (item_b.SubItems [column_index].Text,
3133 item_a.SubItems [column_index].Text);
3140 #region IUpdateFolder
3141 internal interface IUpdateFolder
3143 string CurrentFolder {get; set;}
3147 #region TextEntryDialog
3148 // FIXME: When ListView.LabelEdit is implemented remove me
3149 internal class TextEntryDialog : Form
3151 private Label label1;
3152 private Button okButton;
3153 private TextBox newNameTextBox;
3154 private PictureBox iconPictureBox;
3155 private Button cancelButton;
3156 private GroupBox groupBox1;
3158 public TextEntryDialog ()
3160 groupBox1 = new GroupBox ();
3161 cancelButton = new Button ();
3162 iconPictureBox = new PictureBox ();
3163 newNameTextBox = new TextBox ();
3164 okButton = new Button ();
3165 label1 = new Label ();
3166 groupBox1.SuspendLayout ();
3170 groupBox1.Controls.Add (newNameTextBox);
3171 groupBox1.Controls.Add (label1);
3172 groupBox1.Controls.Add (iconPictureBox);
3173 groupBox1.Location = new Point (8, 8);
3174 groupBox1.Size = new Size (232, 160);
3175 groupBox1.TabIndex = 5;
3176 groupBox1.TabStop = false;
3177 groupBox1.Text = "New Name";
3180 cancelButton.DialogResult = DialogResult.Cancel;
3181 cancelButton.Location = new Point (168, 176);
3182 cancelButton.TabIndex = 4;
3183 cancelButton.Text = "Cancel";
3186 iconPictureBox.BorderStyle = BorderStyle.Fixed3D;
3187 iconPictureBox.Location = new Point (86, 24);
3188 iconPictureBox.Size = new Size (60, 60);
3189 iconPictureBox.TabIndex = 3;
3190 iconPictureBox.TabStop = false;
3191 iconPictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
3194 newNameTextBox.Location = new Point (16, 128);
3195 newNameTextBox.Size = new Size (200, 20);
3196 newNameTextBox.TabIndex = 5;
3197 newNameTextBox.Text = String.Empty;
3200 okButton.DialogResult = DialogResult.OK;
3201 okButton.Location = new Point (80, 176);
3202 okButton.TabIndex = 3;
3203 okButton.Text = "OK";
3206 label1.Location = new Point (16, 96);
3207 label1.Size = new Size (200, 23);
3208 label1.TabIndex = 4;
3209 label1.Text = "Enter Name:";
3210 label1.TextAlign = ContentAlignment.MiddleCenter;
3213 AcceptButton = okButton;
3214 AutoScaleBaseSize = new Size (5, 13);
3215 CancelButton = cancelButton;
3216 ClientSize = new Size (248, 205);
3217 Controls.Add (groupBox1);
3218 Controls.Add (cancelButton);
3219 Controls.Add (okButton);
3220 FormBorderStyle = FormBorderStyle.FixedDialog;
3221 Text = "New Folder or File";
3222 groupBox1.ResumeLayout (false);
3223 ResumeLayout (false);
3225 newNameTextBox.Select ();
3228 public Image IconPictureBoxImage {
3230 iconPictureBox.Image = value;
3234 public string FileName {
3236 return newNameTextBox.Text;
3239 newNameTextBox.Text = value;
3246 internal class MWFVFS
3248 private FileSystem fileSystem;
3250 public static readonly string DesktopPrefix = "Desktop://";
3251 public static readonly string PersonalPrefix = "Personal://";
3252 public static readonly string MyComputerPrefix = "MyComputer://";
3253 public static readonly string RecentlyUsedPrefix = "RecentlyUsed://";
3254 public static readonly string MyNetworkPrefix = "MyNetwork://";
3255 public static readonly string MyComputerPersonalPrefix = "MyComputerPersonal://";
3257 public static Hashtable MyComputerDevicesPrefix = new Hashtable ();
3259 public delegate void UpdateDelegate (ArrayList folders, ArrayList files);
3260 private UpdateDelegate updateDelegate;
3261 private Control calling_control;
3263 private ThreadStart get_folder_content_thread_start;
3264 private Thread worker;
3265 private WorkerThread workerThread = null;
3266 private StringCollection the_filters;
3270 if (XplatUI.RunningOnUnix) {
3271 fileSystem = new UnixFileSystem ();
3273 fileSystem = new WinFileSystem ();
3277 public FSEntry ChangeDirectory (string folder)
3279 return fileSystem.ChangeDirectory (folder);
3282 public void GetFolderContent ()
3284 GetFolderContent (null);
3287 public void GetFolderContent (StringCollection filters)
3289 the_filters = filters;
3291 if (workerThread != null) {
3292 workerThread.Stop ();
3293 workerThread = null;
3296 // Added next line to ensure the control is created before BeginInvoke is called on it
3297 calling_control.CreateControl();
3298 workerThread = new WorkerThread (fileSystem, the_filters, updateDelegate, calling_control);
3300 get_folder_content_thread_start = new ThreadStart (workerThread.GetFolderContentThread);
3301 worker = new Thread (get_folder_content_thread_start);
3302 worker.IsBackground = true;
3306 internal class WorkerThread
3308 private FileSystem fileSystem;
3309 private StringCollection the_filters;
3310 private UpdateDelegate updateDelegate;
3311 private Control calling_control;
3312 private readonly object lockobject = new object ();
3313 private bool stopped = false;
3315 public WorkerThread (FileSystem fileSystem, StringCollection the_filters, UpdateDelegate updateDelegate, Control calling_control)
3317 this.fileSystem = fileSystem;
3318 this.the_filters = the_filters;
3319 this.updateDelegate = updateDelegate;
3320 this.calling_control = calling_control;
3323 public void GetFolderContentThread()
3328 fileSystem.GetFolderContent (the_filters, out folders, out files);
3333 if (updateDelegate != null) {
3335 object[] objectArray = new object[2];
3337 objectArray[0] = folders;
3338 objectArray[1] = files;
3340 calling_control.BeginInvoke (updateDelegate, objectArray);
3353 public ArrayList GetFoldersOnly ()
3355 return fileSystem.GetFoldersOnly ();
3358 public void WriteRecentlyUsedFiles (string filename)
3360 fileSystem.WriteRecentlyUsedFiles (filename);
3363 public ArrayList GetRecentlyUsedFiles ()
3365 return fileSystem.GetRecentlyUsedFiles ();
3368 public ArrayList GetMyComputerContent ()
3370 return fileSystem.GetMyComputerContent ();
3373 public ArrayList GetMyNetworkContent ()
3375 return fileSystem.GetMyNetworkContent ();
3378 public bool CreateFolder (string new_folder)
3381 if (Directory.Exists (new_folder)) {
3382 string message = "Folder \"" + new_folder + "\" already exists.";
3383 MessageBox.Show (message, new_folder, MessageBoxButtons.OK,
3384 MessageBoxIcon.Error);
3387 Directory.CreateDirectory (new_folder);
3388 } catch (Exception e) {
3389 MessageBox.Show (e.Message, new_folder, MessageBoxButtons.OK, MessageBoxIcon.Error);
3396 public bool MoveFolder (string sourceDirName, string destDirName)
3399 if (Directory.Exists (destDirName)) {
3400 string message = "Cannot rename " + Path.GetFileName (sourceDirName)
3401 + ": A folder with the name you specified already exists."
3402 + " Specify a different folder name.";
3403 MessageBox.Show (message, "Error Renaming Folder", MessageBoxButtons.OK,
3404 MessageBoxIcon.Error);
3407 Directory.Move (sourceDirName, destDirName);
3408 } catch (Exception e) {
3409 MessageBox.Show (e.Message, "Error Renaming Folder",
3410 MessageBoxButtons.OK, MessageBoxIcon.Error);
3417 public bool MoveFile (string sourceFileName, string destFileName)
3420 if (File.Exists (destFileName)) {
3421 string message = "Cannot rename " + Path.GetFileName (sourceFileName)
3422 + ": A file with the name you specified already exists."
3423 + " Specify a different file name.";
3424 MessageBox.Show (message, "Error Renaming File",
3425 MessageBoxButtons.OK, MessageBoxIcon.Error);
3428 File.Move (sourceFileName, destFileName);
3429 } catch (Exception e) {
3430 MessageBox.Show (e.Message, "Error Renaming File",
3431 MessageBoxButtons.OK, MessageBoxIcon.Error);
3438 public string GetParent ()
3440 return fileSystem.GetParent ();
3443 public void RegisterUpdateDelegate(UpdateDelegate updateDelegate, Control control)
3445 this.updateDelegate = updateDelegate;
3446 calling_control = control;
3452 internal abstract class FileSystem
3454 protected string currentTopFolder = String.Empty;
3455 protected FSEntry currentFolderFSEntry = null;
3456 protected FSEntry currentTopFolderFSEntry = null;
3457 private FileInfoComparer fileInfoComparer = new FileInfoComparer ();
3458 private FSEntryComparer fsEntryComparer = new FSEntryComparer ();
3460 public FSEntry ChangeDirectory (string folder)
3462 if (folder == MWFVFS.DesktopPrefix) {
3463 currentTopFolder = MWFVFS.DesktopPrefix;
3464 currentTopFolderFSEntry = currentFolderFSEntry = GetDesktopFSEntry ();
3466 if (folder == MWFVFS.PersonalPrefix) {
3467 currentTopFolder = MWFVFS.PersonalPrefix;
3468 currentTopFolderFSEntry = currentFolderFSEntry = GetPersonalFSEntry ();
3470 if (folder == MWFVFS.MyComputerPersonalPrefix) {
3471 currentTopFolder = MWFVFS.MyComputerPersonalPrefix;
3472 currentTopFolderFSEntry = currentFolderFSEntry = GetMyComputerPersonalFSEntry ();
3474 if (folder == MWFVFS.RecentlyUsedPrefix) {
3475 currentTopFolder = MWFVFS.RecentlyUsedPrefix;
3476 currentTopFolderFSEntry = currentFolderFSEntry = GetRecentlyUsedFSEntry ();
3478 if (folder == MWFVFS.MyComputerPrefix) {
3479 currentTopFolder = MWFVFS.MyComputerPrefix;
3480 currentTopFolderFSEntry = currentFolderFSEntry = GetMyComputerFSEntry ();
3482 if (folder == MWFVFS.MyNetworkPrefix) {
3483 currentTopFolder = MWFVFS.MyNetworkPrefix;
3484 currentTopFolderFSEntry = currentFolderFSEntry = GetMyNetworkFSEntry ();
3488 foreach (DictionaryEntry entry in MWFVFS.MyComputerDevicesPrefix) {
3489 FSEntry fsEntry = entry.Value as FSEntry;
3490 if (folder == fsEntry.FullName) {
3491 currentTopFolder = entry.Key as string;
3492 currentTopFolderFSEntry = currentFolderFSEntry = fsEntry;
3499 currentFolderFSEntry = GetDirectoryFSEntry (new DirectoryInfo (folder), currentTopFolderFSEntry);
3503 return currentFolderFSEntry;
3506 public string GetParent ()
3508 return currentFolderFSEntry.Parent;
3511 // directories_out and files_out contain FSEntry objects
3512 public void GetFolderContent (StringCollection filters, out ArrayList directories_out, out ArrayList files_out)
3514 directories_out = new ArrayList ();
3515 files_out = new ArrayList ();
3517 if (currentFolderFSEntry.FullName == MWFVFS.DesktopPrefix) {
3518 FSEntry personalFSEntry = GetPersonalFSEntry ();
3520 directories_out.Add (personalFSEntry);
3522 FSEntry myComputerFSEntry = GetMyComputerFSEntry ();
3524 directories_out.Add (myComputerFSEntry);
3526 FSEntry myNetworkFSEntry = GetMyNetworkFSEntry ();
3528 directories_out.Add (myNetworkFSEntry);
3530 ArrayList d_out = null;
3531 ArrayList f_out = null;
3532 GetNormalFolderContent (ThemeEngine.Current.Places (UIIcon.PlacesDesktop), filters, out d_out, out f_out);
3533 directories_out.AddRange (d_out);
3534 files_out.AddRange (f_out);
3537 if (currentFolderFSEntry.FullName == MWFVFS.RecentlyUsedPrefix) {
3538 files_out = GetRecentlyUsedFiles ();
3540 if (currentFolderFSEntry.FullName == MWFVFS.MyComputerPrefix) {
3541 directories_out.AddRange (GetMyComputerContent ());
3543 if (currentFolderFSEntry.FullName == MWFVFS.PersonalPrefix || currentFolderFSEntry.FullName == MWFVFS.MyComputerPersonalPrefix) {
3544 ArrayList d_out = null;
3545 ArrayList f_out = null;
3546 GetNormalFolderContent (ThemeEngine.Current.Places (UIIcon.PlacesPersonal), filters, out d_out, out f_out);
3547 directories_out.AddRange (d_out);
3548 files_out.AddRange (f_out);
3550 if (currentFolderFSEntry.FullName == MWFVFS.MyNetworkPrefix) {
3551 directories_out.AddRange (GetMyNetworkContent ());
3553 GetNormalFolderContent (currentFolderFSEntry.FullName, filters, out directories_out, out files_out);
3557 public ArrayList GetFoldersOnly ()
3559 ArrayList directories_out = new ArrayList ();
3561 if (currentFolderFSEntry.FullName == MWFVFS.DesktopPrefix) {
3562 FSEntry personalFSEntry = GetPersonalFSEntry ();
3564 directories_out.Add (personalFSEntry);
3566 FSEntry myComputerFSEntry = GetMyComputerFSEntry ();
3568 directories_out.Add (myComputerFSEntry);
3570 FSEntry myNetworkFSEntry = GetMyNetworkFSEntry ();
3572 directories_out.Add (myNetworkFSEntry);
3574 ArrayList d_out = GetNormalFolders (ThemeEngine.Current.Places (UIIcon.PlacesDesktop));
3575 directories_out.AddRange (d_out);
3578 if (currentFolderFSEntry.FullName == MWFVFS.RecentlyUsedPrefix) {
3579 //files_out = GetRecentlyUsedFiles ();
3581 if (currentFolderFSEntry.FullName == MWFVFS.MyComputerPrefix) {
3582 directories_out.AddRange (GetMyComputerContent ());
3584 if (currentFolderFSEntry.FullName == MWFVFS.PersonalPrefix || currentFolderFSEntry.FullName == MWFVFS.MyComputerPersonalPrefix) {
3585 ArrayList d_out = GetNormalFolders (ThemeEngine.Current.Places (UIIcon.PlacesPersonal));
3586 directories_out.AddRange (d_out);
3588 if (currentFolderFSEntry.FullName == MWFVFS.MyNetworkPrefix) {
3589 directories_out.AddRange (GetMyNetworkContent ());
3591 directories_out = GetNormalFolders (currentFolderFSEntry.FullName);
3593 return directories_out;
3596 protected void GetNormalFolderContent (string from_folder, StringCollection filters, out ArrayList directories_out, out ArrayList files_out)
3598 DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
3600 directories_out = new ArrayList ();
3602 DirectoryInfo[] dirs = null;
3605 dirs = dirinfo.GetDirectories ();
3606 } catch (Exception) {}
3609 for (int i = 0; i < dirs.Length; i++) {
3610 directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
3613 directories_out.Sort (fsEntryComparer);
3615 files_out = new ArrayList ();
3617 ArrayList files = new ArrayList ();
3620 if (filters == null) {
3621 files.AddRange (dirinfo.GetFiles ());
3623 foreach (string s in filters)
3624 files.AddRange (dirinfo.GetFiles (s));
3626 files.Sort (fileInfoComparer);
3628 } catch (Exception) {}
3630 for (int i = 0; i < files.Count; i++) {
3631 FSEntry fs = GetFileFSEntry (files [i] as FileInfo);
3637 protected ArrayList GetNormalFolders (string from_folder)
3639 DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
3641 ArrayList directories_out = new ArrayList ();
3643 DirectoryInfo[] dirs = null;
3646 dirs = dirinfo.GetDirectories ();
3647 } catch (Exception) {}
3650 for (int i = 0; i < dirs.Length; i++) {
3651 directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
3654 return directories_out;
3657 protected virtual FSEntry GetDirectoryFSEntry (DirectoryInfo dirinfo, FSEntry topFolderFSEntry)
3659 FSEntry fs = new FSEntry ();
3661 fs.Attributes = dirinfo.Attributes;
3662 fs.FullName = dirinfo.FullName;
3663 fs.Name = dirinfo.Name;
3664 fs.MainTopNode = topFolderFSEntry;
3665 fs.FileType = FSEntry.FSEntryType.Directory;
3666 fs.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
3667 fs.LastAccessTime = dirinfo.LastAccessTime;
3672 protected virtual FSEntry GetFileFSEntry (FileInfo fileinfo)
3674 // *sigh* FileInfo gives us no usable information for links to directories
3676 if ((fileinfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
3679 FSEntry fs = new FSEntry ();
3681 fs.Attributes = fileinfo.Attributes;
3682 fs.FullName = fileinfo.FullName;
3683 fs.Name = fileinfo.Name;
3684 fs.FileType = FSEntry.FSEntryType.File;
3685 fs.IconIndex = MimeIconEngine.GetIconIndexForFile (fileinfo.FullName);
3686 fs.FileSize = fileinfo.Length;
3687 fs.LastAccessTime = fileinfo.LastAccessTime;
3692 internal class FileInfoComparer : IComparer
3694 public int Compare (object fileInfo1, object fileInfo2)
3696 return String.Compare (((FileInfo)fileInfo1).Name, ((FileInfo)fileInfo2).Name);
3700 internal class FSEntryComparer : IComparer
3702 public int Compare (object fileInfo1, object fileInfo2)
3704 return String.Compare (((FSEntry)fileInfo1).Name, ((FSEntry)fileInfo2).Name);
3708 protected abstract FSEntry GetDesktopFSEntry ();
3710 protected abstract FSEntry GetRecentlyUsedFSEntry ();
3712 protected abstract FSEntry GetPersonalFSEntry ();
3714 protected abstract FSEntry GetMyComputerPersonalFSEntry ();
3716 protected abstract FSEntry GetMyComputerFSEntry ();
3718 protected abstract FSEntry GetMyNetworkFSEntry ();
3720 public abstract void WriteRecentlyUsedFiles (string fileToAdd);
3722 public abstract ArrayList GetRecentlyUsedFiles ();
3724 public abstract ArrayList GetMyComputerContent ();
3726 public abstract ArrayList GetMyNetworkContent ();
3730 #region UnixFileSystem
3731 internal class UnixFileSystem : FileSystem
3733 private MasterMount masterMount = new MasterMount ();
3734 private FSEntry desktopFSEntry = null;
3735 private FSEntry recentlyusedFSEntry = null;
3736 private FSEntry personalFSEntry = null;
3737 private FSEntry mycomputerpersonalFSEntry = null;
3738 private FSEntry mycomputerFSEntry = null;
3739 private FSEntry mynetworkFSEntry = null;
3741 private string personal_folder;
3742 private string recently_used_path;
3743 private string full_kde_recent_document_dir;
3745 public UnixFileSystem ()
3747 personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
3748 recently_used_path = Path.Combine (personal_folder, ".recently-used");
3750 full_kde_recent_document_dir = personal_folder + "/.kde/share/apps/RecentDocuments";
3752 desktopFSEntry = new FSEntry ();
3754 desktopFSEntry.Attributes = FileAttributes.Directory;
3755 desktopFSEntry.FullName = MWFVFS.DesktopPrefix;
3756 desktopFSEntry.Name = "Desktop";
3757 desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
3758 desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
3759 desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
3760 desktopFSEntry.LastAccessTime = DateTime.Now;
3762 recentlyusedFSEntry = new FSEntry ();
3764 recentlyusedFSEntry.Attributes = FileAttributes.Directory;
3765 recentlyusedFSEntry.FullName = MWFVFS.RecentlyUsedPrefix;
3766 recentlyusedFSEntry.Name = "Recently Used";
3767 recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directory;
3768 recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
3769 recentlyusedFSEntry.LastAccessTime = DateTime.Now;
3771 personalFSEntry = new FSEntry ();
3773 personalFSEntry.Attributes = FileAttributes.Directory;
3774 personalFSEntry.FullName = MWFVFS.PersonalPrefix;
3775 personalFSEntry.Name = "Personal";
3776 personalFSEntry.MainTopNode = GetDesktopFSEntry ();
3777 personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
3778 personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
3779 personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
3780 personalFSEntry.LastAccessTime = DateTime.Now;
3782 mycomputerpersonalFSEntry = new FSEntry ();
3784 mycomputerpersonalFSEntry.Attributes = FileAttributes.Directory;
3785 mycomputerpersonalFSEntry.FullName = MWFVFS.MyComputerPersonalPrefix;
3786 mycomputerpersonalFSEntry.Name = "Personal";
3787 mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
3788 mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
3789 mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
3790 mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
3791 mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
3793 mycomputerFSEntry = new FSEntry ();
3795 mycomputerFSEntry.Attributes = FileAttributes.Directory;
3796 mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
3797 mycomputerFSEntry.Name = "My Computer";
3798 mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
3799 mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
3800 mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
3801 mycomputerFSEntry.LastAccessTime = DateTime.Now;
3803 mynetworkFSEntry = new FSEntry ();
3805 mynetworkFSEntry.Attributes = FileAttributes.Directory;
3806 mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
3807 mynetworkFSEntry.Name = "My Network";
3808 mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
3809 mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
3810 mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
3811 mynetworkFSEntry.LastAccessTime = DateTime.Now;
3814 public override void WriteRecentlyUsedFiles (string fileToAdd)
3816 if (File.Exists (recently_used_path) && new FileInfo (recently_used_path).Length > 0) {
3817 XmlDocument xml_doc = new XmlDocument ();
3818 xml_doc.Load (recently_used_path);
3820 XmlNode grand_parent_node = xml_doc.SelectSingleNode ("RecentFiles");
3822 if (grand_parent_node != null) {
3823 // create a new element
3824 XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
3826 XmlElement new_child = xml_doc.CreateElement ("URI");
3827 UriBuilder ub = new UriBuilder ();
3828 ub.Path = fileToAdd;
3831 XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
3832 new_child.AppendChild (new_text_child);
3834 new_recent_item_node.AppendChild (new_child);
3836 new_child = xml_doc.CreateElement ("Mime-Type");
3837 new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (fileToAdd));
3838 new_child.AppendChild (new_text_child);
3840 new_recent_item_node.AppendChild (new_child);
3842 new_child = xml_doc.CreateElement ("Timestamp");
3843 long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
3844 new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
3845 new_child.AppendChild (new_text_child);
3847 new_recent_item_node.AppendChild (new_child);
3849 new_child = xml_doc.CreateElement ("Groups");
3851 new_recent_item_node.AppendChild (new_child);
3853 // now search the nodes in grand_parent_node for another instance of the new uri and if found remove it
3854 // so that the new node is the first one
3855 foreach (XmlNode n in grand_parent_node.ChildNodes) {
3856 XmlNode uri_node = n.SelectSingleNode ("URI");
3857 if (uri_node != null) {
3858 XmlNode uri_node_child = uri_node.FirstChild;
3859 if (uri_node_child is XmlText)
3860 if (ub.ToString () == ((XmlText)uri_node_child).Data) {
3861 grand_parent_node.RemoveChild (n);
3867 // prepend the new recent item to the grand parent node list
3868 grand_parent_node.PrependChild (new_recent_item_node);
3870 // limit the # of RecentItems to 10
3871 if (grand_parent_node.ChildNodes.Count > 10) {
3872 while (grand_parent_node.ChildNodes.Count > 10)
3873 grand_parent_node.RemoveChild (grand_parent_node.LastChild);
3877 xml_doc.Save (recently_used_path);
3878 } catch (Exception) {
3882 XmlDocument xml_doc = new XmlDocument ();
3883 xml_doc.AppendChild (xml_doc.CreateXmlDeclaration ("1.0", String.Empty, String.Empty));
3885 XmlElement recentFiles_element = xml_doc.CreateElement ("RecentFiles");
3887 XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
3889 XmlElement new_child = xml_doc.CreateElement ("URI");
3890 UriBuilder ub = new UriBuilder ();
3891 ub.Path = fileToAdd;
3894 XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
3895 new_child.AppendChild (new_text_child);
3897 new_recent_item_node.AppendChild (new_child);
3899 new_child = xml_doc.CreateElement ("Mime-Type");
3900 new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (fileToAdd));
3901 new_child.AppendChild (new_text_child);
3903 new_recent_item_node.AppendChild (new_child);
3905 new_child = xml_doc.CreateElement ("Timestamp");
3906 long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
3907 new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
3908 new_child.AppendChild (new_text_child);
3910 new_recent_item_node.AppendChild (new_child);
3912 new_child = xml_doc.CreateElement ("Groups");
3914 new_recent_item_node.AppendChild (new_child);
3916 recentFiles_element.AppendChild (new_recent_item_node);
3918 xml_doc.AppendChild (recentFiles_element);
3921 xml_doc.Save (recently_used_path);
3922 } catch (Exception) {
3927 // return an ArrayList with FSEntry objects
3928 public override ArrayList GetRecentlyUsedFiles ()
3930 // check for GNOME and KDE
3932 ArrayList files_al = new ArrayList ();
3935 if (File.Exists (recently_used_path)) {
3937 XmlTextReader xtr = new XmlTextReader (recently_used_path);
3938 while (xtr.Read ()) {
3939 if (xtr.NodeType == XmlNodeType.Element && xtr.Name.ToUpper () == "URI") {
3941 Uri uri = new Uri (xtr.Value);
3942 if (!files_al.Contains (uri.LocalPath))
3943 if (File.Exists (uri.LocalPath)) {
3944 FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
3951 } catch (Exception) {
3957 if (Directory.Exists (full_kde_recent_document_dir)) {
3958 string[] files = Directory.GetFiles (full_kde_recent_document_dir, "*.desktop");
3960 foreach (string file_name in files) {
3961 StreamReader sr = new StreamReader (file_name);
3963 string line = sr.ReadLine ();
3965 while (line != null) {
3966 line = line.Trim ();
3968 if (line.StartsWith ("URL=")) {
3969 line = line.Replace ("URL=", String.Empty);
3970 line = line.Replace ("$HOME", personal_folder);
3972 Uri uri = new Uri (line);
3973 if (!files_al.Contains (uri.LocalPath))
3974 if (File.Exists (uri.LocalPath)) {
3975 FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
3982 line = sr.ReadLine ();
3993 // return an ArrayList with FSEntry objects
3994 public override ArrayList GetMyComputerContent ()
3996 ArrayList my_computer_content_arraylist = new ArrayList ();
3998 if (masterMount.ProcMountAvailable) {
3999 masterMount.GetMounts ();
4001 foreach (MasterMount.Mount mount in masterMount.Block_devices) {
4002 FSEntry fsEntry = new FSEntry ();
4003 fsEntry.FileType = FSEntry.FSEntryType.Device;
4005 fsEntry.FullName = mount.mount_point;
4007 fsEntry.Name = "HDD (" + mount.fsType + ", " + mount.device_short + ")";
4009 fsEntry.FsType = mount.fsType;
4010 fsEntry.DeviceShort = mount.device_short;
4012 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
4014 fsEntry.Attributes = FileAttributes.Directory;
4016 fsEntry.MainTopNode = GetMyComputerFSEntry ();
4018 my_computer_content_arraylist.Add (fsEntry);
4020 if (!MWFVFS.MyComputerDevicesPrefix.Contains (fsEntry.FullName + "://"))
4021 MWFVFS.MyComputerDevicesPrefix.Add (fsEntry.FullName + "://", fsEntry);
4024 foreach (MasterMount.Mount mount in masterMount.Removable_devices) {
4025 FSEntry fsEntry = new FSEntry ();
4026 fsEntry.FileType = FSEntry.FSEntryType.RemovableDevice;
4028 fsEntry.FullName = mount.mount_point;
4030 bool is_dvd_cdrom = mount.fsType == MasterMount.FsTypes.usbfs ? false : true;
4031 string type_name = is_dvd_cdrom ? "DVD/CD-Rom" : "USB";
4032 string mime_type = is_dvd_cdrom ? "cdrom/cdrom" : "removable/removable";
4034 fsEntry.Name = type_name +" (" + mount.device_short + ")";
4036 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType (mime_type);
4038 fsEntry.FsType = mount.fsType;
4039 fsEntry.DeviceShort = mount.device_short;
4041 fsEntry.Attributes = FileAttributes.Directory;
4043 fsEntry.MainTopNode = GetMyComputerFSEntry ();
4045 my_computer_content_arraylist.Add (fsEntry);
4047 string contain_string = fsEntry.FullName + "://";
4048 if (!MWFVFS.MyComputerDevicesPrefix.Contains (contain_string))
4049 MWFVFS.MyComputerDevicesPrefix.Add (contain_string, fsEntry);
4053 my_computer_content_arraylist.Add (GetMyComputerPersonalFSEntry ());
4055 return my_computer_content_arraylist;
4058 public override ArrayList GetMyNetworkContent ()
4060 ArrayList fsEntries = new ArrayList ();
4062 foreach (MasterMount.Mount mount in masterMount.Network_devices) {
4063 FSEntry fsEntry = new FSEntry ();
4064 fsEntry.FileType = FSEntry.FSEntryType.Network;
4066 fsEntry.FullName = mount.mount_point;
4068 fsEntry.FsType = mount.fsType;
4069 fsEntry.DeviceShort = mount.device_short;
4071 fsEntry.Name = "Network (" + mount.fsType + ", " + mount.device_short + ")";
4073 switch (mount.fsType) {
4074 case MasterMount.FsTypes.nfs:
4075 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("nfs/nfs");
4077 case MasterMount.FsTypes.smbfs:
4078 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("smb/smb");
4080 case MasterMount.FsTypes.ncpfs:
4081 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
4083 case MasterMount.FsTypes.cifs:
4084 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
4090 fsEntry.Attributes = FileAttributes.Directory;
4092 fsEntry.MainTopNode = GetMyNetworkFSEntry ();
4094 fsEntries.Add (fsEntry);
4099 protected override FSEntry GetDesktopFSEntry ()
4101 return desktopFSEntry;
4104 protected override FSEntry GetRecentlyUsedFSEntry ()
4106 return recentlyusedFSEntry;
4109 protected override FSEntry GetPersonalFSEntry ()
4111 return personalFSEntry;
4114 protected override FSEntry GetMyComputerPersonalFSEntry ()
4116 return mycomputerpersonalFSEntry;
4119 protected override FSEntry GetMyComputerFSEntry ()
4121 return mycomputerFSEntry;
4124 protected override FSEntry GetMyNetworkFSEntry ()
4126 return mynetworkFSEntry;
4131 #region WinFileSystem
4132 internal class WinFileSystem : FileSystem
4134 private FSEntry desktopFSEntry = null;
4135 private FSEntry recentlyusedFSEntry = null;
4136 private FSEntry personalFSEntry = null;
4137 private FSEntry mycomputerpersonalFSEntry = null;
4138 private FSEntry mycomputerFSEntry = null;
4139 private FSEntry mynetworkFSEntry = null;
4141 public WinFileSystem ()
4143 desktopFSEntry = new FSEntry ();
4145 desktopFSEntry.Attributes = FileAttributes.Directory;
4146 desktopFSEntry.FullName = MWFVFS.DesktopPrefix;
4147 desktopFSEntry.Name = "Desktop";
4148 desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
4149 desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
4150 desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
4151 desktopFSEntry.LastAccessTime = DateTime.Now;
4153 recentlyusedFSEntry = new FSEntry ();
4155 recentlyusedFSEntry.Attributes = FileAttributes.Directory;
4156 recentlyusedFSEntry.FullName = MWFVFS.RecentlyUsedPrefix;
4157 recentlyusedFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments);
4158 recentlyusedFSEntry.Name = "Recently Used";
4159 recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directory;
4160 recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
4161 recentlyusedFSEntry.LastAccessTime = DateTime.Now;
4163 personalFSEntry = new FSEntry ();
4165 personalFSEntry.Attributes = FileAttributes.Directory;
4166 personalFSEntry.FullName = MWFVFS.PersonalPrefix;
4167 personalFSEntry.Name = "Personal";
4168 personalFSEntry.MainTopNode = GetDesktopFSEntry ();
4169 personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
4170 personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
4171 personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
4172 personalFSEntry.LastAccessTime = DateTime.Now;
4174 mycomputerpersonalFSEntry = new FSEntry ();
4176 mycomputerpersonalFSEntry.Attributes = FileAttributes.Directory;
4177 mycomputerpersonalFSEntry.FullName = MWFVFS.MyComputerPersonalPrefix;
4178 mycomputerpersonalFSEntry.Name = "Personal";
4179 mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
4180 mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
4181 mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
4182 mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
4183 mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
4185 mycomputerFSEntry = new FSEntry ();
4187 mycomputerFSEntry.Attributes = FileAttributes.Directory;
4188 mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
4189 mycomputerFSEntry.Name = "My Computer";
4190 mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
4191 mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
4192 mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
4193 mycomputerFSEntry.LastAccessTime = DateTime.Now;
4195 mynetworkFSEntry = new FSEntry ();
4197 mynetworkFSEntry.Attributes = FileAttributes.Directory;
4198 mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
4199 mynetworkFSEntry.Name = "My Network";
4200 mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
4201 mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
4202 mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
4203 mynetworkFSEntry.LastAccessTime = DateTime.Now;
4206 public override void WriteRecentlyUsedFiles (string fileToAdd)
4208 // TODO: Implement this method
4209 // use SHAddToRecentDocs ?
4212 public override ArrayList GetRecentlyUsedFiles ()
4214 ArrayList al = new ArrayList ();
4216 DirectoryInfo di = new DirectoryInfo (recentlyusedFSEntry.RealName);
4218 FileInfo[] fileinfos = di.GetFiles ();
4220 foreach (FileInfo fi in fileinfos) {
4221 FSEntry fs = GetFileFSEntry (fi);
4229 public override ArrayList GetMyComputerContent ()
4231 string[] logical_drives = Directory.GetLogicalDrives ();
4233 ArrayList my_computer_content_arraylist = new ArrayList ();
4235 foreach (string drive in logical_drives) {
4236 FSEntry fsEntry = new FSEntry ();
4237 fsEntry.FileType = FSEntry.FSEntryType.Device;
4239 fsEntry.FullName = drive;
4241 fsEntry.Name = drive;
4243 fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
4245 fsEntry.Attributes = FileAttributes.Directory;
4247 fsEntry.MainTopNode = GetMyComputerFSEntry ();
4249 my_computer_content_arraylist.Add (fsEntry);
4251 string contain_string = fsEntry.FullName + "://";
4252 if (!MWFVFS.MyComputerDevicesPrefix.Contains (contain_string))
4253 MWFVFS.MyComputerDevicesPrefix.Add (contain_string, fsEntry);
4256 my_computer_content_arraylist.Add (GetMyComputerPersonalFSEntry ());
4258 return my_computer_content_arraylist;
4261 public override ArrayList GetMyNetworkContent ()
4263 // TODO: Implement this method
4264 return new ArrayList ();
4266 protected override FSEntry GetDesktopFSEntry ()
4268 return desktopFSEntry;
4271 protected override FSEntry GetRecentlyUsedFSEntry ()
4273 return recentlyusedFSEntry;
4276 protected override FSEntry GetPersonalFSEntry ()
4278 return personalFSEntry;
4281 protected override FSEntry GetMyComputerPersonalFSEntry ()
4283 return mycomputerpersonalFSEntry;
4286 protected override FSEntry GetMyComputerFSEntry ()
4288 return mycomputerFSEntry;
4291 protected override FSEntry GetMyNetworkFSEntry ()
4293 return mynetworkFSEntry;
4299 internal class FSEntry
4301 public enum FSEntryType
4313 private MasterMount.FsTypes fsType;
4314 private string device_short;
4315 private string fullName;
4316 private string name;
4317 private string realName = null;
4318 private FileAttributes attributes = FileAttributes.Normal;
4319 private long fileSize;
4320 private FSEntryType fileType;
4321 private DateTime lastAccessTime;
4322 private FSEntry mainTopNode = null;
4324 private int iconIndex;
4326 private string parent;
4328 public MasterMount.FsTypes FsType {
4338 public string DeviceShort {
4340 device_short = value;
4344 return device_short;
4348 public string FullName {
4358 public string Name {
4368 public string RealName {
4378 public FileAttributes Attributes {
4388 public long FileSize {
4398 public FSEntryType FileType {
4408 public DateTime LastAccessTime {
4410 lastAccessTime = value;
4414 return lastAccessTime;
4418 public int IconIndex {
4428 public FSEntry MainTopNode {
4430 mainTopNode = value;
4438 public string Parent {
4444 parent = GetParent ();
4450 private string GetParent ()
4452 if (fullName == MWFVFS.PersonalPrefix) {
4453 return MWFVFS.DesktopPrefix;
4455 if (fullName == MWFVFS.MyComputerPersonalPrefix) {
4456 return MWFVFS.MyComputerPrefix;
4458 if (fullName == MWFVFS.MyComputerPrefix) {
4459 return MWFVFS.DesktopPrefix;
4461 if (fullName == MWFVFS.MyNetworkPrefix) {
4462 return MWFVFS.DesktopPrefix;
4464 if (fullName == MWFVFS.DesktopPrefix) {
4467 if (fullName == MWFVFS.RecentlyUsedPrefix) {
4470 foreach (DictionaryEntry entry in MWFVFS.MyComputerDevicesPrefix) {
4471 FSEntry fsEntry = entry.Value as FSEntry;
4472 if (fullName == fsEntry.FullName) {
4473 return fsEntry.MainTopNode.FullName;
4477 DirectoryInfo dirInfo = new DirectoryInfo (fullName);
4479 DirectoryInfo dirInfoParent = dirInfo.Parent;
4481 if (dirInfoParent != null) {
4482 FSEntry fsEntry = MWFVFS.MyComputerDevicesPrefix [dirInfoParent.FullName + "://"] as FSEntry;
4484 if (fsEntry != null) {
4485 return fsEntry.FullName;
4488 if (mainTopNode != null) {
4489 if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesDesktop) &&
4490 mainTopNode.FullName == MWFVFS.DesktopPrefix) {
4491 return mainTopNode.FullName;
4493 if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal) &&
4494 mainTopNode.FullName == MWFVFS.PersonalPrefix) {
4495 return mainTopNode.FullName;
4497 if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal) &&
4498 mainTopNode.FullName == MWFVFS.MyComputerPersonalPrefix) {
4499 return mainTopNode.FullName;
4503 return dirInfoParent.FullName;
4513 // Alexsantas little *nix helper
4514 internal class MasterMount
4517 internal enum FsTypes
4541 internal struct Mount
4543 public string device_or_filesystem;
4544 public string device_short;
4545 public string mount_point;
4546 public FsTypes fsType;
4549 bool proc_mount_available = false;
4551 ArrayList block_devices = new ArrayList ();
4552 ArrayList network_devices = new ArrayList ();
4553 ArrayList removable_devices = new ArrayList ();
4555 private MountComparer mountComparer = new MountComparer ();
4557 public MasterMount ()
4559 // maybe check if the current user can access /proc/mounts
4560 if (XplatUI.RunningOnUnix)
4561 if (File.Exists ("/proc/mounts"))
4562 proc_mount_available = true;
4565 public ArrayList Block_devices {
4567 return block_devices;
4571 public ArrayList Network_devices {
4573 return network_devices;
4577 public ArrayList Removable_devices {
4579 return removable_devices;
4583 public bool ProcMountAvailable {
4585 return proc_mount_available;
4589 public void GetMounts ()
4591 if (!proc_mount_available)
4594 block_devices.Clear ();
4595 network_devices.Clear ();
4596 removable_devices.Clear ();
4599 StreamReader sr = new StreamReader ("/proc/mounts");
4601 string line = sr.ReadLine ();
4603 ArrayList lines = new ArrayList ();
4604 while (line != null) {
4605 if (lines.IndexOf (line) == -1) { // Avoid duplicates
4606 ProcessProcMountLine (line);
4609 line = sr.ReadLine ();
4614 block_devices.Sort (mountComparer);
4615 network_devices.Sort (mountComparer);
4616 removable_devices.Sort (mountComparer);
4622 private void ProcessProcMountLine (string line)
4624 string[] split = line.Split (new char [] {' '});
4626 if (split != null && split.Length > 0) {
4627 Mount mount = new Mount ();
4629 if (split [0].StartsWith ("/dev/"))
4630 mount.device_short = split [0].Replace ("/dev/", String.Empty);
4632 mount.device_short = split [0];
4634 mount.device_or_filesystem = split [0];
4635 mount.mount_point = split [1];
4637 // TODO: other removable devices, floppy
4641 if (split [2] == "nfs") {
4642 mount.fsType = FsTypes.nfs;
4643 network_devices.Add (mount);
4644 } else if (split [2] == "smbfs") {
4645 mount.fsType = FsTypes.smbfs;
4646 network_devices.Add (mount);
4647 } else if (split [2] == "cifs") {
4648 mount.fsType = FsTypes.cifs;
4649 network_devices.Add (mount);
4650 } else if (split [2] == "ncpfs") {
4651 mount.fsType = FsTypes.ncpfs;
4652 network_devices.Add (mount);
4654 } else if (split [2] == "iso9660") { //cdrom
4655 mount.fsType = FsTypes.iso9660;
4656 removable_devices.Add (mount);
4657 } else if (split [2] == "usbfs") { //usb ? not tested
4658 mount.fsType = FsTypes.usbfs;
4659 removable_devices.Add (mount);
4661 } else if (split [0].StartsWith ("/")) { //block devices
4662 if (split [1].StartsWith ("/dev/")) // root static, do not add
4665 if (split [2] == "ext2")
4666 mount.fsType = FsTypes.ext2;
4667 else if (split [2] == "ext3")
4668 mount.fsType = FsTypes.ext3;
4669 else if (split [2] == "reiserfs")
4670 mount.fsType = FsTypes.reiserfs;
4671 else if (split [2] == "xfs")
4672 mount.fsType = FsTypes.xfs;
4673 else if (split [2] == "vfat")
4674 mount.fsType = FsTypes.vfat;
4675 else if (split [2] == "ntfs")
4676 mount.fsType = FsTypes.ntfs;
4677 else if (split [2] == "msdos")
4678 mount.fsType = FsTypes.msdos;
4679 else if (split [2] == "umsdos")
4680 mount.fsType = FsTypes.umsdos;
4681 else if (split [2] == "hpfs")
4682 mount.fsType = FsTypes.hpfs;
4683 else if (split [2] == "minix")
4684 mount.fsType = FsTypes.minix;
4685 else if (split [2] == "jfs")
4686 mount.fsType = FsTypes.jfs;
4688 block_devices.Add (mount);
4693 public class MountComparer : IComparer
4695 public int Compare (object mount1, object mount2)
4697 return String.Compare (((Mount)mount1).device_short, ((Mount)mount2).device_short);
4704 // easy to use class to store and read internal MWF config settings.
4705 // the config values are stored in the users home dir as a hidden xml file called "mwf_config".
4706 // currently supports int, string, byte, color and arrays (including byte arrays)
4707 // don't forget, when you read a value you still have to cast this value.
4710 // MWFConfig.SetValue ("SomeClass", "What", value);
4711 // object o = MWFConfig.GetValue ("SomeClass", "What");
4715 // string[] configFileNames = (string[])MWFConfig.GetValue ("FileDialog", "FileNames");
4716 // MWFConfig.SetValue ("FileDialog", "LastFolder", "/home/user");
4718 internal class MWFConfig
4720 private static MWFConfigInstance Instance = new MWFConfigInstance ();
4722 private static object lock_object = new object();
4724 public static object GetValue (string class_name, string value_name)
4726 lock (lock_object) {
4727 return Instance.GetValue (class_name, value_name);
4731 public static void SetValue (string class_name, string value_name, object value)
4733 lock (lock_object) {
4734 Instance.SetValue (class_name, value_name, value);
4738 public static void Flush ()
4740 lock (lock_object) {
4745 public static void RemoveClass (string class_name)
4747 lock (lock_object) {
4748 Instance.RemoveClass (class_name);
4752 public static void RemoveClassValue (string class_name, string value_name)
4754 lock (lock_object) {
4755 Instance.RemoveClassValue (class_name, value_name);
4759 public static void RemoveAllClassValues (string class_name)
4761 lock (lock_object) {
4762 Instance.RemoveAllClassValues (class_name);
4766 internal class MWFConfigInstance
4768 Hashtable classes_hashtable = new Hashtable ();
4769 static string full_file_name;
4770 static string default_file_name;
4771 readonly string configName = "MWFConfig";
4773 static MWFConfigInstance ()
4775 string b = "mwf_config";
4776 string dir = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
4778 if (XplatUI.RunningOnUnix) {
4779 dir = Path.Combine (dir, ".mono");
4781 Directory.CreateDirectory (dir);
4785 default_file_name = Path.Combine (dir, b);
4786 full_file_name = default_file_name;
4789 public MWFConfigInstance ()
4791 Open (default_file_name);
4795 public MWFConfigInstance (string filename)
4797 string path = Path.GetDirectoryName (filename);
4798 if (path == null || path == String.Empty) {
4799 path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
4801 full_file_name = Path.Combine (path, filename);
4803 full_file_name = filename;
4805 Open (full_file_name);
4808 ~MWFConfigInstance ()
4813 public object GetValue (string class_name, string value_name)
4815 ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
4817 if (class_entry != null)
4818 return class_entry.GetValue (value_name);
4823 public void SetValue (string class_name, string value_name, object value)
4825 ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
4827 if (class_entry == null) {
4828 class_entry = new ClassEntry ();
4829 class_entry.ClassName = class_name;
4830 classes_hashtable [class_name] = class_entry;
4833 class_entry.SetValue (value_name, value);
4836 private void Open (string filename)
4839 XmlTextReader xtr = new XmlTextReader (filename);
4844 } catch (Exception) {
4848 public void Flush ()
4851 XmlTextWriter xtw = new XmlTextWriter (full_file_name, null);
4852 xtw.Formatting = Formatting.Indented;
4858 if (!XplatUI.RunningOnUnix)
4859 File.SetAttributes (full_file_name, FileAttributes.Hidden);
4860 } catch (Exception){
4864 public void RemoveClass (string class_name)
4866 ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
4868 if (class_entry != null) {
4869 class_entry.RemoveAllClassValues ();
4871 classes_hashtable.Remove (class_name);
4875 public void RemoveClassValue (string class_name, string value_name)
4877 ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
4879 if (class_entry != null) {
4880 class_entry.RemoveClassValue (value_name);
4884 public void RemoveAllClassValues (string class_name)
4886 ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
4888 if (class_entry != null) {
4889 class_entry.RemoveAllClassValues ();
4893 private void ReadConfig (XmlTextReader xtr)
4895 if (!CheckForMWFConfig (xtr))
4898 while (xtr.Read ()) {
4899 switch (xtr.NodeType) {
4900 case XmlNodeType.Element:
4901 ClassEntry class_entry = classes_hashtable [xtr.Name] as ClassEntry;
4903 if (class_entry == null) {
4904 class_entry = new ClassEntry ();
4905 class_entry.ClassName = xtr.Name;
4906 classes_hashtable [xtr.Name] = class_entry;
4909 class_entry.ReadXml (xtr);
4915 private bool CheckForMWFConfig (XmlTextReader xtr)
4918 if (xtr.NodeType == XmlNodeType.Element) {
4919 if (xtr.Name == configName)
4927 private void WriteConfig (XmlTextWriter xtw)
4929 if (classes_hashtable.Count == 0)
4932 xtw.WriteStartElement (configName);
4933 foreach (DictionaryEntry entry in classes_hashtable) {
4934 ClassEntry class_entry = entry.Value as ClassEntry;
4936 class_entry.WriteXml (xtw);
4938 xtw.WriteEndElement ();
4941 internal class ClassEntry
4943 private Hashtable classvalues_hashtable = new Hashtable ();
4944 private string className;
4946 public string ClassName {
4956 public void SetValue (string value_name, object value)
4958 ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
4960 if (class_value == null) {
4961 class_value = new ClassValue ();
4962 class_value.Name = value_name;
4963 classvalues_hashtable [value_name] = class_value;
4966 class_value.SetValue (value);
4969 public object GetValue (string value_name)
4971 ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
4973 if (class_value == null) {
4977 return class_value.GetValue ();
4980 public void RemoveAllClassValues ()
4982 classvalues_hashtable.Clear ();
4985 public void RemoveClassValue (string value_name)
4987 ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
4989 if (class_value != null) {
4990 classvalues_hashtable.Remove (value_name);
4994 public void ReadXml (XmlTextReader xtr)
4996 while (xtr.Read ()) {
4997 switch (xtr.NodeType) {
4998 case XmlNodeType.Element:
4999 string name = xtr.GetAttribute ("name");
5001 ClassValue class_value = classvalues_hashtable [name] as ClassValue;
5003 if (class_value == null) {
5004 class_value = new ClassValue ();
5005 class_value.Name = name;
5006 classvalues_hashtable [name] = class_value;
5009 class_value.ReadXml (xtr);
5012 case XmlNodeType.EndElement:
5018 public void WriteXml (XmlTextWriter xtw)
5020 if (classvalues_hashtable.Count == 0)
5023 xtw.WriteStartElement (className);
5025 foreach (DictionaryEntry entry in classvalues_hashtable) {
5026 ClassValue class_value = entry.Value as ClassValue;
5028 class_value.WriteXml (xtw);
5031 xtw.WriteEndElement ();
5035 internal class ClassValue
5037 private object value;
5038 private string name;
5040 public string Name {
5050 public void SetValue (object value)
5054 public object GetValue ()
5059 public void ReadXml (XmlTextReader xtr)
5062 string single_value;
5064 type = xtr.GetAttribute ("type");
5066 if (type == "byte_array" || type.IndexOf ("-array") == -1) {
5067 single_value = xtr.ReadString ();
5069 if (type == "string") {
5070 value = single_value;
5072 if (type == "int") {
5073 value = Int32.Parse (single_value);
5075 if (type == "byte") {
5076 value = Byte.Parse (single_value);
5078 if (type == "color") {
5079 int color = Int32.Parse (single_value);
5080 value = Color.FromArgb (color);
5082 if (type == "byte-array") {
5083 byte[] b_array = Convert.FromBase64String (single_value);
5087 ReadXmlArrayValues (xtr, type);
5091 private void ReadXmlArrayValues (XmlTextReader xtr, string type)
5093 ArrayList al = new ArrayList ();
5095 while (xtr.Read ()) {
5096 switch (xtr.NodeType) {
5097 case XmlNodeType.Element:
5098 string single_value = xtr.ReadString ();
5100 if (type == "int-array") {
5101 int int_val = Int32.Parse (single_value);
5104 if (type == "string-array") {
5105 string str_val = single_value;
5110 case XmlNodeType.EndElement:
5111 if (xtr.Name == "value") {
5112 if (type == "int-array") {
5113 value = al.ToArray (typeof(int));
5115 if (type == "string-array") {
5116 value = al.ToArray (typeof(string));
5125 public void WriteXml (XmlTextWriter xtw)
5127 xtw.WriteStartElement ("value");
5128 xtw.WriteAttributeString ("name", name);
5129 if (value is Array) {
5130 WriteArrayContent (xtw);
5132 WriteSingleContent (xtw);
5134 xtw.WriteEndElement ();
5137 private void WriteSingleContent (XmlTextWriter xtw)
5139 string type_string = String.Empty;
5141 if (value is string)
5142 type_string = "string";
5145 type_string = "int";
5148 type_string = "byte";
5151 type_string = "color";
5153 xtw.WriteAttributeString ("type", type_string);
5156 xtw.WriteString (((Color)value).ToArgb ().ToString ());
5158 xtw.WriteString (value.ToString ());
5161 private void WriteArrayContent (XmlTextWriter xtw)
5163 string type_string = String.Empty;
5164 string type_name = String.Empty;
5166 if (value is string[]) {
5167 type_string = "string-array";
5168 type_name = "string";
5170 if (value is int[]) {
5171 type_string = "int-array";
5174 if (value is byte[]) {
5175 type_string = "byte-array";
5179 xtw.WriteAttributeString ("type", type_string);
5181 if (type_string != "byte-array") {
5182 Array array = value as Array;
5184 foreach (object o in array) {
5185 xtw.WriteStartElement (type_name);
5186 xtw.WriteString (o.ToString ());
5187 xtw.WriteEndElement ();
5190 byte[] b_array = value as byte [];
5192 xtw.WriteString (Convert.ToBase64String (b_array, 0, b_array.Length));