2006-07-12 Alexander Olk <alex.olk@googlemail.com>
authorAlexander Olk <aolk@mono-cvs.ximian.com>
Wed, 12 Jul 2006 16:53:08 +0000 (16:53 -0000)
committerAlexander Olk <aolk@mono-cvs.ximian.com>
Wed, 12 Jul 2006 16:53:08 +0000 (16:53 -0000)
* FileDialog.cs: Added GetFoldersOnly to MWFVFS
* FolderBrowserDialog.cs: Almost a complete rewrite.
  - Better support for Environment.Specialfolders
  - Added support for MWFVFS
  - Made setting SelectedPath work

svn path=/trunk/mcs/; revision=62508

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/FolderBrowserDialog.cs

index a37408dc61c353e8a849b333e32b2d8ed4d09653..a88edb74adcdadb6187039a2c60e3b4d389360f1 100644 (file)
@@ -1,3 +1,11 @@
+2006-07-12  Alexander Olk  <alex.olk@googlemail.com>
+
+       * FileDialog.cs: Added GetFoldersOnly to MWFVFS
+       * FolderBrowserDialog.cs: Almost a complete rewrite.
+         - Better support for Environment.Specialfolders
+         - Added support for MWFVFS
+         - Made setting SelectedPath work
+
 2006-07-12  Jackson Harper  <jackson@ximian.com>
 
        * Control.cs: Optimze getting all the controls.
index a3fc48beebb0017605a4ac81b665e36b846d8b28..dff0cbc88833a4d57387ad9b530a90958271dade 100644 (file)
@@ -2793,6 +2793,11 @@ namespace System.Windows.Forms {
                        }
                }
                
+               public ArrayList GetFoldersOnly ()
+               {
+                       return fileSystem.GetFoldersOnly ();
+               }
+               
                public void WriteRecentlyUsedFiles (string filename)
                {
                        fileSystem.WriteRecentlyUsedFiles (filename);
@@ -2947,6 +2952,45 @@ 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);
@@ -2975,6 +3019,21 @@ namespace System.Windows.Forms {
                        }
                }
                
+               protected ArrayList GetNormalFolders (string from_folder)
+               {
+                       DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
+                       
+                       ArrayList directories_out = new ArrayList ();
+                       
+                       DirectoryInfo[] dirs = dirinfo.GetDirectories ();
+                       
+                       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 ();
index 9ccc5954d4c5478ede836a9fbbdce0308a184411..e67154012e0b3daaa4ae23fd3b6c66fcaa40f758 100644 (file)
@@ -27,8 +27,6 @@
 // NOT COMPLETE
 // TODO:
 // - create new folder if NewFolderButton is pressed
-// - better handling of Environment.SpecialFolders
-// - fix: if SelectedPath != "" and it is beyond RootFolder then show it (currently TreeNode.EnsureVisible() is missing...)
 
 using System;
 using System.Drawing;
@@ -37,11 +35,10 @@ using System.Resources;
 using System.IO;
 using System.Collections;
 
-namespace System.Windows.Forms
-{
-       [DefaultEvent("HelpRequest")]
-       [DefaultProperty("SelectedPath")]
-       [Designer("System.Windows.Forms.Design.FolderBrowserDialogDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
+namespace System.Windows.Forms {
+       [DefaultEvent ("HelpRequest")]
+       [DefaultProperty ("SelectedPath")]
+       [Designer ("System.Windows.Forms.Design.FolderBrowserDialogDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
        public sealed class FolderBrowserDialog : CommonDialog
        {
                #region Local Variables
@@ -49,32 +46,111 @@ namespace System.Windows.Forms
                private Environment.SpecialFolder rootFolder = Environment.SpecialFolder.Desktop;
                private string selectedPath = "";
                private bool showNewFolderButton = true;
-
+               
+               private Label descriptionLabel;
+               private Button cancelButton;
+               private Button okButton;
+               private FolderBrowserTreeView folderBrowserTreeView;
+               private Button newFolderButton;
+               
+               private string old_selectedPath = "";
                #endregion      // Local Variables
                
                #region Public Constructors
-               public FolderBrowserDialog)
+               public FolderBrowserDialog ()
                {
-                       form = new FolderBrowserDialogForm( this );
-                       form.Size =  new Size( 322, 288 );
-                       form.MinimumSize = new Size( 322, 288 );
+                       newFolderButton = new Button ();
+                       folderBrowserTreeView = new FolderBrowserTreeView (this);
+                       okButton = new Button ();
+                       cancelButton = new Button ();
+                       descriptionLabel = new Label ();
+                       
+                       form.AcceptButton = okButton;
+                       form.CancelButton = cancelButton;
+                       
+                       form.SuspendLayout ();
+                       form.Size =  new Size (322, 288);
+                       form.MinimumSize = new Size (322, 288);
                        form.Text = "Search Folder";
+                       form.SizeGripStyle = SizeGripStyle.Show;
+                       
+                       // descriptionLabel
+                       descriptionLabel.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Left)
+                               | AnchorStyles.Right)));
+                       descriptionLabel.Location = new Point (17, 14);
+                       descriptionLabel.Size = new Size (290, 40);
+                       descriptionLabel.TabIndex = 0;
+                       descriptionLabel.Text = "";
+                       
+                       // folderBrowserTreeView
+                       folderBrowserTreeView.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom)
+                               | AnchorStyles.Left)
+                               | AnchorStyles.Right)));
+                       folderBrowserTreeView.ImageIndex = -1;
+                       folderBrowserTreeView.Location = new Point (20, 61);
+                       folderBrowserTreeView.SelectedImageIndex = -1;
+                       folderBrowserTreeView.Size = new Size (278, 153);
+                       folderBrowserTreeView.TabIndex = 1;
+                       folderBrowserTreeView.ShowLines = false;
+                       folderBrowserTreeView.ShowPlusMinus = true;
+                       folderBrowserTreeView.HotTracking = true;
+                       folderBrowserTreeView.BorderStyle = BorderStyle.Fixed3D;
+                       //folderBrowserTreeView.Indent = 2;
+                       
+                       // newFolderButton
+                       newFolderButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
+                       newFolderButton.FlatStyle = FlatStyle.System;
+                       newFolderButton.Location = new Point (14, 230);
+                       newFolderButton.Size = new Size (125, 23);
+                       newFolderButton.TabIndex = 2;
+                       newFolderButton.Text = "New Folder";
+                       newFolderButton.Enabled = true;
+                       
+                       // okButton
+                       okButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
+                       okButton.FlatStyle = FlatStyle.System;
+                       okButton.Location = new Point (142, 230);
+                       okButton.Size = new Size (80, 23);
+                       okButton.TabIndex = 3;
+                       okButton.Text = "OK";
+                       
+                       // cancelButton
+                       cancelButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
+                       cancelButton.DialogResult = DialogResult.Cancel;
+                       cancelButton.FlatStyle = FlatStyle.System;
+                       cancelButton.Location = new Point (226, 230);
+                       cancelButton.Size = new Size (80, 23);
+                       cancelButton.TabIndex = 4;
+                       cancelButton.Text = "Cancel";
+                       
+                       form.Controls.Add (cancelButton);
+                       form.Controls.Add (okButton);
+                       form.Controls.Add (newFolderButton);
+                       form.Controls.Add (folderBrowserTreeView);
+                       form.Controls.Add (descriptionLabel);
+                       
+                       form.ResumeLayout (false);
+                       
+                       okButton.Click += new EventHandler (OnClickOKButton);
+                       cancelButton.Click += new EventHandler (OnClickCancelButton);
+                       newFolderButton.Click += new EventHandler (OnClickNewFolderButton);
+                       
+                       RootFolder = rootFolder;
                }
+               
                #endregion      // Public Constructors
                
                #region Public Instance Properties
                [Browsable(true)]
                [DefaultValue("")]
                [Localizable(true)]
-               public string Description
-               {
-                       set
-                       {
+               public string Description {
+                       set {
                                description = value;
+                               descriptionLabel.Text = description;
                        }
                        
-                       get
-                       {
+                       get {
                                return description;
                        }
                }
@@ -82,15 +158,15 @@ namespace System.Windows.Forms
                [Browsable(true)]
                [DefaultValue(Environment.SpecialFolder.Desktop)]
                [Localizable(false)]
-               public Environment.SpecialFolder RootFolder
-               {
-                       set
-                       {
-                               rootFolder = value;
+               public Environment.SpecialFolder RootFolder {
+                       set {
+                               if (rootFolder != value)
+                                       rootFolder = value;
+                               
+                               folderBrowserTreeView.RootFolder = rootFolder;
                        }
                        
-                       get
-                       {
+                       get {
                                return rootFolder;
                        }
                }
@@ -99,344 +175,376 @@ namespace System.Windows.Forms
                [DefaultValue("")]
                [Editor("System.Windows.Forms.Design.SelectedPathEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
                [Localizable(true)]
-               public string SelectedPath
-               {
-                       set
-                       {
+               public string SelectedPath {
+                       set {
+                               if (!Path.IsPathRooted(value))
+                                       return;
+                               
                                selectedPath = value;
+                               old_selectedPath = value;
+                               folderBrowserTreeView.SelectedPath = selectedPath;
                        }
                        
-                       get
-                       {
+                       get {
                                return selectedPath;
                        }
                }
-
+               
                [Browsable(true)]
                [DefaultValue(true)]
                [Localizable(false)]
-               public bool ShowNewFolderButton
-               {
-                       set
-                       {
-                               showNewFolderButton = value;
+               public bool ShowNewFolderButton {
+                       set {
+                               if (value != showNewFolderButton) {
+                                       showNewFolderButton = value;
+                                       if (showNewFolderButton)
+                                               newFolderButton.Show ();
+                                       else
+                                               newFolderButton.Hide ();
+                               }
                        }
                        
-                       get
-                       {
+                       get {
                                return showNewFolderButton;
                        }
                }
                #endregion      // Public Instance Properties
                
                #region Public Instance Methods
-               public override void Reset)
+               public override void Reset ()
                {
-                       description = "";
-                       rootFolder = Environment.SpecialFolder.Desktop;
+                       Description = "";
+                       RootFolder = Environment.SpecialFolder.Desktop;
                        selectedPath = "";
-                       showNewFolderButton = true;
+                       ShowNewFolderButton = true;
                }
                
-               protected override bool RunDialog( IntPtr hwndOwner )
+               protected override bool RunDialog (IntPtr hwndOwner)
                {
-                       FolderBrowserDialogPanel fb = new FolderBrowserDialogPanel (this);
-                       form.Controls.Add (fb);
+                       form.Refresh ();
+                       
                        return true;
                }
                #endregion      // Public Instance Methods
-
+               
                #region Internal Methods
-               internal class FolderBrowserDialogForm : DialogForm
+               void OnClickOKButton (object sender, EventArgs e)
+               {
+                       form.DialogResult = DialogResult.OK;
+               }
+               
+               void OnClickCancelButton (object sender, EventArgs e)
+               {
+                       selectedPath = old_selectedPath;
+                       form.DialogResult = DialogResult.Cancel;
+               }
+               
+               void OnClickNewFolderButton (object sender, EventArgs e)
+               {
+                       // TODO
+               }
+               #endregion      // Internal Methods
+               
+               #region Events
+               [Browsable(false)]
+               [EditorBrowsable(EditorBrowsableState.Never)]
+               public event EventHandler HelpRequest;
+               #endregion
+               
+               internal class FolderBrowserTreeView : TreeView
                {
-                       internal FolderBrowserDialogForm( CommonDialog owner )
-                       : base( owner )
-                       {}
+                       private MWFVFS vfs = new MWFVFS ();
+                       private FBTreeNode root_node;
+                       private FolderBrowserDialog parentDialog;
+                       private ImageList imageList = new ImageList ();
+                       private Environment.SpecialFolder rootFolder;
+                       private bool dont_enable = false;
                        
-                       protected override CreateParams CreateParams
+                       public FolderBrowserTreeView (FolderBrowserDialog parent_dialog)
                        {
-                               get
-                               {
-                                       CreateParams    cp;
+                               parentDialog = parent_dialog;
+                               ImageList = imageList;
+                               SetupImageList ();
+                       }
+                       
+                       public Environment.SpecialFolder RootFolder {
+                               set {
+                                       rootFolder = value;
                                        
-                                       ControlBox = true;
-                                       MinimizeBox = false;
-                                       MaximizeBox = false;
+                                       string root_path = "";
                                        
-                                       cp = base.CreateParams;
-                                       cp.Style = (int)( WindowStyles.WS_POPUP | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS );
-                                       cp.Style |= (int)WindowStyles.WS_OVERLAPPEDWINDOW;
-
-                                       if (!is_enabled) {
-                                               cp.Style |= (int)(WindowStyles.WS_DISABLED);
+                                       switch (rootFolder) {
+                                               default:
+                                               case Environment.SpecialFolder.Desktop:
+                                                       root_node = new FBTreeNode ("Desktop");
+                                                       root_node.RealPath = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
+                                                       root_path = MWFVFS.DesktopPrefix;
+                                                       break;
+                                               case Environment.SpecialFolder.MyComputer:
+                                                       root_node = new FBTreeNode ("My Computer");
+                                                       root_path = MWFVFS.MyComputerPrefix;
+                                                       break;
+                                               case Environment.SpecialFolder.Personal:
+                                                       root_node = new FBTreeNode ("Personal");
+                                                       root_path = MWFVFS.PersonalPrefix;
+                                                       root_node.RealPath = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
+                                                       break;
                                        }
                                        
-                                       return cp;
+                                       root_node.Tag = root_path;
+                                       root_node.ImageIndex = NodeImageIndex (root_path);
+                                       
+                                       FillNode (root_node);
+                                       
+                                       root_node.Expand ();
+                                       
+                                       Nodes.Add (root_node);
                                }
                        }
-               }
-               
-               internal class FolderBrowserDialogPanel : Panel
-               {
-                       private Label descriptionLabel;
-                       private Button cancelButton;
-                       private Button okButton;
-                       private TreeView folderBrowserTreeView;
-                       private Button newFolderButton;
                        
-                       private FolderBrowserDialog folderBrowserDialog;
-                       private string selectedPath;
+                       public string SelectedPath {
+                               set {
+                                       if (Check_if_path_is_child_of_RootFolder (value)) {
+                                               SetSelectedPath (Path.GetFullPath (value));
+                                       }
+                               }
+                       }
                        
-                       private ImageList imageList;
-                       private TreeNode selectedPathNode = null;
-                       private TreeNode root_node;
-
-                       public FolderBrowserDialogPanel (FolderBrowserDialog folderBrowserDialog)
+                       private void SetSelectedPath (string path)
                        {
-                               this.folderBrowserDialog = folderBrowserDialog;
-                               
-                               newFolderButton = new Button( );
-                               folderBrowserTreeView = new TreeView( );
-                               okButton = new Button( );
-                               cancelButton = new Button( );
-                               descriptionLabel = new Label( );
-                               
-                               imageList = new ImageList( );
-                               
-                               folderBrowserDialog.form.AcceptButton = okButton;
-                               folderBrowserDialog.form.CancelButton = cancelButton;
-                               
-                               SuspendLayout( );
-                               
-                               // descriptionLabel
-                               descriptionLabel.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Top | AnchorStyles.Left )
-                               | AnchorStyles.Right ) ) );
-                               descriptionLabel.Location = new Point( 17, 14 );
-                               descriptionLabel.Size = new Size( 290, 40 );
-                               descriptionLabel.TabIndex = 0;
-                               descriptionLabel.Text = folderBrowserDialog.Description;
-                               
-                               // folderBrowserTreeView
-                               folderBrowserTreeView.Anchor = ( (AnchorStyles)( ( ( ( AnchorStyles.Top | AnchorStyles.Bottom )
-                               | AnchorStyles.Left )
-                               | AnchorStyles.Right ) ) );
-                               folderBrowserTreeView.ImageIndex = -1;
-                               folderBrowserTreeView.Location = new Point( 20, 61 );
-                               folderBrowserTreeView.SelectedImageIndex = -1;
-                               folderBrowserTreeView.Size = new Size( 278, 153 );
-                               folderBrowserTreeView.TabIndex = 1;
-                               folderBrowserTreeView.ImageList = imageList;
-                               folderBrowserTreeView.ShowLines = false;
-                               folderBrowserTreeView.ShowPlusMinus = true;
-                               folderBrowserTreeView.HotTracking = true;
-                               //folderBrowserTreeView.Indent = 2;
+                               BeginUpdate ();
                                
-                               // newFolderButton
-                               newFolderButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
-                               newFolderButton.FlatStyle = FlatStyle.System;
-                               newFolderButton.Location = new Point( 14, 230 );
-                               newFolderButton.Size = new Size( 125, 23 );
-                               newFolderButton.TabIndex = 2;
-                               newFolderButton.Text = "New Folder";
-                               newFolderButton.Enabled = folderBrowserDialog.ShowNewFolderButton;
+                               FBTreeNode node = FindPathInNodes (path, Nodes);
                                
-                               // okButton
-                               okButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
-                               okButton.FlatStyle = FlatStyle.System;
-                               okButton.Location = new Point( 142, 230 );
-                               okButton.Size = new Size( 80, 23 );
-                               okButton.TabIndex = 3;
-                               okButton.Text = "OK";
-                               
-                               // cancelButton
-                               cancelButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
-                               cancelButton.DialogResult = DialogResult.Cancel;
-                               cancelButton.FlatStyle = FlatStyle.System;
-                               cancelButton.Location = new Point( 226, 230 );
-                               cancelButton.Size = new Size( 80, 23 );
-                               cancelButton.TabIndex = 4;
-                               cancelButton.Text = "Cancel";
-                               
-                               // FolderBrowserDialog
-                               ClientSize = new Size( 322, 288 );
-                               Dock = DockStyle.Fill;
-
-                               Controls.Add( cancelButton );
-                               Controls.Add( okButton );
-                               Controls.Add( newFolderButton );
-                               Controls.Add( folderBrowserTreeView );
-                               Controls.Add( descriptionLabel );
-                               ResumeLayout( false );
-                               
-                               SetupImageList( );
-                               
-                               okButton.Click += new EventHandler( OnClickOKButton );
-                               cancelButton.Click += new EventHandler( OnClickCancelButton );
-
-                               string root_path = Environment.GetFolderPath (folderBrowserDialog.RootFolder);
-                               root_node = new TreeNode (Path.GetFileName (root_path));
-                               root_node.Tag = root_path;
-                               root_node.ImageIndex = NodeImageIndex (root_path);
-
-                               // If we add the sub nodes before the root is added to the
-                               // tree no refreshing will be done whil adding
-                               if (folderBrowserDialog.RootFolder == Environment.SpecialFolder.Desktop) {
-
-
-                                       // Add something similar to 'My Computer'
-                                       TreeNode mycomp = new TreeNode ("My Computer");
-                                       if (Path.DirectorySeparatorChar == '/')
-                                               mycomp.Tag = "/";
-                                       else
-                                               mycomp.Tag = Environment.GetFolderPath (Environment.SpecialFolder.MyComputer);
-                                       mycomp.ImageIndex = NodeImageIndex ((string) mycomp.Tag);
-
-                                       // A home directory
-                                       string home_path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
-                                       TreeNode home = new TreeNode (Path.GetFileName (home_path));
-                                       home.Tag = home_path;
-                                       home.ImageIndex = NodeImageIndex (home_path);
+                               if (node == null) {
+                                       Stack stack = new Stack ();
                                        
-                                       // This is so we get the expand box
-                                       mycomp.Nodes.Add (new TreeNode (String.Empty));
-                                       home.Nodes.Add (new TreeNode (String.Empty)); 
-
-                                       root_node.Nodes.Add (mycomp);
-                                       root_node.Nodes.Add (home);
-                                       root_node.Expand ();
-                               } else {
-                                       FillNode (root_node);
-                               }
-
-                               folderBrowserTreeView.Nodes.Add (root_node);
-
-                               folderBrowserTreeView.BeforeExpand += new TreeViewCancelEventHandler (OnBeforeExpand);
-                               folderBrowserTreeView.AfterSelect += new TreeViewEventHandler( OnAfterSelectFolderBrowserTreeView );
-                       }
-                       
-                       public string SelectedPath
-                       {
-                               set
-                               {
-                                       selectedPath = value;
+                                       string path_cut = path.Substring (0, path.LastIndexOf (Path.AltDirectorySeparatorChar));
+                                       
+                                       while (node == null && path_cut.Length > 0) {
+                                               node = FindPathInNodes (path_cut, Nodes);
+                                               
+                                               if (node == null) {
+                                                       string path_cut_new = path_cut.Substring (0, path_cut.LastIndexOf (Path.AltDirectorySeparatorChar));
+                                                       string leftover = path_cut.Replace (path_cut_new, "");
+                                                       
+                                                       stack.Push (leftover);
+                                                       
+                                                       path_cut = path_cut_new;
+                                               }
+                                       }
+                                       
+                                       if (stack.Count > 0) {
+                                               FillNode (node);
+                                               node.Expand ();
+                                               
+                                               // walk through the subdirs and fill the nodes
+                                               while (stack.Count > 0) {
+                                                       string part_name = stack.Pop () as string;
+                                                       
+                                                       foreach (TreeNode treeNode in node.Nodes) {
+                                                               FBTreeNode fbnode = treeNode as FBTreeNode;
+                                                               
+                                                               if (path_cut + part_name == fbnode.RealPath) {
+                                                                       node = fbnode;
+                                                                       path_cut += part_name;
+                                                                       
+                                                                       FillNode (node);
+                                                                       node.Expand ();
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
+                                               
+                                               // finally find the node for the complete path
+                                               foreach (TreeNode treeNode in node.Nodes) {
+                                                       FBTreeNode fbnode = treeNode as FBTreeNode;
+                                                       
+                                                       if (path == fbnode.RealPath) {
+                                                               node = fbnode;
+                                                               break;
+                                                       }
+                                               }
+                                       }
                                }
                                
-                               get
-                               {
-                                       return selectedPath;
+                               if (node != null) {
+                                       SelectedNode = node;
+                                       node.EnsureVisible ();
                                }
+                               
+                               EndUpdate ();
                        }
                        
-                       void OnClickOKButton( object sender, EventArgs e )
+                       private FBTreeNode FindPathInNodes (string path, TreeNodeCollection nodes)
                        {
-                               folderBrowserDialog.SelectedPath = selectedPath;
+                               foreach (TreeNode node in nodes) {
+                                       FBTreeNode fbnode = node as FBTreeNode;
+                                       
+                                       if (fbnode != null && fbnode.RealPath != null) {
+                                               if (fbnode.RealPath == path)
+                                                       return fbnode;
+                                       }
+                                       
+                                       return FindPathInNodes (path, node.Nodes);
+                               }
                                
-                               folderBrowserDialog.form.Controls.Remove( this );
-                               folderBrowserDialog.form.DialogResult = DialogResult.OK;
+                               return null;
                        }
                        
-                       void OnClickCancelButton( object sender, EventArgs e )
+                       private bool Check_if_path_is_child_of_RootFolder (string path)
                        {
-                               folderBrowserDialog.form.Controls.Remove( this );
-                               folderBrowserDialog.form.DialogResult = DialogResult.Cancel;
+                               string root_path = (string)root_node.RealPath;
+                               
+                               if (root_path != null) {
+                                       try {
+                                               if (!Directory.Exists (path))
+                                                       return false;
+                                               
+                                               switch (rootFolder) {
+                                                       case Environment.SpecialFolder.Desktop:
+                                                       case Environment.SpecialFolder.MyComputer:
+                                                               return true;
+                                                       case Environment.SpecialFolder.Personal:
+                                                               if (!path.StartsWith (root_path))
+                                                                       return false;
+                                                               else
+                                                                       return true;
+                                                       default:
+                                                               return false;
+                                               }
+                                       } catch {}
+                               }
+                               
+                               return false;
                        }
                        
-                       void OnAfterSelectFolderBrowserTreeView( object sender, TreeViewEventArgs e )
-                       {
-                               if (e.Node == null)
-                                       return;
-                               selectedPath = (string) e.Node.Tag;
-                       }
-
-                       private void OnBeforeExpand (object sender, TreeViewCancelEventArgs e)
-                       {
-                               if (e.Node == root_node)
-                                       return;
-                               FillNode (e.Node);
-                       }
-
-                       private void OnAfterCollapse (object sender, TreeViewCancelEventArgs e)
-                       {
-                               if (e.Node == root_node)
-                                       return;
-                               e.Node.Nodes.Clear ();
-                       }
-
                        private void FillNode (TreeNode node)
                        {
-                               Cursor old = folderBrowserTreeView.Cursor;
-                               folderBrowserTreeView.Cursor = Cursors.WaitCursor;
-
-                               folderBrowserTreeView.BeginUpdate ();
-
+                               BeginUpdate ();
+                               
                                node.Nodes.Clear ();
-                               string path = node.Tag as string;
-                               string [] dirs = Directory.GetDirectories (path);
-
-                               foreach (string s in dirs) {
-                                       string name = Path.GetFileName (s);
-                                       // filter out . directories
-                                       if (name.StartsWith ("."))
+                               vfs.ChangeDirectory ((string)node.Tag);
+                               ArrayList folders = vfs.GetFoldersOnly ();
+                               
+                               foreach (FSEntry fsentry in folders) {
+                                       if (fsentry.Name.StartsWith ("."))
                                                continue;
-                                       TreeNode child = new TreeNode (name);
-                                       child.Tag = s;
-                                       child.ImageIndex = NodeImageIndex (s);
-
-                                       try {
-                                               // so we get the plus
-                                               string [] subdirs = Directory.GetDirectories (s);
-                                               foreach (string subdir in subdirs) {
-                                                       // filter out . directories (le sigh)
-                                                       string subdirname = Path.GetFileName (subdir);
-                                                       if (!subdirname.StartsWith (".")) {
-                                                               child.Nodes.Add (new TreeNode (String.Empty));
-                                                               break;
-                                                       }
+                                       
+                                       FBTreeNode child = new FBTreeNode (fsentry.Name);
+                                       child.Tag = fsentry.FullName;
+                                       child.RealPath = fsentry.RealName == null ? fsentry.FullName : fsentry.RealName;
+                                       child.ImageIndex = NodeImageIndex (fsentry.FullName);
+                                       
+                                       vfs.ChangeDirectory (fsentry.FullName);
+                                       ArrayList sub_folders = vfs.GetFoldersOnly ();
+                                       
+                                       foreach (FSEntry fsentry_sub in sub_folders) {
+                                               if (!fsentry_sub.Name.StartsWith (".")) {
+                                                       child.Nodes.Add (new TreeNode (String.Empty));
+                                                       break;
                                                }
-                                       } catch {
-                                               // Probably don't have access
                                        }
-
+                                       
                                        node.Nodes.Add (child);
                                }
-
-                               folderBrowserTreeView.EndUpdate ();
-                               folderBrowserTreeView.Cursor = old;
+                               
+                               EndUpdate ();
                        }
-
-                       private int NodeImageIndex( string path )
+                       
+                       private void SetupImageList ()
+                       {
+                               imageList.ColorDepth = ColorDepth.Depth32Bit;
+                               imageList.ImageSize = new Size (16, 16);
+                               imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 16));
+                               imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 16));
+                               imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 16));
+                               imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 16));
+                               imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 16));
+                               imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.NormalFolder, 16));
+                               imageList.TransparentColor = Color.Transparent;
+                       }
+                       
+                       private int NodeImageIndex (string path)
                        {
                                int index = 5;
                                
-                               if ( path == Environment.GetFolderPath( Environment.SpecialFolder.Desktop ) )
+                               if (path == MWFVFS.DesktopPrefix)
                                        index = 1;
+                               else 
+                               if (path == MWFVFS.RecentlyUsedPrefix)
+                                       index = 0;
                                else
-                               if ( path == Environment.GetFolderPath( Environment.SpecialFolder.Personal ) )
+                               if (path == MWFVFS.PersonalPrefix)
                                        index = 2;
+                               else
+                               if (path == MWFVFS.MyComputerPrefix)
+                                       index = 3;
+                               else
+                               if (path == MWFVFS.MyNetworkPrefix)
+                                       index = 4;
                                
                                return index;
                        }
                        
-                       private void SetupImageList( )
+                       protected override void OnAfterSelect (TreeViewEventArgs e)
                        {
-                               imageList.ColorDepth = ColorDepth.Depth32Bit;
-                               imageList.ImageSize = new Size( 16, 16 );
-                               imageList.Images.Add( (Image)Locale.GetResource( "last_open" ) );
-                               imageList.Images.Add( (Image)Locale.GetResource( "desktop" ) );
-                               imageList.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
-                               imageList.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
-                               imageList.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
-                               imageList.Images.Add( (Image)Locale.GetResource( "folder" ) );
-                               imageList.Images.Add( (Image)Locale.GetResource( "paper" ) );
-                               imageList.TransparentColor = Color.Transparent;
+                               if (e.Node == null)
+                                       return;
+                               
+                               FBTreeNode fbnode = e.Node as FBTreeNode;
+                               
+                               if (fbnode.RealPath == null || fbnode.RealPath.IndexOf ("://") != -1) {
+                                       parentDialog.okButton.Enabled = false;
+                                       dont_enable = true;
+                               } else {
+                                       parentDialog.okButton.Enabled = true;
+                                       parentDialog.selectedPath = fbnode.RealPath;
+                                       dont_enable = false;
+                               }
+                               
+                               base.OnAfterSelect (e);
+                       }
+                       
+                       protected internal override void OnBeforeExpand (TreeViewCancelEventArgs e)
+                       {
+                               if (e.Node == root_node)
+                                       return;
+                               FillNode (e.Node);
+                               
+                               base.OnBeforeExpand (e);
+                       }
+                       
+                       protected override void OnMouseUp (MouseEventArgs e)
+                       {
+                               if (SelectedNode == null)
+                                       parentDialog.okButton.Enabled = false;
+                               else
+                               if (!dont_enable)
+                                       parentDialog.okButton.Enabled = true;
+                               
+                               base.OnMouseUp (e);
+                       }
+               }
+               
+               internal class FBTreeNode : TreeNode
+               {
+                       private string realPath = null;
+                       
+                       public FBTreeNode (string text)
+                       {
+                               Text = text;
+                       }
+                       
+                       public string RealPath {
+                               set {
+                                       realPath = value;
+                               }
+                               
+                               get {
+                                       return realPath;
+                               }
                        }
                }
-               #endregion      // Internal Methods
-
-               #region Events
-               [Browsable(false)]
-               [EditorBrowsable(EditorBrowsableState.Never)]
-               public event EventHandler HelpRequest;
-               #endregion
        }
 }