Author: aolk Date: 2005-03-27 12:05:29 -0500 (Sun, 27 Mar 2005) New Revision: 42286
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/OpenFileDialog.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/SaveFileDialog.cs
Log:
2005-03-27 Alexander Olk <[EMAIL PROTECTED]>
* FileDialog.cs, OpenFileDialog.cs, SaveFileDialog.cs:
- Added missing CreatePrompt property in SaveDialog
- Overall SaveDialog handling should be better now
- Added non standard ShowHiddenFiles property
- Added extension, CreatePrompt and OverwritePrompt support in
SaveDialog
- Added InitialDirectory and RestoreDirectory support
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2005-03-27 14:39:29 UTC (rev 42285)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2005-03-27 17:05:29 UTC (rev 42286)
@@ -1,3 +1,12 @@
+2005-03-27 Alexander Olk <[EMAIL PROTECTED]>
+
+ * FileDialog.cs, OpenFileDialog.cs, SaveFileDialog.cs:
+ - Added missing CreatePrompt property in SaveDialog
+ - Overall SaveDialog handling should be better now
+ - Added non standard ShowHiddenFiles property
+ - Added extension, CreatePrompt and OverwritePrompt support in
SaveDialog
+ - Added InitialDirectory and RestoreDirectory support
+
2005-03-26 Alexander Olk <[EMAIL PROTECTED]>
* FileDialog.cs: Made dirComboBox usable
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs
2005-03-27 14:39:29 UTC (rev 42285)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs
2005-03-27 17:05:29 UTC (rev 42286)
@@ -26,6 +26,9 @@
// NOT COMPLETE - work in progress
+// TODO:
+// file/path security stuff ???
+
using System;
using System.Drawing;
using System.ComponentModel;
@@ -38,6 +41,12 @@
{
public abstract class FileDialog : CommonDialog
{
+ internal enum FileDialogType
+ {
+ OpenFileDialog,
+ SaveFileDialog
+ }
+
internal FileDialogPanel fileDialogPanel;
private bool addExtension = true;
@@ -59,7 +68,13 @@
internal string searchSaveLabelText;
internal bool fileDialogShowReadOnly;
internal bool fileDialogMultiSelect;
+ internal bool saveDialogCreatePrompt = false;
+ internal bool saveDialogOverwritePrompt = true;
+ private bool showHiddenFiles = false;
+
+ internal FileDialogType fileDialogType;
+
public bool AddExtension
{
get
@@ -109,9 +124,20 @@
set
{
defaultExt = value;
+
+ // if there is a dot remove it and everything
before it
+ if ( defaultExt.LastIndexOf( '.' ) != - 1 )
+ {
+ string[] split = defaultExt.Split( new
char[] { '.' } );
+ defaultExt = split[ split.Length - 1 ];
+ }
}
}
+ // in MS.NET it doesn't make a difference if
+ // DerefenceLinks is true or false
+ // if the selected file is a link FileDialog
+ // always returns the link
public bool DereferenceLinks
{
get
@@ -237,6 +263,17 @@
}
}
+ // this one is a hard one ;)
+ // Win32 filename:
+ // - up to MAX_PATH characters (windef.h) = 260
+ // - no trailing dots or spaces
+ // - case preserving
+ // - etc...
+ // NTFS/Posix filename:
+ // - up to 32,768 Unicode characters
+ // - trailing periods or spaces
+ // - case sensitive
+ // - etc...
public bool ValidateNames
{
get
@@ -263,7 +300,7 @@
}
}
- public string SearchSaveLabelText
+ internal string SearchSaveLabelText
{
set
{
@@ -276,7 +313,7 @@
}
}
- public bool FileDialogShowReadOnly
+ internal bool FileDialogShowReadOnly
{
set
{
@@ -311,6 +348,46 @@
}
}
+ // extension to MS.NET framework...
+ public bool ShowHiddenFiles
+ {
+ set
+ {
+ showHiddenFiles = value;
+ }
+
+ get
+ {
+ return showHiddenFiles;
+ }
+ }
+
+ internal bool SaveDialogCreatePrompt
+ {
+ set
+ {
+ saveDialogCreatePrompt = value;
+ }
+
+ get
+ {
+ return saveDialogCreatePrompt;
+ }
+ }
+
+ internal bool SaveDialogOverwritePrompt
+ {
+ set
+ {
+ saveDialogOverwritePrompt = value;
+ }
+
+ get
+ {
+ return saveDialogOverwritePrompt;
+ }
+ }
+
public override void Reset( )
{
addExtension = true;
@@ -453,6 +530,8 @@
private string currentDirectoryName;
+ internal string currentFileName = "";
+
// store current directoryInfo
private DirectoryInfo directoryInfo;
@@ -462,12 +541,12 @@
// store DirectoryInfo for backButton
internal Stack directoryStack = new Stack();
- internal string currentFileName = "";
-
private MenuItem previousCheckedMenuItem;
private bool multiSelect = false;
+ private string restoreDirectory = "";
+
public FileDialogPanel( FileDialog fileDialog )
{
this.fileDialog = fileDialog;
@@ -666,14 +745,19 @@
if ( fileDialog.InitialDirectory ==
String.Empty )
currentDirectoryName =
Environment.CurrentDirectory;
+ else
+ currentDirectoryName =
fileDialog.InitialDirectory;
directoryInfo = new DirectoryInfo(
currentDirectoryName );
dirComboBox.CurrentPath = currentDirectoryName;
+ if ( fileDialog.RestoreDirectory )
+ restoreDirectory = currentDirectoryName;
+
fileListView.UpdateFileListView( );
- openSaveButton.Click += new EventHandler(
OnClickOpenButton );
+ openSaveButton.Click += new EventHandler(
OnClickOpenSaveButton );
cancelButton.Click += new EventHandler(
OnClickCancelButton );
helpButton.Click += new EventHandler(
OnClickHelpButton );
@@ -738,11 +822,12 @@
}
}
- void OnClickOpenButton( object sender, EventArgs e )
+ void OnClickOpenSaveButton( object sender, EventArgs e )
{
if ( !multiSelect )
{
string fileFromComboBox =
fileNameComboBox.Text.Trim( );
+
if ( fileFromComboBox.Length > 0 )
fileFromComboBox =
Path.Combine( currentDirectoryName, fileFromComboBox );
@@ -752,22 +837,72 @@
if ( currentFileName.Length == 0 )
return;
- if ( fileDialog.CheckFileExists )
+
+ if ( fileDialog.fileDialogType ==
FileDialogType.OpenFileDialog )
{
- if ( !File.Exists(
currentFileName ) )
+ if ( fileDialog.CheckFileExists
)
{
- 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;
+ 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;
+ }
}
}
+ else // FileDialogType == SaveFileDialog
+ {
+ if (
fileDialog.SaveDialogOverwritePrompt )
+ {
+ if ( File.Exists(
currentFileName ) )
+ {
+ string message
= currentFileName + " exists. Overwrite ?";
+ DialogResult dr
= MessageBox.Show( message, fileDialog.OpenSaveButtonText,
MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
+
+ if ( dr ==
DialogResult.Cancel )
+ {
+
currentFileName = "";
+
+ return;
+ }
+ }
+ }
+
+ if (
fileDialog.SaveDialogCreatePrompt )
+ {
+ if ( !File.Exists(
currentFileName ) )
+ {
+ string message
= currentFileName + " doesn't exist. Create ?";
+ DialogResult dr
= MessageBox.Show( message, fileDialog.OpenSaveButtonText,
MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
+
+ if ( dr ==
DialogResult.Cancel )
+ {
+
currentFileName = "";
+
+ return;
+ }
+ }
+ }
+ }
+ if ( fileDialog.fileDialogType ==
FileDialogType.SaveFileDialog )
+ {
+ if ( fileDialog.AddExtension &&
fileDialog.DefaultExt.Length > 0 )
+ {
+ if (
!currentFileName.EndsWith( fileDialog.DefaultExt ) )
+ {
+ currentFileName
+= "." + fileDialog.DefaultExt;
+ }
+ }
+ }
+
fileDialog.FileName = currentFileName;
}
else // multiSelect = true
+ if ( fileDialog.fileDialogType !=
FileDialogType.SaveFileDialog )
{
if ( fileListView.SelectedItems.Count >
0 )
{
@@ -804,12 +939,18 @@
string message =
currentDirectoryName + " doesn't exist. Please verify that you have entered the
correct directory name.";
MessageBox.Show( message,
fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
- currentDirectoryName =
Environment.CurrentDirectory;
+ if (
fileDialog.InitialDirectory == String.Empty )
+ currentDirectoryName =
Environment.CurrentDirectory;
+ else
+ currentDirectoryName =
fileDialog.InitialDirectory;
return;
}
}
+ if ( fileDialog.RestoreDirectory )
+ currentDirectoryName = restoreDirectory;
+
CancelEventArgs cancelEventArgs = new
CancelEventArgs( );
cancelEventArgs.Cancel = false;
@@ -822,6 +963,9 @@
void OnClickCancelButton( object sender, EventArgs e )
{
+ if ( fileDialog.RestoreDirectory )
+ currentDirectoryName = restoreDirectory;
+
CancelEventArgs cancelEventArgs = new
CancelEventArgs( );
cancelEventArgs.Cancel = true;
@@ -956,7 +1100,7 @@
public void ForceDialogEnd( )
{
- OnClickOpenButton( this, EventArgs.Empty );
+ OnClickOpenSaveButton( this, EventArgs.Empty );
}
private void PushDirectory( DirectoryInfo di )
@@ -1065,6 +1209,10 @@
foreach ( DirectoryInfo directoryInfoi
in directoryInfoArray )
{
+ if (
!fileDialogPanel.fileDialog.ShowHiddenFiles )
+ if (
directoryInfoi.Name.StartsWith( "." ) || directoryInfoi.Attributes ==
FileAttributes.Hidden )
+ continue;
+
FileStruct fileStruct = new
FileStruct( );
fileStruct.fullname =
directoryInfoi.FullName;
@@ -1086,6 +1234,10 @@
foreach ( FileInfo fileInfo in
fileInfoArrayList )
{
+ if (
!fileDialogPanel.fileDialog.ShowHiddenFiles )
+ if (
fileInfo.Name.StartsWith( "." ) || fileInfo.Attributes ==
FileAttributes.Hidden )
+ continue;
+
FileStruct fileStruct = new
FileStruct( );
fileStruct.fullname =
fileInfo.FullName;
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/OpenFileDialog.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/OpenFileDialog.cs
2005-03-27 14:39:29 UTC (rev 42285)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/OpenFileDialog.cs
2005-03-27 17:05:29 UTC (rev 42286)
@@ -51,6 +51,8 @@
FileDialogShowReadOnly = showReadOnly;
+ fileDialogType = FileDialogType.OpenFileDialog;
+
fileDialogPanel = new FileDialogPanel( this );
}
#endregion // Public Constructors
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/SaveFileDialog.cs
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/SaveFileDialog.cs
2005-03-27 14:39:29 UTC (rev 42285)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/SaveFileDialog.cs
2005-03-27 17:05:29 UTC (rev 42286)
@@ -34,6 +34,7 @@
{
public sealed class SaveFileDialog : FileDialog
{
+ private bool createPrompt = false;
private bool overwritePrompt = true;
#region Public Constructors
@@ -47,6 +48,8 @@
SearchSaveLabelText = "Save in:";
+ fileDialogType = FileDialogType.SaveFileDialog;
+
fileDialogPanel = new FileDialogPanel( this );
}
#endregion // Public Constructors
@@ -57,6 +60,7 @@
set
{
overwritePrompt = value;
+ SaveDialogOverwritePrompt = overwritePrompt;
}
get
@@ -64,6 +68,20 @@
return overwritePrompt;
}
}
+
+ public bool CreatePrompt
+ {
+ set
+ {
+ createPrompt = value;
+ SaveDialogCreatePrompt = createPrompt;
+ }
+
+ get
+ {
+ return createPrompt;
+ }
+ }
#endregion // Public Instance Properties
#region Public Instance Methods
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
