using System.Collections;
using System.Collections.Specialized;
using System.Xml;
+using System.Threading;
namespace System.Windows.Forms {
+ #region FileDialog
[DefaultProperty ("FileName")]
[DefaultEvent ("FileOk")]
- public abstract class FileDialog : CommonDialog {
+ public abstract class FileDialog : CommonDialog
+ {
protected static readonly object EventFileOk = new object ();
- internal enum FileDialogType {
+ internal enum FileDialogType
+ {
OpenFileDialog,
SaveFileDialog
}
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 ToolBarButton backToolBarButton;
private ComboBox fileTypeComboBox;
private ImageList imageListTopToolbar;
- private ContextMenu contextMenu;
private CheckBox readonlyCheckBox;
- private string currentDirectoryName;
- private string currentFileName = "";
- // store current directoryInfo
- private DirectoryInfo currentDirectoryInfo;
- // store DirectoryInfo for backButton
- private Stack directoryStack = new Stack();
- private MenuItem previousCheckedMenuItem;
private bool multiSelect = false;
- private string restoreDirectoryString = "";
-
- private bool show_special_case = false;
-
- internal static readonly string recently_string = "[recently/recently]";
- internal static readonly string network_string = "[network/network]";
- internal static readonly string mycomputer_string = "[mycomputer/mycomputer]";
-
- private string current_special_case;
+ private string restoreDirectoryString = String.Empty;
internal FileDialogType fileDialogType;
private bool do_not_call_OnSelectedIndexChangedFileTypeComboBox = false;
- private bool showHiddenFiles = false;
-
- //protected bool readOnlyChecked = false;
-
private bool showReadOnly = false;
private bool readOnlyChecked = false;
internal bool createPrompt = false;
internal FileFilter fileFilter;
+ private string lastFolder = String.Empty;
+
+ private MWFVFS vfs;
+
+ 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 formConfigSize = Size.Empty;
+ Point formConfigLocation = Point.Empty;
+ string[] configFileNames = null;
+
+ object formWidth = MWFConfig.GetValue (filedialog_string, width_string);
+
+ 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 ();
newdirToolBarButton = new ToolBarButton ();
searchSaveLabel = new Label ();
- mwfFileView = new MWFFileView ();
+ mwfFileView = new MWFFileView (vfs);
fileNameLabel = new Label ();
fileNameComboBox = new ComboBox ();
- dirComboBox = new DirComboBox ();
+ dirComboBox = new DirComboBox (vfs);
smallButtonToolBar = new ToolBar ();
menueToolBarButton = new ToolBarButton ();
fileTypeLabel = new Label ();
openSaveButton = new Button ();
form.AcceptButton = openSaveButton;
helpButton = new Button ();
- popupButtonPanel = new PopupButtonPanel (this);
+ popupButtonPanel = new PopupButtonPanel ();
upToolBarButton = new ToolBarButton ();
cancelButton = new Button ();
form.CancelButton = cancelButton;
imageListTopToolbar = new ImageList ();
menueToolBarButtonContextMenu = new ContextMenu ();
- contextMenu = new ContextMenu ();
readonlyCheckBox = new CheckBox ();
form.SuspendLayout ();
//imageListTopToolbar
imageListTopToolbar.ColorDepth = ColorDepth.Depth32Bit;
imageListTopToolbar.ImageSize = new Size (16, 16); // 16, 16
- imageListTopToolbar.Images.Add ((Image)Locale.GetResource ("back_arrow"));
- imageListTopToolbar.Images.Add ((Image)Locale.GetResource ("folder_arrow_up"));
- imageListTopToolbar.Images.Add ((Image)Locale.GetResource ("folder_star"));
- imageListTopToolbar.Images.Add ((Image)Locale.GetResource ("window"));
+ imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("go-previous.png"));
+ imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("go-top.png"));
+ imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("folder-new.png"));
+ imageListTopToolbar.Images.Add (ResourceImageLoader.Get ("preferences-system-windows.png"));
imageListTopToolbar.TransparentColor = Color.Transparent;
// searchLabel
searchSaveLabel.FlatStyle = FlatStyle.System;
searchSaveLabel.Location = new Point (7, 8);
searchSaveLabel.Size = new Size (72, 21);
- searchSaveLabel.TabIndex = 0;
searchSaveLabel.TextAlign = ContentAlignment.MiddleRight;
// dirComboBox
dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
dirComboBox.Location = new Point (99, 8);
dirComboBox.Size = new Size (260, 21);
- dirComboBox.TabIndex = 1;
+ dirComboBox.TabIndex = 7;
// smallButtonToolBar
smallButtonToolBar.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right)));
smallButtonToolBar.Appearance = ToolBarAppearance.Flat;
smallButtonToolBar.AutoSize = false;
- smallButtonToolBar.Buttons.AddRange (new ToolBarButton [] {
+ smallButtonToolBar.Buttons.AddRange (new ToolBarButton [] {
backToolBarButton,
upToolBarButton,
newdirToolBarButton,
menueToolBarButton});
- smallButtonToolBar.ButtonSize = new Size (21, 16); // 21, 16
+ smallButtonToolBar.ButtonSize = new Size (24, 24); // 21, 16
smallButtonToolBar.Divider = false;
smallButtonToolBar.Dock = DockStyle.None;
smallButtonToolBar.DropDownArrows = true;
smallButtonToolBar.ImageList = imageListTopToolbar;
- smallButtonToolBar.Location = new Point (372, 8);
+ smallButtonToolBar.Location = new Point (372, 6);
smallButtonToolBar.ShowToolTips = true;
- smallButtonToolBar.Size = new Size (110, 20);
- smallButtonToolBar.TabIndex = 2;
+ smallButtonToolBar.Size = new Size (140, 28);
+ smallButtonToolBar.TabIndex = 8;
smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
// buttonPanel
popupButtonPanel.Dock = DockStyle.None;
popupButtonPanel.Location = new Point (7, 37);
- popupButtonPanel.TabIndex = 3;
+ 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 = 4;
- mwfFileView.FilterIndex = FilterIndex;
+ mwfFileView.TabIndex = 10;
+ mwfFileView.RegisterSender (dirComboBox);
+ mwfFileView.RegisterSender (popupButtonPanel);
// fileNameLabel
fileNameLabel.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
fileNameLabel.FlatStyle = FlatStyle.System;
fileNameLabel.Location = new Point (102, 330);
fileNameLabel.Size = new Size (70, 21);
- fileNameLabel.TabIndex = 5;
fileNameLabel.Text = "Filename:";
fileNameLabel.TextAlign = ContentAlignment.MiddleLeft;
fileNameComboBox.Anchor = ((AnchorStyles)(((AnchorStyles.Bottom | AnchorStyles.Left) | AnchorStyles.Right)));
fileNameComboBox.Location = new Point (195, 330);
fileNameComboBox.Size = new Size (245, 21);
- fileNameComboBox.TabIndex = 6;
+ fileNameComboBox.TabIndex = 1;
+ fileNameComboBox.MaxDropDownItems = 10;
fileNameComboBox.Items.Add (" ");
+ if (configFileNames != null) {
+ fileNameComboBox.Items.Clear ();
+
+ foreach (string configFileName in configFileNames) {
+ if (configFileName != null)
+ if (configFileName.Trim ().Length > 0)
+ fileNameComboBox.Items.Add (configFileName);
+ }
+ }
+
+
// fileTypeLabel
fileTypeLabel.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Left)));
fileTypeLabel.FlatStyle = FlatStyle.System;
fileTypeLabel.Location = new Point (102, 356);
fileTypeLabel.Size = new Size (70, 21);
- fileTypeLabel.TabIndex = 7;
fileTypeLabel.Text = "Filetype:";
fileTypeLabel.TextAlign = ContentAlignment.MiddleLeft;
// 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 = 8;
+ fileTypeComboBox.TabIndex = 2;
// backToolBarButton
backToolBarButton.ImageIndex = 0;
backToolBarButton.Enabled = false;
- backToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
+ backToolBarButton.Style = ToolBarButtonStyle.PushButton;
+ mwfFileView.AddControlToEnableDisableByDirStack (backToolBarButton);
// upToolBarButton
upToolBarButton.ImageIndex = 1;
- upToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
+ upToolBarButton.Style = ToolBarButtonStyle.PushButton;
+ mwfFileView.SetFolderUpToolBarButton (upToolBarButton);
// newdirToolBarButton
newdirToolBarButton.ImageIndex = 2;
- newdirToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
+ newdirToolBarButton.Style = ToolBarButtonStyle.PushButton;
// menueToolBarButton
menueToolBarButton.ImageIndex = 3;
menueToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
// menueToolBarButtonContextMenu
- MenuItem mi = new MenuItem ("Small Icon", new EventHandler (OnClickMenuToolBarContextMenu));
- menueToolBarButtonContextMenu.MenuItems.Add (mi);
- mi = new MenuItem ("Tiles", new EventHandler (OnClickMenuToolBarContextMenu));
- menueToolBarButtonContextMenu.MenuItems.Add (mi);
- mi = new MenuItem ("Large Icon", new EventHandler (OnClickMenuToolBarContextMenu));
- menueToolBarButtonContextMenu.MenuItems.Add (mi);
- mi = new MenuItem ("List", new EventHandler (OnClickMenuToolBarContextMenu));
- mi.Checked = true;
- previousCheckedMenuItem = mi;
- menueToolBarButtonContextMenu.MenuItems.Add (mi);
- mi = new MenuItem ("Details", new EventHandler (OnClickMenuToolBarContextMenu));
- menueToolBarButtonContextMenu.MenuItems.Add (mi);
-
- // contextMenu
- mi = new MenuItem ("Show hidden files", new EventHandler (OnClickContextMenu));
- mi.Checked = showHiddenFiles;
- mwfFileView.ShowHiddenFiles = showHiddenFiles;
- contextMenu.MenuItems.Add (mi);
+ menueToolBarButtonContextMenu.MenuItems.AddRange (mwfFileView.ViewMenuItems);
// openSaveButton
openSaveButton.Anchor = ((AnchorStyles)((AnchorStyles.Bottom | AnchorStyles.Right)));
openSaveButton.FlatStyle = FlatStyle.System;
openSaveButton.Location = new Point (475, 330);
openSaveButton.Size = new Size (72, 21);
- openSaveButton.TabIndex = 9;
+ 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 = 10;
+ 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 = 11;
+ 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 = 3;
readonlyCheckBox.FlatStyle = FlatStyle.System;
- readonlyCheckBox.TabIndex = 12;
- form.ContextMenu = contextMenu;
+ form.SizeGripStyle = SizeGripStyle.Show;
- form.Size = new Size (554, 405); // 384
form.MaximizeBox = true;
+ form.MinimizeBox = true;
form.FormBorderStyle = FormBorderStyle.Sizable;
form.MinimumSize = new Size (554, 405);
+ form.ClientSize = new Size (554, 405); // 384
+
form.Controls.Add (smallButtonToolBar);
form.Controls.Add (cancelButton);
form.Controls.Add (openSaveButton);
form.ResumeLayout (false);
- currentDirectoryName = Environment.CurrentDirectory;
-
- currentDirectoryInfo = new DirectoryInfo (currentDirectoryName);
+ if (formConfigSize != Size.Empty) {
+ form.Size = formConfigSize;
+ }
- if (RestoreDirectory)
- restoreDirectoryString = currentDirectoryName;
+ if (formConfigLocation != Point.Empty) {
+ form.Location = formConfigLocation;
+ }
openSaveButton.Click += new EventHandler (OnClickOpenSaveButton);
cancelButton.Click += new EventHandler (OnClickCancelButton);
fileTypeComboBox.SelectedIndexChanged += new EventHandler (OnSelectedIndexChangedFileTypeComboBox);
mwfFileView.SelectedFileChanged += new EventHandler (OnSelectedFileChangedFileView);
- mwfFileView.DirectoryChanged += new EventHandler (OnDirectoryChangedFileView);
mwfFileView.ForceDialogEnd += new EventHandler (OnForceDialogEndFileView);
mwfFileView.SelectedFilesChanged += new EventHandler (OnSelectedFilesChangedFileView);
- mwfFileView.OnDirectoryUp += new EventHandler (OnDirectoryUp);
dirComboBox.DirectoryChanged += new EventHandler (OnDirectoryChangedDirComboBox);
+ popupButtonPanel.DirectoryChanged += new EventHandler (OnDirectoryChangedPopupButtonPanel);
readonlyCheckBox.CheckedChanged += new EventHandler (OnCheckCheckChanged);
-
- ChangeDirectory (null, currentDirectoryName);
}
[DefaultValue(true)]
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 ();
}
if (Directory.Exists (value)) {
initialDirectory = value;
- ChangeDirectory (null, initialDirectory);
+ mwfFileView.ChangeDirectory (null, initialDirectory);
}
}
}
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 {
protected void OnFileOk (CancelEventArgs e)
{
+ WriteConfigValues (e);
+
CancelEventHandler fo = (CancelEventHandler) Events [EventFileOk];
if (fo != null)
fo (this, e);
}
- [MonoTODO]
protected override bool RunDialog (IntPtr hWndOwner)
{
+ ReadConfigValues ();
+
form.Refresh ();
+
+ mwfFileView.ChangeDirectory (null, lastFolder);
+
+ fileNameComboBox.Select ();
+
return true;
}
private void SelectFilter ()
{
+ 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.UpdateFileView (currentDirectoryInfo_or_current_special_case);
+ mwfFileView.FilterIndex = filterIndex;
}
private bool SetFileName (string fname)
bool rooted = Path.IsPathRooted (fname);
if (!rooted) {
- if (File.Exists (Path.Combine (currentDirectoryName, fname))) {
+ string dir = mwfFileView.CurrentRealFolder ;
+ if (dir == null) {
+ dir = Environment.CurrentDirectory;
+ }
+ if (File.Exists (Path.Combine (dir, fname))) {
fileNameComboBox.Text = fname;
mwfFileView.SetSelectedIndexTo (fname);
return true;
- } else
- return false;
+ }
} else {
if (File.Exists (fname)) {
fileNameComboBox.Text = Path.GetFileName (fname);
- ChangeDirectory (null, Path.GetDirectoryName (fname));
+ mwfFileView.ChangeDirectory (null, Path.GetDirectoryName (fname));
mwfFileView.SetSelectedIndexTo (fname);
return true;
return false;
}
- void OnClickContextMenu (object sender, EventArgs e)
- {
- MenuItem senderMenuItem = sender as MenuItem;
-
- if (senderMenuItem.Index == 0) {
- senderMenuItem.Checked = !senderMenuItem.Checked;
- showHiddenFiles = senderMenuItem.Checked;
- mwfFileView.ShowHiddenFiles = showHiddenFiles;
- mwfFileView.UpdateFileView (currentDirectoryInfo_or_current_special_case);
- }
- }
-
void OnClickOpenSaveButton (object sender, EventArgs e)
{
- if (mwfFileView.SelectedItems [0] != null) {
- string path = Path.Combine (currentDirectoryName, mwfFileView.SelectedItems [0].Text);
- if (Directory.Exists (path)) {
- ChangeDirectory (null, path);
- openSaveButton.Select ();
- return;
+ if (fileDialogType == FileDialogType.OpenFileDialog) {
+ ListView.SelectedListViewItemCollection sl = mwfFileView.SelectedItems;
+ if (sl.Count > 0 && sl [0] != null) {
+ if (sl.Count == 1) {
+ FileViewListViewItem item = sl [0] as FileViewListViewItem;
+ FSEntry fsEntry = item.FSEntry;
+
+ if (fsEntry.Attributes == FileAttributes.Directory) {
+ mwfFileView.ChangeDirectory (null, fsEntry.FullName);
+ return;
+ }
+ } else {
+ foreach (FileViewListViewItem item in sl) {
+ FSEntry fsEntry = item.FSEntry;
+ if (fsEntry.Attributes == FileAttributes.Directory) {
+ mwfFileView.ChangeDirectory (null, fsEntry.FullName);
+ return;
+ }
+ }
+ }
}
}
+ string internalfullfilename = String.Empty;
+
if (!multiSelect) {
- if (!show_special_case) {
- string fileFromComboBox = fileNameComboBox.Text.Trim ();
-
- if (fileFromComboBox.Length > 0) {
- if (!Path.IsPathRooted (fileFromComboBox))
- fileFromComboBox = Path.Combine (currentDirectoryName, fileFromComboBox);
-
- FileInfo fileInfo = new FileInfo (fileFromComboBox);
- if (fileInfo.Exists)
- currentFileName = fileFromComboBox;
- else {
- DirectoryInfo dirInfo = new DirectoryInfo (fileFromComboBox);
- if (dirInfo.Exists) {
- ChangeDirectory (null, dirInfo.FullName);
-
- currentFileName = "";
-
- fileNameComboBox.Text = " ";
- return;
- }
+ string fileFromComboBox = fileNameComboBox.Text.Trim ();
+
+ if (fileFromComboBox.Length > 0) {
+ if (!Path.IsPathRooted (fileFromComboBox)) {
+ // on unix currentRealFolder for "Recently used files" is null,
+ // because recently used files don't get saved as links in a directory
+ // recently used files get saved in a xml file
+ if (mwfFileView.CurrentRealFolder != null)
+ fileFromComboBox = Path.Combine (mwfFileView.CurrentRealFolder, fileFromComboBox);
+ else
+ if (mwfFileView.CurrentFSEntry != null) {
+ fileFromComboBox = mwfFileView.CurrentFSEntry.FullName;
}
- } else
- return;
- } else {
- if (currentFileName == null || currentFileName == String.Empty) {
- currentFileName = fileNameComboBox.Text.Trim ();
-
- if (currentFileName.Length > 0) {
- FileInfo fileInfo = new FileInfo (currentFileName);
- if (!fileInfo.Exists) {
- DirectoryInfo dirInfo = new DirectoryInfo (currentFileName);
- if (dirInfo.Exists) {
- ChangeDirectory (null, dirInfo.FullName);
-
- currentFileName = "";
-
- fileNameComboBox.Text = " ";
- return;
- }
- }
- } else
- return;
}
- if (currentDirectoryName == String.Empty)
- currentDirectoryName = Path.GetDirectoryName (currentFileName);
- }
+ FileInfo fileInfo = new FileInfo (fileFromComboBox);
+
+ if (fileInfo.Exists || fileDialogType == FileDialogType.SaveFileDialog) {
+ internalfullfilename = fileFromComboBox;
+ } else {
+ DirectoryInfo dirInfo = new DirectoryInfo (fileFromComboBox);
+ if (dirInfo.Exists) {
+ mwfFileView.ChangeDirectory (null, dirInfo.FullName);
+
+ fileNameComboBox.Text = " ";
+ return;
+ } else {
+ internalfullfilename = fileFromComboBox;
+ }
+ }
+ } else
+ return;
if (fileDialogType == FileDialogType.OpenFileDialog) {
if (checkFileExists) {
- if (!File.Exists (currentFileName)) {
- string message = "\"" + currentFileName + "\" doesn't exist. Please verify that you have entered the correct file name.";
+ if (!File.Exists (internalfullfilename)) {
+ string message = "\"" + internalfullfilename + "\" doesn't exist. Please verify that you have entered the correct file name.";
MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- currentFileName = "";
-
return;
}
}
} else {
if (overwritePrompt) {
- if (File.Exists (currentFileName)) {
- string message = "\"" + currentFileName + "\" exists. Overwrite ?";
+ if (File.Exists (internalfullfilename)) {
+ string message = "\"" + internalfullfilename + "\" exists. Overwrite ?";
DialogResult dr = MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
- if (dr == DialogResult.Cancel) {
- currentFileName = "";
-
+ if (dr == DialogResult.Cancel)
return;
- }
}
}
if (createPrompt) {
- if (!File.Exists (currentFileName)) {
- string message = "\"" + currentFileName + "\" doesn't exist. Create ?";
+ if (!File.Exists (internalfullfilename)) {
+ string message = "\"" + internalfullfilename + "\" doesn't exist. Create ?";
DialogResult dr = MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
- if (dr == DialogResult.Cancel) {
- currentFileName = "";
-
+ if (dr == DialogResult.Cancel)
return;
- }
}
}
}
if (fileDialogType == FileDialogType.SaveFileDialog) {
- if (addExtension && defaultExt.Length > 0) {
- if (!currentFileName.EndsWith (defaultExt)) {
- currentFileName += "." + defaultExt;
+ if (addExtension) {
+ string extension_to_use = String.Empty;
+ string filter_exentsion = String.Empty;
+
+ if (fileFilter != null) {
+ FilterStruct filterstruct = (FilterStruct)fileFilter.FilterArrayList [filterIndex - 1];
+
+ for (int i = 0; i < filterstruct.filters.Count; i++) {
+ string extension = filterstruct.filters [i];
+
+ if (extension.StartsWith ("*"))
+ extension = extension.Remove (0, 1);
+
+ if (extension.IndexOf ('*') != -1)
+ continue;
+
+ filter_exentsion = extension;
+ break;
+ }
}
+
+ if (filter_exentsion != String.Empty)
+ extension_to_use = filter_exentsion;
+ else
+ if (defaultExt != String.Empty)
+ extension_to_use = "." + defaultExt;
+
+ if (!internalfullfilename.EndsWith (extension_to_use))
+ internalfullfilename += extension_to_use;
}
}
fileNames = new string [1];
- fileNames [0] = currentFileName;
+ fileNames [0] = internalfullfilename;
- fileName = currentFileName;
+ fileName = internalfullfilename;
- WriteRecentlyUsed ();
+ mwfFileView.WriteRecentlyUsed (internalfullfilename);
} else // multiSelect = true
if (fileDialogType != FileDialogType.SaveFileDialog) {
if (mwfFileView.SelectedItems.Count > 0) {
// first remove all selected directories
ArrayList al = new ArrayList ();
- foreach (ListViewItem lvi in mwfFileView.SelectedItems) {
- FileStruct fileStruct = (FileStruct)mwfFileView.FileHashtable [lvi.Text];
+ foreach (FileViewListViewItem lvi in mwfFileView.SelectedItems) {
+ FSEntry fsEntry = lvi.FSEntry;
- if (fileStruct.attributes != FileAttributes.Directory) {
- al.Add (fileStruct);
+ if (fsEntry.Attributes != FileAttributes.Directory) {
+ al.Add (fsEntry);
}
}
- fileName = ((FileStruct)al [0]).fullname;
+ fileName = ((FSEntry)al [0]).FullName;
fileNames = new string [al.Count];
for (int i = 0; i < al.Count; i++) {
- fileNames [i] = ((FileStruct)al [i]).fullname;
+ fileNames [i] = ((FSEntry)al [i]).FullName;
}
}
}
- if (checkPathExists) {
- if (!Directory.Exists (currentDirectoryName)) {
- string message = "\"" + currentDirectoryName + "\" doesn't exist. Please verify that you have entered the correct directory name.";
+ if (checkPathExists && mwfFileView.CurrentRealFolder != null) {
+ if (!Directory.Exists (mwfFileView.CurrentRealFolder)) {
+ string message = "\"" + mwfFileView.CurrentRealFolder + "\" doesn't exist. Please verify that you have entered the correct directory name.";
MessageBox.Show (message, openSaveButton.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
if (initialDirectory == String.Empty)
- currentDirectoryName = Environment.CurrentDirectory;
+ mwfFileView.ChangeDirectory (null, lastFolder);
else
- currentDirectoryName = initialDirectory;
+ mwfFileView.ChangeDirectory (null, initialDirectory);
return;
}
}
- if (restoreDirectory)
- currentDirectoryName = restoreDirectoryString;
+ if (restoreDirectory) {
+ lastFolder = restoreDirectoryString;
+ } else {
+ lastFolder = mwfFileView.CurrentFolder;
+ }
+
+ if (fileNameComboBox.Items.Count > 0) {
+ if (fileNameComboBox.Items.IndexOf (fileName) == -1) {
+ fileNameComboBox.Items.Insert (0, fileName);
+ }
+ } else
+ fileNameComboBox.Items.Add (fileName);
+
+ if (fileNameComboBox.Items.Count == 11)
+ fileNameComboBox.Items.RemoveAt (10);
CancelEventArgs cancelEventArgs = new CancelEventArgs ();
void OnClickCancelButton (object sender, EventArgs e)
{
if (restoreDirectory)
- currentDirectoryName = restoreDirectoryString;
+ mwfFileView.CurrentFolder = restoreDirectoryString;
CancelEventArgs cancelEventArgs = new CancelEventArgs ();
void OnClickSmallButtonToolBar (object sender, ToolBarButtonClickEventArgs e)
{
if (e.Button == upToolBarButton) {
- if (currentDirectoryInfo != null && currentDirectoryInfo.Parent != null)
- ChangeDirectory (null, currentDirectoryInfo.Parent.FullName);
+ mwfFileView.OneDirUp ();
} else
if (e.Button == backToolBarButton) {
- PopDirectory ();
+ mwfFileView.PopDir ();
} else
if (e.Button == newdirToolBarButton) {
-
- }
- }
-
- void OnClickMenuToolBarContextMenu (object sender, EventArgs e)
- {
- MenuItem senderMenuItem = (MenuItem)sender;
-
- previousCheckedMenuItem.Checked = false;
- senderMenuItem.Checked = true;
- previousCheckedMenuItem = senderMenuItem;
-
- // FIXME...
-
- switch (senderMenuItem.Index) {
- case 0:
- mwfFileView.View = View.SmallIcon;
- break;
- case 1:
- mwfFileView.View = View.LargeIcon;
- break;
- case 2:
- mwfFileView.View = View.LargeIcon;
- break;
- case 3:
- mwfFileView.View = View.List;
- break;
- case 4:
- mwfFileView.View = View.Details;
- break;
- default:
- break;
+ mwfFileView.CreateNewFolder ();
}
-
-
- mwfFileView.UpdateFileView (currentDirectoryInfo_or_current_special_case);
}
void OnSelectedIndexChangedFileTypeComboBox (object sender, EventArgs e)
filterIndex = fileTypeComboBox.SelectedIndex + 1;
mwfFileView.FilterIndex = filterIndex;
-
- mwfFileView.UpdateFileView (currentDirectoryInfo_or_current_special_case);
}
void OnSelectedFileChangedFileView (object sender, EventArgs e)
{
- fileNameComboBox.Text = mwfFileView.FileName;
- currentFileName = mwfFileView.FullFileName;
+ fileNameComboBox.Text = mwfFileView.CurrentFSEntry.Name;
}
- void OnDirectoryChangedFileView (object sender, EventArgs e)
+ void OnSelectedFilesChangedFileView (object sender, EventArgs e)
{
- ChangeDirectory (sender, mwfFileView.FullFileName);
+ fileNameComboBox.Text = mwfFileView.SelectedFilesString;
}
void OnForceDialogEndFileView (object sender, EventArgs e)
{
- ForceDialogEnd ();
+ OnClickOpenSaveButton (this, EventArgs.Empty);
}
- void OnSelectedFilesChangedFileView (object sender, EventArgs e)
+ void OnDirectoryChangedDirComboBox (object sender, EventArgs e)
{
- fileNameComboBox.Text = mwfFileView.SelectedFilesString;
+ mwfFileView.ChangeDirectory (sender, dirComboBox.CurrentFolder);
}
- void OnDirectoryChangedDirComboBox (object sender, EventArgs e)
+ void OnDirectoryChangedPopupButtonPanel (object sender, EventArgs e)
{
- ChangeDirectory (sender, dirComboBox.CurrentPath);
+ mwfFileView.ChangeDirectory (sender, popupButtonPanel.CurrentFolder);
}
void OnCheckCheckChanged (object sender, EventArgs e)
ReadOnlyChecked = readonlyCheckBox.Checked;
}
- void OnDirectoryUp (Object sender, EventArgs e)
- {
- if (currentDirectoryInfo != null && currentDirectoryInfo.Parent != null)
- ChangeDirectory (null, currentDirectoryInfo.Parent.FullName);
-
- // make mwfFileView the active control
- mwfFileView.Select ();
- }
-
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.UpdateFileView (currentDirectoryInfo_or_current_special_case);
- }
-
- internal void ChangeDirectory (object sender, string path_or_special_case)
- {
- show_special_case = false;
-
- if (sender != dirComboBox)
- dirComboBox.CurrentPath = path_or_special_case;
-
- if (sender != popupButtonPanel)
- popupButtonPanel.SetPopupButtonStateByPath (path_or_special_case);
-
- if (currentDirectoryInfo != null)
- PushDirectory (currentDirectoryInfo);
- else
- PushDirectory (current_special_case);
-
- if (path_or_special_case == recently_string) {
- currentDirectoryName = String.Empty;
-
- currentDirectoryInfo = null;
- show_special_case = true;
-
- current_special_case = recently_string;
-
- mwfFileView.UpdateFileView (recently_string);
-
- } else if (path_or_special_case == mycomputer_string) {
- currentDirectoryName = String.Empty;
-
- currentDirectoryInfo = null;
- show_special_case = true;
-
- current_special_case = mycomputer_string;
-
- mwfFileView.UpdateFileView (mycomputer_string);
-
- } else if (path_or_special_case == network_string) {
- currentDirectoryName = String.Empty;
-
- currentDirectoryInfo = null;
- show_special_case = true;
-
- current_special_case = network_string;
-
- mwfFileView.UpdateFileView (network_string);
-
- } else {
- currentDirectoryName = path_or_special_case;
-
- currentDirectoryInfo = new DirectoryInfo (path_or_special_case);
-
- mwfFileView.UpdateFileView (currentDirectoryInfo);
- }
- }
-
- private void ForceDialogEnd ()
- {
- OnClickOpenSaveButton (this, EventArgs.Empty);
- }
-
- private void PushDirectory (object directoryInfo_or_string)
- {
- directoryStack.Push (directoryInfo_or_string);
- backToolBarButton.Enabled = true;
- }
-
- private void PopDirectory ()
- {
- if (directoryStack.Count == 0)
- return;
-
- show_special_case = false;
-
- object directoryInfo_or_string = directoryStack.Pop ();
-
- if (directoryInfo_or_string is DirectoryInfo) {
- currentDirectoryInfo = directoryInfo_or_string as DirectoryInfo;
-
- currentDirectoryName = currentDirectoryInfo.FullName;
-
- current_special_case = String.Empty;
- } else
- if (directoryInfo_or_string is string) {
- currentDirectoryInfo = null;
- currentDirectoryName = String.Empty;
- show_special_case = true;
- current_special_case = directoryInfo_or_string as string;
- }
-
- if (directoryStack.Count == 0)
- backToolBarButton.Enabled = false;
-
- dirComboBox.CurrentPath = currentDirectoryName_or_special_case;
-
- popupButtonPanel.SetPopupButtonStateByPath (currentDirectoryName_or_special_case);
-
- mwfFileView.UpdateFileView (currentDirectoryInfo_or_current_special_case);
+ mwfFileView.FilterIndex = filterIndex;
}
private void ResizeAndRelocateForHelpOrReadOnly ()
form.ResumeLayout ();
}
- private void WriteRecentlyUsed ()
+ private void WriteConfigValues (CancelEventArgs ce)
{
- int platform = (int) Environment.OSVersion.Platform;
+ 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);
- // on a *nix platform we use "$HOME/.recently-used" to store our recently used files (GNOME, libegg like)
- if ((platform == 4) || (platform == 128)) {
- string personal_folder = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
- string recently_used_path = Path.Combine (personal_folder, ".recently-used");
+ if (!ce.Cancel) {
+ MWFConfig.SetValue (filedialog_string, lastfolder_string, lastFolder);
- if (File.Exists (recently_used_path) && new FileInfo (recently_used_path).Length > 0) {
- XmlDocument xml_doc = new XmlDocument ();
- xml_doc.Load (recently_used_path);
-
- XmlNode grand_parent_node = xml_doc.SelectSingleNode ("RecentFiles");
+ string[] fileNameCBItems = new string [fileNameComboBox.Items.Count];
+
+ fileNameComboBox.Items.CopyTo (fileNameCBItems, 0);
+
+ MWFConfig.SetValue (filedialog_string, filenames_string, fileNameCBItems);
+ }
+ }
+
+ private void ReadConfigValues ()
+ {
+ lastFolder = (string)MWFConfig.GetValue (filedialog_string, lastfolder_string);
+
+ if (lastFolder != null && lastFolder.IndexOf ("://") == -1) {
+ if (!Directory.Exists (lastFolder)) {
+ lastFolder = MWFVFS.DesktopPrefix;
+ }
+ }
+
+ if (initialDirectory != String.Empty)
+ lastFolder = initialDirectory;
+ else
+ if (lastFolder == null || lastFolder == String.Empty)
+ lastFolder = Environment.CurrentDirectory;
+
+ if (RestoreDirectory)
+ restoreDirectoryString = lastFolder;
+ }
+ }
+ #endregion
+
+ #region PopupButtonPanel
+ internal class PopupButtonPanel : Control, IUpdateFolder
+ {
+ #region PopupButton
+ internal class PopupButton : Control
+ {
+ internal enum PopupButtonState
+ { Normal, Down, Up}
+
+ private Image image = null;
+ private PopupButtonState popupButtonState = PopupButtonState.Normal;
+ private StringFormat text_format = new StringFormat();
+ private Rectangle text_rect = Rectangle.Empty;
+
+ public PopupButton ()
+ {
+ text_format.Alignment = StringAlignment.Center;
+ text_format.LineAlignment = StringAlignment.Near;
+
+ SetStyle (ControlStyles.DoubleBuffer, true);
+ SetStyle (ControlStyles.AllPaintingInWmPaint, true);
+ SetStyle (ControlStyles.UserPaint, true);
+ SetStyle (ControlStyles.Selectable, false);
+ }
+
+ public Image Image {
+ set {
+ image = value;
+ Refresh ();
+ }
+
+ get {
+ return image;
+ }
+ }
+
+ public PopupButtonState ButtonState {
+ set {
+ popupButtonState = value;
+ Refresh ();
+ }
+
+ get {
+ return popupButtonState;
+ }
+ }
+
+ protected override void OnPaint (PaintEventArgs pe)
+ {
+ Draw (pe);
+
+ base.OnPaint (pe);
+ }
+
+ private void Draw (PaintEventArgs pe)
+ {
+ Graphics gr = pe.Graphics;
+
+ gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
+
+ // draw image
+ if (image != null) {
+ int i_x = (ClientSize.Width - image.Width) / 2;
+ int i_y = 4;
+ gr.DrawImage (image, i_x, i_y);
+ }
+
+ if (Text != String.Empty) {
+ if (text_rect == Rectangle.Empty)
+ text_rect = new Rectangle (0, Height - 30, Width, Height - 30);
- if (grand_parent_node != null) {
- // create a new element
- XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
-
- XmlElement new_child = xml_doc.CreateElement ("URI");
- UriBuilder ub = new UriBuilder ();
- ub.Path = currentFileName;
- ub.Host = null;
- ub.Scheme = "file";
- XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Mime-Type");
- new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (currentFileName));
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Timestamp");
- long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
- new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Groups");
-
- new_recent_item_node.AppendChild (new_child);
-
- // now search the nodes in grand_parent_node for another instance of the new uri and if found remove it
- // so that the new node is the first one
- foreach (XmlNode n in grand_parent_node.ChildNodes) {
- XmlNode uri_node = n.SelectSingleNode ("URI");
- if (uri_node != null) {
- XmlNode uri_node_child = uri_node.FirstChild;
- if (uri_node_child is XmlText)
- if (ub.ToString () == ((XmlText)uri_node_child).Data) {
- grand_parent_node.RemoveChild (n);
- break;
- }
- }
- }
-
- // prepend the new recent item to the grand parent node list
- grand_parent_node.PrependChild (new_recent_item_node);
-
- // limit the # of RecentItems to 10
- if (grand_parent_node.ChildNodes.Count > 10) {
- while (grand_parent_node.ChildNodes.Count > 10)
- grand_parent_node.RemoveChild (grand_parent_node.LastChild);
- }
-
- try {
- xml_doc.Save (recently_used_path);
- } catch ( Exception e ) {
- }
- }
- } else {
- XmlDocument xml_doc = new XmlDocument ();
- xml_doc.AppendChild (xml_doc.CreateXmlDeclaration ("1.0", "", ""));
-
- XmlElement recentFiles_element = xml_doc.CreateElement ("RecentFiles");
-
- XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
-
- XmlElement new_child = xml_doc.CreateElement ("URI");
- UriBuilder ub = new UriBuilder ();
- ub.Path = currentFileName;
- ub.Host = null;
- ub.Scheme = "file";
- XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Mime-Type");
- new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (currentFileName));
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Timestamp");
- long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
- new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
- new_child.AppendChild (new_text_child);
-
- new_recent_item_node.AppendChild (new_child);
-
- new_child = xml_doc.CreateElement ("Groups");
-
- new_recent_item_node.AppendChild (new_child);
-
- recentFiles_element.AppendChild (new_recent_item_node);
-
- xml_doc.AppendChild (recentFiles_element);
-
- try {
- xml_doc.Save (recently_used_path);
- } catch ( Exception e ) {
- }
- }
- }
- }
-
- private object currentDirectoryInfo_or_current_special_case {
- get {
- if (currentDirectoryInfo != null)
- return currentDirectoryInfo;
- else
- return current_special_case;
- }
- }
-
- private string currentDirectoryName_or_special_case {
- get {
- if (currentDirectoryName != String.Empty)
- return currentDirectoryName;
- else
- return current_special_case;
- }
- }
-
- internal class PopupButtonPanel : Panel {
- internal class PopupButton : Control {
- internal enum PopupButtonState { Normal, Down, Up}
-
- private Image image = null;
- private PopupButtonState popupButtonState = PopupButtonState.Normal;
- private StringFormat text_format = new StringFormat();
-
- public PopupButton ()
- {
- text_format.Alignment = StringAlignment.Center;
- text_format.LineAlignment = StringAlignment.Far;
-
- SetStyle (ControlStyles.DoubleBuffer, true);
- SetStyle (ControlStyles.AllPaintingInWmPaint, true);
- SetStyle (ControlStyles.UserPaint, true);
+ gr.DrawString (Text, Font, ThemeEngine.Current.ResPool.GetSolidBrush (ForeColor), text_rect, text_format);
}
- public Image Image {
- set {
- image = value;
- Refresh ();
- }
-
- get {
- return image;
- }
- }
-
- public PopupButtonState ButtonState {
- set {
- popupButtonState = value;
- Refresh ();
- }
-
- get {
- return popupButtonState;
- }
- }
-
- protected override void OnPaint (PaintEventArgs pe)
- {
- Draw (pe);
-
- base.OnPaint (pe);
- }
-
- private void Draw (PaintEventArgs pe)
- {
- Graphics gr = pe.Graphics;
-
- gr.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
-
- // draw image
- if (image != null) {
- int i_x = (ClientSize.Width - image.Width) / 2;
- int i_y = 4;
- gr.DrawImage (image, i_x, i_y);
- }
-
- if (Text != String.Empty) {
- Rectangle text_rect = Rectangle.Inflate (ClientRectangle, -4, 0);
-
- gr.DrawString (Text, Font, ThemeEngine.Current.ResPool.GetSolidBrush (ForeColor), text_rect, text_format);
- }
-
- switch (popupButtonState) {
+ switch (popupButtonState) {
case PopupButtonState.Up:
gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, 0, ClientSize.Width - 1, 0);
gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, 0, 0, ClientSize.Height - 1);
gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1);
gr.DrawLine (ThemeEngine.Current.ResPool.GetPen (Color.White), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1);
break;
- }
- }
-
- protected override void OnMouseEnter (EventArgs e)
- {
- if (popupButtonState != PopupButtonState.Down)
- popupButtonState = PopupButtonState.Up;
- Refresh ();
- base.OnMouseEnter (e);
}
+ }
+
+ protected override void OnMouseEnter (EventArgs e)
+ {
+ if (popupButtonState != PopupButtonState.Down)
+ popupButtonState = PopupButtonState.Up;
- protected override void OnMouseLeave (EventArgs e)
- {
- if (popupButtonState != PopupButtonState.Down)
- popupButtonState = PopupButtonState.Normal;
- Refresh ();
- base.OnMouseLeave (e);
- }
+ PopupButtonPanel panel = Parent as PopupButtonPanel;
- protected override void OnClick (EventArgs e)
- {
- popupButtonState = PopupButtonState.Down;
- Refresh ();
- base.OnClick (e);
+ if (panel.focusButton != null && panel.focusButton.ButtonState == PopupButtonState.Up) {
+ panel.focusButton.ButtonState = PopupButtonState.Normal;
+ panel.focusButton = null;
}
+ Refresh ();
+ base.OnMouseEnter (e);
}
- private FileDialog fileDialog;
+ protected override void OnMouseLeave (EventArgs e)
+ {
+ if (popupButtonState == PopupButtonState.Up)
+ popupButtonState = PopupButtonState.Normal;
+ Refresh ();
+ base.OnMouseLeave (e);
+ }
- private PopupButton recentlyusedButton;
- private PopupButton desktopButton;
- private PopupButton personalButton;
- private PopupButton mycomputerButton;
- private PopupButton networkButton;
+ protected override void OnClick (EventArgs e)
+ {
+ popupButtonState = PopupButtonState.Down;
+ Refresh ();
+ base.OnClick (e);
+ }
+ }
+ #endregion
+
+ private EventHandler on_directory_changed;
+
+ private PopupButton recentlyusedButton;
+ private PopupButton desktopButton;
+ private PopupButton personalButton;
+ private PopupButton mycomputerButton;
+ private PopupButton networkButton;
+
+ private PopupButton lastPopupButton = null;
+ private PopupButton focusButton = null;
+
+ private string currentPath;
+
+ private int currentFocusIndex;
+
+ public PopupButtonPanel ()
+ {
+ SuspendLayout ();
- private PopupButton lastPopupButton = null;
+ //BackColor = Color.FromArgb (128, 128, 128);
+ Size = new Size (85, 336);
+
+ recentlyusedButton = new PopupButton ();
+ desktopButton = new PopupButton ();
+ personalButton = new PopupButton ();
+ mycomputerButton = new PopupButton ();
+ networkButton = new PopupButton ();
+
+ recentlyusedButton.Size = new Size (81, 64);
+ recentlyusedButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 32);
+ recentlyusedButton.BackColor = BackColor;
+ recentlyusedButton.ForeColor = Color.Black;
+ recentlyusedButton.Location = new Point (2, 2);
+ recentlyusedButton.Text = "Recently\nused";
+ recentlyusedButton.Click += new EventHandler (OnClickButton);
+
+ desktopButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 32);
+ desktopButton.BackColor = BackColor;
+ desktopButton.ForeColor = Color.Black;
+ desktopButton.Size = new Size (81, 64);
+ desktopButton.Location = new Point (2, 66);
+ desktopButton.Text = "Desktop";
+ desktopButton.Click += new EventHandler (OnClickButton);
+
+ personalButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 32);
+ personalButton.BackColor = BackColor;
+ personalButton.ForeColor = Color.Black;
+ personalButton.Size = new Size (81, 64);
+ personalButton.Location = new Point (2, 130);
+ personalButton.Text = "Personal";
+ personalButton.Click += new EventHandler (OnClickButton);
+
+ mycomputerButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 32);
+ mycomputerButton.BackColor = BackColor;
+ mycomputerButton.ForeColor = Color.Black;
+ mycomputerButton.Size = new Size (81, 64);
+ mycomputerButton.Location = new Point (2, 194);
+ mycomputerButton.Text = "My Computer";
+ mycomputerButton.Click += new EventHandler (OnClickButton);
+
+ networkButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 32);
+ networkButton.BackColor = BackColor;
+ networkButton.ForeColor = Color.Black;
+ networkButton.Size = new Size (81, 64);
+ networkButton.Location = new Point (2, 258);
+ networkButton.Text = "My Network";
+ networkButton.Click += new EventHandler (OnClickButton);
+
+ Controls.Add (recentlyusedButton);
+ Controls.Add (desktopButton);
+ Controls.Add (personalButton);
+ Controls.Add (mycomputerButton);
+ Controls.Add (networkButton);
- private int platform = (int) Environment.OSVersion.Platform;
+ ResumeLayout (false);
- public PopupButtonPanel (FileDialog fileDialog)
- {
- this.fileDialog = fileDialog;
-
- SuspendLayout ();
-
- BorderStyle = BorderStyle.Fixed3D;
- BackColor = Color.FromArgb (128, 128, 128);
- Size = new Size (85, 336);
-
- recentlyusedButton = new PopupButton ();
- desktopButton = new PopupButton ();
- personalButton = new PopupButton ();
- mycomputerButton = new PopupButton ();
- networkButton = new PopupButton ();
-
- recentlyusedButton.Size = new Size (82, 64);
- recentlyusedButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 38);
- recentlyusedButton.BackColor = BackColor;
- recentlyusedButton.ForeColor = Color.White;
- recentlyusedButton.Location = new Point (2, 2);
- recentlyusedButton.Text = "Recently\nused";
- recentlyusedButton.Click += new EventHandler (OnClickButton);
-
- desktopButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 38);
- desktopButton.BackColor = BackColor;
- desktopButton.ForeColor = Color.White;
- desktopButton.Size = new Size (82, 64);
- desktopButton.Location = new Point (2, 66);
- desktopButton.Text = "Desktop";
- desktopButton.Click += new EventHandler (OnClickButton);
-
- personalButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 38);
- personalButton.BackColor = BackColor;
- personalButton.ForeColor = Color.White;
- personalButton.Size = new Size (82, 64);
- personalButton.Location = new Point (2, 130);
- personalButton.Text = "Personal";
- personalButton.Click += new EventHandler (OnClickButton);
-
- mycomputerButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 38);
- mycomputerButton.BackColor = BackColor;
- mycomputerButton.ForeColor = Color.White;
- mycomputerButton.Size = new Size (82, 64);
- mycomputerButton.Location = new Point (2, 194);
- mycomputerButton.Text = "My Computer";
- mycomputerButton.Click += new EventHandler (OnClickButton);
-
- networkButton.Image = ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 38);
- networkButton.BackColor = BackColor;
- networkButton.ForeColor = Color.White;
- networkButton.Size = new Size (82, 64);
- networkButton.Location = new Point (2, 258);
- networkButton.Text = "My Network";
- networkButton.Click += new EventHandler (OnClickButton);
-
- Controls.Add (recentlyusedButton);
- Controls.Add (desktopButton);
- Controls.Add (personalButton);
- Controls.Add (mycomputerButton);
- Controls.Add (networkButton);
-
- ResumeLayout (false);
- }
-
- void OnClickButton (object sender, EventArgs e)
- {
- if (lastPopupButton != null && (PopupButton)sender != lastPopupButton)
- lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
- lastPopupButton = sender as PopupButton;
-
- if (sender == recentlyusedButton) {
- if ((platform == 4) || (platform == 128))
- // do NOT change the following line!
- // FileDialog uses a special handling for recently used files on *nix
- // recently used files are not stored as links in a directory but
- // as a xml file called .recently-used in the users home dir
- // This matches the Freedesktop.org spec which gnome uses
- fileDialog.ChangeDirectory (this, FileDialog.recently_string);
- else
- fileDialog.ChangeDirectory (this, ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments));
- } else
- if (sender == desktopButton) {
- fileDialog.ChangeDirectory (this, ThemeEngine.Current.Places (UIIcon.PlacesDesktop));
- } else
- if (sender == personalButton) {
- fileDialog.ChangeDirectory (this, ThemeEngine.Current.Places (UIIcon.PlacesPersonal));
- } else
- if (sender == mycomputerButton) {
- if ((platform == 4) || (platform == 128))
- // do NOT change the following line!
- // on *nix we do not have a special folder MyComputer
- fileDialog.ChangeDirectory (this, FileDialog.mycomputer_string);
- else
- fileDialog.ChangeDirectory (this, ThemeEngine.Current.Places (UIIcon.PlacesMyComputer));
- } else
- if (sender == networkButton) {
- if ((platform == 4) || (platform == 128))
- fileDialog.ChangeDirectory (this, FileDialog.network_string);
- else
- fileDialog.ChangeDirectory (this, ThemeEngine.Current.Places (UIIcon.PlacesMyNetwork));
- }
+ KeyDown += new KeyEventHandler (Key_Down);
+
+ SetStyle (ControlStyles.StandardClick, false);
+ }
+
+ void OnClickButton (object sender, EventArgs e)
+ {
+ if (lastPopupButton != null && lastPopupButton != sender as PopupButton)
+ lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
+ lastPopupButton = sender as PopupButton;
+
+ if (sender == recentlyusedButton) {
+ currentPath = MWFVFS.RecentlyUsedPrefix;
+ } else
+ if (sender == desktopButton) {
+ currentPath = MWFVFS.DesktopPrefix;
+ } else
+ if (sender == personalButton) {
+ currentPath = MWFVFS.PersonalPrefix;
+ } else
+ if (sender == mycomputerButton) {
+ currentPath = MWFVFS.MyComputerPrefix;
+ } else
+ if (sender == networkButton) {
+ currentPath = MWFVFS.MyNetworkPrefix;
}
- public void SetPopupButtonStateByPath (string path)
- {
- if (path == FileDialog.recently_string ||
- path == ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments)) {
+ if (on_directory_changed != null)
+ on_directory_changed (this, EventArgs.Empty);
+ }
+
+ public string CurrentFolder {
+ set {
+ string currentPath = value;
+ if (currentPath == MWFVFS.RecentlyUsedPrefix) {
if (lastPopupButton != recentlyusedButton) {
if (lastPopupButton != null)
lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
lastPopupButton = recentlyusedButton;
}
} else
- if (path == ThemeEngine.Current.Places (UIIcon.PlacesDesktop)) {
+ if (currentPath == MWFVFS.DesktopPrefix) {
if (lastPopupButton != desktopButton) {
if (lastPopupButton != null)
lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
lastPopupButton = desktopButton;
}
} else
- if (path == ThemeEngine.Current.Places (UIIcon.PlacesPersonal)) {
+ if (currentPath == MWFVFS.PersonalPrefix) {
if (lastPopupButton != personalButton) {
if (lastPopupButton != null)
lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
lastPopupButton = personalButton;
}
} else
- if (path == FileDialog.mycomputer_string ||
- path == ThemeEngine.Current.Places (UIIcon.PlacesMyComputer)) {
+ if (currentPath == MWFVFS.MyComputerPrefix) {
if (lastPopupButton != mycomputerButton) {
if (lastPopupButton != null)
lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
lastPopupButton = mycomputerButton;
}
} else
- if (path == FileDialog.network_string ||
- path == ThemeEngine.Current.Places (UIIcon.PlacesMyNetwork)) {
+ if (currentPath == MWFVFS.MyNetworkPrefix) {
if (lastPopupButton != networkButton) {
if (lastPopupButton != null)
lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
}
}
}
+ get {
+ return currentPath;
+ }
}
- }
-
- internal struct FilterStruct {
- public string filterName;
- public StringCollection filters;
- public FilterStruct (string filterName, string filter)
+ protected override void OnPaint (PaintEventArgs e)
{
- this.filterName = filterName;
-
- filters = new StringCollection ();
-
- SplitFilters (filter);
+ ControlPaint.DrawBorder3D (e.Graphics, ClientRectangle, Border3DStyle.Sunken);
+ base.OnPaint (e);
}
- private void SplitFilters (string filter)
+ protected override void OnGotFocus (EventArgs e)
{
- string[] split = filter.Split (new char [] {';'});
+ if (lastPopupButton != recentlyusedButton) {
+ recentlyusedButton.ButtonState = PopupButton.PopupButtonState.Up;
+ focusButton = recentlyusedButton;
+ }
+ currentFocusIndex = 0;
- filters.AddRange (split);
+ base.OnGotFocus (e);
}
- }
-
- internal struct FileStruct {
- public enum FileStructType {
- File,
- Directoy,
- Device,
- Network
+
+ protected override void OnLostFocus (EventArgs e)
+ {
+ if (focusButton != null && focusButton.ButtonState != PopupButton.PopupButtonState.Down)
+ focusButton.ButtonState = PopupButton.PopupButtonState.Normal;
+ base.OnLostFocus (e);
+ }
+
+ protected override bool IsInputKey (Keys key)
+ {
+ switch (key) {
+ case Keys.Up:
+ case Keys.Down:
+ case Keys.Right:
+ case Keys.Left:
+ case Keys.Enter:
+ return true;
+ }
+ return base.IsInputKey (key);
+ }
+
+ private void Key_Down (object sender, KeyEventArgs e)
+ {
+ bool update_focus = false;
+
+ if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Up) {
+ currentFocusIndex --;
+
+ if (currentFocusIndex < 0)
+ currentFocusIndex = Controls.Count - 1;
+
+ update_focus = true;
+ } else
+ if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Right) {
+ currentFocusIndex++;
+
+ if (currentFocusIndex == Controls.Count)
+ currentFocusIndex = 0;
+
+ update_focus = true;
+ } else
+ if (e.KeyCode == Keys.Enter) {
+ focusButton.ButtonState = PopupButton.PopupButtonState.Down;
+ OnClickButton (focusButton, EventArgs.Empty);
+ }
+
+ if (update_focus) {
+ PopupButton newfocusButton = Controls [currentFocusIndex] as PopupButton;
+ if (focusButton != null && focusButton.ButtonState != PopupButton.PopupButtonState.Down)
+ focusButton.ButtonState = PopupButton.PopupButtonState.Normal;
+ if (newfocusButton.ButtonState != PopupButton.PopupButtonState.Down)
+ newfocusButton.ButtonState = PopupButton.PopupButtonState.Up;
+ focusButton = newfocusButton;
+ }
+
+ e.Handled = true;
}
- public string fullname;
- public FileAttributes attributes;
- public long size;
- public FileStructType type;
+ public event EventHandler DirectoryChanged {
+ add { on_directory_changed += value; }
+ remove { on_directory_changed -= value; }
+ }
}
+ #endregion
- // MWFFileView
- internal class MWFFileView : ListView {
- private ArrayList filterArrayList;
+ #region DirComboBox
+ internal class DirComboBox : ComboBox, IUpdateFolder
+ {
+ #region DirComboBoxItem
+ internal class DirComboBoxItem
+ {
+ private int imageIndex;
+ private string name;
+ private string path;
+ private int xPos;
+ private ImageList imageList;
+
+ public DirComboBoxItem (ImageList imageList, int imageIndex, string name, string path, int xPos)
+ {
+ this.imageList = imageList;
+ this.imageIndex = imageIndex;
+ this.name = name;
+ this.path = path;
+ this.xPos = xPos;
+ }
+
+ public int ImageIndex {
+ get {
+ return imageIndex;
+ }
+ }
+
+ public string Name {
+ get {
+ return name;
+ }
+ }
+
+ public string Path {
+ get {
+ return path;
+ }
+ }
+
+ public int XPos {
+ get {
+ return xPos;
+ }
+ }
+
+ public ImageList ImageList {
+ set {
+ imageList = value;
+ }
+
+ get {
+ return imageList;
+ }
+ }
+ }
+ #endregion
- // store the FileStruct of all files in the current directory
- private Hashtable fileHashtable = new Hashtable();
+ private ImageList imageList = new ImageList();
- private bool showHiddenFiles = false;
+ private string currentPath;
- private EventHandler on_selected_file_changed;
- private EventHandler on_selected_files_changed;
private EventHandler on_directory_changed;
- private EventHandler on_force_dialog_end;
- private EventHandler on_one_directory_up;
- private string fileName;
- private string fullFileName;
- private string selectedFilesString;
+ private Stack folderStack = new Stack();
- private int filterIndex;
+ private static readonly int indent = 6;
- private ToolTip toolTip;
- private int oldItemIndexForToolTip = -1;
+ private DirComboBoxItem recentlyUsedDirComboboxItem;
+ private DirComboBoxItem desktopDirComboboxItem;
+ private DirComboBoxItem personalDirComboboxItem;
+ private DirComboBoxItem myComputerDirComboboxItem;
+ private DirComboBoxItem networkDirComboboxItem;
- private bool internal_key_up = false;
+ private ArrayList myComputerItems = new ArrayList ();
- private MasterMount masterMount = new MasterMount ();
+ private DirComboBoxItem mainParentDirComboBoxItem = null;
+ private DirComboBoxItem real_parent = null;
- public MWFFileView ()
+ private MWFVFS vfs;
+
+ public DirComboBox (MWFVFS vfs)
{
SuspendLayout ();
- toolTip = new ToolTip ();
- toolTip.InitialDelay = 300;
- toolTip.ReshowDelay = 0;
-
- LabelWrap = true;
-
- SmallImageList = MimeIconEngine.SmallIcons;
- LargeImageList = MimeIconEngine.LargeIcons;
-
- View = View.List;
+ DrawMode = DrawMode.OwnerDrawFixed;
- ResumeLayout (false);
+ imageList.ColorDepth = ColorDepth.Depth32Bit;
+ imageList.ImageSize = new Size (16, 16);
+ imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 16));
+ imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 16));
+ imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 16));
+ imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 16));
+ imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 16));
+ imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.NormalFolder, 16));
+ imageList.TransparentColor = Color.Transparent;
+
+ recentlyUsedDirComboboxItem = new DirComboBoxItem (imageList, 0, "Recently used", MWFVFS.RecentlyUsedPrefix, 0);
+ desktopDirComboboxItem = new DirComboBoxItem (imageList, 1, "Desktop", MWFVFS.DesktopPrefix, 0);
+ personalDirComboboxItem = new DirComboBoxItem (imageList, 2, "Personal folder", MWFVFS.PersonalPrefix, indent);
+ myComputerDirComboboxItem = new DirComboBoxItem (imageList, 3, "My Computer", MWFVFS.MyComputerPrefix, indent);
+ networkDirComboboxItem = new DirComboBoxItem (imageList, 4, "My Network", MWFVFS.MyNetworkPrefix, indent);
+
+ ArrayList al = vfs.GetMyComputerContent ();
+
+ foreach (FSEntry fsEntry in al) {
+ myComputerItems.Add (new DirComboBoxItem (MimeIconEngine.LargeIcons, fsEntry.IconIndex, fsEntry.Name, fsEntry.FullName, indent * 2));
+ }
+
+ mainParentDirComboBoxItem = myComputerDirComboboxItem;
+
+ ResumeLayout (false);
+ }
+
+ public string CurrentFolder {
+ set {
+ currentPath = value;
+
+ CreateComboList ();
+ }
+ get {
+ return currentPath;
+ }
+ }
+
+ private void CreateComboList ()
+ {
+ real_parent = null;
+ DirComboBoxItem selection = null;
+
+ if (currentPath == MWFVFS.RecentlyUsedPrefix) {
+ mainParentDirComboBoxItem = recentlyUsedDirComboboxItem;
+ selection = recentlyUsedDirComboboxItem;
+ } else
+ if (currentPath == MWFVFS.DesktopPrefix) {
+ selection = desktopDirComboboxItem;
+ mainParentDirComboBoxItem = desktopDirComboboxItem;
+ } else
+ if (currentPath == MWFVFS.PersonalPrefix) {
+ selection = personalDirComboboxItem;
+ mainParentDirComboBoxItem = personalDirComboboxItem;
+ } else
+ if (currentPath == MWFVFS.MyComputerPrefix) {
+ selection = myComputerDirComboboxItem;
+ mainParentDirComboBoxItem = myComputerDirComboboxItem;
+ } else
+ if (currentPath == MWFVFS.MyNetworkPrefix) {
+ selection = networkDirComboboxItem;
+ mainParentDirComboBoxItem = networkDirComboboxItem;
+ } else {
+ foreach (DirComboBoxItem dci in myComputerItems) {
+ if (dci.Path == currentPath) {
+ mainParentDirComboBoxItem = selection = dci;
+ break;
+ }
+ }
+ }
+
+ BeginUpdate ();
+
+ Items.Clear ();
+
+ Items.Add (recentlyUsedDirComboboxItem);
+ Items.Add (desktopDirComboboxItem);
+ Items.Add (personalDirComboboxItem);
+ Items.Add (myComputerDirComboboxItem);
+ Items.AddRange (myComputerItems);
+ Items.Add (networkDirComboboxItem);
+
+ if (selection == null) {
+ real_parent = CreateFolderStack ();
+ }
+
+ if (real_parent != null) {
+ int local_indent = 0;
+
+ if (real_parent == desktopDirComboboxItem)
+ local_indent = 1;
+ else
+ if (real_parent == personalDirComboboxItem || real_parent == networkDirComboboxItem)
+ local_indent = 2;
+ else
+ local_indent = 3;
+
+ selection = AppendToParent (local_indent, real_parent);
+ }
+
+ EndUpdate ();
+
+ if (selection != null)
+ SelectedItem = selection;
+ }
+
+ private DirComboBoxItem CreateFolderStack ()
+ {
+ folderStack.Clear ();
+
+ DirectoryInfo di = new DirectoryInfo (currentPath);
+
+ folderStack.Push (di);
+
+ while (di.Parent != null) {
+ di = di.Parent;
+
+ if (mainParentDirComboBoxItem != personalDirComboboxItem && di.FullName == ThemeEngine.Current.Places (UIIcon.PlacesDesktop))
+ return desktopDirComboboxItem;
+ else
+ if (mainParentDirComboBoxItem == personalDirComboboxItem) {
+ if (di.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal))
+ return personalDirComboboxItem;
+ } else
+ foreach (DirComboBoxItem dci in myComputerItems) {
+ if (dci.Path == di.FullName) {
+ return dci;
+ }
+ }
+
+
+ folderStack.Push (di);
+ }
+
+ return null;
+ }
+
+ private DirComboBoxItem AppendToParent (int nr_indents, DirComboBoxItem parentDirComboBoxItem)
+ {
+ DirComboBoxItem selection = null;
+
+ int index = Items.IndexOf (parentDirComboBoxItem) + 1;
+
+ int xPos = indent * nr_indents;
+
+ while (folderStack.Count != 0) {
+ DirectoryInfo dii = folderStack.Pop () as DirectoryInfo;
+
+ DirComboBoxItem dci = new DirComboBoxItem (imageList, 5, dii.Name, dii.FullName, xPos);
+
+ Items.Insert (index, dci);
+ index++;
+ selection = dci;
+ xPos += indent;
+ }
+
+ return selection;
+ }
+
+ protected override void OnDrawItem (DrawItemEventArgs e)
+ {
+ if (e.Index == -1)
+ return;
+
+ DirComboBoxItem dcbi = Items [e.Index] as DirComboBoxItem;
+
+ Bitmap bmp = new Bitmap (e.Bounds.Width, e.Bounds.Height, e.Graphics);
+ Graphics gr = Graphics.FromImage (bmp);
+
+ Color backColor = e.BackColor;
+ Color foreColor = e.ForeColor;
+
+ int xPos = dcbi.XPos;
+
+ if ((e.State & DrawItemState.ComboBoxEdit) != 0)
+ xPos = 0;
+
+ 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.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)));
+
+ e.Graphics.DrawImage (bmp, e.Bounds.X, e.Bounds.Y);
+ gr.Dispose ();
+ bmp.Dispose ();
+ }
+
+ protected override void OnSelectedIndexChanged (EventArgs e)
+ {
+ if (Items.Count > 0) {
+ DirComboBoxItem dcbi = Items [SelectedIndex] as DirComboBoxItem;
+
+ currentPath = dcbi.Path;
+ }
+ }
+
+ protected override void OnSelectionChangeCommitted (EventArgs e)
+ {
+ if (on_directory_changed != null)
+ on_directory_changed (this, EventArgs.Empty);
+ }
+
+ public event EventHandler DirectoryChanged {
+ add { on_directory_changed += value; }
+ remove { on_directory_changed -= value; }
+ }
+ }
+ #endregion
+
+ #region FilterStruct
+ internal struct FilterStruct
+ {
+ public string filterName;
+ public StringCollection filters;
+
+ public FilterStruct (string filterName, string filter)
+ {
+ this.filterName = filterName;
+
+ filters = new StringCollection ();
+
+ SplitFilters (filter);
+ }
+
+ private void SplitFilters (string filter)
+ {
+ string[] split = filter.Split (new char [] {';'});
+ foreach (string s in split) {
+ filters.Add (s.Trim ());
+ }
+ }
+ }
+ #endregion
+
+ #region FileFilter
+ internal class FileFilter
+ {
+ private ArrayList filterArrayList = new ArrayList();
+
+ private string filter;
+
+ public FileFilter ()
+ {}
+
+ 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;
+ }
+
+ get {
+ return filterArrayList;
+ }
+ }
+
+ public string Filter {
+ set {
+ filter = value;
+
+ SplitFilter ();
+ }
+
+ get {
+ return filter;
+ }
+ }
+
+ private void SplitFilter ()
+ {
+ filterArrayList.Clear ();
+
+ if (filter.Length == 0)
+ return;
+
+ string[] filters = filter.Split (new char [] {'|'});
+
+ for (int i = 0; i < filters.Length; i += 2) {
+ FilterStruct filterStruct = new FilterStruct (filters [i], filters [i + 1]);
+
+ filterArrayList.Add (filterStruct);
+ }
+ }
+ }
+ #endregion
+
+ #region MWFFileView
+ // MWFFileView
+ internal class MWFFileView : ListView
+ {
+ private ArrayList filterArrayList;
+
+ private bool showHiddenFiles = false;
+
+ private EventHandler on_selected_file_changed;
+ private EventHandler on_selected_files_changed;
+ private EventHandler on_directory_changed;
+ private EventHandler on_force_dialog_end;
+
+ private string selectedFilesString;
+
+ private int filterIndex = 1;
+
+ private ToolTip toolTip;
+ private int oldItemIndexForToolTip = -1;
+
+ private ContextMenu contextMenu;
+
+ private MenuItem menuItemView;
+ private MenuItem menuItemNew;
+
+ private MenuItem smallIconMenutItem;
+ private MenuItem tilesMenutItem;
+ private MenuItem largeIconMenutItem;
+ private MenuItem listMenutItem;
+ private MenuItem detailsMenutItem;
+
+ private MenuItem newFolderMenuItem;
+ private MenuItem showHiddenFilesMenuItem;
+
+ private int previousCheckedMenuItemIndex;
+
+ private ArrayList viewMenuItemClones = new ArrayList ();
+
+ private FSEntry currentFSEntry = null;
+
+ private string currentFolder;
+ private string currentRealFolder;
+ private FSEntry currentFolderFSEntry;
+
+ // store DirectoryInfo for a back button for example
+ private Stack directoryStack = new Stack();
+
+ // list of controls(components to enable or disable depending on current directoryStack.Count
+ private ArrayList dirStackControlsOrComponents = new ArrayList ();
+
+ private ToolBarButton folderUpToolBarButton;
+
+ private ArrayList registered_senders = new ArrayList ();
+
+ private bool should_push = true;
+
+ private MWFVFS vfs;
+
+ private View old_view;
+
+ 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 ();
+
+ contextMenu = new ContextMenu ();
+
+ toolTip = new ToolTip ();
+ toolTip.InitialDelay = 300;
+ toolTip.ReshowDelay = 0;
+
+ // contextMenu
+
+ // View menu item
+ menuItemView = new MenuItem ("View");
+
+ smallIconMenutItem = new MenuItem ("Small Icon", new EventHandler (OnClickViewMenuSubItem));
+ smallIconMenutItem.RadioCheck = true;
+ menuItemView.MenuItems.Add (smallIconMenutItem);
+
+ tilesMenutItem = new MenuItem ("Tiles", new EventHandler (OnClickViewMenuSubItem));
+ tilesMenutItem.RadioCheck = true;
+ menuItemView.MenuItems.Add (tilesMenutItem);
+
+ largeIconMenutItem = new MenuItem ("Large Icon", new EventHandler (OnClickViewMenuSubItem));
+ largeIconMenutItem.RadioCheck = true;
+ menuItemView.MenuItems.Add (largeIconMenutItem);
+
+ listMenutItem = new MenuItem ("List", new EventHandler (OnClickViewMenuSubItem));
+ listMenutItem.RadioCheck = true;
+ listMenutItem.Checked = true;
+ menuItemView.MenuItems.Add (listMenutItem);
+ previousCheckedMenuItemIndex = listMenutItem.Index;
+
+ detailsMenutItem = new MenuItem ("Details", new EventHandler (OnClickViewMenuSubItem));
+ detailsMenutItem.RadioCheck = true;
+ menuItemView.MenuItems.Add (detailsMenutItem);
+
+ contextMenu.MenuItems.Add (menuItemView);
+
+ contextMenu.MenuItems.Add (new MenuItem ("-"));
+
+ // New menu item
+ menuItemNew = new MenuItem ("New");
+
+ newFolderMenuItem = new MenuItem ("New Folder", new EventHandler (OnClickNewFolderMenuItem));
+ menuItemNew.MenuItems.Add (newFolderMenuItem);
+
+ contextMenu.MenuItems.Add (menuItemNew);
+
+ contextMenu.MenuItems.Add (new MenuItem ("-"));
+
+ // Show hidden files menu item
+ showHiddenFilesMenuItem = new MenuItem ("Show hidden files", new EventHandler (OnClickContextMenu));
+ showHiddenFilesMenuItem.Checked = showHiddenFiles;
+ contextMenu.MenuItems.Add (showHiddenFilesMenuItem);
+
+ LabelWrap = true;
+
+ SmallImageList = MimeIconEngine.SmallIcons;
+ LargeImageList = MimeIconEngine.LargeIcons;
+
+ View = old_view = View.List;
+ LabelEdit = true;
+
+ ContextMenu = contextMenu;
+
+ ResumeLayout (false);
+
+ KeyDown += new KeyEventHandler (MWF_KeyDown);
+ }
+
+ public string CurrentFolder {
+ get {
+ return currentFolder;
+ }
+ set {
+ currentFolder = value;
+ }
+ }
+
+ public string CurrentRealFolder {
+ get {
+ return currentRealFolder;
+ }
+ }
+
+ public FSEntry CurrentFSEntry {
+ get {
+ return currentFSEntry;
+ }
+ }
+
+ public MenuItem[] ViewMenuItems {
+ get {
+ MenuItem[] menuItemClones = new MenuItem [] {
+ smallIconMenutItem.CloneMenu (),
+ tilesMenutItem.CloneMenu (),
+ largeIconMenutItem.CloneMenu (),
+ listMenutItem.CloneMenu (),
+ detailsMenutItem.CloneMenu ()
+ };
+
+ viewMenuItemClones.Add (menuItemClones);
+
+ return menuItemClones;
+ }
+ }
+
+ public ArrayList FilterArrayList {
+ set {
+ filterArrayList = value;
+ }
+
+ get {
+ return filterArrayList;
+ }
+ }
+
+ public bool ShowHiddenFiles {
+ set {
+ showHiddenFiles = value;
+ }
+
+ get {
+ return showHiddenFiles;
+ }
+ }
+
+ public int FilterIndex {
+ set {
+ filterIndex = value;
+ if (Visible)
+ UpdateFileView ();
+ }
+
+ get {
+ return filterIndex;
+ }
+ }
+
+ public string SelectedFilesString {
+ set {
+ selectedFilesString = value;
+ }
+
+ get {
+ return selectedFilesString;
+ }
+ }
+
+ public void PushDir ()
+ {
+ if (currentFolder != null)
+ directoryStack.Push (currentFolder);
+
+ EnableOrDisableDirstackObjects ();
+ }
+
+ public void PopDir ()
+ {
+ if (directoryStack.Count == 0)
+ return;
+
+ string new_folder = directoryStack.Pop () as string;
+
+ EnableOrDisableDirstackObjects ();
+
+ should_push = false;
+
+ ChangeDirectory (null, new_folder);
+ }
+
+ public void RegisterSender (IUpdateFolder iud)
+ {
+ registered_senders.Add (iud);
+ }
+
+ public void CreateNewFolder ()
+ {
+ if (currentFolder == MWFVFS.MyComputerPrefix ||
+ currentFolder == MWFVFS.RecentlyUsedPrefix)
+ return;
+
+ FSEntry fsEntry = new FSEntry ();
+ fsEntry.Attributes = FileAttributes.Directory;
+ fsEntry.FileType = FSEntry.FSEntryType.Directory;
+ fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
+ fsEntry.LastAccessTime = DateTime.Now;
+
+ // FIXME: when ListView.LabelEdit is available use it
+// listViewItem.BeginEdit();
+
+ TextEntryDialog ted = new TextEntryDialog ();
+ ted.IconPictureBoxImage = MimeIconEngine.LargeIcons.Images.GetImage (fsEntry.IconIndex);
+
+ string folder = String.Empty;
+
+ 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)) {
+ fsEntry.FullName = new_folder;
+ fsEntry.Name = ted.FileName;
+
+ FileViewListViewItem listViewItem = new FileViewListViewItem (fsEntry);
+
+ BeginUpdate ();
+ Items.Add (listViewItem);
+ EndUpdate ();
+
+ listViewItem.EnsureVisible ();
+ }
+ }
+ }
+
+ public void SetSelectedIndexTo (string fname)
+ {
+ foreach (FileViewListViewItem item in Items) {
+ if (item.Text == fname) {
+ BeginUpdate ();
+ SelectedItems.Clear ();
+ item.Selected = true;
+ EndUpdate ();
+ break;
+ }
+ }
+ }
+
+ public void OneDirUp ()
+ {
+ string parent_folder = vfs.GetParent ();
+ if (parent_folder != null)
+ ChangeDirectory (null, parent_folder);
+ }
+
+ public void ChangeDirectory (object sender, string folder)
+ {
+ if (folder == MWFVFS.DesktopPrefix || folder == MWFVFS.RecentlyUsedPrefix)
+ folderUpToolBarButton.Enabled = false;
+ else
+ folderUpToolBarButton.Enabled = true;
+
+ foreach (IUpdateFolder iuf in registered_senders) {
+ iuf.CurrentFolder = folder;
+ }
+
+ if (should_push)
+ PushDir ();
+ else
+ should_push = true;
+
+ currentFolderFSEntry = vfs.ChangeDirectory (folder);
+
+ currentFolder = folder;
+
+ if (currentFolder.IndexOf ("://") != -1)
+ currentRealFolder = currentFolderFSEntry.RealName;
+ else
+ currentRealFolder = currentFolder;
+
+ BeginUpdate ();
+
+ Items.Clear ();
+ SelectedItems.Clear ();
+
+ if (folder == MWFVFS.RecentlyUsedPrefix) {
+ old_view = View;
+ View = View.Details;
+ old_menuitem_index = previousCheckedMenuItemIndex;
+ UpdateMenuItems (detailsMenutItem);
+ do_update_view = true;
+ } else
+ if (View != old_view && do_update_view) {
+ UpdateMenuItems (menuItemView.MenuItems [old_menuitem_index]);
+ View = old_view;
+ do_update_view = false;
+ }
+ EndUpdate ();
+
+ try {
+ UpdateFileView ();
+ } catch (Exception e) {
+ if (should_push)
+ PopDir ();
+ MessageBox.Show (e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ public void UpdateFileView ()
+ {
+ if (filterArrayList != null && filterArrayList.Count != 0) {
+ FilterStruct fs = (FilterStruct)filterArrayList [filterIndex - 1];
+
+ vfs.GetFolderContent (fs.filters);
+ } else
+ vfs.GetFolderContent ();
+ }
+
+ public void RealFileViewUpdate (ArrayList directoriesArrayList, ArrayList fileArrayList)
+ {
+ BeginUpdate ();
+
+ Items.Clear ();
+ SelectedItems.Clear ();
+
+ foreach (FSEntry directoryFSEntry in directoriesArrayList) {
+ if (!ShowHiddenFiles)
+ if (directoryFSEntry.Name.StartsWith (".") || directoryFSEntry.Attributes == FileAttributes.Hidden)
+ continue;
+
+ FileViewListViewItem listViewItem = new FileViewListViewItem (directoryFSEntry);
+
+ Items.Add (listViewItem);
+ }
+
+ StringCollection collection = new StringCollection ();
+
+ foreach (FSEntry fsEntry in fileArrayList) {
+
+ // remove duplicates. that can happen when you read recently used files for example
+ if (collection.Contains (fsEntry.Name)) {
+
+ string fileName = fsEntry.Name;
+
+ if (collection.Contains (fileName)) {
+ int i = 1;
+
+ while (collection.Contains (fileName + "(" + i + ")")) {
+ i++;
+ }
+
+ fileName = fileName + "(" + i + ")";
+ }
+
+ fsEntry.Name = fileName;
+ }
+
+ collection.Add (fsEntry.Name);
+
+ DoOneFSEntry (fsEntry);
+ }
+
+ EndUpdate ();
+ }
+
+ public void AddControlToEnableDisableByDirStack (object control)
+ {
+ dirStackControlsOrComponents.Add (control);
+ }
+
+ public void SetFolderUpToolBarButton (ToolBarButton tb)
+ {
+ folderUpToolBarButton = tb;
+ }
+
+ public void WriteRecentlyUsed (string fullfilename)
+ {
+ vfs.WriteRecentlyUsedFiles (fullfilename);
+ }
+
+ private void EnableOrDisableDirstackObjects ()
+ {
+ foreach (object o in dirStackControlsOrComponents) {
+ if (o is Control) {
+ Control c = o as Control;
+ c.Enabled = (directoryStack.Count > 1);
+ } else
+ if (o is ToolBarButton) {
+ ToolBarButton t = o as ToolBarButton;
+ t.Enabled = (directoryStack.Count > 0);
+ }
+ }
+ }
+
+ private void DoOneFSEntry (FSEntry fsEntry)
+ {
+ if (!ShowHiddenFiles)
+ if (fsEntry.Name.StartsWith (".") || fsEntry.Attributes == FileAttributes.Hidden)
+ return;
+
+ FileViewListViewItem listViewItem = new FileViewListViewItem (fsEntry);
+
+ Items.Add (listViewItem);
+ }
+
+ private void MWF_KeyDown (object sender, KeyEventArgs e)
+ {
+ if (e.KeyCode == Keys.Back) {
+ OneDirUp ();
+ }
+ }
+
+ protected override void OnClick (EventArgs e)
+ {
+ if (!MultiSelect) {
+ if (SelectedItems.Count > 0) {
+ FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
+
+ FSEntry fsEntry = listViewItem.FSEntry;
+
+ if (fsEntry.FileType == FSEntry.FSEntryType.File) {
+ currentFSEntry = fsEntry;
+
+ if (on_selected_file_changed != null)
+ on_selected_file_changed (this, EventArgs.Empty);
+ }
+ }
+ }
+
+ base.OnClick (e);
+ }
+
+ protected override void OnDoubleClick (EventArgs e)
+ {
+ if (SelectedItems.Count > 0) {
+ FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
+
+ FSEntry fsEntry = listViewItem.FSEntry;
+
+ if (fsEntry.Attributes == FileAttributes.Directory) {
+
+ ChangeDirectory (null, fsEntry.FullName);
+
+ if (on_directory_changed != null)
+ on_directory_changed (this, EventArgs.Empty);
+ } else {
+ currentFSEntry = fsEntry;
+
+ if (on_selected_file_changed != null)
+ on_selected_file_changed (this, EventArgs.Empty);
+
+ if (on_force_dialog_end != null)
+ on_force_dialog_end (this, EventArgs.Empty);
+
+ return;
+ }
+ }
+
+ base.OnDoubleClick (e);
+ }
+
+ protected override void OnSelectedIndexChanged (EventArgs e)
+ {
+ if (SelectedItems.Count > 0) {
+ selectedFilesString = String.Empty;
+
+ if (SelectedItems.Count == 1) {
+ FileViewListViewItem listViewItem = SelectedItems [0] as FileViewListViewItem;
+
+ FSEntry fsEntry = listViewItem.FSEntry;
+
+ if (fsEntry.Attributes != FileAttributes.Directory)
+ selectedFilesString = SelectedItems [0].Text;
+ } else {
+ foreach (FileViewListViewItem lvi in SelectedItems) {
+ FSEntry fsEntry = lvi.FSEntry;
+
+ if (fsEntry.Attributes != FileAttributes.Directory)
+ selectedFilesString = selectedFilesString + "\"" + lvi.Text + " ";
+ }
+ }
+
+ if (on_selected_files_changed != null)
+ on_selected_files_changed (this, EventArgs.Empty);
+ }
+
+ base.OnSelectedIndexChanged (e);
+ }
+
+ protected override void OnMouseMove (MouseEventArgs e)
+ {
+ FileViewListViewItem item = GetItemAt (e.X, e.Y) as FileViewListViewItem;
+
+ if (item != null) {
+ int currentItemIndex = item.Index;
+
+ if (currentItemIndex != oldItemIndexForToolTip) {
+ oldItemIndexForToolTip = currentItemIndex;
+
+ if (toolTip != null && toolTip.Active)
+ toolTip.Active = false;
+
+ FSEntry fsEntry = item.FSEntry;
+
+ string output = String.Empty;
+
+ if (fsEntry.FileType == FSEntry.FSEntryType.Directory)
+ output = "Directory: " + fsEntry.FullName;
+ else if (fsEntry.FileType == FSEntry.FSEntryType.Device)
+ output = "Device: "+ fsEntry.FullName;
+ else if (fsEntry.FileType == FSEntry.FSEntryType.Network)
+ output = "Network: " + fsEntry.FullName;
+ else
+ output = "File: " + fsEntry.FullName;
+
+ toolTip.SetToolTip (this, output);
+
+ toolTip.Active = true;
+ }
+ } else
+ toolTip.Active = false;
- KeyUp += new KeyEventHandler (MWF_KeyUp);
+ base.OnMouseMove (e);
}
- public ArrayList FilterArrayList {
- set {
- filterArrayList = value;
- }
+ void OnClickContextMenu (object sender, EventArgs e)
+ {
+ MenuItem senderMenuItem = sender as MenuItem;
- get {
- return filterArrayList;
+ if (senderMenuItem == showHiddenFilesMenuItem) {
+ senderMenuItem.Checked = !senderMenuItem.Checked;
+ showHiddenFiles = senderMenuItem.Checked;
+ UpdateFileView ();
}
}
- public Hashtable FileHashtable {
- get {
- return fileHashtable;
+ void OnClickViewMenuSubItem (object sender, EventArgs e)
+ {
+ MenuItem senderMenuItem = (MenuItem)sender;
+
+ UpdateMenuItems (senderMenuItem);
+
+ // update me
+
+ switch (senderMenuItem.Index) {
+ case 0:
+ View = View.SmallIcon;
+ break;
+ case 1:
+ View = View.LargeIcon;
+ break;
+ case 2:
+ View = View.LargeIcon;
+ break;
+ case 3:
+ View = View.List;
+ break;
+ case 4:
+ View = View.Details;
+ break;
+ default:
+ break;
}
}
- public bool ShowHiddenFiles {
- set {
- showHiddenFiles = value;
- }
+ private void UpdateMenuItems (MenuItem senderMenuItem)
+ {
+ menuItemView.MenuItems [previousCheckedMenuItemIndex].Checked = false;
+ menuItemView.MenuItems [senderMenuItem.Index].Checked = true;
- get {
- return showHiddenFiles;
+ foreach (MenuItem[] items in viewMenuItemClones) {
+ items [previousCheckedMenuItemIndex].Checked = false;
+ items [senderMenuItem.Index].Checked = true;
}
+
+ previousCheckedMenuItemIndex = senderMenuItem.Index;
}
- public string FileName {
- get {
- return fileName;
- }
+ void OnClickNewFolderMenuItem (object sender, EventArgs e)
+ {
+ CreateNewFolder ();
}
- public string FullFileName {
- get {
- return fullFileName;
+ public event EventHandler SelectedFileChanged {
+ add { on_selected_file_changed += value; }
+ remove { on_selected_file_changed -= value; }
+ }
+
+ public event EventHandler SelectedFilesChanged {
+ add { on_selected_files_changed += value; }
+ remove { on_selected_files_changed -= value; }
+ }
+
+ public event EventHandler DirectoryChanged {
+ add { on_directory_changed += value; }
+ remove { on_directory_changed -= value; }
+ }
+
+ public event EventHandler ForceDialogEnd {
+ add { on_force_dialog_end += value; }
+ remove { on_force_dialog_end -= value; }
+ }
+ }
+ #endregion
+
+ #region FileListViewItem
+ internal class FileViewListViewItem : ListViewItem
+ {
+ private FSEntry fsEntry;
+
+ public FileViewListViewItem (FSEntry fsEntry)
+ {
+ this.fsEntry = fsEntry;
+
+ ImageIndex = fsEntry.IconIndex;
+
+ Text = fsEntry.Name;
+
+ switch (fsEntry.FileType) {
+ case FSEntry.FSEntryType.Directory:
+ SubItems.Add (String.Empty);
+ SubItems.Add ("Directory");
+ SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
+ break;
+ case FSEntry.FSEntryType.File:
+ long fileLen = 1;
+ try {
+ if (fsEntry.FileSize > 1024)
+ fileLen = fsEntry.FileSize / 1024;
+ } catch (Exception) {
+ fileLen = 1;
+ }
+
+ SubItems.Add (fileLen.ToString () + " KB");
+ SubItems.Add ("File");
+ SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
+ break;
+ case FSEntry.FSEntryType.Device:
+ SubItems.Add (String.Empty);
+ SubItems.Add ("Device");
+ SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
+ break;
+ case FSEntry.FSEntryType.RemovableDevice:
+ SubItems.Add (String.Empty);
+ SubItems.Add ("RemovableDevice");
+ SubItems.Add (fsEntry.LastAccessTime.ToShortDateString () + " " + fsEntry.LastAccessTime.ToShortTimeString ());
+ break;
+ default:
+ break;
}
}
- public int FilterIndex {
+ public FSEntry FSEntry {
set {
- filterIndex = value;
+ fsEntry = value;
}
get {
- return filterIndex;
+ return fsEntry;
}
}
+ }
+ #endregion
+
+ #region IUpdateFolder
+ internal interface IUpdateFolder
+ {
+ string CurrentFolder {get; set;}
+ }
+ #endregion
+
+ #region TextEntryDialog
+ // FIXME: When ListView.LabelEdit is implemented remove me
+ internal class TextEntryDialog : Form
+ {
+ private Label label1;
+ private Button okButton;
+ private TextBox newNameTextBox;
+ private PictureBox iconPictureBox;
+ private Button cancelButton;
+ private GroupBox groupBox1;
- public string SelectedFilesString {
+ public TextEntryDialog ()
+ {
+ groupBox1 = new GroupBox ();
+ cancelButton = new Button ();
+ iconPictureBox = new PictureBox ();
+ newNameTextBox = new TextBox ();
+ okButton = new Button ();
+ label1 = new Label ();
+ groupBox1.SuspendLayout ();
+ SuspendLayout ();
+
+ // groupBox1
+ groupBox1.Controls.Add (newNameTextBox);
+ groupBox1.Controls.Add (label1);
+ groupBox1.Controls.Add (iconPictureBox);
+ groupBox1.Location = new Point (8, 8);
+ groupBox1.Size = new Size (232, 160);
+ groupBox1.TabIndex = 5;
+ groupBox1.TabStop = false;
+ groupBox1.Text = "New Name";
+
+ // cancelButton
+ cancelButton.DialogResult = DialogResult.Cancel;
+ cancelButton.Location = new Point (168, 176);
+ cancelButton.TabIndex = 4;
+ cancelButton.Text = "Cancel";
+
+ // iconPictureBox
+ iconPictureBox.BorderStyle = BorderStyle.Fixed3D;
+ iconPictureBox.Location = new Point (86, 24);
+ iconPictureBox.Size = new Size (60, 60);
+ iconPictureBox.TabIndex = 3;
+ iconPictureBox.TabStop = false;
+ iconPictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
+
+ // newNameTextBox
+ newNameTextBox.Location = new Point (16, 128);
+ newNameTextBox.Size = new Size (200, 20);
+ newNameTextBox.TabIndex = 5;
+ newNameTextBox.Text = String.Empty;
+
+ // okButton
+ okButton.DialogResult = DialogResult.OK;
+ okButton.Location = new Point (80, 176);
+ okButton.TabIndex = 3;
+ okButton.Text = "OK";
+
+ // label1
+ label1.Location = new Point (16, 96);
+ label1.Size = new Size (200, 23);
+ label1.TabIndex = 4;
+ label1.Text = "Enter Name:";
+ label1.TextAlign = ContentAlignment.MiddleCenter;
+
+ // MainForm
+ AcceptButton = okButton;
+ AutoScaleBaseSize = new Size (5, 13);
+ CancelButton = cancelButton;
+ ClientSize = new Size (248, 205);
+ Controls.Add (groupBox1);
+ Controls.Add (cancelButton);
+ Controls.Add (okButton);
+ FormBorderStyle = FormBorderStyle.FixedDialog;
+ Text = "New Folder or File";
+ groupBox1.ResumeLayout (false);
+ ResumeLayout (false);
+
+ newNameTextBox.Select ();
+ }
+
+ public Image IconPictureBoxImage {
set {
- selectedFilesString = value;
+ iconPictureBox.Image = value;
}
-
+ }
+
+ public string FileName {
get {
- return selectedFilesString;
+ return newNameTextBox.Text;
+ }
+ set {
+ newNameTextBox.Text = value;
}
}
+ }
+ #endregion
+
+ #region MWFVFS
+ internal class MWFVFS
+ {
+ private FileSystem fileSystem;
- public void SetSelectedIndexTo (string fname)
+ private int platform = (int) Environment.OSVersion.Platform;
+
+ public static readonly string DesktopPrefix = "Desktop://";
+ public static readonly string PersonalPrefix = "Personal://";
+ public static readonly string MyComputerPrefix = "MyComputer://";
+ public static readonly string RecentlyUsedPrefix = "RecentlyUsed://";
+ public static readonly string MyNetworkPrefix = "MyNetwork://";
+ public static readonly string MyComputerPersonalPrefix = "MyComputerPersonal://";
+
+ 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 ()
{
- foreach (ListViewItem item in Items) {
- if (item.Text == fname) {
- BeginUpdate ();
- SelectedItems.Clear ();
- item.Selected = true;
- EndUpdate ();
- break;
- }
+ if ((platform == 4) || (platform == 128)) {
+ fileSystem = new UnixFileSystem ();
+ } else {
+ fileSystem = new WinFileSystem ();
}
}
- private ArrayList GetFileInfoArrayList (DirectoryInfo directoryInfo)
+ public FSEntry ChangeDirectory (string folder)
{
- ArrayList arrayList = new ArrayList ();
-
- if (filterArrayList != null && filterArrayList.Count != 0) {
- FilterStruct fs = (FilterStruct)filterArrayList [filterIndex - 1];
-
- foreach (string s in fs.filters)
- arrayList.AddRange (directoryInfo.GetFiles (s));
- } else
- arrayList.AddRange (directoryInfo.GetFiles ());
-
- return arrayList;
+ return fileSystem.ChangeDirectory (folder);
}
- private ArrayList GetFileInfoArrayListByArrayList (ArrayList al)
+ public void GetFolderContent ()
{
- ArrayList arrayList = new ArrayList ();
-
- foreach (string path in al) {
- if (File.Exists (path)) {
- FileInfo fi = new FileInfo (path);
- arrayList.Add (fi);
- }
- }
-
- return arrayList;
+ GetFolderContent (null);
}
- public void UpdateFileView (object directoryInfo_or_string)
+ public void GetFolderContent (StringCollection filters)
{
- if (directoryInfo_or_string is DirectoryInfo)
- UpdateFileViewByDirectoryInfo (directoryInfo_or_string as DirectoryInfo);
- else
- UpdateFileViewByString (directoryInfo_or_string as string);
-
- if (Items.Count > 0 && !internal_key_up) {
- ListViewItem item = Items [0];
- item.Selected = true;
- } else
- internal_key_up = false;
+ 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();
}
- private void UpdateFileViewByDirectoryInfo (DirectoryInfo inputDirectoryInfo)
+ internal class WorkerThread
{
- DirectoryInfo directoryInfo = inputDirectoryInfo;
-
- DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories ();
-
- ArrayList fileInfoArrayList = GetFileInfoArrayList (directoryInfo);
-
- fileHashtable.Clear ();
-
- BeginUpdate ();
-
- Items.Clear ();
- SelectedItems.Clear ();
+ 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;
+ }
- foreach (DirectoryInfo directoryInfoi in directoryInfoArray) {
- if (!ShowHiddenFiles)
- if (directoryInfoi.Name.StartsWith (".") || directoryInfoi.Attributes == FileAttributes.Hidden)
- continue;
-
- FileStruct fileStruct = new FileStruct ();
- fileStruct.type = FileStruct.FileStructType.Directoy;
-
- fileStruct.fullname = directoryInfoi.FullName;
-
- ListViewItem listViewItem = new ListViewItem (directoryInfoi.Name);
-
- int index = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
-
- listViewItem.ImageIndex = index;
-
- listViewItem.SubItems.Add ("");
- listViewItem.SubItems.Add ("Directory");
- listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
+ public void GetFolderContentThread()
+ {
+ ArrayList folders;
+ ArrayList files;
- fileStruct.attributes = FileAttributes.Directory;
+ fileSystem.GetFolderContent (the_filters, out folders, out files);
- fileHashtable.Add (directoryInfoi.Name, fileStruct);
+ if (stopped)
+ return;
- Items.Add (listViewItem);
+ if (updateDelegate != null) {
+ lock (this) {
+ object[] objectArray = new object[2];
+
+ objectArray[0] = folders;
+ objectArray[1] = files;
+
+ calling_control.BeginInvoke (updateDelegate, objectArray);
+ }
+ }
}
- foreach (FileInfo fileInfo in fileInfoArrayList) {
- DoOneFileInfo (fileInfo);
+ public void Stop ()
+ {
+ lock (lockobject) {
+ stopped = true;
+ }
+ }
+ }
+
+ public ArrayList GetFoldersOnly ()
+ {
+ return fileSystem.GetFoldersOnly ();
+ }
+
+ public void WriteRecentlyUsedFiles (string filename)
+ {
+ fileSystem.WriteRecentlyUsedFiles (filename);
+ }
+
+ public ArrayList GetRecentlyUsedFiles ()
+ {
+ return fileSystem.GetRecentlyUsedFiles ();
+ }
+
+ public ArrayList GetMyComputerContent ()
+ {
+ return fileSystem.GetMyComputerContent ();
+ }
+
+ public ArrayList GetMyNetworkContent ()
+ {
+ return fileSystem.GetMyNetworkContent ();
+ }
+
+ public bool CreateFolder (string new_folder)
+ {
+ try {
+ if (Directory.Exists (new_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 e) {
+ MessageBox.Show (e.Message, new_folder, MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
}
- EndUpdate ();
+ return true;
}
- private void UpdateFileViewByString (string kind)
+ public string GetParent ()
{
- if (kind == FileDialog.recently_string) {
- ArrayList fileInfoArrayList = GetFileInfoArrayListByArrayList (GetFreedesktopSpecRecentlyUsed ());
-
- fileHashtable.Clear ();
-
- BeginUpdate ();
-
- Items.Clear ();
- SelectedItems.Clear ();
-
- foreach (FileInfo fileInfo in fileInfoArrayList) {
- DoOneFileInfo (fileInfo);
- }
-
- EndUpdate ();
-
- } else if (kind == FileDialog.mycomputer_string) {
-
- if (masterMount.ProcMountAvailable) {
- masterMount.GetMounts ();
-
- fileHashtable.Clear ();
-
- BeginUpdate ();
-
- Items.Clear ();
- SelectedItems.Clear ();
-
- foreach (MasterMount.Mount mount in masterMount.Block_devices) {
- FileStruct fileStruct = new FileStruct ();
- fileStruct.type = FileStruct.FileStructType.Device;
-
- fileStruct.fullname = mount.mount_point;
-
- string item_name = "HDD (" + mount.fsType + ", " + mount.device_short + ")";
- ListViewItem listViewItem = new ListViewItem (item_name);
-
- int index = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
-
- listViewItem.ImageIndex = index;
-
- listViewItem.SubItems.Add ("");
- listViewItem.SubItems.Add ("Harddisk");
-// listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
-
- fileStruct.attributes = FileAttributes.Directory;
-
- fileHashtable.Add (item_name, fileStruct);
-
- Items.Add (listViewItem);
- }
-
- foreach (MasterMount.Mount mount in masterMount.Removable_devices) {
- FileStruct fileStruct = new FileStruct ();
- fileStruct.type = FileStruct.FileStructType.Device;
-
- fileStruct.fullname = mount.mount_point;
-
- bool is_dvd_cdrom = mount.fsType == MasterMount.FsTypes.usbfs ? false : true;
- string type_name = is_dvd_cdrom ? "DVD/CD-Rom" : "USB";
- string mime_type = is_dvd_cdrom ? "cdrom/cdrom" : "removable/removable";
-
- string item_name = type_name + " (" + mount.device_short + ")";
-
- ListViewItem listViewItem = new ListViewItem (item_name);
-
- int index = MimeIconEngine.GetIconIndexForMimeType (mime_type);
-
- listViewItem.ImageIndex = index;
-
- listViewItem.SubItems.Add ("");
- listViewItem.SubItems.Add (type_name);
-// listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
-
- fileStruct.attributes = FileAttributes.Directory;
-
- fileHashtable.Add (item_name, fileStruct);
-
- Items.Add (listViewItem);
- }
-
- ListViewItem listViewItem2 = new ListViewItem ("Desktop");
-
- int index2 = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
-
- FileStruct fileStruct2 = new FileStruct ();
- fileStruct2.type = FileStruct.FileStructType.Directoy;
-
- fileStruct2.fullname = ThemeEngine.Current.Places (UIIcon.PlacesDesktop);
-
- listViewItem2.ImageIndex = index2;
-
- listViewItem2.SubItems.Add ("");
- listViewItem2.SubItems.Add ("Desktop");
-// listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
-
- fileStruct2.attributes = FileAttributes.Directory;
-
- fileHashtable.Add ("Desktop", fileStruct2);
-
- Items.Add (listViewItem2);
-
-
- listViewItem2 = new ListViewItem ("Personal");
-
- index2 = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
-
- fileStruct2 = new FileStruct ();
- fileStruct2.type = FileStruct.FileStructType.Directoy;
-
- fileStruct2.fullname = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
-
- listViewItem2.ImageIndex = index2;
-
- listViewItem2.SubItems.Add ("");
- listViewItem2.SubItems.Add ("Personal");
-// listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
-
- fileStruct2.attributes = FileAttributes.Directory;
-
- fileHashtable.Add ("Personal", fileStruct2);
-
- Items.Add (listViewItem2);
-
- AddNetwork ();
-
- EndUpdate ();
- }
+ return fileSystem.GetParent ();
+ }
+
+ public void RegisterUpdateDelegate(UpdateDelegate updateDelegate, Control control)
+ {
+ this.updateDelegate = updateDelegate;
+ calling_control = control;
+ }
+ }
+ #endregion
+
+ #region FileSystem
+ internal abstract class FileSystem
+ {
+ protected string currentTopFolder = String.Empty;
+ protected FSEntry currentFolderFSEntry = null;
+ protected FSEntry currentTopFolderFSEntry = null;
+ private FileInfoComparer fileInfoComparer = new FileInfoComparer ();
+
+ public FSEntry ChangeDirectory (string folder)
+ {
+ if (folder == MWFVFS.DesktopPrefix) {
+ currentTopFolder = MWFVFS.DesktopPrefix;
+ currentTopFolderFSEntry = currentFolderFSEntry = GetDesktopFSEntry ();
+ } else
+ if (folder == MWFVFS.PersonalPrefix) {
+ currentTopFolder = MWFVFS.PersonalPrefix;
+ currentTopFolderFSEntry = currentFolderFSEntry = GetPersonalFSEntry ();
+ } else
+ if (folder == MWFVFS.MyComputerPersonalPrefix) {
+ currentTopFolder = MWFVFS.MyComputerPersonalPrefix;
+ currentTopFolderFSEntry = currentFolderFSEntry = GetMyComputerPersonalFSEntry ();
+ } else
+ if (folder == MWFVFS.RecentlyUsedPrefix) {
+ currentTopFolder = MWFVFS.RecentlyUsedPrefix;
+ currentTopFolderFSEntry = currentFolderFSEntry = GetRecentlyUsedFSEntry ();
+ } else
+ if (folder == MWFVFS.MyComputerPrefix) {
+ currentTopFolder = MWFVFS.MyComputerPrefix;
+ currentTopFolderFSEntry = currentFolderFSEntry = GetMyComputerFSEntry ();
+ } else
+ if (folder == MWFVFS.MyNetworkPrefix) {
+ currentTopFolder = MWFVFS.MyNetworkPrefix;
+ currentTopFolderFSEntry = currentFolderFSEntry = GetMyNetworkFSEntry ();
+ } else {
+ bool found = false;
- } else if (kind == FileDialog.network_string) {
+ foreach (DictionaryEntry entry in MWFVFS.MyComputerDevicesPrefix) {
+ FSEntry fsEntry = entry.Value as FSEntry;
+ if (folder == fsEntry.FullName) {
+ currentTopFolder = entry.Key as string;
+ currentTopFolderFSEntry = currentFolderFSEntry = fsEntry;
+ found = true;
+ break;
+ }
+ }
- if (masterMount.ProcMountAvailable) {
- masterMount.GetMounts ();
-
- fileHashtable.Clear ();
-
- BeginUpdate ();
-
- Items.Clear ();
- SelectedItems.Clear ();
-
- AddNetwork ();
-
- EndUpdate ();
+ if (!found) {
+ currentFolderFSEntry = GetDirectoryFSEntry (new DirectoryInfo (folder), currentTopFolderFSEntry);
}
}
+
+ return currentFolderFSEntry;
}
- private void AddNetwork ()
+ public string GetParent ()
{
- foreach (MasterMount.Mount mount in masterMount.Network_devices) {
- FileStruct fileStruct = new FileStruct ();
- fileStruct.type = FileStruct.FileStructType.Network;
+ return currentFolderFSEntry.Parent;
+ }
+
+ // directories_out and files_out contain FSEntry objects
+ public void GetFolderContent (StringCollection filters, out ArrayList directories_out, out ArrayList files_out)
+ {
+ directories_out = new ArrayList ();
+ files_out = new ArrayList ();
+
+ if (currentFolderFSEntry.FullName == MWFVFS.DesktopPrefix) {
+ FSEntry personalFSEntry = GetPersonalFSEntry ();
- fileStruct.fullname = mount.mount_point;
+ directories_out.Add (personalFSEntry);
- string item_name = "Network (" + mount.fsType + ", " + mount.device_short + ")";
+ FSEntry myComputerFSEntry = GetMyComputerFSEntry ();
- ListViewItem listViewItem = new ListViewItem (item_name);
+ directories_out.Add (myComputerFSEntry);
- int index = 0;
+ FSEntry myNetworkFSEntry = GetMyNetworkFSEntry ();
- switch (mount.fsType) {
- case MasterMount.FsTypes.nfs:
- index = MimeIconEngine.GetIconIndexForMimeType ("nfs/nfs");
- break;
- case MasterMount.FsTypes.smbfs:
- index = MimeIconEngine.GetIconIndexForMimeType ("smb/smb");
- break;
- case MasterMount.FsTypes.ncpfs:
- index = MimeIconEngine.GetIconIndexForMimeType ("network/network");
- break;
- default:
- break;
- }
+ directories_out.Add (myNetworkFSEntry);
- listViewItem.ImageIndex = index;
+ 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);
- listViewItem.SubItems.Add ("");
- listViewItem.SubItems.Add ("Network");
-// listViewItem.SubItems.Add (directoryInfoi.LastAccessTime.ToShortDateString () + " " + directoryInfoi.LastAccessTime.ToShortTimeString ());
+ } 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 = 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);
+ } else
+ if (currentFolderFSEntry.FullName == MWFVFS.MyNetworkPrefix) {
+ directories_out.AddRange (GetMyNetworkContent ());
+ } else {
+ GetNormalFolderContent (currentFolderFSEntry.FullName, filters, out directories_out, out files_out);
+ }
+ }
+
+ public ArrayList GetFoldersOnly ()
+ {
+ ArrayList directories_out = new ArrayList ();
+
+ if (currentFolderFSEntry.FullName == MWFVFS.DesktopPrefix) {
+ FSEntry personalFSEntry = GetPersonalFSEntry ();
- fileStruct.attributes = FileAttributes.Directory;
+ directories_out.Add (personalFSEntry);
- fileHashtable.Add (item_name, fileStruct);
+ FSEntry myComputerFSEntry = GetMyComputerFSEntry ();
- Items.Add (listViewItem);
+ 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;
}
- private void DoOneFileInfo (FileInfo fileInfo)
+ protected void GetNormalFolderContent (string from_folder, StringCollection filters, out ArrayList directories_out, out ArrayList files_out)
{
- if (!ShowHiddenFiles)
- if (fileInfo.Name.StartsWith (".") || fileInfo.Attributes == FileAttributes.Hidden)
- return;
+ DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
- FileStruct fileStruct = new FileStruct ();
- fileStruct.type = FileStruct.FileStructType.File;
+ directories_out = new ArrayList ();
- fileStruct.fullname = fileInfo.FullName;
+ DirectoryInfo[] dirs = null;
- string fileName = fileInfo.Name;
+ try {
+ dirs = dirinfo.GetDirectories ();
+ } catch (Exception) {}
- if (fileHashtable.ContainsKey (fileName)) {
- int i = 1;
- while (fileHashtable.ContainsKey (fileName + "[" + i + "]")) {
- i++;
+ if (dirs != null)
+ for (int i = 0; i < dirs.Length; i++) {
+ directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
}
- fileName += "[" + i + "]";
- }
- ListViewItem listViewItem = new ListViewItem (fileName);
+ files_out = new ArrayList ();
- listViewItem.ImageIndex = MimeIconEngine.GetIconIndexForFile (fileStruct.fullname);
+ ArrayList files = new ArrayList ();
- long fileLen = 1;
try {
- if (fileInfo.Length > 1024)
- fileLen = fileInfo.Length / 1024;
- } catch ( Exception e ) {
- fileLen = 1;
+ 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++) {
+ FSEntry fs = GetFileFSEntry (files [i] as FileInfo);
+ if (fs != null)
+ files_out.Add (fs);
}
+ }
+
+ protected ArrayList GetNormalFolders (string from_folder)
+ {
+ DirectoryInfo dirinfo = new DirectoryInfo (from_folder);
- fileStruct.size = fileLen;
+ ArrayList directories_out = new ArrayList ();
- listViewItem.SubItems.Add (fileLen.ToString () + " KB");
- listViewItem.SubItems.Add ("File");
- listViewItem.SubItems.Add (fileInfo.LastAccessTime.ToShortDateString () + " " + fileInfo.LastAccessTime.ToShortTimeString ());
+ DirectoryInfo[] dirs = null;
- fileStruct.attributes = FileAttributes.Normal;
+ try {
+ dirs = dirinfo.GetDirectories ();
+ } catch (Exception) {}
- fileHashtable.Add (fileName, fileStruct);
+ if (dirs != null)
+ for (int i = 0; i < dirs.Length; i++) {
+ directories_out.Add (GetDirectoryFSEntry (dirs [i], currentTopFolderFSEntry));
+ }
- Items.Add (listViewItem);
+ return directories_out;
+ }
+
+ protected virtual FSEntry GetDirectoryFSEntry (DirectoryInfo dirinfo, FSEntry topFolderFSEntry)
+ {
+ FSEntry fs = new FSEntry ();
+
+ fs.Attributes = dirinfo.Attributes;
+ fs.FullName = dirinfo.FullName;
+ fs.Name = dirinfo.Name;
+ fs.MainTopNode = topFolderFSEntry;
+ fs.FileType = FSEntry.FSEntryType.Directory;
+ fs.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("inode/directory");
+ fs.LastAccessTime = dirinfo.LastAccessTime;
+
+ return fs;
+ }
+
+ 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.FullName = fileinfo.FullName;
+ fs.Name = fileinfo.Name;
+ fs.FileType = FSEntry.FSEntryType.File;
+ fs.IconIndex = MimeIconEngine.GetIconIndexForFile (fileinfo.FullName);
+ fs.FileSize = fileinfo.Length;
+ fs.LastAccessTime = fileinfo.LastAccessTime;
+
+ 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 ();
+
+ protected abstract FSEntry GetRecentlyUsedFSEntry ();
+
+ protected abstract FSEntry GetPersonalFSEntry ();
+
+ protected abstract FSEntry GetMyComputerPersonalFSEntry ();
+
+ protected abstract FSEntry GetMyComputerFSEntry ();
+
+ protected abstract FSEntry GetMyNetworkFSEntry ();
+
+ public abstract void WriteRecentlyUsedFiles (string fileToAdd);
+
+ public abstract ArrayList GetRecentlyUsedFiles ();
+
+ public abstract ArrayList GetMyComputerContent ();
+
+ public abstract ArrayList GetMyNetworkContent ();
+ }
+ #endregion
+
+ #region UnixFileSystem
+ internal class UnixFileSystem : FileSystem
+ {
+ private MasterMount masterMount = new MasterMount ();
+ private FSEntry desktopFSEntry = null;
+ private FSEntry recentlyusedFSEntry = null;
+ private FSEntry personalFSEntry = null;
+ private FSEntry mycomputerpersonalFSEntry = null;
+ 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.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.Directory;
+ recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
+ recentlyusedFSEntry.LastAccessTime = DateTime.Now;
+
+ personalFSEntry = new FSEntry ();
+
+ personalFSEntry.Attributes = FileAttributes.Directory;
+ personalFSEntry.FullName = MWFVFS.PersonalPrefix;
+ personalFSEntry.Name = "Personal";
+ personalFSEntry.MainTopNode = GetDesktopFSEntry ();
+ personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
+ personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
+ personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
+ personalFSEntry.LastAccessTime = DateTime.Now;
+
+ mycomputerpersonalFSEntry = new FSEntry ();
+
+ mycomputerpersonalFSEntry.Attributes = FileAttributes.Directory;
+ mycomputerpersonalFSEntry.FullName = MWFVFS.MyComputerPersonalPrefix;
+ mycomputerpersonalFSEntry.Name = "Personal";
+ mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
+ mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
+ mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
+ mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
+ mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
+
+ mycomputerFSEntry = new FSEntry ();
+
+ mycomputerFSEntry.Attributes = FileAttributes.Directory;
+ mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
+ mycomputerFSEntry.Name = "My Computer";
+ mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
+ mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
+ mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
+ mycomputerFSEntry.LastAccessTime = DateTime.Now;
+
+ mynetworkFSEntry = new FSEntry ();
+
+ mynetworkFSEntry.Attributes = FileAttributes.Directory;
+ mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
+ mynetworkFSEntry.Name = "My Network";
+ mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
+ mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
+ mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
+ mynetworkFSEntry.LastAccessTime = DateTime.Now;
+ }
+
+ public override void WriteRecentlyUsedFiles (string fileToAdd)
+ {
+ if (File.Exists (recently_used_path) && new FileInfo (recently_used_path).Length > 0) {
+ XmlDocument xml_doc = new XmlDocument ();
+ xml_doc.Load (recently_used_path);
+
+ XmlNode grand_parent_node = xml_doc.SelectSingleNode ("RecentFiles");
+
+ if (grand_parent_node != null) {
+ // create a new element
+ XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
+
+ XmlElement new_child = xml_doc.CreateElement ("URI");
+ UriBuilder ub = new UriBuilder ();
+ ub.Path = fileToAdd;
+ ub.Host = null;
+ ub.Scheme = "file";
+ XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
+ new_child.AppendChild (new_text_child);
+
+ new_recent_item_node.AppendChild (new_child);
+
+ new_child = xml_doc.CreateElement ("Mime-Type");
+ new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (fileToAdd));
+ new_child.AppendChild (new_text_child);
+
+ new_recent_item_node.AppendChild (new_child);
+
+ new_child = xml_doc.CreateElement ("Timestamp");
+ long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
+ new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
+ new_child.AppendChild (new_text_child);
+
+ new_recent_item_node.AppendChild (new_child);
+
+ new_child = xml_doc.CreateElement ("Groups");
+
+ new_recent_item_node.AppendChild (new_child);
+
+ // now search the nodes in grand_parent_node for another instance of the new uri and if found remove it
+ // so that the new node is the first one
+ foreach (XmlNode n in grand_parent_node.ChildNodes) {
+ XmlNode uri_node = n.SelectSingleNode ("URI");
+ if (uri_node != null) {
+ XmlNode uri_node_child = uri_node.FirstChild;
+ if (uri_node_child is XmlText)
+ if (ub.ToString () == ((XmlText)uri_node_child).Data) {
+ grand_parent_node.RemoveChild (n);
+ break;
+ }
+ }
+ }
+
+ // prepend the new recent item to the grand parent node list
+ grand_parent_node.PrependChild (new_recent_item_node);
+
+ // limit the # of RecentItems to 10
+ if (grand_parent_node.ChildNodes.Count > 10) {
+ while (grand_parent_node.ChildNodes.Count > 10)
+ grand_parent_node.RemoveChild (grand_parent_node.LastChild);
+ }
+
+ try {
+ xml_doc.Save (recently_used_path);
+ } catch (Exception) {
+ }
+ }
+ } else {
+ XmlDocument xml_doc = new XmlDocument ();
+ xml_doc.AppendChild (xml_doc.CreateXmlDeclaration ("1.0", String.Empty, String.Empty));
+
+ XmlElement recentFiles_element = xml_doc.CreateElement ("RecentFiles");
+
+ XmlElement new_recent_item_node = xml_doc.CreateElement ("RecentItem");
+
+ XmlElement new_child = xml_doc.CreateElement ("URI");
+ UriBuilder ub = new UriBuilder ();
+ ub.Path = fileToAdd;
+ ub.Host = null;
+ ub.Scheme = "file";
+ XmlText new_text_child = xml_doc.CreateTextNode (ub.ToString ());
+ new_child.AppendChild (new_text_child);
+
+ new_recent_item_node.AppendChild (new_child);
+
+ new_child = xml_doc.CreateElement ("Mime-Type");
+ new_text_child = xml_doc.CreateTextNode (Mime.GetMimeTypeForFile (fileToAdd));
+ new_child.AppendChild (new_text_child);
+
+ new_recent_item_node.AppendChild (new_child);
+
+ new_child = xml_doc.CreateElement ("Timestamp");
+ long seconds = (long)(DateTime.UtcNow - new DateTime (1970, 1, 1)).TotalSeconds;
+ new_text_child = xml_doc.CreateTextNode (seconds.ToString ());
+ new_child.AppendChild (new_text_child);
+
+ new_recent_item_node.AppendChild (new_child);
+
+ new_child = xml_doc.CreateElement ("Groups");
+
+ new_recent_item_node.AppendChild (new_child);
+
+ recentFiles_element.AppendChild (new_recent_item_node);
+
+ xml_doc.AppendChild (recentFiles_element);
+
+ try {
+ xml_doc.Save (recently_used_path);
+ } catch (Exception) {
+ }
+ }
}
- private ArrayList GetFreedesktopSpecRecentlyUsed ()
+ // return an ArrayList with FSEntry objects
+ 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 ();
xtr.Read ();
Uri uri = new Uri (xtr.Value);
if (!files_al.Contains (uri.LocalPath))
- files_al.Add (uri.LocalPath);
+ if (File.Exists (uri.LocalPath)) {
+ FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
+ if (fs != null)
+ files_al.Add (fs);
+ }
}
}
xtr.Close ();
- } catch ( Exception e ) {
+ } catch (Exception) {
}
}
// 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");
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))
- files_al.Add (uri.LocalPath);
+ if (File.Exists (uri.LocalPath)) {
+ FSEntry fs = GetFileFSEntry (new FileInfo (uri.LocalPath));
+ if (fs != null)
+ files_al.Add (fs);
+ }
break;
}
return files_al;
}
- protected override void OnClick (EventArgs e)
+ // return an ArrayList with FSEntry objects
+ public override ArrayList GetMyComputerContent ()
{
- if (!MultiSelect) {
- if (SelectedItems.Count > 0) {
- ListViewItem listViewItem = SelectedItems [0];
+ ArrayList my_computer_content_arraylist = new ArrayList ();
+
+ if (masterMount.ProcMountAvailable) {
+ masterMount.GetMounts ();
+
+ foreach (MasterMount.Mount mount in masterMount.Block_devices) {
+ FSEntry fsEntry = new FSEntry ();
+ fsEntry.FileType = FSEntry.FSEntryType.Device;
- FileStruct fileStruct = (FileStruct)fileHashtable [listViewItem.Text];
+ fsEntry.FullName = mount.mount_point;
- if (fileStruct.type == FileStruct.FileStructType.File) {
- fileName = listViewItem.Text;
- fullFileName = fileStruct.fullname;
-
- if (on_selected_file_changed != null)
- on_selected_file_changed (this, EventArgs.Empty);
- }
+ fsEntry.Name = "HDD (" + mount.fsType + ", " + mount.device_short + ")";
+
+ fsEntry.FsType = mount.fsType;
+ fsEntry.DeviceShort = mount.device_short;
+
+ fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
+
+ fsEntry.Attributes = FileAttributes.Directory;
+
+ fsEntry.MainTopNode = GetMyComputerFSEntry ();
+
+ my_computer_content_arraylist.Add (fsEntry);
+
+ if (!MWFVFS.MyComputerDevicesPrefix.Contains (fsEntry.FullName + "://"))
+ MWFVFS.MyComputerDevicesPrefix.Add (fsEntry.FullName + "://", fsEntry);
}
- }
-
- base.OnClick (e);
- }
-
- protected override void OnDoubleClick (EventArgs e)
- {
- if (SelectedItems.Count > 0) {
- ListViewItem listViewItem = SelectedItems [0];
-
- FileStruct fileStruct = (FileStruct)fileHashtable [listViewItem.Text];
- if (fileStruct.attributes == FileAttributes.Directory) {
- fullFileName = fileStruct.fullname;
+ foreach (MasterMount.Mount mount in masterMount.Removable_devices) {
+ FSEntry fsEntry = new FSEntry ();
+ fsEntry.FileType = FSEntry.FSEntryType.RemovableDevice;
- if (on_directory_changed != null)
- on_directory_changed (this, EventArgs.Empty);
- } else {
- fileName = listViewItem.Text;
- fullFileName = fileStruct.fullname;
+ fsEntry.FullName = mount.mount_point;
- if (on_selected_file_changed != null)
- on_selected_file_changed (this, EventArgs.Empty);
+ bool is_dvd_cdrom = mount.fsType == MasterMount.FsTypes.usbfs ? false : true;
+ string type_name = is_dvd_cdrom ? "DVD/CD-Rom" : "USB";
+ string mime_type = is_dvd_cdrom ? "cdrom/cdrom" : "removable/removable";
- if (on_force_dialog_end != null)
- on_force_dialog_end (this, EventArgs.Empty);
+ fsEntry.Name = type_name +" (" + mount.device_short + ")";
- return;
+ fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType (mime_type);
+
+ fsEntry.FsType = mount.fsType;
+ fsEntry.DeviceShort = mount.device_short;
+
+ fsEntry.Attributes = FileAttributes.Directory;
+
+ fsEntry.MainTopNode = GetMyComputerFSEntry ();
+
+ my_computer_content_arraylist.Add (fsEntry);
+
+ string contain_string = fsEntry.FullName + "://";
+ if (!MWFVFS.MyComputerDevicesPrefix.Contains (contain_string))
+ MWFVFS.MyComputerDevicesPrefix.Add (contain_string, fsEntry);
}
}
- base.OnDoubleClick (e);
+ my_computer_content_arraylist.Add (GetMyComputerPersonalFSEntry ());
+
+ return my_computer_content_arraylist;
}
- protected override void OnSelectedIndexChanged (EventArgs e)
+ public override ArrayList GetMyNetworkContent ()
{
- if (MultiSelect) {
- if (SelectedItems.Count > 0) {
- selectedFilesString = "";
-
- if (SelectedItems.Count == 1) {
- FileStruct fileStruct = (FileStruct)fileHashtable [SelectedItems [0].Text];
-
- if (fileStruct.attributes != FileAttributes.Directory)
- selectedFilesString = SelectedItems [0].Text;
- } else {
- foreach (ListViewItem lvi in SelectedItems) {
- FileStruct fileStruct = (FileStruct)fileHashtable [lvi.Text];
-
- if (fileStruct.attributes != FileAttributes.Directory)
- selectedFilesString += "\"" + lvi.Text + "\" ";
- }
- }
-
- if (on_selected_files_changed != null)
- on_selected_files_changed (this, EventArgs.Empty);
+ ArrayList fsEntries = new ArrayList ();
+
+ foreach (MasterMount.Mount mount in masterMount.Network_devices) {
+ FSEntry fsEntry = new FSEntry ();
+ fsEntry.FileType = FSEntry.FSEntryType.Network;
+
+ fsEntry.FullName = mount.mount_point;
+
+ fsEntry.FsType = mount.fsType;
+ fsEntry.DeviceShort = mount.device_short;
+
+ fsEntry.Name = "Network (" + mount.fsType + ", " + mount.device_short + ")";
+
+ switch (mount.fsType) {
+ case MasterMount.FsTypes.nfs:
+ fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("nfs/nfs");
+ break;
+ case MasterMount.FsTypes.smbfs:
+ fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("smb/smb");
+ break;
+ case MasterMount.FsTypes.ncpfs:
+ fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
+ break;
+ case MasterMount.FsTypes.cifs:
+ fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
+ break;
+ default:
+ break;
}
+
+ fsEntry.Attributes = FileAttributes.Directory;
+
+ fsEntry.MainTopNode = GetMyNetworkFSEntry ();
+
+ fsEntries.Add (fsEntry);
+ }
+ return fsEntries;
+ }
+
+ protected override FSEntry GetDesktopFSEntry ()
+ {
+ return desktopFSEntry;
+ }
+
+ protected override FSEntry GetRecentlyUsedFSEntry ()
+ {
+ return recentlyusedFSEntry;
+ }
+
+ protected override FSEntry GetPersonalFSEntry ()
+ {
+ return personalFSEntry;
+ }
+
+ protected override FSEntry GetMyComputerPersonalFSEntry ()
+ {
+ return mycomputerpersonalFSEntry;
+ }
+
+ protected override FSEntry GetMyComputerFSEntry ()
+ {
+ return mycomputerFSEntry;
+ }
+
+ protected override FSEntry GetMyNetworkFSEntry ()
+ {
+ return mynetworkFSEntry;
+ }
+ }
+ #endregion
+
+ #region WinFileSystem
+ internal class WinFileSystem : FileSystem
+ {
+ private FSEntry desktopFSEntry = null;
+ private FSEntry recentlyusedFSEntry = null;
+ private FSEntry personalFSEntry = null;
+ private FSEntry mycomputerpersonalFSEntry = null;
+ private FSEntry mycomputerFSEntry = null;
+ private FSEntry mynetworkFSEntry = null;
+
+ public WinFileSystem ()
+ {
+ 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.Directory;
+ desktopFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("desktop/desktop");
+ desktopFSEntry.LastAccessTime = DateTime.Now;
+
+ recentlyusedFSEntry = new FSEntry ();
+
+ recentlyusedFSEntry.Attributes = FileAttributes.Directory;
+ recentlyusedFSEntry.FullName = MWFVFS.RecentlyUsedPrefix;
+ recentlyusedFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments);
+ recentlyusedFSEntry.Name = "Recently Used";
+ recentlyusedFSEntry.FileType = FSEntry.FSEntryType.Directory;
+ recentlyusedFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("recently/recently");
+ recentlyusedFSEntry.LastAccessTime = DateTime.Now;
+
+ personalFSEntry = new FSEntry ();
+
+ personalFSEntry.Attributes = FileAttributes.Directory;
+ personalFSEntry.FullName = MWFVFS.PersonalPrefix;
+ personalFSEntry.Name = "Personal";
+ personalFSEntry.MainTopNode = GetDesktopFSEntry ();
+ personalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
+ personalFSEntry.FileType = FSEntry.FSEntryType.Directory;
+ personalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
+ personalFSEntry.LastAccessTime = DateTime.Now;
+
+ mycomputerpersonalFSEntry = new FSEntry ();
+
+ mycomputerpersonalFSEntry.Attributes = FileAttributes.Directory;
+ mycomputerpersonalFSEntry.FullName = MWFVFS.MyComputerPersonalPrefix;
+ mycomputerpersonalFSEntry.Name = "Personal";
+ mycomputerpersonalFSEntry.MainTopNode = GetMyComputerFSEntry ();
+ mycomputerpersonalFSEntry.RealName = ThemeEngine.Current.Places (UIIcon.PlacesPersonal);
+ mycomputerpersonalFSEntry.FileType = FSEntry.FSEntryType.Directory;
+ mycomputerpersonalFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("directory/home");
+ mycomputerpersonalFSEntry.LastAccessTime = DateTime.Now;
+
+ mycomputerFSEntry = new FSEntry ();
+
+ mycomputerFSEntry.Attributes = FileAttributes.Directory;
+ mycomputerFSEntry.FullName = MWFVFS.MyComputerPrefix;
+ mycomputerFSEntry.Name = "My Computer";
+ mycomputerFSEntry.MainTopNode = GetDesktopFSEntry ();
+ mycomputerFSEntry.FileType = FSEntry.FSEntryType.Directory;
+ mycomputerFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("workplace/workplace");
+ mycomputerFSEntry.LastAccessTime = DateTime.Now;
+
+ mynetworkFSEntry = new FSEntry ();
+
+ mynetworkFSEntry.Attributes = FileAttributes.Directory;
+ mynetworkFSEntry.FullName = MWFVFS.MyNetworkPrefix;
+ mynetworkFSEntry.Name = "My Network";
+ mynetworkFSEntry.MainTopNode = GetDesktopFSEntry ();
+ mynetworkFSEntry.FileType = FSEntry.FSEntryType.Directory;
+ mynetworkFSEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("network/network");
+ mynetworkFSEntry.LastAccessTime = DateTime.Now;
+ }
+
+ public override void WriteRecentlyUsedFiles (string fileToAdd)
+ {
+ // TODO: Implement this method
+ // use SHAddToRecentDocs ?
+ }
+
+ public override ArrayList GetRecentlyUsedFiles ()
+ {
+ ArrayList al = new ArrayList ();
+
+ DirectoryInfo di = new DirectoryInfo (recentlyusedFSEntry.RealName);
+
+ FileInfo[] fileinfos = di.GetFiles ();
+
+ foreach (FileInfo fi in fileinfos) {
+ FSEntry fs = GetFileFSEntry (fi);
+ if (fs != null)
+ al.Add (fs);
}
- base.OnSelectedIndexChanged (e);
+ return al;
}
- protected override void OnMouseMove (MouseEventArgs e)
+ public override ArrayList GetMyComputerContent ()
{
- ListViewItem item = GetItemAt (e.X, e.Y);
+ string[] logical_drives = Directory.GetLogicalDrives ();
- if (item != null) {
- int currentItemIndex = item.Index;
+ ArrayList my_computer_content_arraylist = new ArrayList ();
+
+ foreach (string drive in logical_drives) {
+ FSEntry fsEntry = new FSEntry ();
+ fsEntry.FileType = FSEntry.FSEntryType.Device;
- if (currentItemIndex != oldItemIndexForToolTip) {
- oldItemIndexForToolTip = currentItemIndex;
-
- if (toolTip != null && toolTip.Active)
- toolTip.Active = false;
-
- object fileStructObject = fileHashtable [item.Text];
-
- if (fileStructObject != null) {
-
- FileStruct fileStruct = (FileStruct)fileStructObject;
-
- string output = String.Empty;
-
- if (fileStruct.type == FileStruct.FileStructType.Directoy)
- output = String.Format ("Directory: {0}\n", fileStruct.fullname);
- else if (fileStruct.type == FileStruct.FileStructType.Device)
- output = String.Format ("Device: {0}", fileStruct.fullname);
- else if (fileStruct.type == FileStruct.FileStructType.Network)
- output = String.Format ("Network: {0}", fileStruct.fullname);
- else
- output = String.Format ("File: {0}", fileStruct.fullname);
-
- toolTip.SetToolTip (this, output);
-
- toolTip.Active = true;
- }
- }
+ fsEntry.FullName = drive;
+
+ fsEntry.Name = drive;
+
+ fsEntry.IconIndex = MimeIconEngine.GetIconIndexForMimeType ("harddisk/harddisk");
+
+ fsEntry.Attributes = FileAttributes.Directory;
+
+ fsEntry.MainTopNode = GetMyComputerFSEntry ();
+
+ my_computer_content_arraylist.Add (fsEntry);
+
+ string contain_string = fsEntry.FullName + "://";
+ if (!MWFVFS.MyComputerDevicesPrefix.Contains (contain_string))
+ MWFVFS.MyComputerDevicesPrefix.Add (contain_string, fsEntry);
}
- base.OnMouseMove (e);
+ my_computer_content_arraylist.Add (GetMyComputerPersonalFSEntry ());
+
+ return my_computer_content_arraylist;
}
- private void MWF_KeyUp (object sender, KeyEventArgs e)
+ public override ArrayList GetMyNetworkContent ()
{
- if (SelectedItems.Count > 0 && e.KeyCode == Keys.Back)
- if (on_one_directory_up != null) {
- internal_key_up = true;
- on_one_directory_up (this, EventArgs.Empty);
- }
+ // TODO: Implement this method
+ return new ArrayList ();
+ }
+ protected override FSEntry GetDesktopFSEntry ()
+ {
+ return desktopFSEntry;
}
- public event EventHandler SelectedFileChanged {
- add { on_selected_file_changed += value; }
- remove { on_selected_file_changed -= value; }
+ protected override FSEntry GetRecentlyUsedFSEntry ()
+ {
+ return recentlyusedFSEntry;
}
- public event EventHandler SelectedFilesChanged {
- add { on_selected_files_changed += value; }
- remove { on_selected_files_changed -= value; }
+ protected override FSEntry GetPersonalFSEntry ()
+ {
+ return personalFSEntry;
}
- public event EventHandler DirectoryChanged {
- add { on_directory_changed += value; }
- remove { on_directory_changed -= value; }
+ protected override FSEntry GetMyComputerPersonalFSEntry ()
+ {
+ return mycomputerpersonalFSEntry;
}
- public event EventHandler ForceDialogEnd {
- add { on_force_dialog_end += value; }
- remove { on_force_dialog_end -= value; }
+ protected override FSEntry GetMyComputerFSEntry ()
+ {
+ return mycomputerFSEntry;
}
- public event EventHandler OnDirectoryUp {
- add { on_one_directory_up += value; }
- remove { on_one_directory_up -= value; }
+ protected override FSEntry GetMyNetworkFSEntry ()
+ {
+ return mynetworkFSEntry;
}
}
+ #endregion
- internal class FileFilter {
- private ArrayList filterArrayList = new ArrayList();
+ #region FSEntry
+ internal class FSEntry
+ {
+ public enum FSEntryType
+ {
+ Desktop,
+ RecentlyUsed,
+ MyComputer,
+ File,
+ Directory,
+ Device,
+ RemovableDevice,
+ Network
+ }
- private string filter;
+ private MasterMount.FsTypes fsType;
+ private string device_short;
+ private string fullName;
+ private string name;
+ private string realName = null;
+ private FileAttributes attributes = FileAttributes.Normal;
+ private long fileSize;
+ private FSEntryType fileType;
+ private DateTime lastAccessTime;
+ private FSEntry mainTopNode = null;
- public FileFilter ()
- {}
+ private int iconIndex;
- public FileFilter (string filter)
- {
- this.filter = filter;
-
- SplitFilter ();
- }
+ private string parent;
- public ArrayList FilterArrayList {
+ public MasterMount.FsTypes FsType {
set {
- filterArrayList = value;
+ fsType = value;
}
get {
- return filterArrayList;
+ return fsType;
}
}
- public string Filter {
+ public string DeviceShort {
set {
- filter = value;
-
- SplitFilter ();
+ device_short = value;
}
get {
- return filter;
+ return device_short;
}
}
- private void SplitFilter ()
- {
- 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");
+ public string FullName {
+ set {
+ fullName = value;
+ }
- for (int i = 0; i < filters.Length; i += 2) {
- FilterStruct filterStruct = new FilterStruct (filters [i], filters [i + 1]);
-
- filterArrayList.Add (filterStruct);
+ get {
+ return fullName;
}
}
- }
-
- internal class DirComboBox : ComboBox {
- internal class DirComboBoxItem {
- private int imageIndex;
- private string name;
- private string path;
- private int xPos;
-
- public DirComboBoxItem (int imageIndex, string name, string path, int xPos)
- {
- this.imageIndex = imageIndex;
- this.name = name;
- this.path = path;
- this.xPos = xPos;
+
+ public string Name {
+ set {
+ name = value;
}
- public int ImageIndex {
- set {
- imageIndex = value;
- }
-
- get {
- return imageIndex;
- }
+ get {
+ return name;
}
-
- public string Name {
- set {
- name = value;
- }
-
- get {
- return name;
- }
+ }
+
+ public string RealName {
+ set {
+ realName = value;
}
- public string Path {
- set {
- path = value;
- }
-
- get {
- return path;
- }
+ get {
+ return realName;
+ }
+ }
+
+ public FileAttributes Attributes {
+ set {
+ attributes = value;
}
- public int XPos {
- set {
- xPos = value;
- }
-
- get {
- return xPos;
- }
+ get {
+ return attributes;
}
}
- private ImageList imageList = new ImageList();
-
- private string currentPath;
-
- private EventHandler on_directory_changed;
-
- private bool currentpath_internal_change = false;
-
- private int platform = (int) Environment.OSVersion.Platform;
- private string recently_used_tmp;
- private string my_computer_tmp;
- private string my_network_tmp;
- private Stack dirStack = new Stack();
-
- public DirComboBox ()
- {
- SuspendLayout ();
-
- DrawMode = DrawMode.OwnerDrawFixed;
-
- imageList.ColorDepth = ColorDepth.Depth32Bit;
- imageList.ImageSize = new Size (16, 16);
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesRecentDocuments, 16));
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesDesktop, 16));
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesPersonal, 16));
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyComputer, 16));
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.PlacesMyNetwork, 16));
- imageList.Images.Add (ThemeEngine.Current.Images (UIIcon.NormalFolder, 16));
- imageList.TransparentColor = Color.Transparent;
-
- if ((platform == 4) || (platform == 128)) {
- recently_used_tmp = FileDialog.recently_string;
- my_computer_tmp = FileDialog.mycomputer_string;
- my_network_tmp = FileDialog.network_string;
- } else {
- recently_used_tmp = ThemeEngine.Current.Places (UIIcon.PlacesRecentDocuments);
- my_computer_tmp = ThemeEngine.Current.Places (UIIcon.PlacesMyComputer);
- my_network_tmp = ThemeEngine.Current.Places (UIIcon.PlacesMyNetwork);
+ public long FileSize {
+ set {
+ fileSize = value;
}
- Items.AddRange (new object [] {
- new DirComboBoxItem (0, "Recently used", recently_used_tmp, 0),
- new DirComboBoxItem (1, "Desktop", ThemeEngine.Current.Places (UIIcon.PlacesDesktop), 0),
- new DirComboBoxItem (2, "Personal folder", ThemeEngine.Current.Places (UIIcon.PlacesPersonal), 0),
- new DirComboBoxItem (3, "My Computer", my_computer_tmp, 0),
- new DirComboBoxItem (4, "My Network", my_network_tmp, 0)
- }
- );
-
- ResumeLayout (false);
+ get {
+ return fileSize;
+ }
}
- public string CurrentPath {
+ public FSEntryType FileType {
set {
- currentPath = value;
-
- currentpath_internal_change = true;
-
- CreateComboList ();
+ fileType = value;
}
+
get {
- return currentPath;
+ return fileType;
}
}
- private void CreateComboList ()
- {
- int selection = -1;
- int child_of = - 1;
-
- if (currentPath == recently_used_tmp)
- selection = 0;
- else
- if (currentPath == ThemeEngine.Current.Places (UIIcon.PlacesDesktop))
- selection = 1;
- else
- if (currentPath == ThemeEngine.Current.Places (UIIcon.PlacesPersonal))
- selection = 2;
- else
- if (currentPath == my_computer_tmp)
- selection = 3;
- else
- if (currentPath == my_network_tmp)
- selection = 4;
-
- child_of = CheckChildOf ();
-
- BeginUpdate ();
-
- Items.Clear ();
-
- Items.Add (new DirComboBoxItem (0, "Recently used", recently_used_tmp, 0));
-
- Items.Add (new DirComboBoxItem (1, "Desktop", ThemeEngine.Current.Places (UIIcon.PlacesDesktop), 0));
- if (child_of == 1)
- selection = AppendToParent ();
-
- Items.Add (new DirComboBoxItem (2, "Personal folder", ThemeEngine.Current.Places (UIIcon.PlacesPersonal), 0));
- if (child_of == 2)
- selection = AppendToParent ();
-
- Items.Add (new DirComboBoxItem (3, "My Computer", my_computer_tmp, 0));
-
- Items.Add (new DirComboBoxItem (4, "My Network", my_network_tmp, 0));
-
- if (selection != -1)
- SelectedIndex = selection;
+ public DateTime LastAccessTime {
+ set {
+ lastAccessTime = value;
+ }
- EndUpdate ();
+ get {
+ return lastAccessTime;
+ }
}
- private int CheckChildOf ()
- {
- dirStack.Clear ();
-
- if (currentPath == FileDialog.mycomputer_string ||
- currentPath == FileDialog.network_string ||
- currentPath == FileDialog.recently_string)
- return -1;
-
- DirectoryInfo di = new DirectoryInfo (currentPath);
-
- dirStack.Push (di);
-
- while (di.Parent != null) {
- di = di.Parent;
- if (di.FullName == ThemeEngine.Current.Places (UIIcon.PlacesDesktop))
- return 1;
- else
- if (di.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal))
- return 2;
-
- dirStack.Push (di);
+ public int IconIndex {
+ set {
+ iconIndex = value;
}
- return -1;
+ get {
+ return iconIndex;
+ }
}
- private int AppendToParent ()
- {
- int xPos = 0;
- int selection = -1;
-
- while (dirStack.Count != 0) {
- DirectoryInfo dii = dirStack.Pop () as DirectoryInfo;
- selection = Items.Add (new DirComboBoxItem (5, dii.Name, dii.FullName, xPos + 4));
- xPos += 4;
+ public FSEntry MainTopNode {
+ set {
+ mainTopNode = value;
}
- return selection;
+ get {
+ return mainTopNode;
+ }
}
- protected override void OnDrawItem (DrawItemEventArgs e)
- {
- if (e.Index == -1)
- return;
-
- Bitmap bmp = new Bitmap (e.Bounds.Width, e.Bounds.Height, e.Graphics);
- Graphics gr = Graphics.FromImage (bmp);
-
- DirComboBoxItem dcbi = Items [e.Index] as DirComboBoxItem;
-
- Color backColor = e.BackColor;
- 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;
- foreColor = ThemeEngine.Current.ColorHighlightText;
+ public string Parent {
+ set {
+ parent = value;
}
- 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 (imageList.Images [dcbi.ImageIndex], new Rectangle (new Point (xPos + 2, 0), new Size (16, 16)));
-
- e.Graphics.DrawImage (bmp, e.Bounds.X, e.Bounds.Y);
- gr.Dispose ();
- bmp.Dispose ();
+ get {
+ parent = GetParent ();
+
+ return parent;
+ }
}
- protected override void OnSelectedIndexChanged (EventArgs e)
+ private string GetParent ()
{
- if (Items.Count > 0) {
- DirComboBoxItem dcbi = Items [SelectedIndex] as DirComboBoxItem;
+ if (fullName == MWFVFS.PersonalPrefix) {
+ return MWFVFS.DesktopPrefix;
+ } else
+ if (fullName == MWFVFS.MyComputerPersonalPrefix) {
+ return MWFVFS.MyComputerPrefix;
+ } else
+ if (fullName == MWFVFS.MyComputerPrefix) {
+ return MWFVFS.DesktopPrefix;
+ } else
+ if (fullName == MWFVFS.MyNetworkPrefix) {
+ return MWFVFS.DesktopPrefix;
+ } else
+ if (fullName == MWFVFS.DesktopPrefix) {
+ return null;
+ } else
+ if (fullName == MWFVFS.RecentlyUsedPrefix) {
+ return null;
+ } else {
+ foreach (DictionaryEntry entry in MWFVFS.MyComputerDevicesPrefix) {
+ FSEntry fsEntry = entry.Value as FSEntry;
+ if (fullName == fsEntry.FullName) {
+ return fsEntry.MainTopNode.FullName;
+ }
+ }
- currentPath = dcbi.Path;
+ DirectoryInfo dirInfo = new DirectoryInfo (fullName);
- // 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);
+ DirectoryInfo dirInfoParent = dirInfo.Parent;
+
+ if (dirInfoParent != null) {
+ FSEntry fsEntry = MWFVFS.MyComputerDevicesPrefix [dirInfoParent.FullName + "://"] as FSEntry;
+
+ if (fsEntry != null) {
+ return fsEntry.FullName;
+ }
+
+ if (mainTopNode != null) {
+ if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesDesktop) &&
+ mainTopNode.FullName == MWFVFS.DesktopPrefix) {
+ return mainTopNode.FullName;
+ } else
+ if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal) &&
+ mainTopNode.FullName == MWFVFS.PersonalPrefix) {
+ return mainTopNode.FullName;
+ } else
+ if (dirInfoParent.FullName == ThemeEngine.Current.Places (UIIcon.PlacesPersonal) &&
+ mainTopNode.FullName == MWFVFS.MyComputerPersonalPrefix) {
+ return mainTopNode.FullName;
+ }
+ }
+
+ return dirInfoParent.FullName;
}
}
- currentpath_internal_change = false;
- }
-
- public event EventHandler DirectoryChanged {
- add { on_directory_changed += value; }
- remove { on_directory_changed -= value; }
+ return null;
}
}
+ #endregion
- // Alexsantas little helper
- internal class MasterMount {
+ #region MasterMount
+ // Alexsantas little *nix helper
+ internal class MasterMount
+ {
// add more...
- internal enum FsTypes {
+ internal enum FsTypes
+ {
+ none,
ext2,
ext3,
hpfs,
ncpfs,
nfs,
smbfs,
- usbfs
+ usbfs,
+ cifs
}
- internal struct Mount {
+ internal struct Mount
+ {
public string device_or_filesystem;
public string device_short;
public string mount_point;
string line = sr.ReadLine ();
- while (line != null) {
- ProcessProcMountLine (line);
- line = sr.ReadLine ();
- }
+ ArrayList lines = new ArrayList ();
+ while (line != null) {
+ if (lines.IndexOf (line) == -1) { // Avoid duplicates
+ ProcessProcMountLine (line);
+ lines.Add (line);
+ }
+ line = sr.ReadLine ();
+ }
sr.Close ();
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];
} else if (split [2] == "smbfs") {
mount.fsType = FsTypes.smbfs;
network_devices.Add (mount);
+ } else if (split [2] == "cifs") {
+ mount.fsType = FsTypes.cifs;
+ network_devices.Add (mount);
} else if (split [2] == "ncpfs") {
mount.fsType = FsTypes.ncpfs;
network_devices.Add (mount);
public class MountComparer : IComparer
{
- public int Compare(object mount1, object mount2)
+ public int Compare (object mount1, object mount2)
+ {
+ return String.Compare (((Mount)mount1).device_short, ((Mount)mount2).device_short);
+ }
+ }
+ }
+ #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 ()
{
- return String.Compare(((Mount)mount1).device_short, ((Mount)mount2).device_short);
+ 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 = String.Empty;
+
+ 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.Empty;
+ string type_name = String.Empty;
+
+ 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
}