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;
private bool multiSelect = false;
- private string restoreDirectoryString = "";
+ private string restoreDirectoryString = String.Empty;
internal FileDialogType fileDialogType;
internal FileFilter fileFilter;
- private string lastFolder = "";
+ private string lastFolder = String.Empty;
private MWFVFS vfs;
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);
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 = " ";
}
}
}
}
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 ();
}
[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 ();
}
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 ();
public override string ToString ()
{
- return base.ToString ();
+ return String.Format("{0}: Title: {1}, FileName: {2}", base.ToString (), Title, fileName);
}
public event CancelEventHandler FileOk {
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)
}
}
- string internalfullfilename = "";
+ string internalfullfilename = String.Empty;
if (!multiSelect) {
string fileFromComboBox = fileNameComboBox.Text.Trim ();
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];
}
}
- 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;
}
}
private void UpdateFilters ()
{
+ if (fileFilter == null)
+ fileFilter = new FileFilter ();
+
ArrayList filters = fileFilter.FilterArrayList;
fileTypeComboBox.BeginUpdate ();
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 ()
}
}
- if (initialDirectory != "")
+ if (initialDirectory != String.Empty)
lastFolder = initialDirectory;
else
- if (lastFolder == null || lastFolder == "")
+ if (lastFolder == null || lastFolder == String.Empty)
lastFolder = Environment.CurrentDirectory;
if (RestoreDirectory)
private EventHandler on_directory_changed;
- private bool currentpath_internal_change = false;
-
private Stack folderStack = new Stack();
private static readonly int indent = 6;
set {
currentPath = value;
- currentpath_internal_change = true;
-
CreateComboList ();
}
get {
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 {
private void SplitFilters (string filter)
{
string[] split = filter.Split (new char [] {';'});
-
- filters.AddRange (split);
+ foreach (string s in split) {
+ filters.Add (s.Trim ());
+ }
}
}
#endregion
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;
{
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]);
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;
protected override void OnSelectedIndexChanged (EventArgs e)
{
if (SelectedItems.Count > 0) {
- selectedFilesString = "";
+ selectedFilesString = String.Empty;
if (SelectedItems.Count == 1) {
FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
toolTip.Active = true;
}
- }
+ } else
+ toolTip.Active = false;
base.OnMouseMove (e);
}
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;
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;
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;
#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)
{
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);
}
}
ArrayList 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));
+ }
return directories_out;
}
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;
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 ();
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 ();
}
} 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");
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 ();
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;
}
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 ();
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;
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];
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 ()
{
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 ();
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)
private void WriteSingleContent (XmlTextWriter xtw)
{
- string type_string = "";
+ string type_string = String.Empty;
if (value is string)
type_string = "string";
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";