Author: aolk
Date: 2006-07-07 13:16:52 -0400 (Fri, 07 Jul 2006)
New Revision: 62350

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs
Log:
2006-07-07  Alexander Olk  <[EMAIL PROTECTED]>

        * FileDialog.cs:
          - Fixed really nasty bug #78771
          - Don't block the whole GUI when reading directories with a lot of
            entries. Use an other thread instead and call BeginInvoke to
            update the ListView in MWFFileView



Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-07-07 16:50:37 UTC (rev 62349)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2006-07-07 17:16:52 UTC (rev 62350)
@@ -1,3 +1,11 @@
+2006-07-07  Alexander Olk  <[EMAIL PROTECTED]>
+
+       * FileDialog.cs:
+         - Fixed really nasty bug #78771
+         - Don't block the whole GUI when reading directories with a lot of
+           entries. Use an other thread instead and call BeginInvoke to
+           update the ListView in MWFFileView
+
 2006-07-07  Chris Toshok  <[EMAIL PROTECTED]>
 
        * Control.cs (Dispose): release any Capture when disposing.

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs    
2006-07-07 16:50:37 UTC (rev 62349)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs    
2006-07-07 17:16:52 UTC (rev 62350)
@@ -34,6 +34,7 @@
 using System.Collections;
 using System.Collections.Specialized;
 using System.Xml;
+using System.Threading;
 
 namespace System.Windows.Forms {
        #region FileDialog
@@ -256,6 +257,7 @@
                        
                        // fileTypeComboBox
                        fileTypeComboBox.Anchor = 
((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | 
AnchorStyles.Right)));
+                       fileTypeComboBox.DropDownStyle = 
ComboBoxStyle.DropDownList;
                        fileTypeComboBox.Location = new Point (195, 356);
                        fileTypeComboBox.Size = new Size (245, 21);
                        fileTypeComboBox.TabIndex = 2;
@@ -1906,6 +1908,7 @@
                public MWFFileView (MWFVFS vfs)
                {
                        this.vfs = vfs;
+                       vfs.RegisterUpdateDelegate (new MWFVFS.UpdateDelegate 
(RealFileViewUpdate), this);
                        
                        SuspendLayout ();
                        
@@ -2039,7 +2042,7 @@
                        set {
                                filterIndex = value;
                                if (Visible)
-                                       UpdateFileView (currentFolder);
+                                       UpdateFileView ();
                        }
                        
                        get {
@@ -2206,7 +2209,7 @@
                        EndUpdate ();
 
                        try {
-                               UpdateFileView (folder);
+                               UpdateFileView ();
                        } catch (Exception e) {
                                if (should_push)
                                        PopDir ();
@@ -2214,18 +2217,18 @@
                        }
                }
                
-               public void UpdateFileView (string folder)
+               public void UpdateFileView ()
                {
-                       ArrayList directoriesArrayList;
-                       ArrayList fileArrayList;
-                       
                        if (filterArrayList != null && filterArrayList.Count != 
0) {
                                FilterStruct fs = (FilterStruct)filterArrayList 
[filterIndex - 1];
                                
-                               vfs.GetFolderContent (fs.filters, out 
directoriesArrayList, out fileArrayList);
+                               vfs.GetFolderContent (fs.filters);
                        } else
-                               vfs.GetFolderContent (out directoriesArrayList, 
out fileArrayList);
-                       
+                               vfs.GetFolderContent ();
+               }
+               
+               public void RealFileViewUpdate (ArrayList directoriesArrayList, 
ArrayList fileArrayList)
+               {
                        BeginUpdate ();
                        
                        Items.Clear ();
@@ -2437,7 +2440,7 @@
                        if (senderMenuItem == showHiddenFilesMenuItem) {
                                senderMenuItem.Checked = 
!senderMenuItem.Checked;
                                showHiddenFiles = senderMenuItem.Checked;
-                               UpdateFileView (currentFolder);
+                               UpdateFileView ();
                        }
                }
                
@@ -2690,6 +2693,15 @@
                
                public static Hashtable MyComputerDevicesPrefix = new Hashtable 
();
                
+               public delegate void UpdateDelegate (ArrayList folders, 
ArrayList files);
+               private UpdateDelegate updateDelegate;
+               private Control calling_control;
+               
+               private ThreadStart get_folder_content_thread_start;
+               private Thread worker;
+               private WorkerThread workerThread = null;
+               private StringCollection the_filters;
+               
                public MWFVFS ()
                {
                        if ((platform == 4) || (platform == 128)) {
@@ -2704,16 +2716,75 @@
                        return fileSystem.ChangeDirectory (folder);
                }
                
-               public void GetFolderContent (out ArrayList folders_out, out 
ArrayList files_out)
+               public void GetFolderContent ()
                {
-                       fileSystem.GetFolderContent (null, out folders_out, out 
files_out);
+                       GetFolderContent (null);
                }
                
-               public void GetFolderContent (StringCollection filters, out 
ArrayList folders_out, out ArrayList files_out)
+               public void GetFolderContent (StringCollection filters)
                {
-                       fileSystem.GetFolderContent (filters, out folders_out, 
out files_out);
+                       the_filters = filters;
+
+                       if (workerThread != null) {
+                               workerThread.Stop ();
+                               workerThread = null;
+                       }
+
+                       workerThread = new WorkerThread (fileSystem, 
the_filters, updateDelegate, calling_control);
+                       
+                       get_folder_content_thread_start = new ThreadStart 
(workerThread.GetFolderContentThread);
+                       worker = new Thread (get_folder_content_thread_start);
+                       worker.IsBackground = true;
+                       worker.Start();
                }
                
+               internal class WorkerThread
+               {
+                       private FileSystem fileSystem;
+                       private StringCollection the_filters;
+                       private UpdateDelegate updateDelegate;
+                       private Control calling_control;
+                       private readonly object lockobject = new object ();
+                       private bool stopped = false;
+                       
+                       public WorkerThread (FileSystem fileSystem, 
StringCollection the_filters, UpdateDelegate updateDelegate, Control 
calling_control)
+                       {
+                               this.fileSystem = fileSystem;
+                               this.the_filters = the_filters;
+                               this.updateDelegate = updateDelegate;
+                               this.calling_control = calling_control;
+                       }
+                       
+                       public void GetFolderContentThread()
+                       {
+                               ArrayList folders;
+                               ArrayList files;
+                               
+                               fileSystem.GetFolderContent (the_filters, out 
folders, out files);
+                               
+                               if (stopped)
+                                       return;
+                               
+                               if (updateDelegate != null) {
+                                       lock (this) {
+                                               object[] objectArray = new 
object[2];
+                                               
+                                               objectArray[0] = folders;
+                                               objectArray[1] = files;
+                                               
+                                               calling_control.BeginInvoke 
(updateDelegate, objectArray);
+                                       }
+                               }
+                       }
+                       
+                       public void Stop ()
+                       {
+                               lock (lockobject) {
+                                       stopped = true;
+                               }
+                       }
+               }
+               
                public void WriteRecentlyUsedFiles (string filename)
                {
                        fileSystem.WriteRecentlyUsedFiles (filename);
@@ -2755,6 +2826,12 @@
                {
                        return fileSystem.GetParent ();
                }
+               
+               public void RegisterUpdateDelegate(UpdateDelegate 
updateDelegate, Control control)
+               {
+                       this.updateDelegate = updateDelegate;
+                       calling_control = control;
+               }
        }
        #endregion
        

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to