2005-03-19 Alexander Olk <xenomorph2@onlinehome.de>
authorAlexander Olk <aolk@mono-cvs.ximian.com>
Sat, 19 Mar 2005 13:44:31 +0000 (13:44 -0000)
committerAlexander Olk <aolk@mono-cvs.ximian.com>
Sat, 19 Mar 2005 13:44:31 +0000 (13:44 -0000)
* FileDialog.cs, OpenFileDialog.cs: OpenFileDialog Multiselect now works

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

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/OpenFileDialog.cs

index 7d1f0c7bb90a18e88b9bd22fc72ed8752bb80015..be117c5973aec36eae18def53c745561c498e1f8 100644 (file)
@@ -1,3 +1,7 @@
+2005-03-19  Alexander Olk  <xenomorph2@onlinehome.de>
+
+       * FileDialog.cs, OpenFileDialog.cs: OpenFileDialog Multiselect now works
+
 2005-03-18  Peter Bartok  <pbartok@novell.com>
 
        * ThemeWin32Classic.cs: Moved listview column headers a bit, to avoid
@@ -9,9 +13,9 @@
 
 2005-03-18  Peter Bartok  <pbartok@novell.com>
 
-       * ControlPaint.cs: 
-         - Don't throw NotImplemented exceptions, just print a notice once 
-           instead (requested by Miguel). This makes running existing SWF 
+       * ControlPaint.cs:
+         - Don't throw NotImplemented exceptions, just print a notice once
+           instead (requested by Miguel). This makes running existing SWF
            apps a bit easier
        * Control.cs:
          - Commented out Drag'N'Drop XplatUI call (no driver support yet)
@@ -23,7 +27,7 @@
        * ListView.cs:
          - Removed debug output
        * ThemeWin32Classic.cs:
-         - Fixed drawing of status bar, now draws Text property if there 
+         - Fixed drawing of status bar, now draws Text property if there
            are no defined panels
 
 2005-03-18  Jackson Harper  <jackson@ximian.com>
index 096fa7f01a9b1c994248355e3474470bd30a3fcb..4b3e780cfb4e563effe2a0d113bb7050834adc6e 100644 (file)
@@ -58,6 +58,7 @@ namespace System.Windows.Forms
                internal string openSaveButtonText;
                internal string searchSaveLabelText;
                internal bool fileDialogShowReadOnly;
+               internal bool fileDialogMultiSelect;
                
                public bool AddExtension
                {
@@ -141,7 +142,10 @@ namespace System.Windows.Forms
                {
                        get
                        {
-                               return fileNames;
+                               if ( fileDialogMultiSelect )
+                                       return fileNames;
+                               
+                               return null;
                        }
                }
                
@@ -285,6 +289,20 @@ namespace System.Windows.Forms
                        }
                }
                
+               internal bool FileDialogMultiSelect
+               {
+                       set
+                       {
+                               fileDialogMultiSelect = value;
+                               fileDialogPanel.MultiSelect = value;
+                       }
+                       
+                       get
+                       {
+                               return fileDialogMultiSelect;
+                       }
+               }
+               
                public override void Reset( )
                {
                        addExtension = true;
@@ -382,6 +400,11 @@ namespace System.Windows.Forms
                        }
                }
                
+               internal void SetFilenames( string[] filenames )
+               {
+                       fileNames = filenames;
+               }
+               
                internal ArrayList filterArrayList = new ArrayList();
                
                internal class FileDialogPanel : Panel
@@ -441,6 +464,8 @@ namespace System.Windows.Forms
                        
                        private MenuItem previousCheckedMenuItem;
                        
+                       private bool multiSelect = false;
+                       
                        public FileDialogPanel( FileDialog fileDialog )
                        {
                                this.fileDialog = fileDialog;
@@ -518,6 +543,7 @@ namespace System.Windows.Forms
                                fileListView.Columns.Add( " Type", 100, HorizontalAlignment.Left );
                                fileListView.Columns.Add( " Last Access", 150, HorizontalAlignment.Left );
                                fileListView.AllowColumnReorder = true;
+                               fileListView.MultiSelect = false;
                                fileListView.TabIndex = 2;
                                
                                // fileNameLabel
@@ -756,24 +782,72 @@ namespace System.Windows.Forms
                                }
                        }
                        
+                       public bool MultiSelect
+                       {
+                               set
+                               {
+                                       multiSelect = value;
+                                       fileListView.MultiSelect = value;
+                               }
+                               
+                               get
+                               {
+                                       return multiSelect;
+                               }
+                       }
+                       
                        void OnClickOpenButton( object sender, EventArgs e )
                        {
-                               currentFileName = Path.Combine(currentDirectoryName, fileNameComboBox.Text.Trim());
+                               currentFileName = Path.Combine( currentDirectoryName, fileNameComboBox.Text.Trim( ) );
                                Console.WriteLine( "OnClickOpenButton currentFileName: " + currentFileName );
                                
-                               if ( currentFileName.Length == 0 )
-                                       return;
-                               
-                               if ( fileDialog.CheckFileExists )
+                               if ( !multiSelect )
+                               {
+                                       if ( currentFileName.Length == 0 )
+                                               return;
+                                       
+                                       if ( fileDialog.CheckFileExists )
+                                       {
+                                               if ( !File.Exists( currentFileName ) )
+                                               {
+                                                       string message = currentFileName + " doesn't exist. Please verify that you have entered the correct file name.";
+                                                       MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
+                                                       
+                                                       currentFileName = "";
+                                                       
+                                                       return;
+                                               }
+                                       }
+                                       
+                                       fileDialog.FileName = currentFileName;
+                               }
+                               else // multiSelect = true
                                {
-                                       if ( !File.Exists( currentFileName ) )
+                                       if ( fileListView.SelectedItems.Count > 0 )
                                        {
-                                               string message = currentFileName + " doesn't exist. Please verify that you have entered the correct file name.";
-                                               MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
+                                               // first remove all selected directories
+                                               ArrayList al = new ArrayList( );
+                                               
+                                               foreach ( ListViewItem lvi in fileListView.SelectedItems )
+                                               {
+                                                       FileStruct fileStruct = (FileStruct)fileHashtable[ lvi.Text ];
+                                                       
+                                                       if ( fileStruct.attributes != FileAttributes.Directory )
+                                                       {
+                                                               al.Add( fileStruct );
+                                                       }
+                                               }
                                                
-                                               currentFileName = "";
+                                               fileDialog.FileName = ( (FileStruct)al[ 0 ] ).fullname;
                                                
-                                               return;
+                                               string[] filenames = new string[ al.Count ];
+                                               
+                                               for ( int i = 0; i < al.Count; i++ )
+                                               {
+                                                       filenames[ i ] = ( (FileStruct)al[ i ] ).fullname;
+                                               }
+                                               
+                                               fileDialog.SetFilenames( filenames );
                                        }
                                }
                                
@@ -790,8 +864,6 @@ namespace System.Windows.Forms
                                        }
                                }
                                
-                               fileDialog.FileName = currentFileName;
-                               
                                CancelEventArgs cancelEventArgs = new CancelEventArgs( );
                                
                                cancelEventArgs.Cancel = false;
@@ -844,6 +916,11 @@ namespace System.Windows.Forms
                                                fileListView.UpdateFileListView( );
                                        }
                                }
+                               else
+                               if ( e.Button == newdirToolBarButton )
+                               {
+                                       
+                               }
                        }
                        
                        void OnClickMenuToolBarContextMenu( object sender, EventArgs e )
@@ -1064,17 +1141,21 @@ namespace System.Windows.Forms
                                
                                protected override void OnClick( EventArgs e )
                                {
-                                       ListViewItem listViewItem;
-
-                                       if (SelectedItems.Count > 0) {
-                                               listViewItem = SelectedItems[ 0 ];
-
-                                               FileStruct fileStruct = (FileStruct)fileDialogPanel.fileHashtable[ listViewItem.Text ];
+                                       Console.WriteLine( "SelectedItems.Count: " + SelectedItems.Count );
                                        
-                                               if ( fileStruct.attributes != FileAttributes.Directory )
+                                       if ( !MultiSelect )
+                                       {
+                                               if ( SelectedItems.Count > 0 )
                                                {
-                                                       fileDialogPanel.FileNameComboBox.Text = listViewItem.Text;
-                                                       fileDialogPanel.CurrentFileName = fileStruct.fullname;
+                                                       ListViewItem listViewItem = SelectedItems[ 0 ];
+                                                       
+                                                       FileStruct fileStruct = (FileStruct)fileDialogPanel.fileHashtable[ listViewItem.Text ];
+                                                       
+                                                       if ( fileStruct.attributes != FileAttributes.Directory )
+                                                       {
+                                                               fileDialogPanel.FileNameComboBox.Text = listViewItem.Text;
+                                                               fileDialogPanel.CurrentFileName = fileStruct.fullname;
+                                                       }
                                                }
                                        }
                                        
@@ -1083,23 +1164,59 @@ namespace System.Windows.Forms
                                
                                protected override void OnDoubleClick( EventArgs e )
                                {
-                                       ListViewItem listViewItem = SelectedItems[ 0 ];
-                                       
-                                       FileStruct fileStruct = (FileStruct)fileDialogPanel.fileHashtable[ listViewItem.Text ];
-                                       
-                                       if ( fileStruct.attributes == FileAttributes.Directory )
+                                       if ( SelectedItems.Count > 0 )
                                        {
-                                               fileDialogPanel.ChangeDirectory( fileStruct.fullname );
+                                               ListViewItem listViewItem = SelectedItems[ 0 ];
+                                               
+                                               FileStruct fileStruct = (FileStruct)fileDialogPanel.fileHashtable[ listViewItem.Text ];
+                                               
+                                               if ( fileStruct.attributes == FileAttributes.Directory )
+                                               {
+                                                       fileDialogPanel.ChangeDirectory( fileStruct.fullname );
+                                               }
+                                               else
+                                               {
+                                                       fileDialogPanel.FileNameComboBox.Text =  listViewItem.Text;
+                                                       fileDialogPanel.CurrentFileName = fileStruct.fullname;
+                                                       fileDialogPanel.ForceDialogEnd( );
+                                                       return;
+                                               }
                                        }
-                                       else
+                                       
+                                       base.OnDoubleClick( e );
+                               }
+                               
+                               protected override void OnSelectedIndexChanged( EventArgs e )
+                               {
+                                       if ( MultiSelect )
                                        {
-                                               fileDialogPanel.FileNameComboBox.Text =  listViewItem.Text;
-                                               fileDialogPanel.CurrentFileName = fileStruct.fullname;
-                                               fileDialogPanel.ForceDialogEnd( );
-                                               return;
+                                               if ( SelectedItems.Count > 0 )
+                                               {
+                                                       string combotext = "";
+                                                       
+                                                       if ( SelectedItems.Count == 1 )
+                                                       {
+                                                               FileStruct fileStruct = (FileStruct)fileDialogPanel.fileHashtable[ SelectedItems[ 0 ].Text ];
+                                                               
+                                                               if ( fileStruct.attributes != FileAttributes.Directory )
+                                                                       combotext = SelectedItems[ 0 ].Text;
+                                                       }
+                                                       else
+                                                       {
+                                                               foreach ( ListViewItem lvi in SelectedItems )
+                                                               {
+                                                                       FileStruct fileStruct = (FileStruct)fileDialogPanel.fileHashtable[ lvi.Text ];
+                                                                       
+                                                                       if ( fileStruct.attributes != FileAttributes.Directory )
+                                                                               combotext += "\"" + lvi.Text + "\" ";
+                                                               }
+                                                       }
+                                                       
+                                                       fileDialogPanel.FileNameComboBox.Text = combotext;
+                                               }
                                        }
                                        
-                                       base.OnDoubleClick( e );
+                                       base.OnSelectedIndexChanged( e );
                                }
                        }
                        
index c79d4ff8dec65f91c9212ef6b085f0c877d54130..0590b0e079d486535b1d96aab814dd04eee4bad0 100644 (file)
@@ -66,6 +66,7 @@ namespace System.Windows.Forms
                        set
                        {
                                multiSelect = value;
+                               FileDialogMultiSelect = value;
                        }
                }