New test.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / FileDialog.cs
index a3fc48beebb0017605a4ac81b665e36b846d8b28..b5078c50c0398f28815fb28a59a43550254b12ac 100644 (file)
@@ -53,16 +53,17 @@ namespace System.Windows.Forms {
                private bool addExtension = true;
                private bool checkFileExists = false;
                private bool checkPathExists = true;
-               private string defaultExt = "";
+               private string defaultExt = String.Empty;
                private bool dereferenceLinks = true;
-               private string fileName = "";
+               private string fileName = String.Empty;
                private string[] fileNames;
-               private string filter;
+               private string filter = "";
                private int filterIndex = 1;
-               private string initialDirectory = "";
+               private int setFilterIndex = 1;
+               private string initialDirectory = String.Empty;
                private bool restoreDirectory = false;
                private bool showHelp = false;
-               private string title = "";
+               private string title = String.Empty;
                private bool validateNames = true;
                
                private Button cancelButton;
@@ -87,7 +88,7 @@ namespace System.Windows.Forms {
                
                private bool multiSelect = false;
                
-               private string restoreDirectoryString = "";
+               private string restoreDirectoryString = String.Empty;
                
                internal FileDialogType fileDialogType;
                
@@ -100,7 +101,7 @@ namespace System.Windows.Forms {
                
                internal FileFilter fileFilter;
                
-               private string lastFolder = "";
+               private string lastFolder = String.Empty;
                
                private MWFVFS vfs;
                
@@ -322,10 +323,11 @@ namespace System.Windows.Forms {
                        form.SizeGripStyle = SizeGripStyle.Show;
                        
                        form.MaximizeBox = true;
+                       form.MinimizeBox = true;
                        form.FormBorderStyle = FormBorderStyle.Sizable;
                        form.MinimumSize = new Size (554, 405);
                        
-                       form.Size =  new Size (554, 405); // 384
+                       form.ClientSize =  new Size (554, 405); // 384
                        
                        form.Controls.Add (smallButtonToolBar);
                        form.Controls.Add (cancelButton);
@@ -440,8 +442,19 @@ namespace System.Windows.Forms {
                        
                        set {
                                if (value != null) {
-                                       if (SetFileName (value))
+                                       if (SetFileName (value)) {
                                                fileName = value;
+                                               if (fileNames == null) {
+                                                       fileNames = new string [1];
+                                                       fileNames [0] = value;
+                                               }
+                                       }
+                               } else {
+                                       fileName = String.Empty;
+                                       fileNames = new string [0];
+                                       // this does not match ms exactly,
+                                       // but there is no other way to clear that %#&?ยง combobox
+                                       fileNameComboBox.Text = " ";
                                }
                        }
                }
@@ -469,12 +482,18 @@ namespace System.Windows.Forms {
                        }
                        
                        set {
-                               if (value == null)
-                                       throw new NullReferenceException ("Filter");
-                               
-                               filter = value;
-                               
-                               fileFilter = new FileFilter (filter);
+                               if (value == null) {
+                                       filter = "";
+                                       if (fileFilter != null)
+                                               fileFilter.FilterArrayList.Clear ();
+                               } else {
+                                       if (FileFilter.CheckFilter (value)) {
+                                               filter = value;
+                                               
+                                               fileFilter = new FileFilter (filter);
+                                       } else
+                                               throw new ArgumentException ();
+                               }
                                
                                UpdateFilters ();
                        }
@@ -483,14 +502,16 @@ namespace System.Windows.Forms {
                [DefaultValue(1)]
                public int FilterIndex {
                        get {
-                               return filterIndex;
+                               return setFilterIndex;
                        }
                        
                        set {
-                               if (fileFilter != null && fileFilter.FilterArrayList.Count > value)
-                                       return;  // FIXME: throw an exception ?
+                               setFilterIndex = value;
                                
-                               filterIndex = value;
+                               if (value < 1)
+                                       filterIndex = 1;
+                               else
+                                       filterIndex = value;
                                
                                SelectFilter ();
                        }
@@ -575,16 +596,15 @@ namespace System.Windows.Forms {
                        addExtension = true;
                        checkFileExists = false;
                        checkPathExists = true;
-                       defaultExt = "";
+                       defaultExt = String.Empty;
                        dereferenceLinks = true;
-                       fileName = "";
-                       fileNames = null;
-                       Filter = "";
-                       filterIndex = 1;
-                       initialDirectory = "";
+                       FileName = String.Empty;
+                       Filter = String.Empty;
+                       FilterIndex = 1;
+                       initialDirectory = String.Empty;
                        restoreDirectory = false;
                        ShowHelp = false;
-                       Title = "";
+                       Title = String.Empty;
                        validateNames = true;
                        
                        UpdateFilters ();
@@ -592,7 +612,7 @@ namespace System.Windows.Forms {
                
                public override string ToString ()
                {
-                       return base.ToString ();
+                       return String.Format("{0}: Title: {1}, FileName: {2}", base.ToString (), Title, fileName);
                }
                
                public event CancelEventHandler FileOk {
@@ -689,15 +709,15 @@ namespace System.Windows.Forms {
                
                private void SelectFilter ()
                {
-                       if (FilterIndex > mwfFileView.FilterArrayList.Count)
+                       if (mwfFileView.FilterArrayList == null || filterIndex > mwfFileView.FilterArrayList.Count)
                                return;
                        
                        do_not_call_OnSelectedIndexChangedFileTypeComboBox = true;
                        fileTypeComboBox.BeginUpdate ();
-                       fileTypeComboBox.SelectedIndex = FilterIndex - 1;
+                       fileTypeComboBox.SelectedIndex = filterIndex - 1;
                        fileTypeComboBox.EndUpdate ();
                        
-                       mwfFileView.FilterIndex = FilterIndex;
+                       mwfFileView.FilterIndex = filterIndex;
                }
                
                private bool SetFileName (string fname)
@@ -753,7 +773,7 @@ namespace System.Windows.Forms {
                                }
                        }
                        
-                       string internalfullfilename = "";
+                       string internalfullfilename = String.Empty;
                        
                        if (!multiSelect) {
                                string fileFromComboBox = fileNameComboBox.Text.Trim ();
@@ -822,8 +842,8 @@ namespace System.Windows.Forms {
                                
                                if (fileDialogType == FileDialogType.SaveFileDialog) {
                                        if (addExtension) {
-                                               string extension_to_use = "";
-                                               string filter_exentsion = "";
+                                               string extension_to_use = String.Empty;
+                                               string filter_exentsion = String.Empty;
                                                
                                                if (fileFilter != null) {
                                                        FilterStruct filterstruct = (FilterStruct)fileFilter.FilterArrayList [filterIndex - 1];
@@ -842,13 +862,14 @@ namespace System.Windows.Forms {
                                                        }
                                                }
                                                
-                                               if (filter_exentsion != "")
+                                               if (filter_exentsion != String.Empty)
                                                        extension_to_use = filter_exentsion;
                                                else
-                                               if (defaultExt != "")
+                                               if (defaultExt != String.Empty)
                                                        extension_to_use = "." + defaultExt;
                                                
-                                               internalfullfilename += extension_to_use;
+                                               if (!internalfullfilename.EndsWith (extension_to_use))
+                                                       internalfullfilename += extension_to_use;
                                        }
                                }
                                
@@ -998,6 +1019,9 @@ namespace System.Windows.Forms {
                
                private void UpdateFilters ()
                {
+                       if (fileFilter == null)
+                               fileFilter = new FileFilter ();
+                       
                        ArrayList filters = fileFilter.FilterArrayList;
                        
                        fileTypeComboBox.BeginUpdate ();
@@ -1008,13 +1032,14 @@ namespace System.Windows.Forms {
                                fileTypeComboBox.Items.Add (fs.filterName);
                        }
                        
-                       fileTypeComboBox.SelectedIndex = FilterIndex - 1;
+                       if (filters.Count > 0 && FilterIndex <= filters.Count)
+                               fileTypeComboBox.SelectedIndex = filterIndex - 1;
                        
                        fileTypeComboBox.EndUpdate ();
                        
                        mwfFileView.FilterArrayList = filters;
                        
-                       mwfFileView.FilterIndex = FilterIndex;
+                       mwfFileView.FilterIndex = filterIndex;
                }
                
                private void ResizeAndRelocateForHelpOrReadOnly ()
@@ -1072,10 +1097,16 @@ namespace System.Windows.Forms {
                {
                        lastFolder = (string)MWFConfig.GetValue (filedialog_string, lastfolder_string);
                        
-                       if (initialDirectory != "")
+                       if (lastFolder != null && lastFolder.IndexOf ("://") == -1) {
+                               if (!Directory.Exists (lastFolder)) {
+                                       lastFolder = MWFVFS.DesktopPrefix;
+                               }
+                       }
+                       
+                       if (initialDirectory != String.Empty)
                                lastFolder = initialDirectory;
                        else
-                       if (lastFolder == null || lastFolder == "")
+                       if (lastFolder == null || lastFolder == String.Empty)
                                lastFolder = Environment.CurrentDirectory;
                        
                        if (RestoreDirectory)
@@ -1512,8 +1543,6 @@ namespace System.Windows.Forms {
                
                private EventHandler on_directory_changed;
                
-               private bool currentpath_internal_change = false;
-               
                private Stack folderStack = new Stack();
                
                private static readonly int indent = 6;
@@ -1568,8 +1597,6 @@ namespace System.Windows.Forms {
                        set {
                                currentPath = value;
                                
-                               currentpath_internal_change = true;
-                               
                                CreateComboList ();
                        }
                        get {
@@ -1712,17 +1739,27 @@ namespace System.Windows.Forms {
                        Color foreColor = e.ForeColor;
                        
                        int xPos = dcbi.XPos;
-                       
+
                        if ((e.State & DrawItemState.ComboBoxEdit) != 0)
                                xPos = 0;
-                       else
-                       if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
-                               backColor = ThemeEngine.Current.ColorHighlight;
+
+                       gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (backColor),
+                                       new Rectangle (0, 0, bmp.Width, bmp.Height));
+                       
+                       if ((e.State & DrawItemState.Selected) == DrawItemState.Selected &&
+                                       (!DroppedDown || (e.State & DrawItemState.ComboBoxEdit) != DrawItemState.ComboBoxEdit)) {
                                foreColor = ThemeEngine.Current.ColorHighlightText;
+
+                               int w = (int) gr.MeasureString (dcbi.Name, e.Font).Width;
+
+                               gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ThemeEngine.Current.ColorHighlight),
+                                               new Rectangle (xPos + 23, 1, w + 3, e.Bounds.Height - 2));
+                               if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
+                                       ControlPaint.DrawFocusRectangle (gr, new Rectangle (xPos + 22, 0, w + 5,
+                                                       e.Bounds.Height), foreColor, ThemeEngine.Current.ColorHighlight);
+                               }
                        }
-                       
-                       gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (backColor), new Rectangle (0, 0, bmp.Width, bmp.Height));
-                       
+
                        gr.DrawString (dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush (foreColor), new Point (24 + xPos, (bmp.Height - e.Font.Height) / 2));
                        gr.DrawImage (dcbi.ImageList.Images [dcbi.ImageIndex], new Rectangle (new Point (xPos + 2, 0), new Size (16, 16)));
                        
@@ -1737,15 +1774,13 @@ namespace System.Windows.Forms {
                                DirComboBoxItem dcbi = Items [SelectedIndex] as DirComboBoxItem;
                                
                                currentPath = dcbi.Path;
-                               // call DirectoryChange event only if the user changes the index with the ComboBox
-                               
-                               if (!currentpath_internal_change) {
-                                       if (on_directory_changed != null)
-                                               on_directory_changed (this, EventArgs.Empty);
-                               }
                        }
-                       
-                       currentpath_internal_change = false;
+               }
+               
+               protected override void OnSelectionChangeCommitted (EventArgs e)
+               {
+                       if (on_directory_changed != null)
+                               on_directory_changed (this, EventArgs.Empty);
                }
                
                public event EventHandler DirectoryChanged {
@@ -1773,8 +1808,9 @@ namespace System.Windows.Forms {
                private void SplitFilters (string filter)
                {
                        string[] split = filter.Split (new char [] {';'});
-                       
-                       filters.AddRange (split);
+                       foreach (string s in split) {
+                               filters.Add (s.Trim ());
+                       }
                }
        }
        #endregion
@@ -1789,13 +1825,26 @@ namespace System.Windows.Forms {
                public FileFilter ()
                {}
                
-               public FileFilter (string filter)
+               public FileFilter (string filter) : base ()
                {
                        this.filter = filter;
                        
                        SplitFilter ();
                }
                
+               public static bool CheckFilter (string val)
+               {
+                       if (val.Length == 0)
+                               return true;
+                       
+                       string[] filters = val.Split (new char [] {'|'});
+                       
+                       if ((filters.Length % 2) != 0)
+                               return false;
+                       
+                       return true;
+               }
+               
                public ArrayList FilterArrayList {
                        set {
                                filterArrayList = value;
@@ -1822,17 +1871,11 @@ namespace System.Windows.Forms {
                {
                        filterArrayList.Clear ();
                        
-                       if (filter == null)
-                               throw new NullReferenceException ("Filter");
-                       
                        if (filter.Length == 0)
                                return;
                        
                        string[] filters = filter.Split (new char [] {'|'});
                        
-                       if ((filters.Length % 2) != 0)
-                               throw new ArgumentException ("Filter");
-                       
                        for (int i = 0; i < filters.Length; i += 2) {
                                FilterStruct filterStruct = new FilterStruct (filters [i], filters [i + 1]);
                                
@@ -2089,7 +2132,8 @@ namespace System.Windows.Forms {
                
                public void CreateNewFolder ()
                {
-                       if (currentFolder == MWFVFS.RecentlyUsedPrefix)
+                       if (currentFolder == MWFVFS.MyComputerPrefix ||
+                           currentFolder == MWFVFS.RecentlyUsedPrefix)
                                return;
                        
                        FSEntry fsEntry = new FSEntry ();
@@ -2104,7 +2148,7 @@ namespace System.Windows.Forms {
                        TextEntryDialog ted = new TextEntryDialog ();
                        ted.IconPictureBoxImage = MimeIconEngine.LargeIcons.Images.GetImage (fsEntry.IconIndex);
                        
-                       string folder = "";
+                       string folder = String.Empty;
                        
                        if (currentFolderFSEntry.RealName != null)
                                folder = currentFolderFSEntry.RealName;
@@ -2306,7 +2350,7 @@ namespace System.Windows.Forms {
                                } else
                                if (o is ToolBarButton) {
                                        ToolBarButton t = o as ToolBarButton;
-                                       t.Enabled = (directoryStack.Count > 1);
+                                       t.Enabled = (directoryStack.Count > 0);
                                }
                        }
                }
@@ -2381,7 +2425,7 @@ namespace System.Windows.Forms {
                protected override void OnSelectedIndexChanged (EventArgs e)
                {
                        if (SelectedItems.Count > 0) {
-                               selectedFilesString = "";
+                               selectedFilesString = String.Empty;
                                
                                if (SelectedItems.Count == 1) {
                                        FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
@@ -2436,7 +2480,8 @@ namespace System.Windows.Forms {
                                        
                                        toolTip.Active = true;
                                }
-                       }
+                       } else
+                               toolTip.Active = false;
                        
                        base.OnMouseMove (e);
                }
@@ -2536,7 +2581,7 @@ namespace System.Windows.Forms {
                        
                        switch (fsEntry.FileType) {
                                case FSEntry.FSEntryType.Directory:
-                                       SubItems.Add ("");
+                                       SubItems.Add (String.Empty);
                                        SubItems.Add ("Directory");
                                        SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ()); 
                                        break;
@@ -2554,12 +2599,12 @@ namespace System.Windows.Forms {
                                        SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ()); 
                                        break;
                                case FSEntry.FSEntryType.Device:
-                                       SubItems.Add ("");
+                                       SubItems.Add (String.Empty);
                                        SubItems.Add ("Device");
                                        SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ()); 
                                        break;
                                case FSEntry.FSEntryType.RemovableDevice:
-                                       SubItems.Add ("");
+                                       SubItems.Add (String.Empty);
                                        SubItems.Add ("RemovableDevice");
                                        SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ()); 
                                        break;
@@ -2637,7 +2682,7 @@ namespace System.Windows.Forms {
                        newNameTextBox.Location = new Point (16, 128);
                        newNameTextBox.Size = new Size (200, 20);
                        newNameTextBox.TabIndex = 5;
-                       newNameTextBox.Text = "";
+                       newNameTextBox.Text = String.Empty;
                        
                        // okButton
                        okButton.DialogResult = DialogResult.OK;
@@ -2738,6 +2783,8 @@ namespace System.Windows.Forms {
                                workerThread = null;
                        }
 
+                       // Added next line to ensure the control is created before BeginInvoke is called on it
+                       calling_control.CreateControl();
                        workerThread = new WorkerThread (fileSystem, the_filters, updateDelegate, calling_control);
                        
                        get_folder_content_thread_start = new ThreadStart (workerThread.GetFolderContentThread);
@@ -2793,6 +2840,11 @@ namespace System.Windows.Forms {
                        }
                }
                
+               public ArrayList GetFoldersOnly ()
+               {
+                       return fileSystem.GetFoldersOnly ();
+               }
+               
                public void WriteRecentlyUsedFiles (string filename)
                {
                        fileSystem.WriteRecentlyUsedFiles (filename);
@@ -2846,9 +2898,10 @@ namespace System.Windows.Forms {
        #region FileSystem
        internal abstract class FileSystem
        {
-               protected string currentTopFolder = "";
+               protected string currentTopFolder = String.Empty;
                protected FSEntry currentFolderFSEntry = null;
                protected FSEntry currentTopFolderFSEntry = null;
+               private FileInfoComparer fileInfoComparer = new FileInfoComparer ();
                
                public FSEntry ChangeDirectory (string folder)
                {
@@ -2947,34 +3000,104 @@ namespace System.Windows.Forms {
                        }
                }
                
+               public ArrayList GetFoldersOnly ()
+               {
+                       ArrayList directories_out = new ArrayList ();
+                       
+                       if (currentFolderFSEntry.FullName == MWFVFS.DesktopPrefix) {
+                               FSEntry personalFSEntry = GetPersonalFSEntry ();
+                               
+                               directories_out.Add (personalFSEntry);
+                               
+                               FSEntry myComputerFSEntry = GetMyComputerFSEntry ();
+                               
+                               directories_out.Add (myComputerFSEntry);
+                               
+                               FSEntry myNetworkFSEntry = GetMyNetworkFSEntry ();
+                               
+                               directories_out.Add (myNetworkFSEntry);
+                               
+                               ArrayList d_out = GetNormalFolders (ThemeEngine.Current.Places (UIIcon.PlacesDesktop));
+                               directories_out.AddRange (d_out);
+                               
+                       } else
+                       if (currentFolderFSEntry.FullName == MWFVFS.RecentlyUsedPrefix) {
+                               //files_out = GetRecentlyUsedFiles ();
+                       } else
+                       if (currentFolderFSEntry.FullName == MWFVFS.MyComputerPrefix) {
+                               directories_out.AddRange (GetMyComputerContent ());
+                       } else
+                       if (currentFolderFSEntry.FullName == MWFVFS.PersonalPrefix || currentFolderFSEntry.FullName == MWFVFS.MyComputerPersonalPrefix) {
+                               ArrayList d_out = GetNormalFolders (ThemeEngine.Current.Places (UIIcon.PlacesPersonal));
+                               directories_out.AddRange (d_out);
+                       } else
+                       if (currentFolderFSEntry.FullName == MWFVFS.MyNetworkPrefix) {
+                               directories_out.AddRange (GetMyNetworkContent ());
+                       } else {
+                               directories_out = GetNormalFolders (currentFolderFSEntry.FullName);
+                       }
+                       return directories_out;
+               }
+               
                protected void GetNormalFolderContent (string from_folder, StringCollection filters, out ArrayList directories_out, out ArrayList files_out)
                {
                        DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
                        
                        directories_out = new ArrayList ();
                        
-                       DirectoryInfo[] dirs = dirinfo.GetDirectories ();
+                       DirectoryInfo[] dirs = null;
                        
-                       for (int i = 0; i < dirs.Length; i++) {
-                               directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
-                       }
+                       try {
+                               dirs = dirinfo.GetDirectories ();
+                       } catch (Exception) {}
+                       
+                       if (dirs != null)
+                               for (int i = 0; i < dirs.Length; i++) {
+                                       directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
+                               }
                        
                        files_out = new ArrayList ();
                        
                        ArrayList files = new ArrayList ();
                        
-                       if (filters == null) {
-                               files.AddRange (dirinfo.GetFiles ());
-                       } else {
-                               foreach (string s in filters)
-                                       files.AddRange (dirinfo.GetFiles (s));
-                       }
+                       try {
+                               if (filters == null) {
+                                       files.AddRange (dirinfo.GetFiles ());
+                               } else {
+                                       foreach (string s in filters)
+                                               files.AddRange (dirinfo.GetFiles (s));
+                                       
+                                       files.Sort (fileInfoComparer);
+                               }
+                       } catch (Exception) {}
                        
                        for (int i = 0; i < files.Count; i++) {
-                               files_out.Add (GetFileFSEntry (files [i] as FileInfo));
+                               FSEntry fs = GetFileFSEntry (files [i] as FileInfo);
+                               if (fs != null)
+                                       files_out.Add (fs);
                        }
                }
                
+               protected ArrayList GetNormalFolders (string from_folder)
+               {
+                       DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
+                       
+                       ArrayList directories_out = new ArrayList ();
+                       
+                       DirectoryInfo[] dirs = null;
+                       
+                       try {
+                               dirs = dirinfo.GetDirectories ();
+                       } catch (Exception) {}
+                       
+                       if (dirs != null)
+                               for (int i = 0; i < dirs.Length; i++) {
+                                       directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
+                               }
+                       
+                       return directories_out;
+               }
+               
                protected virtual FSEntry GetDirectoryFSEntry (DirectoryInfo dirinfo, FSEntry topFolderFSEntry)
                {
                        FSEntry fs = new FSEntry ();
@@ -2992,6 +3115,11 @@ namespace System.Windows.Forms {
                
                protected virtual FSEntry GetFileFSEntry (FileInfo fileinfo)
                {
+                       // *sigh* FileInfo gives us no usable information for links to directories
+                       // so, return null
+                       if ((fileinfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
+                               return null;
+                       
                        FSEntry fs = new FSEntry ();
                        
                        fs.Attributes = fileinfo.Attributes;
@@ -2999,14 +3127,19 @@ namespace System.Windows.Forms {
                        fs.Name = fileinfo.Name;
                        fs.FileType = FSEntry.FSEntryType.File;
                        fs.IconIndex = MimeIconEngine.GetIconIndexForFile (fileinfo.FullName);
+                       fs.FileSize = fileinfo.Length;
                        fs.LastAccessTime = fileinfo.LastAccessTime;
-                       // the following catches broken symbolic links
-                       if ((int)fs.Attributes != 0)
-                               fs.FileSize = fileinfo.Length;
                        
                        return fs;
                }
                
+               internal class FileInfoComparer : IComparer
+               {
+                       public int Compare (object fileInfo1, object fileInfo2)
+                       {
+                               return String.Compare (((FileInfo)fileInfo1).Name, ((FileInfo)fileInfo2).Name);
+                       }
+               }
                
                protected abstract FSEntry GetDesktopFSEntry ();
                
@@ -3041,8 +3174,17 @@ namespace System.Windows.Forms {
                private FSEntry mycomputerFSEntry = null;
                private FSEntry mynetworkFSEntry = null;
                
+               private string personal_folder;
+               private string recently_used_path;
+               private string full_kde_recent_document_dir;
+               
                public UnixFileSystem ()
                {
+                       personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
+                       recently_used_path = Path.Combine (personal_folder, ".recently-used");
+                       
+                       full_kde_recent_document_dir = personal_folder + "/.kde/share/apps/RecentDocuments";
+                       
                        desktopFSEntry = new FSEntry ();
                        
                        desktopFSEntry.Attributes = FileAttributes.Directory;
@@ -3050,7 +3192,7 @@ namespace System.Windows.Forms {
                        desktopFSEntry.Name = "Desktop";
                        desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
                        desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
-                       desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("deskop/desktop");
+                       desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
                        desktopFSEntry.LastAccessTime = DateTime.Now;
                        
                        recentlyusedFSEntry = new FSEntry ();
@@ -3107,9 +3249,6 @@ namespace System.Windows.Forms {
                
                public override void WriteRecentlyUsedFiles (string fileToAdd)
                {
-                       string personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
-                       string recently_used_path = Path.Combine (personal_folder, ".recently-used");
-                       
                        if (File.Exists (recently_used_path) && new FileInfo (recently_used_path).Length > 0) {
                                XmlDocument xml_doc = new XmlDocument ();
                                xml_doc.Load (recently_used_path);
@@ -3177,7 +3316,7 @@ namespace System.Windows.Forms {
                                }
                        } else {
                                XmlDocument xml_doc = new XmlDocument ();
-                               xml_doc.AppendChild (xml_doc.CreateXmlDeclaration ("1.0", "", ""));
+                               xml_doc.AppendChild (xml_doc.CreateXmlDeclaration ("1.0", String.Empty, String.Empty));
                                
                                XmlElement recentFiles_element = xml_doc.CreateElement ("RecentFiles");
                                
@@ -3225,8 +3364,6 @@ namespace System.Windows.Forms {
                public override ArrayList GetRecentlyUsedFiles ()
                {
                        // check for GNOME and KDE
-                       string personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
-                       string recently_used_path = Path.Combine (personal_folder, ".recently-used");
                        
                        ArrayList files_al = new ArrayList ();
                        
@@ -3239,8 +3376,11 @@ namespace System.Windows.Forms {
                                                        xtr.Read ();
                                                        Uri uri = new Uri (xtr.Value);
                                                        if (!files_al.Contains (uri.LocalPath))
-                                                               if (File.Exists (uri.LocalPath))
-                                                                       files_al.Add (GetFileFSEntry (new FileInfo (uri.LocalPath)));
+                                                               if (File.Exists (uri.LocalPath)) {
+                                                                       FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
+                                                                       if (fs != null)
+                                                                               files_al.Add (fs);
+                                                               }
                                                }
                                        }
                                        xtr.Close ();
@@ -3250,8 +3390,6 @@ namespace System.Windows.Forms {
                        }
                        
                        // KDE
-                       string full_kde_recent_document_dir = personal_folder + "/.kde/share/apps/RecentDocuments";
-                       
                        if (Directory.Exists (full_kde_recent_document_dir)) {
                                string[] files = Directory.GetFiles (full_kde_recent_document_dir, "*.desktop");
                                
@@ -3264,13 +3402,16 @@ namespace System.Windows.Forms {
                                                line = line.Trim ();
                                                
                                                if (line.StartsWith ("URL=")) {
-                                                       line = line.Replace ("URL=", "");
+                                                       line = line.Replace ("URL=", String.Empty);
                                                        line = line.Replace ("$HOME", personal_folder);
                                                        
                                                        Uri uri = new Uri (line);
                                                        if (!files_al.Contains (uri.LocalPath))
-                                                               if (File.Exists (uri.LocalPath))
-                                                                       files_al.Add (GetFileFSEntry (new FileInfo (uri.LocalPath)));
+                                                               if (File.Exists (uri.LocalPath)) {
+                                                                       FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
+                                                                       if (fs != null)
+                                                                               files_al.Add (fs);
+                                                               }
                                                        break;
                                                }
                                                
@@ -3442,7 +3583,7 @@ namespace System.Windows.Forms {
                        desktopFSEntry.Name = "Desktop";
                        desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
                        desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
-                       desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("deskop/desktop");
+                       desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
                        desktopFSEntry.LastAccessTime = DateTime.Now;
                        
                        recentlyusedFSEntry = new FSEntry ();
@@ -3513,7 +3654,9 @@ namespace System.Windows.Forms {
                        FileInfo[] fileinfos = di.GetFiles ();
                        
                        foreach (FileInfo fi in fileinfos) {
-                               al.Add (GetFileFSEntry (fi));
+                               FSEntry fs = GetFileFSEntry (fi);
+                               if (fs != null)
+                                       al.Add (fs);
                        }
                        
                        return al;
@@ -3921,7 +4064,7 @@ namespace System.Windows.Forms {
                                Mount mount = new Mount ();
                                
                                if (split [0].StartsWith ("/dev/"))
-                                       mount.device_short = split [0].Replace ("/dev/", "");
+                                       mount.device_short = split [0].Replace ("/dev/", String.Empty);
                                else 
                                        mount.device_short = split [0];
                                
@@ -4059,35 +4202,54 @@ namespace System.Windows.Forms {
        
                internal class MWFConfigInstance
                {
-                       private Hashtable classes_hashtable = new Hashtable ();
-                       
-                       private string path;
-                       private string fullFileName;
-                       private XmlTextReader xtr;
-                       private XmlTextWriter xtw;
-                       
-                       private static string defaultFileName;
-                       
-                       private readonly string configName = "MWFConfig";
-                       
-                       private int platform = (int) Environment.OSVersion.Platform;
+                       Hashtable classes_hashtable = new Hashtable ();
+                       string path;
+                       static string full_file_name;
+                       XmlTextReader xtr;
+                       XmlTextWriter xtw;
+                       static string default_file_name;
+                       readonly string configName = "MWFConfig";
+                       static int platform = (int) Environment.OSVersion.Platform;
+
+                       static bool IsUnix ()
+                       {
+                               return (platform == 4 || platform == 128);
+                       }
+
+                       static MWFConfigInstance ()
+                       {
+                               string b = "mwf_config";
+                               string dir = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
+                                       
+                               if (IsUnix ()){
+                                       dir = Path.Combine (dir, ".mono");
+                                       try {
+                                               Directory.CreateDirectory (dir);
+                                       } catch {}
+                               } 
+
+                               default_file_name = Path.Combine (dir, b);
+                               full_file_name = default_file_name;
+                       }
                        
                        public MWFConfigInstance ()
                        {
-                               if ((platform == 4) || (platform == 128)) {
-                                       defaultFileName = ".mwf_config";
-                               } else {
-                                       defaultFileName = "mwf_config";
-                               }
-                               
-                               Open (defaultFileName);
+                               Open (default_file_name);
                        }
                        
                        // only for testing
-                       public MWFConfigInstance (string fileName)
+                       public MWFConfigInstance (string filename)
                        {
-                               Open (fileName);
-                       }
+                               path = Path.GetDirectoryName (filename);
+                               if (path == null || path == String.Empty) {
+                                       path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
+                                       
+                                       full_file_name = Path.Combine (path, filename);
+                               }  else 
+                                       full_file_name = filename;
+
+                               Open (full_file_name);
+                       }                               
                        
                        ~MWFConfigInstance ()
                        {
@@ -4117,19 +4279,10 @@ namespace System.Windows.Forms {
                                class_entry.SetValue (value_name, value);
                        }
                        
-                       private void Open (string fileName)
+                       private void Open (string filename)
                        {
-                               path = Path.GetDirectoryName (fileName);
-                               
-                               if (path == null || path == String.Empty) {
-                                       path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
-                                       
-                                       fullFileName = Path.Combine (path, fileName);
-                               } else
-                                       fullFileName = fileName;
-                               
                                try {
-                                       xtr = new XmlTextReader (fullFileName);
+                                       xtr = new XmlTextReader (filename);
                                        
                                        ReadConfig ();
                                        
@@ -4141,16 +4294,17 @@ namespace System.Windows.Forms {
                        public void Flush ()
                        {
                                try {
-                                       xtw = new XmlTextWriter (fullFileName, null);
+                                       xtw = new XmlTextWriter (full_file_name, null);
                                        xtw.Formatting = Formatting.Indented;
                                        
                                        WriteConfig ();
                                        
                                        xtw.Close ();
-                                       
-                                       if ((platform != 4) && (platform != 128))
-                                               File.SetAttributes (fullFileName, FileAttributes.Hidden);
-                               } catch (Exception) {}
+
+                                       if (!IsUnix ())
+                                               File.SetAttributes (full_file_name, FileAttributes.Hidden);
+                               } catch (Exception){
+                               }
                        }
                        
                        public void RemoveClass (string class_name)
@@ -4428,7 +4582,7 @@ namespace System.Windows.Forms {
                                
                                private void WriteSingleContent (XmlTextWriter xtw)
                                {
-                                       string type_string = "";
+                                       string type_string = String.Empty;
                                        
                                        if (value is string)
                                                type_string = "string";
@@ -4452,8 +4606,8 @@ namespace System.Windows.Forms {
                                
                                private void WriteArrayContent (XmlTextWriter xtw)
                                {
-                                       string type_string = "";
-                                       string type_name = "";
+                                       string type_string = String.Empty;
+                                       string type_name = String.Empty;
                                        
                                        if (value is string[]) {
                                                type_string = "string-array";