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) 2004-2006 Novell, Inc. (http://www.novell.com)
24 // Alexander Olk xenomorph2@onlinehome.de
27 // NOT COMPLETE - work in progress
31 using System.ComponentModel;
32 using System.Resources;
34 using System.Collections;
35 using System.Collections.Specialized;
38 namespace System.Windows.Forms {
39 [DefaultProperty ("FileName")]
40 [DefaultEvent ("FileOk")]
41 public abstract class FileDialog : CommonDialog {
42 protected static readonly object EventFileOk = new object ();
44 internal enum FileDialogType {
49 private bool addExtension = true;
50 private bool checkFileExists = false;
51 private bool checkPathExists = true;
52 private string defaultExt = "";
53 private bool dereferenceLinks = true;
54 private string fileName = "";
55 private string[] fileNames;
56 private string filter;
57 private int filterIndex = 1;
58 private string initialDirectory = "";
59 private bool restoreDirectory = false;
60 private bool showHelp = false;
61 private string title = "";
62 private bool validateNames = true;
64 private Button cancelButton;
65 private ToolBarButton upToolBarButton;
66 private PopupButtonPanel popupButtonPanel;
67 private Button openSaveButton;
68 private Button helpButton;
69 private Label fileTypeLabel;
70 private ToolBarButton menueToolBarButton;
71 private ContextMenu menueToolBarButtonContextMenu;
72 private ToolBar smallButtonToolBar;
73 private DirComboBox dirComboBox;
74 private ComboBox fileNameComboBox;
75 private Label fileNameLabel;
76 private MWFFileView mwfFileView;
77 private Label searchSaveLabel;
78 private ToolBarButton newdirToolBarButton;
79 private ToolBarButton backToolBarButton;
80 private ComboBox fileTypeComboBox;
81 private ImageList imageListTopToolbar;
82 private ContextMenu contextMenu;
83 private CheckBox readonlyCheckBox;
85 private string currentDirectoryName;
86 private string currentFileName = "";
87 // store current directoryInfo
88 private DirectoryInfo currentDirectoryInfo;
89 // store DirectoryInfo for backButton
90 private Stack directoryStack = new Stack();
91 private MenuItem previousCheckedMenuItem;
92 private bool multiSelect = false;
94 private string restoreDirectoryString = "";
96 private bool show_special_case = false;
98 internal static readonly string recently_string = "[recently/recently]";
99 internal static readonly string network_string = "[network/network]";
100 internal static readonly string mycomputer_string = "[mycomputer/mycomputer]";
102 private string current_special_case;
104 internal FileDialogType fileDialogType;
106 private bool do_not_call_OnSelectedIndexChangedFileTypeComboBox = false;
108 private bool showHiddenFiles = false;
110 //protected bool readOnlyChecked = false;
112 private bool showReadOnly = false;
113 private bool readOnlyChecked = false;
114 internal bool createPrompt = false;
115 internal bool overwritePrompt = true;
117 internal FileFilter fileFilter;
119 private static string last_dir_when_opened_or_saved = String.Empty;
120 private string start_dir;
122 internal FileDialog ()
124 fileTypeComboBox = new ComboBox ();
125 backToolBarButton = new ToolBarButton ();
126 newdirToolBarButton = new ToolBarButton ();
127 searchSaveLabel = new Label ();
128 mwfFileView = new MWFFileView ();
129 fileNameLabel = new Label ();
130 fileNameComboBox = new ComboBox ();
131 dirComboBox = new DirComboBox ();
132 smallButtonToolBar = new ToolBar ();
133 menueToolBarButton = new ToolBarButton ();
134 fileTypeLabel = new Label ();
135 openSaveButton = new Button ();
136 form.AcceptButton = openSaveButton;
137 helpButton = new Button ();
138 popupButtonPanel = new PopupButtonPanel (this);
139 upToolBarButton = new ToolBarButton ();
140 cancelButton = new Button ();
141 form.CancelButton = cancelButton;
142 imageListTopToolbar = new ImageList ();
143 menueToolBarButtonContextMenu = new ContextMenu ();
144 contextMenu = new ContextMenu ();
145 readonlyCheckBox = new CheckBox ();
147 form.SuspendLayout ();
149 //imageListTopToolbar
150 imageListTopToolbar.ColorDepth = ColorDepth.Depth32Bit;
151 imageListTopToolbar.ImageSize = new Size (16, 16); // 16, 16
152 imageListTopToolbar.Images.Add ((Image)Locale.GetResource ("back_arrow"));
153 imageListTopToolbar.Images.Add ((Image)Locale.GetResource ("folder_arrow_up"));
154 imageListTopToolbar.Images.Add ((Image)Locale.GetResource ("folder_star"));
155 imageListTopToolbar.Images.Add ((Image)Locale.GetResource ("window"));
156 imageListTopToolbar.TransparentColor = Color.Transparent;
159 searchSaveLabel.FlatStyle = FlatStyle.System;
160 searchSaveLabel.Location = new Point (7, 8);
161 searchSaveLabel.Size = new Size (72, 21);
162 searchSaveLabel.TextAlign = ContentAlignment.MiddleRight;
165 dirComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Left) | AnchorStyles.Right)));
166 dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
167 dirComboBox.Location = new Point (99, 8);
168 dirComboBox.Size = new Size (260, 21);
169 dirComboBox.TabIndex = 0;
171 // smallButtonToolBar
172 smallButtonToolBar.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right)));
173 smallButtonToolBar.Appearance = ToolBarAppearance.Flat;
174 smallButtonToolBar.AutoSize = false;
175 smallButtonToolBar.Buttons.AddRange (new ToolBarButton [] {
179 menueToolBarButton});
180 smallButtonToolBar.ButtonSize = new Size (24, 24); // 21, 16
181 smallButtonToolBar.Divider = false;
182 smallButtonToolBar.Dock = DockStyle.None;
183 smallButtonToolBar.DropDownArrows = true;
184 smallButtonToolBar.ImageList = imageListTopToolbar;
185 smallButtonToolBar.Location = new Point (372, 6);
186 smallButtonToolBar.ShowToolTips = true;
187 smallButtonToolBar.Size = new Size (140, 28);
188 smallButtonToolBar.TabIndex = 1;
189 smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
192 popupButtonPanel.Dock = DockStyle.None;
193 popupButtonPanel.Location = new Point (7, 37);
194 popupButtonPanel.TabIndex = 2;
197 mwfFileView.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
198 mwfFileView.Location = new Point (99, 37);
199 mwfFileView.Size = new Size (449, 282);
200 mwfFileView.Columns.Add (" Name", 170, HorizontalAlignment.Left);
201 mwfFileView.Columns.Add ("Size ", 80, HorizontalAlignment.Right);
202 mwfFileView.Columns.Add (" Type", 100, HorizontalAlignment.Left);
203 mwfFileView.Columns.Add (" Last Access", 150, HorizontalAlignment.Left);
204 mwfFileView.AllowColumnReorder = true;
205 mwfFileView.MultiSelect = false;
206 mwfFileView.TabIndex = 3;
207 mwfFileView.FilterIndex = FilterIndex;
210 fileNameLabel.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
211 fileNameLabel.FlatStyle = FlatStyle.System;
212 fileNameLabel.Location = new Point (102, 330);
213 fileNameLabel.Size = new Size (70, 21);
214 fileNameLabel.Text = "Filename:";
215 fileNameLabel.TextAlign = ContentAlignment.MiddleLeft;
218 fileNameComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
219 fileNameComboBox.Location = new Point (195, 330);
220 fileNameComboBox.Size = new Size (245, 21);
221 fileNameComboBox.TabIndex = 4;
222 fileNameComboBox.Items.Add (" ");
225 fileTypeLabel.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
226 fileTypeLabel.FlatStyle = FlatStyle.System;
227 fileTypeLabel.Location = new Point (102, 356);
228 fileTypeLabel.Size = new Size (70, 21);
229 fileTypeLabel.Text = "Filetype:";
230 fileTypeLabel.TextAlign = ContentAlignment.MiddleLeft;
233 fileTypeComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
234 fileTypeComboBox.Location = new Point (195, 356);
235 fileTypeComboBox.Size = new Size (245, 21);
236 fileTypeComboBox.TabIndex = 5;
239 backToolBarButton.ImageIndex = 0;
240 backToolBarButton.Enabled = false;
241 backToolBarButton.Style = ToolBarButtonStyle.PushButton;
244 upToolBarButton.ImageIndex = 1;
245 upToolBarButton.Style = ToolBarButtonStyle.PushButton;
247 // newdirToolBarButton
248 newdirToolBarButton.ImageIndex = 2;
249 newdirToolBarButton.Style = ToolBarButtonStyle.PushButton;
251 // menueToolBarButton
252 menueToolBarButton.ImageIndex = 3;
253 menueToolBarButton.DropDownMenu = menueToolBarButtonContextMenu;
254 menueToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
256 // menueToolBarButtonContextMenu
257 MenuItem mi = new MenuItem ("Small Icon", new EventHandler (OnClickMenuToolBarContextMenu));
258 mi.RadioCheck = true;
259 menueToolBarButtonContextMenu.MenuItems.Add (mi);
260 mi = new MenuItem ("Tiles", new EventHandler (OnClickMenuToolBarContextMenu));
261 mi.RadioCheck = true;
262 menueToolBarButtonContextMenu.MenuItems.Add (mi);
263 mi = new MenuItem ("Large Icon", new EventHandler (OnClickMenuToolBarContextMenu));
264 mi.RadioCheck = true;
265 menueToolBarButtonContextMenu.MenuItems.Add (mi);
266 mi = new MenuItem ("List", new EventHandler (OnClickMenuToolBarContextMenu));
267 mi.RadioCheck = true;
269 previousCheckedMenuItem = mi;
270 menueToolBarButtonContextMenu.MenuItems.Add (mi);
271 mi = new MenuItem ("Details", new EventHandler (OnClickMenuToolBarContextMenu));
272 mi.RadioCheck = true;
273 menueToolBarButtonContextMenu.MenuItems.Add (mi);
276 mi = new MenuItem ("Show hidden files", new EventHandler (OnClickContextMenu));
277 mi.Checked = showHiddenFiles;
278 mwfFileView.ShowHiddenFiles = showHiddenFiles;
279 contextMenu.MenuItems.Add (mi);
282 openSaveButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
283 openSaveButton.FlatStyle = FlatStyle.System;
284 openSaveButton.Location = new Point (475, 330);
285 openSaveButton.Size = new Size (72, 21);
286 openSaveButton.TabIndex = 7;
287 openSaveButton.FlatStyle = FlatStyle.System;
290 cancelButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
291 cancelButton.FlatStyle = FlatStyle.System;
292 cancelButton.Location = new Point (475, 356);
293 cancelButton.Size = new Size (72, 21);
294 cancelButton.TabIndex = 8;
295 cancelButton.Text = "Cancel";
296 cancelButton.FlatStyle = FlatStyle.System;
299 helpButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
300 helpButton.FlatStyle = FlatStyle.System;
301 helpButton.Location = new Point (475, 350);
302 helpButton.Size = new Size (72, 21);
303 helpButton.TabIndex = 9;
304 helpButton.Text = "Help";
305 helpButton.FlatStyle = FlatStyle.System;
308 readonlyCheckBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
309 readonlyCheckBox.Text = "Open Readonly";
310 readonlyCheckBox.Location = new Point (195, 350);
311 readonlyCheckBox.Size = new Size (245, 21);
312 readonlyCheckBox.TabIndex = 6;
313 readonlyCheckBox.FlatStyle = FlatStyle.System;
315 form.ContextMenu = contextMenu;
317 form.SizeGripStyle = SizeGripStyle.Show;
319 form.Size = new Size (554, 405); // 384
320 form.MaximizeBox = true;
321 form.FormBorderStyle = FormBorderStyle.Sizable;
322 form.MinimumSize = new Size (554, 405);
324 form.Controls.Add (smallButtonToolBar);
325 form.Controls.Add (cancelButton);
326 form.Controls.Add (openSaveButton);
327 form.Controls.Add (mwfFileView);
328 form.Controls.Add (fileTypeLabel);
329 form.Controls.Add (fileNameLabel);
330 form.Controls.Add (fileTypeComboBox);
331 form.Controls.Add (fileNameComboBox);
332 form.Controls.Add (dirComboBox);
333 form.Controls.Add (searchSaveLabel);
334 form.Controls.Add (popupButtonPanel);
336 form.ResumeLayout (false);
338 currentDirectoryName = Environment.CurrentDirectory;
340 currentDirectoryInfo = new DirectoryInfo (currentDirectoryName);
342 if (RestoreDirectory)
343 restoreDirectoryString = currentDirectoryName;
345 openSaveButton.Click += new EventHandler (OnClickOpenSaveButton);
346 cancelButton.Click += new EventHandler (OnClickCancelButton);
347 helpButton.Click += new EventHandler (OnClickHelpButton);
349 smallButtonToolBar.ButtonClick += new ToolBarButtonClickEventHandler (OnClickSmallButtonToolBar);
351 fileTypeComboBox.SelectedIndexChanged += new EventHandler (OnSelectedIndexChangedFileTypeComboBox);
353 mwfFileView.SelectedFileChanged += new EventHandler (OnSelectedFileChangedFileView);
354 mwfFileView.DirectoryChanged += new EventHandler (OnDirectoryChangedFileView);
355 mwfFileView.ForceDialogEnd += new EventHandler (OnForceDialogEndFileView);
356 mwfFileView.SelectedFilesChanged += new EventHandler (OnSelectedFilesChangedFileView);
357 mwfFileView.OnDirectoryUp += new EventHandler (OnDirectoryUp);
359 dirComboBox.DirectoryChanged += new EventHandler (OnDirectoryChangedDirComboBox);
361 readonlyCheckBox.CheckedChanged += new EventHandler (OnCheckCheckChanged);
363 start_dir = currentDirectoryName;
367 public bool AddExtension {
373 addExtension = value;
377 [DefaultValue(false)]
378 public virtual bool CheckFileExists {
380 return checkFileExists;
384 checkFileExists = value;
389 public bool CheckPathExists {
391 return checkPathExists;
395 checkPathExists = value;
400 public string DefaultExt {
408 // if there is a dot remove it and everything before it
409 if (defaultExt.LastIndexOf ('.') != - 1) {
410 string[] split = defaultExt.Split (new char [] { '.' });
411 defaultExt = split [split.Length - 1];
416 // in MS.NET it doesn't make a difference if
417 // DerefenceLinks is true or false
418 // if the selected file is a link FileDialog
419 // always returns the link
421 public bool DereferenceLinks {
423 return dereferenceLinks;
427 dereferenceLinks = value;
432 public string FileName {
439 if (SetFileName (value))
446 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
447 public string[] FileNames {
449 if (fileNames == null || fileNames.Length == 0) {
450 string[] null_nada_nothing_filenames = new string [0];
451 return null_nada_nothing_filenames;
454 string[] new_filenames = new string [fileNames.Length];
455 fileNames.CopyTo (new_filenames, 0);
456 return new_filenames;
462 public string Filter {
469 throw new NullReferenceException ("Filter");
473 fileFilter = new FileFilter (filter);
480 public int FilterIndex {
486 if (fileFilter != null && fileFilter.FilterArrayList.Count > value)
487 return; // FIXME: throw an exception ?
496 public string InitialDirectory {
498 return initialDirectory;
502 if (Directory.Exists (value)) {
503 initialDirectory = value;
506 ChangeDirectory (null, initialDirectory);
511 [DefaultValue(false)]
512 public bool RestoreDirectory {
514 return restoreDirectory;
518 restoreDirectory = value;
522 [DefaultValue(false)]
523 public bool ShowHelp {
530 ResizeAndRelocateForHelpOrReadOnly ();
536 public string Title {
548 // this one is a hard one ;)
550 // - up to MAX_PATH characters (windef.h) = 260
551 // - no trailing dots or spaces
554 // NTFS/Posix filename:
555 // - up to 32,768 Unicode characters
556 // - trailing periods or spaces
560 public bool ValidateNames {
562 return validateNames;
566 validateNames = value;
570 public override void Reset ()
573 checkFileExists = false;
574 checkPathExists = true;
576 dereferenceLinks = true;
581 initialDirectory = "";
582 restoreDirectory = false;
585 validateNames = true;
590 public override string ToString ()
592 return base.ToString ();
595 public event CancelEventHandler FileOk {
596 add { Events.AddHandler (EventFileOk, value); }
597 remove { Events.RemoveHandler (EventFileOk, value); }
600 protected virtual IntPtr Instance {
608 // This is just for internal use with MSs version, so it doesn't need to be implemented
609 // as it can't really be accessed anyways
610 protected int Options {
615 protected override IntPtr HookProc (IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
617 throw new NotImplementedException ();
620 protected void OnFileOk (CancelEventArgs e)
622 CancelEventHandler fo = (CancelEventHandler) Events [EventFileOk];
627 protected override bool RunDialog (IntPtr hWndOwner)
631 if (last_dir_when_opened_or_saved != String.Empty)
632 ChangeDirectory (null, last_dir_when_opened_or_saved);
634 ChangeDirectory (null, start_dir);
636 fileNameComboBox.Select ();
641 internal virtual bool ShowReadOnly {
643 showReadOnly = value;
644 ResizeAndRelocateForHelpOrReadOnly ();
652 internal virtual bool ReadOnlyChecked {
654 readOnlyChecked = value;
655 readonlyCheckBox.Checked = value;
659 return readOnlyChecked;
663 internal bool BMultiSelect {
666 mwfFileView.MultiSelect = value;
674 internal string OpenSaveButtonText {
676 openSaveButton.Text = value;
680 internal string SearchSaveLabel {
682 searchSaveLabel.Text = value;
686 private void SelectFilter ()
688 do_not_call_OnSelectedIndexChangedFileTypeComboBox = true;
689 fileTypeComboBox.BeginUpdate ();
690 fileTypeComboBox.SelectedIndex = FilterIndex - 1;
691 fileTypeComboBox.EndUpdate ();
693 mwfFileView.FilterIndex = FilterIndex;
695 mwfFileView.UpdateFileView (currentDirectoryInfo_or_current_special_case);
698 private bool SetFileName (string fname)
700 bool rooted = Path.IsPathRooted (fname);
703 if (File.Exists (Path.Combine (currentDirectoryName, fname))) {
704 fileNameComboBox.Text = fname;
705 mwfFileView.SetSelectedIndexTo (fname);
711 if (File.Exists (fname)) {
712 fileNameComboBox.Text = Path.GetFileName (fname);
713 ChangeDirectory (null, Path.GetDirectoryName (fname));
714 mwfFileView.SetSelectedIndexTo (fname);
723 void OnClickContextMenu (object sender, EventArgs e)
725 MenuItem senderMenuItem = sender as MenuItem;
727 if (senderMenuItem.Index == 0) {
728 senderMenuItem.Checked = !senderMenuItem.Checked;
729 showHiddenFiles = senderMenuItem.Checked;
730 mwfFileView.ShowHiddenFiles = showHiddenFiles;
731 mwfFileView.UpdateFileView (currentDirectoryInfo_or_current_special_case);
735 void OnClickOpenSaveButton (object sender, EventArgs e)
737 if (fileDialogType == FileDialogType.OpenFileDialog && mwfFileView.SelectedItems [0] != null) {
738 string path = Path.Combine (currentDirectoryName, mwfFileView.SelectedItems [0].Text);
739 if (Directory.Exists (path)) {
740 ChangeDirectory (null, path);
741 openSaveButton.Select ();
747 if (!show_special_case) {
748 string fileFromComboBox = fileNameComboBox.Text.Trim ();
750 if (fileFromComboBox.Length > 0) {
751 if (!Path.IsPathRooted (fileFromComboBox))
752 fileFromComboBox = Path.Combine (currentDirectoryName, fileFromComboBox);
754 FileInfo fileInfo = new FileInfo (fileFromComboBox);
755 if (fileInfo.Exists || fileDialogType == FileDialogType.SaveFileDialog)
756 currentFileName = fileFromComboBox;
758 DirectoryInfo dirInfo = new DirectoryInfo (fileFromComboBox);
759 if (dirInfo.Exists) {
760 ChangeDirectory (null, dirInfo.FullName);
762 currentFileName = "";
764 fileNameComboBox.Text = " ";
771 if (currentFileName == null || currentFileName == String.Empty) {
772 currentFileName = fileNameComboBox.Text.Trim ();
774 if (currentFileName.Length > 0) {
775 FileInfo fileInfo = new FileInfo (currentFileName);
776 if (!fileInfo.Exists) {
777 DirectoryInfo dirInfo = new DirectoryInfo (currentFileName);
778 if (dirInfo.Exists) {
779 ChangeDirectory (null, dirInfo.FullName);
781 currentFileName = "";
783 fileNameComboBox.Text = " ";
791 if (currentDirectoryName == String.Empty)
792 currentDirectoryName = Path.GetDirectoryName (currentFileName);
795 if (fileDialogType == FileDialogType.OpenFileDialog) {
796 if (checkFileExists) {
797 if (!File.Exists (currentFileName)) {
798 string message = "\"" + currentFileName + "\" doesn't exist. Please verify that you have entered the correct file name.";
799 MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
801 currentFileName = "";
807 if (overwritePrompt) {
808 if (File.Exists (currentFileName)) {
809 string message = "\"" + currentFileName + "\" exists. Overwrite ?";
810 DialogResult dr = MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
812 if (dr == DialogResult.Cancel) {
813 currentFileName = "";
821 if (!File.Exists (currentFileName)) {
822 string message = "\"" + currentFileName + "\" doesn't exist. Create ?";
823 DialogResult dr = MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
825 if (dr == DialogResult.Cancel) {
826 currentFileName = "";
834 if (fileDialogType == FileDialogType.SaveFileDialog) {
835 if (addExtension && defaultExt.Length > 0) {
836 if (!currentFileName.EndsWith (defaultExt)) {
837 currentFileName += "." + defaultExt;
842 fileNames = new string [1];
844 fileNames [0] = currentFileName;
846 fileName = currentFileName;
848 WriteRecentlyUsed ();
849 } else // multiSelect = true
850 if (fileDialogType != FileDialogType.SaveFileDialog) {
851 if (mwfFileView.SelectedItems.Count > 0) {
852 // first remove all selected directories
853 ArrayList al = new ArrayList ();
855 foreach (ListViewItem lvi in mwfFileView.SelectedItems) {
856 FileStruct fileStruct = (FileStruct)mwfFileView.FileHashtable [lvi.Text];
858 if (fileStruct.attributes != FileAttributes.Directory) {
863 fileName = ((FileStruct)al [0]).fullname;
865 fileNames = new string [al.Count];
867 for (int i = 0; i < al.Count; i++) {
868 fileNames [i] = ((FileStruct)al [i]).fullname;
873 if (checkPathExists) {
874 if (!Directory.Exists (currentDirectoryName)) {
875 string message = "\"" + currentDirectoryName + "\" doesn't exist. Please verify that you have entered the correct directory name.";
876 MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
878 if (initialDirectory == String.Empty)
879 currentDirectoryName = Environment.CurrentDirectory;
881 currentDirectoryName = initialDirectory;
887 if (restoreDirectory)
888 currentDirectoryName = restoreDirectoryString;
890 if (current_special_case != String.Empty)
891 last_dir_when_opened_or_saved = current_special_case;
893 last_dir_when_opened_or_saved = currentDirectoryName;
895 CancelEventArgs cancelEventArgs = new CancelEventArgs ();
897 cancelEventArgs.Cancel = false;
899 OnFileOk (cancelEventArgs);
901 form.DialogResult = DialogResult.OK;
904 void OnClickCancelButton (object sender, EventArgs e)
906 if (restoreDirectory)
907 currentDirectoryName = restoreDirectoryString;
909 CancelEventArgs cancelEventArgs = new CancelEventArgs ();
911 cancelEventArgs.Cancel = true;
913 OnFileOk (cancelEventArgs);
915 form.DialogResult = DialogResult.Cancel;
918 void OnClickHelpButton (object sender, EventArgs e)
923 void OnClickSmallButtonToolBar (object sender, ToolBarButtonClickEventArgs e)
925 if (e.Button == upToolBarButton) {
926 if (currentDirectoryInfo != null && currentDirectoryInfo.Parent != null)
927 ChangeDirectory (null, currentDirectoryInfo.Parent.FullName);
929 if (e.Button == backToolBarButton) {
932 if (e.Button == newdirToolBarButton) {
937 void OnClickMenuToolBarContextMenu (object sender, EventArgs e)
939 MenuItem senderMenuItem = (MenuItem)sender;
941 previousCheckedMenuItem.Checked = false;
942 senderMenuItem.Checked = true;
943 previousCheckedMenuItem = senderMenuItem;
947 switch (senderMenuItem.Index) {
949 mwfFileView.View = View.SmallIcon;
952 mwfFileView.View = View.LargeIcon;
955 mwfFileView.View = View.LargeIcon;
958 mwfFileView.View = View.List;
961 mwfFileView.View = View.Details;
968 mwfFileView.UpdateFileView (currentDirectoryInfo_or_current_special_case);
971 void OnSelectedIndexChangedFileTypeComboBox (object sender, EventArgs e)
973 if (do_not_call_OnSelectedIndexChangedFileTypeComboBox) {
974 do_not_call_OnSelectedIndexChangedFileTypeComboBox = false;
978 filterIndex = fileTypeComboBox.SelectedIndex + 1;
980 mwfFileView.FilterIndex = filterIndex;
982 mwfFileView.UpdateFileView (currentDirectoryInfo_or_current_special_case);
985 void OnSelectedFileChangedFileView (object sender, EventArgs e)
987 fileNameComboBox.Text = mwfFileView.FileName;
988 currentFileName = mwfFileView.FullFileName;
991 void OnDirectoryChangedFileView (object sender, EventArgs e)
993 ChangeDirectory (sender, mwfFileView.FullFileName);
996 void OnForceDialogEndFileView (object sender, EventArgs e)
1001 void OnSelectedFilesChangedFileView (object sender, EventArgs e)
1003 fileNameComboBox.Text = mwfFileView.SelectedFilesString;
1006 void OnDirectoryChangedDirComboBox (object sender, EventArgs e)
1008 ChangeDirectory (sender, dirComboBox.CurrentPath);
1011 void OnCheckCheckChanged (object sender, EventArgs e)
1013 ReadOnlyChecked = readonlyCheckBox.Checked;
1016 void OnDirectoryUp (Object sender, EventArgs e)
1018 if (currentDirectoryInfo != null && currentDirectoryInfo.Parent != null)
1019 ChangeDirectory (null, currentDirectoryInfo.Parent.FullName);
1021 // make mwfFileView the active control
1022 mwfFileView.Select ();
1025 private void UpdateFilters ()
1027 ArrayList filters = fileFilter.FilterArrayList;
1029 fileTypeComboBox.BeginUpdate ();
1031 fileTypeComboBox.Items.Clear ();
1033 foreach (FilterStruct fs in filters) {
1034 fileTypeComboBox.Items.Add (fs.filterName);
1037 fileTypeComboBox.SelectedIndex = FilterIndex - 1;
1039 fileTypeComboBox.EndUpdate ();
1041 mwfFileView.FilterArrayList = filters;
1043 mwfFileView.FilterIndex = FilterIndex;
1045 mwfFileView.UpdateFileView (currentDirectoryInfo_or_current_special_case);
1048 internal void ChangeDirectory (object sender, string path_or_special_case)
1050 show_special_case = false;
1052 if (sender != dirComboBox)
1053 dirComboBox.CurrentPath = path_or_special_case;
1055 if (sender != popupButtonPanel)
1056 popupButtonPanel.SetPopupButtonStateByPath (path_or_special_case);
1058 if (currentDirectoryInfo != null)
1059 PushDirectory (currentDirectoryInfo);
1061 PushDirectory (current_special_case);
1063 if (path_or_special_case == recently_string) {
1064 currentDirectoryName = String.Empty;
1066 currentDirectoryInfo = null;
1067 show_special_case = true;
1069 current_special_case = recently_string;
1071 mwfFileView.UpdateFileView (recently_string);
1073 } else if (path_or_special_case == mycomputer_string) {
1074 currentDirectoryName = String.Empty;
1076 currentDirectoryInfo = null;
1077 show_special_case = true;
1079 current_special_case = mycomputer_string;
1081 mwfFileView.UpdateFileView (mycomputer_string);
1083 } else if (path_or_special_case == network_string) {
1084 currentDirectoryName = String.Empty;
1086 currentDirectoryInfo = null;
1087 show_special_case = true;
1089 current_special_case = network_string;
1091 mwfFileView.UpdateFileView (network_string);
1094 currentDirectoryName = path_or_special_case;
1096 current_special_case = "";
1098 currentDirectoryInfo = new DirectoryInfo (path_or_special_case);
1100 mwfFileView.UpdateFileView (currentDirectoryInfo);
1104 private void ForceDialogEnd ()
1106 OnClickOpenSaveButton (this, EventArgs.Empty);
1109 private void PushDirectory (object directoryInfo_or_string)
1111 directoryStack.Push (directoryInfo_or_string);
1112 backToolBarButton.Enabled = (directoryStack.Count > 1);
1115 private void PopDirectory ()
1117 if (directoryStack.Count == 0)
1120 show_special_case = false;
1122 object directoryInfo_or_string = directoryStack.Pop ();
1124 if (directoryInfo_or_string is DirectoryInfo) {
1125 currentDirectoryInfo = directoryInfo_or_string as DirectoryInfo;
1127 currentDirectoryName = currentDirectoryInfo.FullName;
1129 current_special_case = String.Empty;
1131 if (directoryInfo_or_string is string) {
1132 currentDirectoryInfo = null;
1133 currentDirectoryName = String.Empty;
1134 show_special_case = true;
1135 current_special_case = directoryInfo_or_string as string;
1138 backToolBarButton.Enabled = (directoryStack.Count > 1);
1140 dirComboBox.CurrentPath = currentDirectoryName_or_special_case;
1142 popupButtonPanel.SetPopupButtonStateByPath (currentDirectoryName_or_special_case);
1144 mwfFileView.UpdateFileView (currentDirectoryInfo_or_current_special_case);
1147 private void ResizeAndRelocateForHelpOrReadOnly ()
1149 form.SuspendLayout ();
1150 if (ShowHelp || ShowReadOnly) {
1151 mwfFileView.Size = new Size (449, 250);
1152 fileNameLabel.Location = new Point (102, 298);
1153 fileNameComboBox.Location = new Point (195, 298);
1154 fileTypeLabel.Location = new Point (102, 324);
1155 fileTypeComboBox.Location = new Point (195, 324);
1156 openSaveButton.Location = new Point (475, 298);
1157 cancelButton.Location = new Point (475, 324);
1159 mwfFileView.Size = new Size (449, 282);
1160 fileNameLabel.Location = new Point (102, 330);
1161 fileNameComboBox.Location = new Point (195, 330);
1162 fileTypeLabel.Location = new Point (102, 356);
1163 fileTypeComboBox.Location = new Point (195, 356);
1164 openSaveButton.Location = new Point (475, 330);
1165 cancelButton.Location = new Point (475, 356);
1169 form.Controls.Add (helpButton);
1171 form.Controls.Remove (helpButton);
1174 form.Controls.Add (readonlyCheckBox);
1176 form.Controls.Remove (readonlyCheckBox);
1177 form.ResumeLayout ();
1180 private void WriteRecentlyUsed ()
1182 int platform = (int) Environment.OSVersion.Platform;
1184 // on a *nix platform we use "$HOME/.recently-used" to store our recently used files (GNOME, libegg like)
1185 if ((platform == 4) || (platform == 128)) {
1186 string personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
1187 string recently_used_path = Path.Combine (personal_folder, ".recently-used");
1189 if (File.Exists (recently_used_path) && new FileInfo (recently_used_path).Length > 0) {
1190 XmlDocument xml_doc = new XmlDocument ();
1191 xml_doc.Load (recently_used_path);
1193 XmlNode grand_parent_node = xml_doc.SelectSingleNode ("RecentFiles");
1195 if (grand_parent_node != null) {
1196 // create a new element
1197 XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
1199 XmlElement new_child = xml_doc.CreateElement ("URI");
1200 UriBuilder ub = new UriBuilder ();
1201 ub.Path = currentFileName;
1204 XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
1205 new_child.AppendChild (new_text_child);
1207 new_recent_item_node.AppendChild (new_child);
1209 new_child = xml_doc.CreateElement ("Mime-Type");
1210 new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (currentFileName));
1211 new_child.AppendChild (new_text_child);
1213 new_recent_item_node.AppendChild (new_child);
1215 new_child = xml_doc.CreateElement ("Timestamp");
1216 long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
1217 new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
1218 new_child.AppendChild (new_text_child);
1220 new_recent_item_node.AppendChild (new_child);
1222 new_child = xml_doc.CreateElement ("Groups");
1224 new_recent_item_node.AppendChild (new_child);
1226 // now search the nodes in grand_parent_node for another instance of the new uri and if found remove it
1227 // so that the new node is the first one
1228 foreach (XmlNode n in grand_parent_node.ChildNodes) {
1229 XmlNode uri_node = n.SelectSingleNode ("URI");
1230 if (uri_node != null) {
1231 XmlNode uri_node_child = uri_node.FirstChild;
1232 if (uri_node_child is XmlText)
1233 if (ub.ToString () == ((XmlText)uri_node_child).Data) {
1234 grand_parent_node.RemoveChild (n);
1240 // prepend the new recent item to the grand parent node list
1241 grand_parent_node.PrependChild (new_recent_item_node);
1243 // limit the # of RecentItems to 10
1244 if (grand_parent_node.ChildNodes.Count > 10) {
1245 while (grand_parent_node.ChildNodes.Count > 10)
1246 grand_parent_node.RemoveChild (grand_parent_node.LastChild);
1250 xml_doc.Save (recently_used_path);
1251 } catch (Exception) {
1255 XmlDocument xml_doc = new XmlDocument ();
1256 xml_doc.AppendChild (xml_doc.CreateXmlDeclaration ("1.0", "", ""));
1258 XmlElement recentFiles_element = xml_doc.CreateElement ("RecentFiles");
1260 XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
1262 XmlElement new_child = xml_doc.CreateElement ("URI");
1263 UriBuilder ub = new UriBuilder ();
1264 ub.Path = currentFileName;
1267 XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
1268 new_child.AppendChild (new_text_child);
1270 new_recent_item_node.AppendChild (new_child);
1272 new_child = xml_doc.CreateElement ("Mime-Type");
1273 new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (currentFileName));
1274 new_child.AppendChild (new_text_child);
1276 new_recent_item_node.AppendChild (new_child);
1278 new_child = xml_doc.CreateElement ("Timestamp");
1279 long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
1280 new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
1281 new_child.AppendChild (new_text_child);
1283 new_recent_item_node.AppendChild (new_child);
1285 new_child = xml_doc.CreateElement ("Groups");
1287 new_recent_item_node.AppendChild (new_child);
1289 recentFiles_element.AppendChild (new_recent_item_node);
1291 xml_doc.AppendChild (recentFiles_element);
1294 xml_doc.Save (recently_used_path);
1295 } catch (Exception) {
1301 private object currentDirectoryInfo_or_current_special_case {
1303 if (currentDirectoryInfo != null)
1304 return currentDirectoryInfo;
1306 return current_special_case;
1310 private string currentDirectoryName_or_special_case {
1312 if (currentDirectoryName != String.Empty)
1313 return currentDirectoryName;
1315 return current_special_case;
1319 internal class PopupButtonPanel : Panel {
1320 internal class PopupButton : Control {
1321 internal enum PopupButtonState { Normal, Down, Up}
1323 private Image image = null;
1324 private PopupButtonState popupButtonState = PopupButtonState.Normal;
1325 private StringFormat text_format = new StringFormat();
1326 private Rectangle text_rect = Rectangle.Empty;
1328 public PopupButton ()
1330 text_format.Alignment = StringAlignment.Center;
1331 text_format.LineAlignment = StringAlignment.Near;
1333 SetStyle (ControlStyles.DoubleBuffer, true);
1334 SetStyle (ControlStyles.AllPaintingInWmPaint, true);
1335 SetStyle (ControlStyles.UserPaint, true);
1338 public Image Image {
1349 public PopupButtonState ButtonState {
1351 popupButtonState = value;
1356 return popupButtonState;
1360 protected override void OnPaint (PaintEventArgs pe)
1367 private void Draw (PaintEventArgs pe)
1369 Graphics gr = pe.Graphics;
1371 gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
1374 if (image != null) {
1375 int i_x = (ClientSize.Width - image.Width) / 2;
1377 gr.DrawImage (image, i_x, i_y);
1380 if (Text != String.Empty) {
1381 if (text_rect == Rectangle.Empty)
1382 text_rect = new Rectangle (0, Height - 30, Width, Height - 30);
1384 gr.DrawString (Text, Font, ThemeEngine.Current.ResPool.GetSolidBrush (ForeColor), text_rect, text_format);
1387 switch (popupButtonState) {
1388 case PopupButtonState.Up:
1389 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, 0, ClientSize.Width - 1, 0);
1390 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, 0, 0, ClientSize.Height - 1);
1391 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1);
1392 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1);
1395 case PopupButtonState.Down:
1396 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, 0, ClientSize.Width - 1, 0);
1397 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.Black), 0, 0, 0, ClientSize.Height - 1);
1398 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1);
1399 gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1);
1404 protected override void OnMouseEnter (EventArgs e)
1406 if (popupButtonState != PopupButtonState.Down)
1407 popupButtonState = PopupButtonState.Up;
1409 base.OnMouseEnter (e);
1412 protected override void OnMouseLeave (EventArgs e)
1414 if (popupButtonState != PopupButtonState.Down)
1415 popupButtonState = PopupButtonState.Normal;
1417 base.OnMouseLeave (e);
1420 protected override void OnClick (EventArgs e)
1422 popupButtonState = PopupButtonState.Down;
1428 private FileDialog fileDialog;
1430 private PopupButton recentlyusedButton;
1431 private PopupButton desktopButton;
1432 private PopupButton personalButton;
1433 private PopupButton mycomputerButton;
1434 private PopupButton networkButton;
1436 private PopupButton lastPopupButton = null;
1438 private int platform = (int) Environment.OSVersion.Platform;
1440 public PopupButtonPanel (FileDialog fileDialog)
1442 this.fileDialog = fileDialog;
1446 BorderStyle = BorderStyle.Fixed3D;
1447 BackColor = Color.FromArgb (128, 128, 128);
1448 Size = new Size (85, 336);
1450 recentlyusedButton = new PopupButton ();
1451 desktopButton = new PopupButton ();
1452 personalButton = new PopupButton ();
1453 mycomputerButton = new PopupButton ();
1454 networkButton = new PopupButton ();
1456 recentlyusedButton.Size = new Size (81, 64);
1457 recentlyusedButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 30);
1458 recentlyusedButton.BackColor = BackColor;
1459 recentlyusedButton.ForeColor = Color.White;
1460 recentlyusedButton.Location = new Point (0, 0);
1461 recentlyusedButton.Text = "Recently\nused";
1462 recentlyusedButton.Click += new EventHandler (OnClickButton);
1464 desktopButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 30);
1465 desktopButton.BackColor = BackColor;
1466 desktopButton.ForeColor = Color.White;
1467 desktopButton.Size = new Size (81, 64);
1468 desktopButton.Location = new Point (0, 64);
1469 desktopButton.Text = "Desktop";
1470 desktopButton.Click += new EventHandler (OnClickButton);
1472 personalButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 30);
1473 personalButton.BackColor = BackColor;
1474 personalButton.ForeColor = Color.White;
1475 personalButton.Size = new Size (81, 64);
1476 personalButton.Location = new Point (0, 128);
1477 personalButton.Text = "Personal";
1478 personalButton.Click += new EventHandler (OnClickButton);
1480 mycomputerButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 30);
1481 mycomputerButton.BackColor = BackColor;
1482 mycomputerButton.ForeColor = Color.White;
1483 mycomputerButton.Size = new Size (81, 64);
1484 mycomputerButton.Location = new Point (0, 192);
1485 mycomputerButton.Text = "My Computer";
1486 mycomputerButton.Click += new EventHandler (OnClickButton);
1488 networkButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 30);
1489 networkButton.BackColor = BackColor;
1490 networkButton.ForeColor = Color.White;
1491 networkButton.Size = new Size (81, 64);
1492 networkButton.Location = new Point (0, 256);
1493 networkButton.Text = "My Network";
1494 networkButton.Click += new EventHandler (OnClickButton);
1496 Controls.Add (recentlyusedButton);
1497 Controls.Add (desktopButton);
1498 Controls.Add (personalButton);
1499 Controls.Add (mycomputerButton);
1500 Controls.Add (networkButton);
1502 ResumeLayout (false);
1505 void OnClickButton (object sender, EventArgs e)
1507 if (lastPopupButton != null && (PopupButton)sender != lastPopupButton)
1508 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1509 lastPopupButton = sender as PopupButton;
1511 if (sender == recentlyusedButton) {
1512 if ((platform == 4) || (platform == 128))
1513 // do NOT change the following line!
1514 // FileDialog uses a special handling for recently used files on *nix
1515 // recently used files are not stored as links in a directory but
1516 // as a xml file called .recently-used in the users home dir
1517 // This matches the Freedesktop.org spec which gnome uses
1518 fileDialog.ChangeDirectory (this, FileDialog.recently_string);
1520 fileDialog.ChangeDirectory (this, ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments));
1522 if (sender == desktopButton) {
1523 fileDialog.ChangeDirectory (this, ThemeEngine.Current.Places (UIIcon.PlacesDesktop));
1525 if (sender == personalButton) {
1526 fileDialog.ChangeDirectory (this, ThemeEngine.Current.Places (UIIcon.PlacesPersonal));
1528 if (sender == mycomputerButton) {
1529 if ((platform == 4) || (platform == 128))
1530 // do NOT change the following line!
1531 // on *nix we do not have a special folder MyComputer
1532 fileDialog.ChangeDirectory (this, FileDialog.mycomputer_string);
1534 fileDialog.ChangeDirectory (this, ThemeEngine.Current.Places (UIIcon.PlacesMyComputer));
1536 if (sender == networkButton) {
1537 if ((platform == 4) || (platform == 128))
1538 fileDialog.ChangeDirectory (this, FileDialog.network_string);
1540 fileDialog.ChangeDirectory (this, ThemeEngine.Current.Places (UIIcon.PlacesMyNetwork));
1544 public void SetPopupButtonStateByPath (string path)
1546 if (path == FileDialog.recently_string ||
1547 path == ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments)) {
1548 if (lastPopupButton != recentlyusedButton) {
1549 if (lastPopupButton != null)
1550 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1551 recentlyusedButton.ButtonState = PopupButton.PopupButtonState.Down;
1552 lastPopupButton = recentlyusedButton;
1555 if (path == ThemeEngine.Current.Places (UIIcon.PlacesDesktop)) {
1556 if (lastPopupButton != desktopButton) {
1557 if (lastPopupButton != null)
1558 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1559 desktopButton.ButtonState = PopupButton.PopupButtonState.Down;
1560 lastPopupButton = desktopButton;
1563 if (path == ThemeEngine.Current.Places (UIIcon.PlacesPersonal)) {
1564 if (lastPopupButton != personalButton) {
1565 if (lastPopupButton != null)
1566 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1567 personalButton.ButtonState = PopupButton.PopupButtonState.Down;
1568 lastPopupButton = personalButton;
1571 if (path == FileDialog.mycomputer_string ||
1572 path == ThemeEngine.Current.Places (UIIcon.PlacesMyComputer)) {
1573 if (lastPopupButton != mycomputerButton) {
1574 if (lastPopupButton != null)
1575 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1576 mycomputerButton.ButtonState = PopupButton.PopupButtonState.Down;
1577 lastPopupButton = mycomputerButton;
1580 if (path == FileDialog.network_string ||
1581 path == ThemeEngine.Current.Places (UIIcon.PlacesMyNetwork)) {
1582 if (lastPopupButton != networkButton) {
1583 if (lastPopupButton != null)
1584 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1585 networkButton.ButtonState = PopupButton.PopupButtonState.Down;
1586 lastPopupButton = networkButton;
1589 if (lastPopupButton != null) {
1590 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1591 lastPopupButton = null;
1598 internal struct FilterStruct {
1599 public string filterName;
1600 public StringCollection filters;
1602 public FilterStruct (string filterName, string filter)
1604 this.filterName = filterName;
1606 filters = new StringCollection ();
1608 SplitFilters (filter);
1611 private void SplitFilters (string filter)
1613 string[] split = filter.Split (new char [] {';'});
1615 filters.AddRange (split);
1619 internal struct FileStruct {
1620 public enum FileStructType {
1627 public string fullname;
1628 public FileAttributes attributes;
1630 public FileStructType type;
1634 internal class MWFFileView : ListView {
1635 private ArrayList filterArrayList;
1637 // store the FileStruct of all files in the current directory
1638 private Hashtable fileHashtable = new Hashtable();
1640 private bool showHiddenFiles = false;
1642 private EventHandler on_selected_file_changed;
1643 private EventHandler on_selected_files_changed;
1644 private EventHandler on_directory_changed;
1645 private EventHandler on_force_dialog_end;
1646 private EventHandler on_one_directory_up;
1648 private string fileName;
1649 private string fullFileName;
1650 private string selectedFilesString;
1652 private int filterIndex;
1654 private ToolTip toolTip;
1655 private int oldItemIndexForToolTip = -1;
1657 private bool internal_key_up = false;
1659 private MasterMount masterMount = new MasterMount ();
1661 public MWFFileView ()
1665 toolTip = new ToolTip ();
1666 toolTip.InitialDelay = 300;
1667 toolTip.ReshowDelay = 0;
1671 SmallImageList = MimeIconEngine.SmallIcons;
1672 LargeImageList = MimeIconEngine.LargeIcons;
1676 ResumeLayout (false);
1678 KeyUp += new KeyEventHandler (MWF_KeyUp);
1681 public ArrayList FilterArrayList {
1683 filterArrayList = value;
1687 return filterArrayList;
1691 public Hashtable FileHashtable {
1693 return fileHashtable;
1697 public bool ShowHiddenFiles {
1699 showHiddenFiles = value;
1703 return showHiddenFiles;
1707 public string FileName {
1713 public string FullFileName {
1715 return fullFileName;
1719 public int FilterIndex {
1721 filterIndex = value;
1729 public string SelectedFilesString {
1731 selectedFilesString = value;
1735 return selectedFilesString;
1739 public void SetSelectedIndexTo (string fname)
1741 foreach (ListViewItem item in Items) {
1742 if (item.Text == fname) {
1744 SelectedItems.Clear ();
1745 item.Selected = true;
1752 private ArrayList GetFileInfoArrayList (DirectoryInfo directoryInfo)
1754 ArrayList arrayList = new ArrayList ();
1756 if (filterArrayList != null && filterArrayList.Count != 0) {
1757 FilterStruct fs = (FilterStruct)filterArrayList [filterIndex - 1];
1759 foreach (string s in fs.filters)
1760 arrayList.AddRange (directoryInfo.GetFiles (s));
1762 arrayList.AddRange (directoryInfo.GetFiles ());
1767 private ArrayList GetFileInfoArrayListByArrayList (ArrayList al)
1769 ArrayList arrayList = new ArrayList ();
1771 foreach (string path in al) {
1772 if (File.Exists (path)) {
1773 FileInfo fi = new FileInfo (path);
1781 public void UpdateFileView (object directoryInfo_or_string)
1783 if (directoryInfo_or_string is DirectoryInfo)
1784 UpdateFileViewByDirectoryInfo (directoryInfo_or_string as DirectoryInfo);
1786 UpdateFileViewByString (directoryInfo_or_string as string);
1788 if (Items.Count > 0 && !internal_key_up) {
1789 ListViewItem item = Items [0];
1790 item.Selected = true;
1792 internal_key_up = false;
1795 private void UpdateFileViewByDirectoryInfo (DirectoryInfo inputDirectoryInfo)
1797 DirectoryInfo directoryInfo = inputDirectoryInfo;
1799 DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories ();
1801 ArrayList fileInfoArrayList = GetFileInfoArrayList (directoryInfo);
1803 fileHashtable.Clear ();
1808 SelectedItems.Clear ();
1810 foreach (DirectoryInfo directoryInfoi in directoryInfoArray) {
1811 if (!ShowHiddenFiles)
1812 if (directoryInfoi.Name.StartsWith (".") || directoryInfoi.Attributes == FileAttributes.Hidden)
1815 FileStruct fileStruct = new FileStruct ();
1816 fileStruct.type = FileStruct.FileStructType.Directoy;
1818 fileStruct.fullname = directoryInfoi.FullName;
1820 ListViewItem listViewItem = new ListViewItem (directoryInfoi.Name);
1822 int index = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
1824 listViewItem.ImageIndex = index;
1826 listViewItem.SubItems.Add ("");
1827 listViewItem.SubItems.Add ("Directory");
1828 listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
1830 fileStruct.attributes = FileAttributes.Directory;
1832 fileHashtable.Add (directoryInfoi.Name, fileStruct);
1834 Items.Add (listViewItem);
1837 foreach (FileInfo fileInfo in fileInfoArrayList) {
1838 DoOneFileInfo (fileInfo);
1844 private void UpdateFileViewByString (string kind)
1846 if (kind == FileDialog.recently_string) {
1847 ArrayList fileInfoArrayList = GetFileInfoArrayListByArrayList (GetFreedesktopSpecRecentlyUsed ());
1849 fileHashtable.Clear ();
1854 SelectedItems.Clear ();
1856 foreach (FileInfo fileInfo in fileInfoArrayList) {
1857 DoOneFileInfo (fileInfo);
1862 } else if (kind == FileDialog.mycomputer_string) {
1864 if (masterMount.ProcMountAvailable) {
1865 masterMount.GetMounts ();
1867 fileHashtable.Clear ();
1872 SelectedItems.Clear ();
1874 foreach (MasterMount.Mount mount in masterMount.Block_devices) {
1875 FileStruct fileStruct = new FileStruct ();
1876 fileStruct.type = FileStruct.FileStructType.Device;
1878 fileStruct.fullname = mount.mount_point;
1880 string item_name = "HDD (" + mount.fsType + ", " + mount.device_short + ")";
1881 ListViewItem listViewItem = new ListViewItem (item_name);
1883 int index = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
1885 listViewItem.ImageIndex = index;
1887 listViewItem.SubItems.Add ("");
1888 listViewItem.SubItems.Add ("Harddisk");
1889 // listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
1891 fileStruct.attributes = FileAttributes.Directory;
1893 fileHashtable.Add (item_name, fileStruct);
1895 Items.Add (listViewItem);
1898 foreach (MasterMount.Mount mount in masterMount.Removable_devices) {
1899 FileStruct fileStruct = new FileStruct ();
1900 fileStruct.type = FileStruct.FileStructType.Device;
1902 fileStruct.fullname = mount.mount_point;
1904 bool is_dvd_cdrom = mount.fsType == MasterMount.FsTypes.usbfs ? false : true;
1905 string type_name = is_dvd_cdrom ? "DVD/CD-Rom" : "USB";
1906 string mime_type = is_dvd_cdrom ? "cdrom/cdrom" : "removable/removable";
1908 string item_name = type_name + " (" + mount.device_short + ")";
1910 ListViewItem listViewItem = new ListViewItem (item_name);
1912 int index = MimeIconEngine.GetIconIndexForMimeType (mime_type);
1914 listViewItem.ImageIndex = index;
1916 listViewItem.SubItems.Add ("");
1917 listViewItem.SubItems.Add (type_name);
1918 // listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
1920 fileStruct.attributes = FileAttributes.Directory;
1922 fileHashtable.Add (item_name, fileStruct);
1924 Items.Add (listViewItem);
1927 ListViewItem listViewItem2 = new ListViewItem ("Desktop");
1929 int index2 = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
1931 FileStruct fileStruct2 = new FileStruct ();
1932 fileStruct2.type = FileStruct.FileStructType.Directoy;
1934 fileStruct2.fullname = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
1936 listViewItem2.ImageIndex = index2;
1938 listViewItem2.SubItems.Add ("");
1939 listViewItem2.SubItems.Add ("Desktop");
1940 // listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
1942 fileStruct2.attributes = FileAttributes.Directory;
1944 fileHashtable.Add ("Desktop", fileStruct2);
1946 Items.Add (listViewItem2);
1949 listViewItem2 = new ListViewItem ("Personal");
1951 index2 = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
1953 fileStruct2 = new FileStruct ();
1954 fileStruct2.type = FileStruct.FileStructType.Directoy;
1956 fileStruct2.fullname = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
1958 listViewItem2.ImageIndex = index2;
1960 listViewItem2.SubItems.Add ("");
1961 listViewItem2.SubItems.Add ("Personal");
1962 // listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
1964 fileStruct2.attributes = FileAttributes.Directory;
1966 fileHashtable.Add ("Personal", fileStruct2);
1968 Items.Add (listViewItem2);
1975 } else if (kind == FileDialog.network_string) {
1977 if (masterMount.ProcMountAvailable) {
1978 masterMount.GetMounts ();
1980 fileHashtable.Clear ();
1985 SelectedItems.Clear ();
1994 private void AddNetwork ()
1996 foreach (MasterMount.Mount mount in masterMount.Network_devices) {
1997 FileStruct fileStruct = new FileStruct ();
1998 fileStruct.type = FileStruct.FileStructType.Network;
2000 fileStruct.fullname = mount.mount_point;
2002 string item_name = "Network (" + mount.fsType + ", " + mount.device_short + ")";
2004 ListViewItem listViewItem = new ListViewItem (item_name);
2008 switch (mount.fsType) {
2009 case MasterMount.FsTypes.nfs:
2010 index = MimeIconEngine.GetIconIndexForMimeType ("nfs/nfs");
2012 case MasterMount.FsTypes.smbfs:
2013 index = MimeIconEngine.GetIconIndexForMimeType ("smb/smb");
2015 case MasterMount.FsTypes.ncpfs:
2016 index = MimeIconEngine.GetIconIndexForMimeType ("network/network");
2022 listViewItem.ImageIndex = index;
2024 listViewItem.SubItems.Add ("");
2025 listViewItem.SubItems.Add ("Network");
2026 // listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
2028 fileStruct.attributes = FileAttributes.Directory;
2030 fileHashtable.Add (item_name, fileStruct);
2032 Items.Add (listViewItem);
2036 private void DoOneFileInfo (FileInfo fileInfo)
2038 if (!ShowHiddenFiles)
2039 if (fileInfo.Name.StartsWith (".") || fileInfo.Attributes == FileAttributes.Hidden)
2042 FileStruct fileStruct = new FileStruct ();
2043 fileStruct.type = FileStruct.FileStructType.File;
2045 fileStruct.fullname = fileInfo.FullName;
2047 string fileName = fileInfo.Name;
2049 if (fileHashtable.ContainsKey (fileName)) {
2051 while (fileHashtable.ContainsKey (fileName + "[" + i + "]")) {
2054 fileName += "[" + i + "]";
2057 ListViewItem listViewItem = new ListViewItem (fileName);
2059 listViewItem.ImageIndex = MimeIconEngine.GetIconIndexForFile (fileStruct.fullname);
2063 if (fileInfo.Length > 1024)
2064 fileLen = fileInfo.Length / 1024;
2065 } catch (Exception) {
2069 fileStruct.size = fileLen;
2071 listViewItem.SubItems.Add (fileLen.ToString () + " KB");
2072 listViewItem.SubItems.Add ("File");
2073 listViewItem.SubItems.Add (fileInfo.LastAccessTime.ToShortDateString () + " " + fileInfo.LastAccessTime.ToShortTimeString ());
2075 fileStruct.attributes = FileAttributes.Normal;
2077 fileHashtable.Add (fileName, fileStruct);
2079 Items.Add (listViewItem);
2082 private ArrayList GetFreedesktopSpecRecentlyUsed ()
2084 // check for GNOME and KDE
2085 string personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
2086 string recently_used_path = Path.Combine (personal_folder, ".recently-used");
2088 ArrayList files_al = new ArrayList ();
2091 if (File.Exists (recently_used_path)) {
2093 XmlTextReader xtr = new XmlTextReader (recently_used_path);
2094 while (xtr.Read ()) {
2095 if (xtr.NodeType == XmlNodeType.Element && xtr.Name.ToUpper () == "URI") {
2097 Uri uri = new Uri (xtr.Value);
2098 if (!files_al.Contains (uri.LocalPath))
2099 files_al.Add (uri.LocalPath);
2103 } catch (Exception) {
2109 string full_kde_recent_document_dir = personal_folder
2111 + ".kde/share/apps/RecentDocuments";
2113 if (Directory.Exists (full_kde_recent_document_dir)) {
2114 string[] files = Directory.GetFiles (full_kde_recent_document_dir, "*.desktop");
2116 foreach (string file_name in files) {
2117 StreamReader sr = new StreamReader (file_name);
2119 string line = sr.ReadLine ();
2121 while (line != null) {
2122 line = line.Trim ();
2124 if (line.StartsWith ("URL=")) {
2125 line = line.Replace ("URL=", "");
2126 line = line.Replace ("$HOME", personal_folder);
2128 Uri uri = new Uri (line);
2129 if (!files_al.Contains (uri.LocalPath))
2130 files_al.Add (uri.LocalPath);
2134 line = sr.ReadLine ();
2145 protected override void OnClick (EventArgs e)
2148 if (SelectedItems.Count > 0) {
2149 ListViewItem listViewItem = SelectedItems [0];
2151 FileStruct fileStruct = (FileStruct)fileHashtable [listViewItem.Text];
2153 if (fileStruct.type == FileStruct.FileStructType.File) {
2154 fileName = listViewItem.Text;
2155 fullFileName = fileStruct.fullname;
2157 if (on_selected_file_changed != null)
2158 on_selected_file_changed (this, EventArgs.Empty);
2166 protected override void OnDoubleClick (EventArgs e)
2168 if (SelectedItems.Count > 0) {
2169 ListViewItem listViewItem = SelectedItems [0];
2171 FileStruct fileStruct = (FileStruct)fileHashtable [listViewItem.Text];
2173 if (fileStruct.attributes == FileAttributes.Directory) {
2174 fullFileName = fileStruct.fullname;
2176 if (on_directory_changed != null)
2177 on_directory_changed (this, EventArgs.Empty);
2179 fileName = listViewItem.Text;
2180 fullFileName = fileStruct.fullname;
2182 if (on_selected_file_changed != null)
2183 on_selected_file_changed (this, EventArgs.Empty);
2185 if (on_force_dialog_end != null)
2186 on_force_dialog_end (this, EventArgs.Empty);
2192 base.OnDoubleClick (e);
2195 protected override void OnSelectedIndexChanged (EventArgs e)
2198 if (SelectedItems.Count > 0) {
2199 selectedFilesString = "";
2201 if (SelectedItems.Count == 1) {
2202 FileStruct fileStruct = (FileStruct)fileHashtable [SelectedItems [0].Text];
2204 if (fileStruct.attributes != FileAttributes.Directory)
2205 selectedFilesString = SelectedItems [0].Text;
2207 foreach (ListViewItem lvi in SelectedItems) {
2208 FileStruct fileStruct = (FileStruct)fileHashtable [lvi.Text];
2210 if (fileStruct.attributes != FileAttributes.Directory)
2211 selectedFilesString += "\"" + lvi.Text + "\" ";
2215 if (on_selected_files_changed != null)
2216 on_selected_files_changed (this, EventArgs.Empty);
2220 base.OnSelectedIndexChanged (e);
2223 protected override void OnMouseMove (MouseEventArgs e)
2225 ListViewItem item = GetItemAt (e.X, e.Y);
2228 int currentItemIndex = item.Index;
2230 if (currentItemIndex != oldItemIndexForToolTip) {
2231 oldItemIndexForToolTip = currentItemIndex;
2233 if (toolTip != null && toolTip.Active)
2234 toolTip.Active = false;
2236 object fileStructObject = fileHashtable [item.Text];
2238 if (fileStructObject != null) {
2240 FileStruct fileStruct = (FileStruct)fileStructObject;
2242 string output = String.Empty;
2244 if (fileStruct.type == FileStruct.FileStructType.Directoy)
2245 output = String.Format ("Directory: {0}\n", fileStruct.fullname);
2246 else if (fileStruct.type == FileStruct.FileStructType.Device)
2247 output = String.Format ("Device: {0}", fileStruct.fullname);
2248 else if (fileStruct.type == FileStruct.FileStructType.Network)
2249 output = String.Format ("Network: {0}", fileStruct.fullname);
2251 output = String.Format ("File: {0}", fileStruct.fullname);
2253 toolTip.SetToolTip (this, output);
2255 toolTip.Active = true;
2260 base.OnMouseMove (e);
2263 private void MWF_KeyUp (object sender, KeyEventArgs e)
2265 if (SelectedItems.Count > 0 && e.KeyCode == Keys.Back)
2266 if (on_one_directory_up != null) {
2267 internal_key_up = true;
2268 on_one_directory_up (this, EventArgs.Empty);
2272 public event EventHandler SelectedFileChanged {
2273 add { on_selected_file_changed += value; }
2274 remove { on_selected_file_changed -= value; }
2277 public event EventHandler SelectedFilesChanged {
2278 add { on_selected_files_changed += value; }
2279 remove { on_selected_files_changed -= value; }
2282 public event EventHandler DirectoryChanged {
2283 add { on_directory_changed += value; }
2284 remove { on_directory_changed -= value; }
2287 public event EventHandler ForceDialogEnd {
2288 add { on_force_dialog_end += value; }
2289 remove { on_force_dialog_end -= value; }
2292 public event EventHandler OnDirectoryUp {
2293 add { on_one_directory_up += value; }
2294 remove { on_one_directory_up -= value; }
2298 internal class FileFilter {
2299 private ArrayList filterArrayList = new ArrayList();
2301 private string filter;
2303 public FileFilter ()
2306 public FileFilter (string filter)
2308 this.filter = filter;
2313 public ArrayList FilterArrayList {
2315 filterArrayList = value;
2319 return filterArrayList;
2323 public string Filter {
2335 private void SplitFilter ()
2337 filterArrayList.Clear ();
2340 throw new NullReferenceException ("Filter");
2342 if (filter.Length == 0)
2345 string[] filters = filter.Split (new char [] {'|'});
2347 if ((filters.Length % 2) != 0)
2348 throw new ArgumentException ("Filter");
2350 for (int i = 0; i < filters.Length; i += 2) {
2351 FilterStruct filterStruct = new FilterStruct (filters [i], filters [i + 1]);
2353 filterArrayList.Add (filterStruct);
2358 internal class DirComboBox : ComboBox {
2359 internal class DirComboBoxItem {
2360 private int imageIndex;
2361 private string name;
2362 private string path;
2365 public DirComboBoxItem (int imageIndex, string name, string path, int xPos)
2367 this.imageIndex = imageIndex;
2373 public int ImageIndex {
2383 public string Name {
2393 public string Path {
2414 private ImageList imageList = new ImageList();
2416 private string currentPath;
2418 private EventHandler on_directory_changed;
2420 private bool currentpath_internal_change = false;
2422 private int platform = (int) Environment.OSVersion.Platform;
2423 private string recently_used_tmp;
2424 private string my_computer_tmp;
2425 private string my_network_tmp;
2426 private string my_root_tmp;
2427 private Stack dirStack = new Stack();
2429 public DirComboBox ()
2433 DrawMode = DrawMode.OwnerDrawFixed;
2435 imageList.ColorDepth = ColorDepth.Depth32Bit;
2436 imageList.ImageSize = new Size (16, 16);
2437 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 16));
2438 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 16));
2439 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 16));
2440 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 16));
2441 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 16));
2442 imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.NormalFolder, 16));
2443 imageList.TransparentColor = Color.Transparent;
2445 if ((platform == 4) || (platform == 128)) {
2446 recently_used_tmp = FileDialog.recently_string;
2447 my_computer_tmp = FileDialog.mycomputer_string;
2448 my_network_tmp = FileDialog.network_string;
2451 recently_used_tmp = ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments);
2452 my_computer_tmp = ThemeEngine.Current.Places (UIIcon.PlacesMyComputer);
2453 my_network_tmp = ThemeEngine.Current.Places (UIIcon.PlacesMyNetwork);
2456 Items.AddRange (new object [] {
2457 new DirComboBoxItem (0, "Recently used", recently_used_tmp, 0),
2458 new DirComboBoxItem (1, "Desktop", ThemeEngine.Current.Places (UIIcon.PlacesDesktop), 0),
2459 new DirComboBoxItem (2, "Personal folder", ThemeEngine.Current.Places (UIIcon.PlacesPersonal), 0),
2460 new DirComboBoxItem (3, "My Computer", my_computer_tmp, 0),
2461 new DirComboBoxItem (4, "My Network", my_network_tmp, 0)
2465 if ((platform == 4) || (platform == 128)) {
2466 Items.Add(new DirComboBoxItem (5, "/", my_root_tmp, 0));
2469 ResumeLayout (false);
2472 public string CurrentPath {
2474 currentPath = value;
2476 currentpath_internal_change = true;
2485 private void CreateComboList ()
2490 if (currentPath == recently_used_tmp)
2493 if (currentPath == ThemeEngine.Current.Places (UIIcon.PlacesDesktop))
2496 if (currentPath == ThemeEngine.Current.Places (UIIcon.PlacesPersonal))
2499 if (currentPath == my_computer_tmp)
2502 if (currentPath == my_network_tmp)
2505 if (currentPath == my_root_tmp)
2508 child_of = CheckChildOf ();
2514 Items.Add (new DirComboBoxItem (0, "Recently used", recently_used_tmp, 0));
2516 Items.Add (new DirComboBoxItem (1, "Desktop", ThemeEngine.Current.Places (UIIcon.PlacesDesktop), 0));
2518 selection = AppendToParent ();
2520 Items.Add (new DirComboBoxItem (2, "Personal folder", ThemeEngine.Current.Places (UIIcon.PlacesPersonal), 0));
2522 selection = AppendToParent ();
2524 Items.Add (new DirComboBoxItem (3, "My Computer", my_computer_tmp, 0));
2526 Items.Add (new DirComboBoxItem (4, "My Network", my_network_tmp, 0));
2528 if ((platform == 4) || (platform == 128)) {
2529 Items.Add (new DirComboBoxItem (5, "/", my_root_tmp, 0));
2531 selection = AppendToParent ();
2534 if (selection != -1)
2535 SelectedIndex = selection;
2540 private int CheckChildOf ()
2544 if (currentPath == FileDialog.mycomputer_string ||
2545 currentPath == FileDialog.network_string ||
2546 currentPath == FileDialog.recently_string)
2549 DirectoryInfo di = new DirectoryInfo (currentPath);
2553 while (di.Parent != null) {
2555 if (di.FullName == ThemeEngine.Current.Places (UIIcon.PlacesDesktop))
2558 if (di.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal) || di.FullName == "/home")
2561 if (di.FullName == "/")
2570 private int AppendToParent ()
2575 while (dirStack.Count != 0) {
2576 DirectoryInfo dii = dirStack.Pop () as DirectoryInfo;
2577 selection = Items.Add (new DirComboBoxItem (5, dii.Name, dii.FullName, xPos + 4));
2584 protected override void OnDrawItem (DrawItemEventArgs e)
2589 Bitmap bmp = new Bitmap (e.Bounds.Width, e.Bounds.Height, e.Graphics);
2590 Graphics gr = Graphics.FromImage (bmp);
2592 DirComboBoxItem dcbi = Items [e.Index] as DirComboBoxItem;
2594 Color backColor = e.BackColor;
2595 Color foreColor = e.ForeColor;
2597 int xPos = dcbi.XPos;
2599 if ((e.State & DrawItemState.ComboBoxEdit) != 0)
2602 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
2603 backColor = ThemeEngine.Current.ColorHighlight;
2604 foreColor = ThemeEngine.Current.ColorHighlightText;
2607 gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (backColor), new Rectangle (0, 0, bmp.Width, bmp.Height));
2609 gr.DrawString (dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush (foreColor), new Point (24 + xPos, (bmp.Height - e.Font.Height) / 2));
2610 gr.DrawImage (imageList.Images [dcbi.ImageIndex], new Rectangle (new Point (xPos + 2, 0), new Size (16, 16)));
2612 e.Graphics.DrawImage (bmp, e.Bounds.X, e.Bounds.Y);
2617 protected override void OnSelectedIndexChanged (EventArgs e)
2619 if (Items.Count > 0) {
2620 DirComboBoxItem dcbi = Items [SelectedIndex] as DirComboBoxItem;
2622 currentPath = dcbi.Path;
2624 // call DirectoryChange event only if the user changes the index with the ComboBox
2625 if (!currentpath_internal_change) {
2626 if (on_directory_changed != null)
2627 on_directory_changed (this, EventArgs.Empty);
2631 currentpath_internal_change = false;
2634 public event EventHandler DirectoryChanged {
2635 add { on_directory_changed += value; }
2636 remove { on_directory_changed -= value; }
2640 // Alexsantas little helper
2641 internal class MasterMount {
2643 internal enum FsTypes {
2664 internal struct Mount {
2665 public string device_or_filesystem;
2666 public string device_short;
2667 public string mount_point;
2668 public FsTypes fsType;
2671 bool proc_mount_available = false;
2673 ArrayList block_devices = new ArrayList ();
2674 ArrayList network_devices = new ArrayList ();
2675 ArrayList removable_devices = new ArrayList ();
2677 private int platform = (int) Environment.OSVersion.Platform;
2678 private MountComparer mountComparer = new MountComparer ();
2680 public MasterMount ()
2682 // maybe check if the current user can access /proc/mounts
2683 if ((platform == 4) || (platform == 128))
2684 if (File.Exists ("/proc/mounts"))
2685 proc_mount_available = true;
2688 public ArrayList Block_devices {
2690 return block_devices;
2694 public ArrayList Network_devices {
2696 return network_devices;
2700 public ArrayList Removable_devices {
2702 return removable_devices;
2706 public bool ProcMountAvailable {
2708 return proc_mount_available;
2712 public void GetMounts ()
2714 if (!proc_mount_available)
2717 block_devices.Clear ();
2718 network_devices.Clear ();
2719 removable_devices.Clear ();
2722 StreamReader sr = new StreamReader ("/proc/mounts");
2724 string line = sr.ReadLine ();
2726 while (line != null) {
2727 ProcessProcMountLine (line);
2728 line = sr.ReadLine ();
2733 block_devices.Sort (mountComparer);
2734 network_devices.Sort (mountComparer);
2735 removable_devices.Sort (mountComparer);
2741 private void ProcessProcMountLine (string line)
2743 string[] split = line.Split (new char [] {' '});
2745 if (split != null && split.Length > 0) {
2746 Mount mount = new Mount ();
2748 if (split [0].StartsWith ("/dev/"))
2749 mount.device_short = split [0].Replace ("/dev/", "");
2751 mount.device_short = split [0];
2753 mount.device_or_filesystem = split [0];
2754 mount.mount_point = split [1];
2756 // TODO: other removable devices, floppy
2760 if (split [2] == "nfs") {
2761 mount.fsType = FsTypes.nfs;
2762 network_devices.Add (mount);
2763 } else if (split [2] == "smbfs") {
2764 mount.fsType = FsTypes.smbfs;
2765 network_devices.Add (mount);
2766 } else if (split [2] == "ncpfs") {
2767 mount.fsType = FsTypes.ncpfs;
2768 network_devices.Add (mount);
2770 } else if (split [2] == "iso9660") { //cdrom
2771 mount.fsType = FsTypes.iso9660;
2772 removable_devices.Add (mount);
2773 } else if (split [2] == "usbfs") { //usb ? not tested
2774 mount.fsType = FsTypes.usbfs;
2775 removable_devices.Add (mount);
2777 } else if (split [0].StartsWith ("/")) { //block devices
2778 if (split [1].StartsWith ("/dev/")) // root static, do not add
2781 if (split [2] == "ext2")
2782 mount.fsType = FsTypes.ext2;
2783 else if (split [2] == "ext3")
2784 mount.fsType = FsTypes.ext3;
2785 else if (split [2] == "reiserfs")
2786 mount.fsType = FsTypes.reiserfs;
2787 else if (split [2] == "xfs")
2788 mount.fsType = FsTypes.xfs;
2789 else if (split [2] == "vfat")
2790 mount.fsType = FsTypes.vfat;
2791 else if (split [2] == "ntfs")
2792 mount.fsType = FsTypes.ntfs;
2793 else if (split [2] == "msdos")
2794 mount.fsType = FsTypes.msdos;
2795 else if (split [2] == "umsdos")
2796 mount.fsType = FsTypes.umsdos;
2797 else if (split [2] == "hpfs")
2798 mount.fsType = FsTypes.hpfs;
2799 else if (split [2] == "minix")
2800 mount.fsType = FsTypes.minix;
2801 else if (split [2] == "jfs")
2802 mount.fsType = FsTypes.jfs;
2804 block_devices.Add (mount);
2809 public class MountComparer : IComparer
2811 public int Compare(object mount1, object mount2)
2813 return String.Compare(((Mount)mount1).device_short, ((Mount)mount2).device_short);