using System.Collections;
using System.Collections.Specialized;
using System.Xml;
-using Microsoft.Win32;
+using System.Threading;
namespace System.Windows.Forms {
#region FileDialog
private MWFVFS vfs;
- private RegistryKey rootRegistryKey;
- private RegistryKey filedialogRegistryKey;
- private string registryKeyName = @"SOFTWARE\Mono.MWF\FileDialog";
+ private readonly string filedialog_string = "FileDialog";
+ private readonly string lastfolder_string = "LastFolder";
+ private readonly string width_string = "Width";
+ private readonly string height_string = "Height";
+ private readonly string filenames_string = "FileNames";
+ private readonly string x_string = "X";
+ private readonly string y_string = "Y";
internal FileDialog ()
{
vfs = new MWFVFS ();
- Size formRegistrySize = Size.Empty;
- Point formRegistryLocation = Point.Empty;
- string[] registryFileNames = null;
+ Size formConfigSize = Size.Empty;
+ Point formConfigLocation = Point.Empty;
+ string[] configFileNames = null;
- rootRegistryKey = Microsoft.Win32.Registry.CurrentUser;
- filedialogRegistryKey = rootRegistryKey.OpenSubKey (registryKeyName);
+ object formWidth = MWFConfig.GetValue (filedialog_string, width_string);
- if (filedialogRegistryKey != null) {
- int formWidth = (int)filedialogRegistryKey.GetValue ("Width");
- int formHeight = (int)filedialogRegistryKey.GetValue ("Height");
-
- formRegistrySize = new Size (formWidth, formHeight);
-
- int formLocationX = (int)filedialogRegistryKey.GetValue ("X");
- int formLocationY = (int)filedialogRegistryKey.GetValue ("Y");
-
- formRegistryLocation = new Point (formLocationX, formLocationY);
-
- registryFileNames = (string[])filedialogRegistryKey.GetValue ("FileNames");
- }
+ object formHeight = MWFConfig.GetValue (filedialog_string, height_string);
+
+ if (formHeight != null && formWidth != null)
+ formConfigSize = new Size ((int)formWidth, (int)formHeight);
+
+ object formLocationX = MWFConfig.GetValue (filedialog_string, x_string);
+ object formLocationY = MWFConfig.GetValue (filedialog_string, y_string);
+
+ if (formLocationX != null && formLocationY != null)
+ formConfigLocation = new Point ((int)formLocationX, (int)formLocationY);
+
+ configFileNames = (string[])MWFConfig.GetValue (filedialog_string, filenames_string);
fileTypeComboBox = new ComboBox ();
backToolBarButton = new ToolBarButton ();
dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
dirComboBox.Location = new Point (99, 8);
dirComboBox.Size = new Size (260, 21);
- dirComboBox.TabIndex = 0;
+ dirComboBox.TabIndex = 7;
// smallButtonToolBar
smallButtonToolBar.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right)));
smallButtonToolBar.Location = new Point (372, 6);
smallButtonToolBar.ShowToolTips = true;
smallButtonToolBar.Size = new Size (140, 28);
- smallButtonToolBar.TabIndex = 1;
+ smallButtonToolBar.TabIndex = 8;
smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
// buttonPanel
popupButtonPanel.Dock = DockStyle.None;
popupButtonPanel.Location = new Point (7, 37);
- popupButtonPanel.TabIndex = 2;
+ popupButtonPanel.TabIndex = 9;
// mwfFileView
mwfFileView.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
mwfFileView.Columns.Add (" Last Access", 150, HorizontalAlignment.Left);
mwfFileView.AllowColumnReorder = true;
mwfFileView.MultiSelect = false;
- mwfFileView.TabIndex = 3;
+ mwfFileView.TabIndex = 10;
mwfFileView.RegisterSender (dirComboBox);
mwfFileView.RegisterSender (popupButtonPanel);
fileNameComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
fileNameComboBox.Location = new Point (195, 330);
fileNameComboBox.Size = new Size (245, 21);
- fileNameComboBox.TabIndex = 4;
+ fileNameComboBox.TabIndex = 1;
fileNameComboBox.MaxDropDownItems = 10;
fileNameComboBox.Items.Add (" ");
- if (registryFileNames != null) {
+ if (configFileNames != null) {
fileNameComboBox.Items.Clear ();
- foreach (string registryFileName in registryFileNames) {
- if (registryFileName != null)
- if (registryFileName.Trim ().Length > 0)
- fileNameComboBox.Items.Add (registryFileName);
+ foreach (string configFileName in configFileNames) {
+ if (configFileName != null)
+ if (configFileName.Trim ().Length > 0)
+ fileNameComboBox.Items.Add (configFileName);
}
}
// 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 = 5;
+ fileTypeComboBox.TabIndex = 2;
// backToolBarButton
backToolBarButton.ImageIndex = 0;
openSaveButton.FlatStyle = FlatStyle.System;
openSaveButton.Location = new Point (475, 330);
openSaveButton.Size = new Size (72, 21);
- openSaveButton.TabIndex = 7;
+ openSaveButton.TabIndex = 4;
openSaveButton.FlatStyle = FlatStyle.System;
// cancelButton
cancelButton.FlatStyle = FlatStyle.System;
cancelButton.Location = new Point (475, 356);
cancelButton.Size = new Size (72, 21);
- cancelButton.TabIndex = 8;
+ cancelButton.TabIndex = 5;
cancelButton.Text = "Cancel";
cancelButton.FlatStyle = FlatStyle.System;
helpButton.FlatStyle = FlatStyle.System;
helpButton.Location = new Point (475, 350);
helpButton.Size = new Size (72, 21);
- helpButton.TabIndex = 9;
+ helpButton.TabIndex = 6;
helpButton.Text = "Help";
helpButton.FlatStyle = FlatStyle.System;
readonlyCheckBox.Text = "Open Readonly";
readonlyCheckBox.Location = new Point (195, 350);
readonlyCheckBox.Size = new Size (245, 21);
- readonlyCheckBox.TabIndex = 6;
+ readonlyCheckBox.TabIndex = 3;
readonlyCheckBox.FlatStyle = FlatStyle.System;
form.SizeGripStyle = SizeGripStyle.Show;
form.MaximizeBox = true;
+ form.MinimizeBox = true;
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);
form.ResumeLayout (false);
- if (formRegistrySize != Size.Empty) {
- form.Size = formRegistrySize;
+ if (formConfigSize != Size.Empty) {
+ form.Size = formConfigSize;
}
- if (formRegistryLocation != Point.Empty) {
- form.Location = formRegistryLocation;
+ if (formConfigLocation != Point.Empty) {
+ form.Location = formConfigLocation;
}
openSaveButton.Click += new EventHandler (OnClickOpenSaveButton);
protected void OnFileOk (CancelEventArgs e)
{
- WriteRegistryValues (e);
+ WriteConfigValues (e);
CancelEventHandler fo = (CancelEventHandler) Events [EventFileOk];
if (fo != null)
protected override bool RunDialog (IntPtr hWndOwner)
{
- ReadRegistryValues ();
+ ReadConfigValues ();
form.Refresh ();
bool rooted = Path.IsPathRooted (fname);
if (!rooted) {
- if (File.Exists (Path.Combine (mwfFileView.CurrentRealFolder, fname))) {
+ string dir = mwfFileView.CurrentRealFolder ;
+ if (dir == null) {
+ dir = Environment.CurrentDirectory;
+ }
+ if (File.Exists (Path.Combine (dir, fname))) {
fileNameComboBox.Text = fname;
mwfFileView.SetSelectedIndexTo (fname);
form.ResumeLayout ();
}
- private void WriteRegistryValues (CancelEventArgs ce)
+ private void WriteConfigValues (CancelEventArgs ce)
{
- filedialogRegistryKey = rootRegistryKey.OpenSubKey (registryKeyName);
-
- if (filedialogRegistryKey == null)
- filedialogRegistryKey = rootRegistryKey.CreateSubKey (registryKeyName);
-
- filedialogRegistryKey.SetValue ("Width", form.Width);
- filedialogRegistryKey.SetValue ("Height", form.Height);
- filedialogRegistryKey.SetValue ("X", form.Location.X);
- filedialogRegistryKey.SetValue ("Y", form.Location.Y);
+ MWFConfig.SetValue (filedialog_string, width_string, form.Width);
+ MWFConfig.SetValue (filedialog_string, height_string, form.Height);
+ MWFConfig.SetValue (filedialog_string, x_string, form.Location.X);
+ MWFConfig.SetValue (filedialog_string, y_string, form.Location.Y);
if (!ce.Cancel) {
- filedialogRegistryKey.SetValue ("LastFolder", lastFolder);
+ MWFConfig.SetValue (filedialog_string, lastfolder_string, lastFolder);
string[] fileNameCBItems = new string [fileNameComboBox.Items.Count];
fileNameComboBox.Items.CopyTo (fileNameCBItems, 0);
- filedialogRegistryKey.SetValue ("FileNames", fileNameCBItems);
+ MWFConfig.SetValue (filedialog_string, filenames_string, fileNameCBItems);
}
}
- private void ReadRegistryValues ()
+ private void ReadConfigValues ()
{
- rootRegistryKey = Microsoft.Win32.Registry.CurrentUser;
- filedialogRegistryKey = rootRegistryKey.OpenSubKey (registryKeyName);
+ lastFolder = (string)MWFConfig.GetValue (filedialog_string, lastfolder_string);
- if (filedialogRegistryKey != null) {
- lastFolder = (string)filedialogRegistryKey.GetValue ("LastFolder");
+ if (lastFolder != null && lastFolder.IndexOf ("://") == -1) {
+ if (!Directory.Exists (lastFolder)) {
+ lastFolder = MWFVFS.DesktopPrefix;
+ }
}
if (initialDirectory != "")
Color foreColor = e.ForeColor;
int xPos = dcbi.XPos;
-
+
if ((e.State & DrawItemState.ComboBoxEdit) != 0)
xPos = 0;
- else
- if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
- backColor = ThemeEngine.Current.ColorHighlight;
+
+ gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (backColor),
+ new Rectangle (0, 0, bmp.Width, bmp.Height));
+
+ if ((e.State & DrawItemState.Selected) == DrawItemState.Selected &&
+ (!DroppedDown || (e.State & DrawItemState.ComboBoxEdit) != DrawItemState.ComboBoxEdit)) {
foreColor = ThemeEngine.Current.ColorHighlightText;
+
+ int w = (int) gr.MeasureString (dcbi.Name, e.Font).Width;
+
+ gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ThemeEngine.Current.ColorHighlight),
+ new Rectangle (xPos + 23, 1, w + 3, e.Bounds.Height - 2));
+ if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
+ ControlPaint.DrawFocusRectangle (gr, new Rectangle (xPos + 22, 0, w + 5,
+ e.Bounds.Height), foreColor, ThemeEngine.Current.ColorHighlight);
+ }
}
-
- gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (backColor), new Rectangle (0, 0, bmp.Width, bmp.Height));
-
+
gr.DrawString (dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush (foreColor), new Point (24 + xPos, (bmp.Height - e.Font.Height) / 2));
gr.DrawImage (dcbi.ImageList.Images [dcbi.ImageIndex], new Rectangle (new Point (xPos + 2, 0), new Size (16, 16)));
private string currentFolder;
private string currentRealFolder;
- private string currentTopFolder;
private FSEntry currentFolderFSEntry;
// store DirectoryInfo for a back button for example
private int old_menuitem_index;
private bool do_update_view = false;
+ private int platform = (int) Environment.OSVersion.Platform;
+
public MWFFileView (MWFVFS vfs)
{
this.vfs = vfs;
+ vfs.RegisterUpdateDelegate (new MWFVFS.UpdateDelegate (RealFileViewUpdate), this);
SuspendLayout ();
ResumeLayout (false);
-// currentFolder = Environment.CurrentDirectory;
-
KeyDown += new KeyEventHandler (MWF_KeyDown);
}
set {
filterIndex = value;
if (Visible)
- UpdateFileView (currentFolder);
+ UpdateFileView ();
}
get {
public void CreateNewFolder ()
{
- if (currentFolder == MWFVFS.RecentlyUsedPrefix)
+ if (currentFolder == MWFVFS.MyComputerPrefix ||
+ currentFolder == MWFVFS.RecentlyUsedPrefix)
return;
FSEntry fsEntry = new FSEntry ();
fsEntry.Attributes = FileAttributes.Directory;
- fsEntry.FileType = FSEntry.FSEntryType.Directoy;
+ fsEntry.FileType = FSEntry.FSEntryType.Directory;
fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
fsEntry.LastAccessTime = DateTime.Now;
TextEntryDialog ted = new TextEntryDialog ();
ted.IconPictureBoxImage = MimeIconEngine.LargeIcons.Images.GetImage (fsEntry.IconIndex);
- ted.FileName = "New Folder";
- if (ted.ShowDialog () == DialogResult.OK) {
- string folder = "";
- if (currentFolderFSEntry.RealName != null)
- folder = currentFolderFSEntry.RealName;
- else
- folder = currentFolder;
+ string folder = "";
+
+ if (currentFolderFSEntry.RealName != null)
+ folder = currentFolderFSEntry.RealName;
+ else
+ folder = currentFolder;
+
+ string tmp_filename = "New Folder";
+
+ if (Directory.Exists (Path.Combine (folder, tmp_filename))) {
+ int i = 1;
+
+ if ((platform == 4) || (platform == 128)) {
+ tmp_filename = tmp_filename + "-" + i;
+ } else {
+ tmp_filename = tmp_filename + " (" + i + ")";
+ }
+ while (Directory.Exists (Path.Combine (folder, tmp_filename))) {
+ i++;
+ if ((platform == 4) || (platform == 128)) {
+ tmp_filename = "New Folder" + "-" + i;
+ } else {
+ tmp_filename = "New Folder" + " (" + i + ")";
+ }
+ }
+ }
+
+ ted.FileName = tmp_filename;
+
+ if (ted.ShowDialog () == DialogResult.OK) {
string new_folder = Path.Combine (folder, ted.FileName);
if (vfs.CreateFolder (new_folder)) {
do_update_view = false;
}
EndUpdate ();
-
- UpdateFileView (folder);
+
+ try {
+ UpdateFileView ();
+ } catch (Exception e) {
+ if (should_push)
+ PopDir ();
+ MessageBox.Show (e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
}
- 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 ();
if (collection.Contains (fileName)) {
int i = 1;
- while (collection.Contains (fileName + "[" + i + "]")) {
+ while (collection.Contains (fileName + "(" + i + ")")) {
i++;
}
- fileName = fileName + "[" + i + "]";
+ fileName = fileName + "(" + i + ")";
}
fsEntry.Name = fileName;
} else
if (o is ToolBarButton) {
ToolBarButton t = o as ToolBarButton;
- t.Enabled = (directoryStack.Count > 1);
+ t.Enabled = (directoryStack.Count > 0);
}
}
}
string output = String.Empty;
- if (fsEntry.FileType == FSEntry.FSEntryType.Directoy)
+ if (fsEntry.FileType == FSEntry.FSEntryType.Directory)
output = "Directory: " + fsEntry.FullName;
else if (fsEntry.FileType == FSEntry.FSEntryType.Device)
output = "Device: "+ fsEntry.FullName;
if (senderMenuItem == showHiddenFilesMenuItem) {
senderMenuItem.Checked = !senderMenuItem.Checked;
showHiddenFiles = senderMenuItem.Checked;
- UpdateFileView (currentFolder);
+ UpdateFileView ();
}
}
Text = fsEntry.Name;
switch (fsEntry.FileType) {
- case FSEntry.FSEntryType.Directoy:
+ case FSEntry.FSEntryType.Directory:
SubItems.Add ("");
SubItems.Add ("Directory");
SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
Text = "New Folder or File";
groupBox1.ResumeLayout (false);
ResumeLayout (false);
+
+ newNameTextBox.Select ();
}
public Image IconPictureBoxImage {
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)) {
return fileSystem.ChangeDirectory (folder);
}
- public void GetFolderContent (out ArrayList folders_out, out ArrayList files_out)
+ public void GetFolderContent ()
+ {
+ GetFolderContent (null);
+ }
+
+ public void GetFolderContent (StringCollection filters)
{
- fileSystem.GetFolderContent (null, out folders_out, out files_out);
+ the_filters = filters;
+
+ if (workerThread != null) {
+ workerThread.Stop ();
+ workerThread = null;
+ }
+
+ // Added next line to ensure the control is created before BeginInvoke is called on it
+ calling_control.CreateControl();
+ 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 GetFolderContent (StringCollection filters, out ArrayList folders_out, out ArrayList files_out)
+ public ArrayList GetFoldersOnly ()
{
- fileSystem.GetFolderContent (filters, out folders_out, out files_out);
+ return fileSystem.GetFoldersOnly ();
}
public void WriteRecentlyUsedFiles (string filename)
{
try {
if (Directory.Exists (new_folder)) {
- int i = 1;
- string folder = new_folder + "[" + i + "]";
-
- while (Directory.Exists(folder)) {
- i++;
- folder = new_folder + "[" + i + "]";
- }
-
- Directory.CreateDirectory (folder);
+ string message = "Folder \"" + new_folder + "\" already exists.";
+ MessageBox.Show (message, new_folder, MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return false;
} else
Directory.CreateDirectory (new_folder);
- } catch (Exception) {
+ } catch (Exception e) {
+ MessageBox.Show (e.Message, new_folder, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
{
return fileSystem.GetParent ();
}
+
+ public void RegisterUpdateDelegate(UpdateDelegate updateDelegate, Control control)
+ {
+ this.updateDelegate = updateDelegate;
+ calling_control = control;
+ }
}
#endregion
directories_out.Add (myNetworkFSEntry);
- ArrayList d_out = new ArrayList ();
- ArrayList f_out = new ArrayList ();
+ ArrayList d_out = null;
+ ArrayList f_out = null;
GetNormalFolderContent (ThemeEngine.Current.Places (UIIcon.PlacesDesktop), filters, out d_out, out f_out);
directories_out.AddRange (d_out);
files_out.AddRange (f_out);
directories_out.AddRange (GetMyComputerContent ());
} else
if (currentFolderFSEntry.FullName == MWFVFS.PersonalPrefix || currentFolderFSEntry.FullName == MWFVFS.MyComputerPersonalPrefix) {
- ArrayList d_out = new ArrayList ();
- ArrayList f_out = new ArrayList ();
+ ArrayList d_out = null;
+ ArrayList f_out = null;
GetNormalFolderContent (ThemeEngine.Current.Places (UIIcon.PlacesPersonal), filters, out d_out, out f_out);
directories_out.AddRange (d_out);
files_out.AddRange (f_out);
}
}
+ 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);
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));
+ }
+ } catch (Exception) {}
for (int i = 0; i < files.Count; i++) {
files_out.Add (GetFileFSEntry (files [i] as FileInfo));
}
}
+ protected ArrayList GetNormalFolders (string from_folder)
+ {
+ DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
+
+ ArrayList directories_out = new ArrayList ();
+
+ DirectoryInfo[] dirs = null;
+
+ 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 GetDirectoryFSEntry (DirectoryInfo dirinfo, FSEntry topFolderFSEntry)
{
FSEntry fs = new FSEntry ();
fs.FullName = dirinfo.FullName;
fs.Name = dirinfo.Name;
fs.MainTopNode = topFolderFSEntry;
- fs.FileType = FSEntry.FSEntryType.Directoy;
+ fs.FileType = FSEntry.FSEntryType.Directory;
fs.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
fs.LastAccessTime = dirinfo.LastAccessTime;
private FSEntry mycomputerFSEntry = null;
private FSEntry mynetworkFSEntry = null;
+ private string personal_folder;
+ private string recently_used_path;
+ private string full_kde_recent_document_dir;
+
public UnixFileSystem ()
{
+ personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
+ recently_used_path = Path.Combine (personal_folder, ".recently-used");
+
+ full_kde_recent_document_dir = personal_folder + "/.kde/share/apps/RecentDocuments";
+
desktopFSEntry = new FSEntry ();
desktopFSEntry.Attributes = FileAttributes.Directory;
desktopFSEntry.FullName = MWFVFS.DesktopPrefix;
desktopFSEntry.Name = "Desktop";
desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
- desktopFSEntry.FileType = FSEntry.FSEntryType.Directoy;
- desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("deskop/desktop");
+ desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
+ desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
desktopFSEntry.LastAccessTime = DateTime.Now;
recentlyusedFSEntry = new FSEntry ();
recentlyusedFSEntry.Attributes = FileAttributes.Directory;
recentlyusedFSEntry.FullName = MWFVFS.RecentlyUsedPrefix;
recentlyusedFSEntry.Name = "Recently Used";
- recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directoy;
+ recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directory;
recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
recentlyusedFSEntry.LastAccessTime = DateTime.Now;
personalFSEntry.Name = "Personal";
personalFSEntry.MainTopNode = GetDesktopFSEntry ();
personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- personalFSEntry.FileType = FSEntry.FSEntryType.Directoy;
+ personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
personalFSEntry.LastAccessTime = DateTime.Now;
mycomputerpersonalFSEntry.Name = "Personal";
mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directoy;
+ mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
mycomputerFSEntry.Name = "My Computer";
mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
- mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directoy;
+ mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
mycomputerFSEntry.LastAccessTime = DateTime.Now;
mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
mynetworkFSEntry.Name = "My Network";
mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
- mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directoy;
+ mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
mynetworkFSEntry.LastAccessTime = DateTime.Now;
}
public override void WriteRecentlyUsedFiles (string fileToAdd)
{
- string personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- string recently_used_path = Path.Combine (personal_folder, ".recently-used");
-
if (File.Exists (recently_used_path) && new FileInfo (recently_used_path).Length > 0) {
XmlDocument xml_doc = new XmlDocument ();
xml_doc.Load (recently_used_path);
public override ArrayList GetRecentlyUsedFiles ()
{
// check for GNOME and KDE
- string personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- string recently_used_path = Path.Combine (personal_folder, ".recently-used");
ArrayList files_al = new ArrayList ();
}
// KDE
- string full_kde_recent_document_dir = personal_folder + "/.kde/share/apps/RecentDocuments";
-
if (Directory.Exists (full_kde_recent_document_dir)) {
string[] files = Directory.GetFiles (full_kde_recent_document_dir, "*.desktop");
desktopFSEntry.FullName = MWFVFS.DesktopPrefix;
desktopFSEntry.Name = "Desktop";
desktopFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
- desktopFSEntry.FileType = FSEntry.FSEntryType.Directoy;
- desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("deskop/desktop");
+ desktopFSEntry.FileType = FSEntry.FSEntryType.Directory;
+ desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
desktopFSEntry.LastAccessTime = DateTime.Now;
recentlyusedFSEntry = new FSEntry ();
recentlyusedFSEntry.FullName = MWFVFS.RecentlyUsedPrefix;
recentlyusedFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments);
recentlyusedFSEntry.Name = "Recently Used";
- recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directoy;
+ recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directory;
recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
recentlyusedFSEntry.LastAccessTime = DateTime.Now;
personalFSEntry.Name = "Personal";
personalFSEntry.MainTopNode = GetDesktopFSEntry ();
personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- personalFSEntry.FileType = FSEntry.FSEntryType.Directoy;
+ personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
personalFSEntry.LastAccessTime = DateTime.Now;
mycomputerpersonalFSEntry.Name = "Personal";
mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directoy;
+ mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
mycomputerFSEntry.Name = "My Computer";
mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
- mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directoy;
+ mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
mycomputerFSEntry.LastAccessTime = DateTime.Now;
mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
mynetworkFSEntry.Name = "My Network";
mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
- mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directoy;
+ mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
mynetworkFSEntry.LastAccessTime = DateTime.Now;
}
RecentlyUsed,
MyComputer,
File,
- Directoy,
+ Directory,
Device,
RemovableDevice,
Network
}
}
#endregion
+
+ #region MWFConfig
+ // easy to use class to store and read internal MWF config settings.
+ // the config values are stored in the users home dir as a hidden xml file called "mwf_config".
+ // currently supports int, string, byte, color and arrays (including byte arrays)
+ // don't forget, when you read a value you still have to cast this value.
+ //
+ // usage:
+ // MWFConfig.SetValue ("SomeClass", "What", value);
+ // object o = MWFConfig.GetValue ("SomeClass", "What");
+ //
+ // example:
+ //
+ // string[] configFileNames = (string[])MWFConfig.GetValue ("FileDialog", "FileNames");
+ // MWFConfig.SetValue ("FileDialog", "LastFolder", "/home/user");
+
+ internal class MWFConfig
+ {
+ private static MWFConfigInstance Instance = new MWFConfigInstance ();
+
+ private static object lock_object = new object();
+
+ public static object GetValue (string class_name, string value_name)
+ {
+ lock (lock_object) {
+ return Instance.GetValue (class_name, value_name);
+ }
+ }
+
+ public static void SetValue (string class_name, string value_name, object value)
+ {
+ lock (lock_object) {
+ Instance.SetValue (class_name, value_name, value);
+ }
+ }
+
+ public static void Flush ()
+ {
+ lock (lock_object) {
+ Instance.Flush ();
+ }
+ }
+
+ public static void RemoveClass (string class_name)
+ {
+ lock (lock_object) {
+ Instance.RemoveClass (class_name);
+ }
+ }
+
+ public static void RemoveClassValue (string class_name, string value_name)
+ {
+ lock (lock_object) {
+ Instance.RemoveClassValue (class_name, value_name);
+ }
+ }
+
+ public static void RemoveAllClassValues (string class_name)
+ {
+ lock (lock_object) {
+ Instance.RemoveAllClassValues (class_name);
+ }
+ }
+
+ internal class MWFConfigInstance
+ {
+ 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 ()
+ {
+ Open (default_file_name);
+ }
+
+ // only for testing
+ public MWFConfigInstance (string 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 ()
+ {
+ Flush ();
+ }
+
+ public object GetValue (string class_name, string value_name)
+ {
+ ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
+
+ if (class_entry != null)
+ return class_entry.GetValue (value_name);
+
+ return null;
+ }
+
+ public void SetValue (string class_name, string value_name, object value)
+ {
+ ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
+
+ if (class_entry == null) {
+ class_entry = new ClassEntry ();
+ class_entry.ClassName = class_name;
+ classes_hashtable [class_name] = class_entry;
+ }
+
+ class_entry.SetValue (value_name, value);
+ }
+
+ private void Open (string filename)
+ {
+ try {
+ xtr = new XmlTextReader (filename);
+
+ ReadConfig ();
+
+ xtr.Close ();
+ } catch (Exception) {
+ }
+ }
+
+ public void Flush ()
+ {
+ try {
+ xtw = new XmlTextWriter (full_file_name, null);
+ xtw.Formatting = Formatting.Indented;
+
+ WriteConfig ();
+
+ xtw.Close ();
+
+ if (!IsUnix ())
+ File.SetAttributes (full_file_name, FileAttributes.Hidden);
+ } catch (Exception){
+ }
+ }
+
+ public void RemoveClass (string class_name)
+ {
+ ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
+
+ if (class_entry != null) {
+ class_entry.RemoveAllClassValues ();
+
+ classes_hashtable.Remove (class_name);
+ }
+ }
+
+ public void RemoveClassValue (string class_name, string value_name)
+ {
+ ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
+
+ if (class_entry != null) {
+ class_entry.RemoveClassValue (value_name);
+ }
+ }
+
+ public void RemoveAllClassValues (string class_name)
+ {
+ ClassEntry class_entry = classes_hashtable [class_name] as ClassEntry;
+
+ if (class_entry != null) {
+ class_entry.RemoveAllClassValues ();
+ }
+ }
+
+ private void ReadConfig ()
+ {
+ if (!CheckForMWFConfig ())
+ return;
+
+ while (xtr.Read ()) {
+ switch (xtr.NodeType) {
+ case XmlNodeType.Element:
+ ClassEntry class_entry = classes_hashtable [xtr.Name] as ClassEntry;
+
+ if (class_entry == null) {
+ class_entry = new ClassEntry ();
+ class_entry.ClassName = xtr.Name;
+ classes_hashtable [xtr.Name] = class_entry;
+ }
+
+ class_entry.ReadXml (xtr);
+ break;
+ }
+ }
+ }
+
+ private bool CheckForMWFConfig ()
+ {
+ if (xtr.Read ()) {
+ if (xtr.NodeType == XmlNodeType.Element) {
+ if (xtr.Name == configName)
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private void WriteConfig ()
+ {
+ if (classes_hashtable.Count == 0)
+ return;
+
+ xtw.WriteStartElement (configName);
+ foreach (DictionaryEntry entry in classes_hashtable) {
+ ClassEntry class_entry = entry.Value as ClassEntry;
+
+ class_entry.WriteXml (xtw);
+ }
+ xtw.WriteEndElement ();
+ }
+
+ internal class ClassEntry
+ {
+ private Hashtable classvalues_hashtable = new Hashtable ();
+ private string className;
+
+ public string ClassName {
+ set {
+ className = value;
+ }
+
+ get {
+ return className;
+ }
+ }
+
+ public void SetValue (string value_name, object value)
+ {
+ ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
+
+ if (class_value == null) {
+ class_value = new ClassValue ();
+ class_value.Name = value_name;
+ classvalues_hashtable [value_name] = class_value;
+ }
+
+ class_value.SetValue (value);
+ }
+
+ public object GetValue (string value_name)
+ {
+ ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
+
+ if (class_value == null) {
+ return null;
+ }
+
+ return class_value.GetValue ();
+ }
+
+ public void RemoveAllClassValues ()
+ {
+ classvalues_hashtable.Clear ();
+ }
+
+ public void RemoveClassValue (string value_name)
+ {
+ ClassValue class_value = classvalues_hashtable [value_name] as ClassValue;
+
+ if (class_value != null) {
+ classvalues_hashtable.Remove (value_name);
+ }
+ }
+
+ public void ReadXml (XmlTextReader xtr)
+ {
+ while (xtr.Read ()) {
+ switch (xtr.NodeType) {
+ case XmlNodeType.Element:
+ string name = xtr.GetAttribute ("name");
+
+ ClassValue class_value = classvalues_hashtable [name] as ClassValue;
+
+ if (class_value == null) {
+ class_value = new ClassValue ();
+ class_value.Name = name;
+ classvalues_hashtable [name] = class_value;
+ }
+
+ class_value.ReadXml (xtr);
+ break;
+
+ case XmlNodeType.EndElement:
+ return;
+ }
+ }
+ }
+
+ public void WriteXml (XmlTextWriter xtw)
+ {
+ if (classvalues_hashtable.Count == 0)
+ return;
+
+ xtw.WriteStartElement (className);
+
+ foreach (DictionaryEntry entry in classvalues_hashtable) {
+ ClassValue class_value = entry.Value as ClassValue;
+
+ class_value.WriteXml (xtw);
+ }
+
+ xtw.WriteEndElement ();
+ }
+ }
+
+ internal class ClassValue
+ {
+ private object value;
+ private string name;
+
+ public string Name {
+ set {
+ name = value;
+ }
+
+ get {
+ return name;
+ }
+ }
+
+ public void SetValue (object value)
+ {
+ this.value = value;
+ }
+ public object GetValue ()
+ {
+ return value;
+ }
+
+ public void ReadXml (XmlTextReader xtr)
+ {
+ string type;
+ string single_value;
+
+ type = xtr.GetAttribute ("type");
+
+ if (type == "byte_array" || type.IndexOf ("-array") == -1) {
+ single_value = xtr.ReadString ();
+
+ if (type == "string") {
+ value = single_value;
+ } else
+ if (type == "int") {
+ value = Int32.Parse (single_value);
+ } else
+ if (type == "byte") {
+ value = Byte.Parse (single_value);
+ } else
+ if (type == "color") {
+ int color = Int32.Parse (single_value);
+ value = Color.FromArgb (color);
+ } else
+ if (type == "byte-array") {
+ byte[] b_array = Convert.FromBase64String (single_value);
+ value = b_array;
+ }
+ } else {
+ ReadXmlArrayValues (xtr, type);
+ }
+ }
+
+ private void ReadXmlArrayValues (XmlTextReader xtr, string type)
+ {
+ ArrayList al = new ArrayList ();
+
+ while (xtr.Read ()) {
+ switch (xtr.NodeType) {
+ case XmlNodeType.Element:
+ string single_value = xtr.ReadString ();
+
+ if (type == "int-array") {
+ int int_val = Int32.Parse (single_value);
+ al.Add (int_val);
+ } else
+ if (type == "string-array") {
+ string str_val = single_value;
+ al.Add (str_val);
+ }
+ break;
+
+ case XmlNodeType.EndElement:
+ if (xtr.Name == "value") {
+ if (type == "int-array") {
+ value = al.ToArray (typeof(int));
+ } else
+ if (type == "string-array") {
+ value = al.ToArray (typeof(string));
+ }
+ return;
+ }
+ break;
+ }
+ }
+ }
+
+ public void WriteXml (XmlTextWriter xtw)
+ {
+ xtw.WriteStartElement ("value");
+ xtw.WriteAttributeString ("name", name);
+ if (value is Array) {
+ WriteArrayContent (xtw);
+ } else {
+ WriteSingleContent (xtw);
+ }
+ xtw.WriteEndElement ();
+ }
+
+ private void WriteSingleContent (XmlTextWriter xtw)
+ {
+ string type_string = "";
+
+ if (value is string)
+ type_string = "string";
+ else
+ if (value is int)
+ type_string = "int";
+ else
+ if (value is byte)
+ type_string = "byte";
+ else
+ if (value is Color)
+ type_string = "color";
+
+ xtw.WriteAttributeString ("type", type_string);
+
+ if (value is Color)
+ xtw.WriteString (((Color)value).ToArgb ().ToString ());
+ else
+ xtw.WriteString (value.ToString ());
+ }
+
+ private void WriteArrayContent (XmlTextWriter xtw)
+ {
+ string type_string = "";
+ string type_name = "";
+
+ if (value is string[]) {
+ type_string = "string-array";
+ type_name = "string";
+ } else
+ if (value is int[]) {
+ type_string = "int-array";
+ type_name = "int";
+ } else
+ if (value is byte[]) {
+ type_string = "byte-array";
+ type_name = "byte";
+ }
+
+ xtw.WriteAttributeString ("type", type_string);
+
+ if (type_string != "byte-array") {
+ Array array = value as Array;
+
+ foreach (object o in array) {
+ xtw.WriteStartElement (type_name);
+ xtw.WriteString (o.ToString ());
+ xtw.WriteEndElement ();
+ }
+ } else {
+ byte[] b_array = value as byte [];
+
+ xtw.WriteString (Convert.ToBase64String (b_array, 0, b_array.Length));
+ }
+ }
+ }
+ }
+ }
+ #endregion
}