1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
24 // Alexander Olk xenomorph2@onlinehome.de
27 // NOT COMPLETE - work in progress
30 // file/path security stuff ???
34 using System.ComponentModel;
35 using System.Resources;
37 using System.Collections;
38 using System.Collections.Specialized;
40 namespace System.Windows.Forms
42 [DefaultProperty( "FileName" )]
43 [DefaultEvent( "FileOk" )]
44 public abstract class FileDialog : CommonDialog
46 internal class FileDialogForm : DialogForm
48 internal FileDialogForm( CommonDialog owner )
52 protected override CreateParams CreateParams
61 cp = base.CreateParams;
62 cp.Style = (int)( WindowStyles.WS_POPUP | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS );
63 cp.Style |= (int)WindowStyles.WS_OVERLAPPEDWINDOW;
70 internal enum FileDialogType
76 internal FileDialogPanel fileDialogPanel;
78 private bool addExtension = true;
79 internal bool checkFileExists = false;
80 private bool checkPathExists = true;
81 private string defaultExt = "";
82 private bool dereferenceLinks = true;
83 private string fileName = "";
84 private string[] fileNames;
85 private string filter;
86 private int filterIndex = 1;
87 private string initialDirectory = "";
88 private bool restoreDirectory = false;
89 private bool showHelp = false;
90 private string title = "";
91 private bool validateNames = true;
93 //protected bool readOnlyChecked = false;
95 internal string openSaveButtonText;
96 internal string searchSaveLabelText;
97 internal bool showReadOnly = false;
98 internal bool readOnlyChecked = false;
99 internal bool multiSelect = false;
100 internal bool createPrompt = false;
101 internal bool overwritePrompt = true;
103 private bool showHiddenFiles = false;
105 internal FileDialogType fileDialogType;
107 internal FileDialog( ) : base()
112 public bool AddExtension
119 addExtension = value;
123 [DefaultValue(false)]
124 public virtual bool CheckFileExists
127 return checkFileExists;
131 checkFileExists = value;
136 public bool CheckPathExists
139 return checkPathExists;
143 checkPathExists = value;
148 public string DefaultExt
157 // if there is a dot remove it and everything before it
158 if ( defaultExt.LastIndexOf( '.' ) != - 1 )
160 string[] split = defaultExt.Split( new char[] { '.' } );
161 defaultExt = split[ split.Length - 1 ];
166 // in MS.NET it doesn't make a difference if
167 // DerefenceLinks is true or false
168 // if the selected file is a link FileDialog
169 // always returns the link
171 public bool DereferenceLinks
174 return dereferenceLinks;
178 dereferenceLinks = value;
183 public string FileName
195 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
196 public string[] FileNames
216 throw new NullReferenceException( "Filter" );
220 fileFilter = new FileFilter( filter );
222 fileDialogPanel.UpdateFilters( );
227 public int FilterIndex
239 public string InitialDirectory
242 return initialDirectory;
246 initialDirectory = value;
250 [DefaultValue(false)]
251 public bool RestoreDirectory
254 return restoreDirectory;
258 restoreDirectory = value;
262 [DefaultValue(false)]
271 fileDialogPanel.ResizeAndRelocateForHelpOrReadOnly( );
290 // this one is a hard one ;)
292 // - up to MAX_PATH characters (windef.h) = 260
293 // - no trailing dots or spaces
296 // NTFS/Posix filename:
297 // - up to 32,768 Unicode characters
298 // - trailing periods or spaces
302 public bool ValidateNames
305 return validateNames;
309 validateNames = value;
313 internal string OpenSaveButtonText
316 openSaveButtonText = value;
320 return openSaveButtonText;
324 internal string SearchSaveLabelText
327 searchSaveLabelText = value;
331 return searchSaveLabelText;
335 internal virtual bool ShowReadOnly
338 showReadOnly = value;
339 fileDialogPanel.ResizeAndRelocateForHelpOrReadOnly( );
347 internal virtual bool ReadOnlyChecked
350 readOnlyChecked = value;
351 fileDialogPanel.CheckBox.Checked = value;
355 return readOnlyChecked;
359 internal virtual bool Multiselect
363 fileDialogPanel.MultiSelect = value;
371 // extension to MS.NET framework...
372 // Must keep this internal, otherwise our signature doesn't match MS
373 internal bool ShowHiddenFiles
376 showHiddenFiles = value;
380 return showHiddenFiles;
384 internal virtual bool CreatePrompt
387 createPrompt = value;
395 internal virtual bool OverwritePrompt
398 overwritePrompt = value;
402 return overwritePrompt;
406 internal FileFilter FileFilter
417 public override void Reset( )
420 checkFileExists = false;
421 checkPathExists = true;
423 dereferenceLinks = true;
428 initialDirectory = "";
429 restoreDirectory = false;
432 validateNames = true;
434 fileDialogPanel.UpdateFilters( );
437 public override string ToString( )
439 return base.ToString( );
442 public event CancelEventHandler FileOk;
444 protected override IntPtr HookProc( IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam )
446 throw new NotImplementedException( );
449 protected void OnFileOk( CancelEventArgs e )
451 if ( FileOk != null ) FileOk( this, e );
455 protected override bool RunDialog( IntPtr hWndOwner )
457 form.Controls.Add( fileDialogPanel );
462 internal void SendHelpRequest( EventArgs e )
467 internal void SetFilenames( string[] filenames )
469 fileNames = filenames;
472 internal FileFilter fileFilter;
474 internal class FileDialogPanel : Panel
476 private Button cancelButton;
477 private ToolBarButton upToolBarButton;
478 private PopupButtonPanel popupButtonPanel;
479 private Button openSaveButton;
480 private Button helpButton;
481 private Label fileTypeLabel;
482 private ToolBarButton menueToolBarButton;
483 private ContextMenu menueToolBarButtonContextMenu;
484 private ToolBarButton desktopToolBarButton;
485 private ToolBar smallButtonToolBar;
486 private DirComboBox dirComboBox;
487 private ToolBarButton lastUsedToolBarButton;
488 private ComboBox fileNameComboBox;
489 private ToolBarButton networkToolBarButton;
490 private Label fileNameLabel;
491 private MWFFileView mwfFileView;
492 private Label searchSaveLabel;
493 private ToolBarButton newdirToolBarButton;
494 private ToolBarButton backToolBarButton;
495 private ToolBarButton homeToolBarButton;
496 private ToolBarButton workplaceToolBarButton;
497 private ComboBox fileTypeComboBox;
498 private ImageList imageListTopToolbar;
499 private ContextMenu contextMenu;
500 private CheckBox checkBox;
502 internal FileDialog fileDialog;
504 private string currentDirectoryName;
506 internal string currentFileName = "";
508 // store current directoryInfo
509 private DirectoryInfo directoryInfo;
511 // store DirectoryInfo for backButton
512 internal Stack directoryStack = new Stack();
514 private MenuItem previousCheckedMenuItem;
516 private bool multiSelect = false;
518 private string restoreDirectory = "";
520 public FileDialogPanel( FileDialog fileDialog )
522 this.fileDialog = fileDialog;
524 fileTypeComboBox = new ComboBox( );
525 workplaceToolBarButton = new ToolBarButton( );
526 homeToolBarButton = new ToolBarButton( );
527 backToolBarButton = new ToolBarButton( );
528 newdirToolBarButton = new ToolBarButton( );
529 searchSaveLabel = new Label( );
530 mwfFileView = new MWFFileView( );
531 fileNameLabel = new Label( );
532 networkToolBarButton = new ToolBarButton( );
533 fileNameComboBox = new ComboBox( );
534 lastUsedToolBarButton = new ToolBarButton( );
535 dirComboBox = new DirComboBox( );
536 smallButtonToolBar = new ToolBar( );
537 desktopToolBarButton = new ToolBarButton( );
538 menueToolBarButton = new ToolBarButton( );
539 fileTypeLabel = new Label( );
540 openSaveButton = new Button( );
541 fileDialog.form.AcceptButton = openSaveButton;
542 helpButton = new Button( );
543 popupButtonPanel = new PopupButtonPanel( this );
544 upToolBarButton = new ToolBarButton( );
545 cancelButton = new Button( );
546 fileDialog.form.CancelButton = cancelButton;
547 imageListTopToolbar = new ImageList( );
548 menueToolBarButtonContextMenu = new ContextMenu( );
549 contextMenu = new ContextMenu( );
550 checkBox = new CheckBox( );
554 //imageListTopToolbar
555 imageListTopToolbar.ColorDepth = ColorDepth.Depth32Bit;
556 imageListTopToolbar.ImageSize = new Size( 16, 16 ); // 16, 16
557 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "back_arrow" ) );
558 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_arrow_up" ) );
559 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_star" ) );
560 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "window" ) );
561 imageListTopToolbar.TransparentColor = Color.Transparent;
564 searchSaveLabel.FlatStyle = FlatStyle.System;
565 searchSaveLabel.Location = new Point( 7, 8 );
566 searchSaveLabel.Size = new Size( 72, 21 );
567 searchSaveLabel.TabIndex = 0;
568 searchSaveLabel.Text = fileDialog.SearchSaveLabelText;
569 searchSaveLabel.TextAlign = ContentAlignment.MiddleRight;
572 dirComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Top | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
573 dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
574 dirComboBox.Location = new Point( 99, 8 );
575 dirComboBox.Size = new Size( 260, 21 );
576 dirComboBox.TabIndex = 1;
578 // smallButtonToolBar
579 smallButtonToolBar.Anchor = ( (AnchorStyles)( ( AnchorStyles.Top | AnchorStyles.Right ) ) );
580 smallButtonToolBar.Appearance = ToolBarAppearance.Flat;
581 smallButtonToolBar.AutoSize = false;
582 smallButtonToolBar.Buttons.AddRange( new ToolBarButton[] {
586 menueToolBarButton} );
587 smallButtonToolBar.ButtonSize = new Size( 21, 16 ); // 21, 16
588 smallButtonToolBar.Divider = false;
589 smallButtonToolBar.Dock = DockStyle.None;
590 smallButtonToolBar.DropDownArrows = true;
591 smallButtonToolBar.ImageList = imageListTopToolbar;
592 smallButtonToolBar.Location = new Point( 372, 8 );
593 smallButtonToolBar.ShowToolTips = true;
594 smallButtonToolBar.Size = new Size( 110, 20 );
595 smallButtonToolBar.TabIndex = 2;
596 smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
599 popupButtonPanel.Dock = DockStyle.None;
600 popupButtonPanel.Location = new Point( 7, 37 );
601 popupButtonPanel.TabIndex = 3;
604 mwfFileView.Anchor = ( (AnchorStyles)( ( ( ( AnchorStyles.Top | AnchorStyles.Bottom ) | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
605 mwfFileView.Location = new Point( 99, 37 );
606 mwfFileView.Size = new Size( 449, 282 );
607 mwfFileView.Columns.Add( " Name", 170, HorizontalAlignment.Left );
608 mwfFileView.Columns.Add( "Size ", 80, HorizontalAlignment.Right );
609 mwfFileView.Columns.Add( " Type", 100, HorizontalAlignment.Left );
610 mwfFileView.Columns.Add( " Last Access", 150, HorizontalAlignment.Left );
611 mwfFileView.AllowColumnReorder = true;
612 mwfFileView.MultiSelect = false;
613 mwfFileView.TabIndex = 4;
614 mwfFileView.FilterIndex = fileDialog.FilterIndex;
617 fileNameLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
618 fileNameLabel.FlatStyle = FlatStyle.System;
619 fileNameLabel.Location = new Point( 102, 330 );
620 fileNameLabel.Size = new Size( 70, 21 );
621 fileNameLabel.TabIndex = 5;
622 fileNameLabel.Text = "Filename:";
623 fileNameLabel.TextAlign = ContentAlignment.MiddleLeft;
626 fileNameComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
627 fileNameComboBox.Location = new Point( 195, 330 );
628 fileNameComboBox.Size = new Size( 245, 21 );
629 fileNameComboBox.TabIndex = 6;
632 fileTypeLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
633 fileTypeLabel.FlatStyle = FlatStyle.System;
634 fileTypeLabel.Location = new Point( 102, 356 );
635 fileTypeLabel.Size = new Size( 70, 21 );
636 fileTypeLabel.TabIndex = 7;
637 fileTypeLabel.Text = "Filetype:";
638 fileTypeLabel.TextAlign = ContentAlignment.MiddleLeft;
641 fileTypeComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
642 fileTypeComboBox.Location = new Point( 195, 356 );
643 fileTypeComboBox.Size = new Size( 245, 21 );
644 fileTypeComboBox.TabIndex = 8;
647 backToolBarButton.ImageIndex = 0;
648 backToolBarButton.Enabled = false;
649 backToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
652 upToolBarButton.ImageIndex = 1;
653 upToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
655 // newdirToolBarButton
656 newdirToolBarButton.ImageIndex = 2;
657 newdirToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
659 // menueToolBarButton
660 menueToolBarButton.ImageIndex = 3;
661 menueToolBarButton.DropDownMenu = menueToolBarButtonContextMenu;
662 menueToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
664 // menueToolBarButtonContextMenu
665 MenuItem mi = new MenuItem( "Small Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
666 menueToolBarButtonContextMenu.MenuItems.Add( mi );
667 mi = new MenuItem( "Tiles", new EventHandler( OnClickMenuToolBarContextMenu ) );
668 menueToolBarButtonContextMenu.MenuItems.Add( mi );
669 mi = new MenuItem( "Large Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
670 menueToolBarButtonContextMenu.MenuItems.Add( mi );
671 mi = new MenuItem( "List", new EventHandler( OnClickMenuToolBarContextMenu ) );
673 previousCheckedMenuItem = mi;
674 menueToolBarButtonContextMenu.MenuItems.Add( mi );
675 mi = new MenuItem( "Details", new EventHandler( OnClickMenuToolBarContextMenu ) );
676 menueToolBarButtonContextMenu.MenuItems.Add( mi );
679 mi = new MenuItem( "Show hidden files", new EventHandler( OnClickContextMenu ) );
680 mi.Checked = fileDialog.ShowHiddenFiles;
681 mwfFileView.ShowHiddenFiles = fileDialog.ShowHiddenFiles;
682 contextMenu.MenuItems.Add( mi );
685 openSaveButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
686 openSaveButton.FlatStyle = FlatStyle.System;
687 openSaveButton.Location = new Point( 475, 330 );
688 openSaveButton.Size = new Size( 72, 21 );
689 openSaveButton.TabIndex = 9;
690 openSaveButton.Text = fileDialog.OpenSaveButtonText;
691 openSaveButton.FlatStyle = FlatStyle.System;
694 cancelButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
695 cancelButton.FlatStyle = FlatStyle.System;
696 cancelButton.Location = new Point( 475, 356 );
697 cancelButton.Size = new Size( 72, 21 );
698 cancelButton.TabIndex = 10;
699 cancelButton.Text = "Cancel";
700 cancelButton.FlatStyle = FlatStyle.System;
703 helpButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
704 helpButton.FlatStyle = FlatStyle.System;
705 helpButton.Location = new Point( 475, 350 );
706 helpButton.Size = new Size( 72, 21 );
707 helpButton.TabIndex = 11;
708 helpButton.Text = "Help";
709 helpButton.FlatStyle = FlatStyle.System;
713 checkBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
714 checkBox.Text = "Open Readonly";
715 checkBox.Location = new Point( 195, 350 );
716 checkBox.Size = new Size( 245, 21 );
717 checkBox.FlatStyle = FlatStyle.System;
718 checkBox.TabIndex = 12;
721 ClientSize = new Size( 554, 405 ); // 384
723 ContextMenu = contextMenu;
725 Dock = DockStyle.Fill;
727 Controls.Add( smallButtonToolBar );
728 Controls.Add( cancelButton );
729 Controls.Add( openSaveButton );
730 Controls.Add( helpButton );
731 Controls.Add( mwfFileView );
732 Controls.Add( fileTypeLabel );
733 Controls.Add( fileNameLabel );
734 Controls.Add( fileTypeComboBox );
735 Controls.Add( fileNameComboBox );
736 Controls.Add( dirComboBox );
737 Controls.Add( searchSaveLabel );
738 Controls.Add( popupButtonPanel );
739 Controls.Add( checkBox );
741 ResumeLayout( false );
743 if ( fileDialog.InitialDirectory == String.Empty )
744 currentDirectoryName = Environment.CurrentDirectory;
746 currentDirectoryName = fileDialog.InitialDirectory;
748 directoryInfo = new DirectoryInfo( currentDirectoryName );
750 dirComboBox.CurrentPath = currentDirectoryName;
752 if ( fileDialog.RestoreDirectory )
753 restoreDirectory = currentDirectoryName;
755 mwfFileView.UpdateFileView( directoryInfo );
757 openSaveButton.Click += new EventHandler( OnClickOpenSaveButton );
758 cancelButton.Click += new EventHandler( OnClickCancelButton );
759 helpButton.Click += new EventHandler( OnClickHelpButton );
761 smallButtonToolBar.ButtonClick += new ToolBarButtonClickEventHandler( OnClickSmallButtonToolBar );
763 // Key events DONT'T work
764 fileNameComboBox.KeyUp += new KeyEventHandler( OnKeyUpFileNameComboBox );
766 fileTypeComboBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFileTypeComboBox );
768 mwfFileView.SelectedFileChanged += new EventHandler( OnSelectedFileChangedFileView );
769 mwfFileView.DirectoryChanged += new EventHandler( OnDirectoryChangedFileView );
770 mwfFileView.ForceDialogEnd += new EventHandler( OnForceDialogEndFileView );
771 mwfFileView.SelectedFilesChanged += new EventHandler( OnSelectedFilesChangedFileView );
773 dirComboBox.DirectoryChanged += new EventHandler( OnDirectoryChangedDirComboBox );
775 checkBox.CheckedChanged += new EventHandler( OnCheckCheckChanged );
778 public ComboBox FileNameComboBox
781 fileNameComboBox = value;
785 return fileNameComboBox;
789 public string CurrentFileName
792 currentFileName = value;
796 return currentFileName;
800 public DirectoryInfo DirectoryInfo
803 directoryInfo = value;
807 return directoryInfo;
811 public bool MultiSelect
815 mwfFileView.MultiSelect = value;
823 public CheckBox CheckBox
834 void OnClickContextMenu( object sender, EventArgs e )
836 MenuItem senderMenuItem = sender as MenuItem;
838 if ( senderMenuItem.Index == 0 )
840 senderMenuItem.Checked = !senderMenuItem.Checked;
841 fileDialog.ShowHiddenFiles = senderMenuItem.Checked;
842 mwfFileView.ShowHiddenFiles = fileDialog.ShowHiddenFiles;
843 mwfFileView.UpdateFileView( directoryInfo );
847 void OnClickOpenSaveButton( object sender, EventArgs e )
851 string fileFromComboBox = fileNameComboBox.Text.Trim( );
853 if ( fileFromComboBox.Length > 0 ) {
854 if (!Path.IsPathRooted (fileFromComboBox))
855 fileFromComboBox = Path.Combine( currentDirectoryName, fileFromComboBox );
857 FileInfo fileInfo = new FileInfo (fileFromComboBox);
859 currentFileName = fileFromComboBox;
861 DirectoryInfo dirInfo = new DirectoryInfo (fileFromComboBox);
862 if (dirInfo.Exists) {
864 PushDirectory( dirInfo );
865 directoryInfo = dirInfo.Parent;
866 currentDirectoryName = dirInfo.FullName;
867 dirComboBox.CurrentPath = currentDirectoryName;
868 mwfFileView.UpdateFileView( dirInfo );
870 currentFileName = "";
876 if ( currentFileName != fileFromComboBox )
877 currentFileName = fileFromComboBox;
879 if ( currentFileName.Length == 0 )
883 if ( fileDialog.fileDialogType == FileDialogType.OpenFileDialog )
885 if ( fileDialog.CheckFileExists )
887 if ( !File.Exists( currentFileName ) )
889 string message = currentFileName + " doesn't exist. Please verify that you have entered the correct file name.";
890 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
892 currentFileName = "";
898 else // FileDialogType == SaveFileDialog
900 if ( fileDialog.OverwritePrompt )
902 if ( File.Exists( currentFileName ) )
904 string message = currentFileName + " exists. Overwrite ?";
905 DialogResult dr = MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
907 if ( dr == DialogResult.Cancel )
909 currentFileName = "";
916 if ( fileDialog.CreatePrompt )
918 if ( !File.Exists( currentFileName ) )
920 string message = currentFileName + " doesn't exist. Create ?";
921 DialogResult dr = MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
923 if ( dr == DialogResult.Cancel )
925 currentFileName = "";
933 if ( fileDialog.fileDialogType == FileDialogType.SaveFileDialog )
935 if ( fileDialog.AddExtension && fileDialog.DefaultExt.Length > 0 )
937 if ( !currentFileName.EndsWith( fileDialog.DefaultExt ) )
939 currentFileName += "." + fileDialog.DefaultExt;
944 fileDialog.FileName = currentFileName;
946 else // multiSelect = true
947 if ( fileDialog.fileDialogType != FileDialogType.SaveFileDialog )
949 if ( mwfFileView.SelectedItems.Count > 0 )
951 // first remove all selected directories
952 ArrayList al = new ArrayList( );
954 foreach ( ListViewItem lvi in mwfFileView.SelectedItems )
956 FileStruct fileStruct = (FileStruct)mwfFileView.FileHashtable[ lvi.Text ];
958 if ( fileStruct.attributes != FileAttributes.Directory )
960 al.Add( fileStruct );
964 fileDialog.FileName = ( (FileStruct)al[ 0 ] ).fullname;
966 string[] filenames = new string[ al.Count ];
968 for ( int i = 0; i < al.Count; i++ )
970 filenames[ i ] = ( (FileStruct)al[ i ] ).fullname;
973 fileDialog.SetFilenames( filenames );
977 if ( fileDialog.CheckPathExists )
979 if ( !Directory.Exists( currentDirectoryName ) )
981 string message = currentDirectoryName + " doesn't exist. Please verify that you have entered the correct directory name.";
982 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
984 if ( fileDialog.InitialDirectory == String.Empty )
985 currentDirectoryName = Environment.CurrentDirectory;
987 currentDirectoryName = fileDialog.InitialDirectory;
993 if ( fileDialog.RestoreDirectory )
994 currentDirectoryName = restoreDirectory;
996 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
998 cancelEventArgs.Cancel = false;
1000 fileDialog.OnFileOk( cancelEventArgs );
1002 fileDialog.form.Controls.Remove( this );
1003 fileDialog.form.DialogResult = DialogResult.OK;
1006 void OnClickCancelButton( object sender, EventArgs e )
1008 if ( fileDialog.RestoreDirectory )
1009 currentDirectoryName = restoreDirectory;
1011 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
1013 cancelEventArgs.Cancel = true;
1015 fileDialog.OnFileOk( cancelEventArgs );
1017 fileDialog.form.Controls.Remove( this );
1018 fileDialog.form.DialogResult = DialogResult.Cancel;
1021 void OnClickHelpButton( object sender, EventArgs e )
1023 fileDialog.SendHelpRequest( e );
1026 void OnClickSmallButtonToolBar( object sender, ToolBarButtonClickEventArgs e )
1028 if ( e.Button == upToolBarButton )
1030 if ( directoryInfo.Parent != null )
1032 PushDirectory( directoryInfo );
1034 directoryInfo = directoryInfo.Parent;
1036 currentDirectoryName = directoryInfo.FullName;
1038 dirComboBox.CurrentPath = currentDirectoryName;
1040 mwfFileView.UpdateFileView( directoryInfo );
1044 if ( e.Button == backToolBarButton )
1046 if ( directoryStack.Count != 0 )
1050 dirComboBox.CurrentPath = currentDirectoryName;
1052 mwfFileView.UpdateFileView( directoryInfo );
1056 if ( e.Button == newdirToolBarButton )
1062 void OnClickMenuToolBarContextMenu( object sender, EventArgs e )
1064 MenuItem senderMenuItem = (MenuItem)sender;
1066 previousCheckedMenuItem.Checked = false;
1067 senderMenuItem.Checked = true;
1068 previousCheckedMenuItem = senderMenuItem;
1072 switch ( senderMenuItem.Index )
1075 mwfFileView.View = View.SmallIcon;
1078 mwfFileView.View = View.LargeIcon;
1081 mwfFileView.View = View.LargeIcon;
1084 mwfFileView.View = View.List;
1087 mwfFileView.View = View.Details;
1094 mwfFileView.UpdateFileView( directoryInfo );
1097 void OnKeyUpFileNameComboBox( object sender, KeyEventArgs e )
1099 if ( e.KeyCode == Keys.Enter )
1101 currentFileName = currentDirectoryName + fileNameComboBox.Text;
1106 void OnSelectedIndexChangedFileTypeComboBox( object sender, EventArgs e )
1108 fileDialog.FilterIndex = fileTypeComboBox.SelectedIndex + 1;
1110 mwfFileView.FilterIndex = fileDialog.FilterIndex;
1112 mwfFileView.UpdateFileView( directoryInfo );
1115 void OnSelectedFileChangedFileView( object sender, EventArgs e )
1117 fileNameComboBox.Text = mwfFileView.FileName;
1118 currentFileName = mwfFileView.FullFileName;
1121 void OnDirectoryChangedFileView( object sender, EventArgs e )
1123 ChangeDirectory( sender, mwfFileView.FullFileName );
1126 void OnForceDialogEndFileView( object sender, EventArgs e )
1131 void OnSelectedFilesChangedFileView( object sender, EventArgs e )
1133 fileNameComboBox.Text = mwfFileView.SelectedFilesString;
1136 void OnDirectoryChangedDirComboBox( object sender, EventArgs e )
1138 ChangeDirectory( sender, dirComboBox.CurrentPath );
1141 void OnCheckCheckChanged( object sender, EventArgs e )
1143 fileDialog.ReadOnlyChecked = checkBox.Checked;
1146 public void UpdateFilters( )
1148 ArrayList filters = fileDialog.FileFilter.FilterArrayList;
1150 fileTypeComboBox.Items.Clear( );
1152 fileTypeComboBox.BeginUpdate( );
1154 foreach ( FilterStruct fs in filters )
1156 fileTypeComboBox.Items.Add( fs.filterName );
1159 fileTypeComboBox.SelectedIndex = fileDialog.FilterIndex - 1;
1161 fileTypeComboBox.EndUpdate( );
1163 mwfFileView.FilterArrayList = filters;
1165 mwfFileView.FilterIndex = fileDialog.FilterIndex;
1167 mwfFileView.UpdateFileView( directoryInfo );
1170 public void ChangeDirectory( object sender, string path )
1172 currentDirectoryName = path;
1174 PushDirectory( directoryInfo );
1176 directoryInfo = new DirectoryInfo( path );
1178 if ( sender != dirComboBox )
1179 dirComboBox.CurrentPath = path;
1181 mwfFileView.UpdateFileView( directoryInfo );
1184 public void ForceDialogEnd( )
1186 OnClickOpenSaveButton( this, EventArgs.Empty );
1189 private void PushDirectory( DirectoryInfo di )
1191 directoryStack.Push( directoryInfo );
1192 backToolBarButton.Enabled = true;
1195 private void PopDirectory( )
1197 directoryInfo = (DirectoryInfo)directoryStack.Pop( );
1199 currentDirectoryName = directoryInfo.FullName;
1201 if ( directoryStack.Count == 0 )
1202 backToolBarButton.Enabled = false;
1205 public void ResizeAndRelocateForHelpOrReadOnly( )
1207 if ( fileDialog.ShowHelp || fileDialog.ShowReadOnly )
1209 mwfFileView.Size = new Size( 449, 250 );
1210 fileNameLabel.Location = new Point( 102, 298 );
1211 fileNameComboBox.Location = new Point( 195, 298 );
1212 fileTypeLabel.Location = new Point( 102, 324 );
1213 fileTypeComboBox.Location = new Point( 195, 324 );
1214 openSaveButton.Location = new Point( 475, 298 );
1215 cancelButton.Location = new Point( 475, 324 );
1219 mwfFileView.Size = new Size( 449, 282 );
1220 fileNameLabel.Location = new Point( 102, 330 );
1221 fileNameComboBox.Location = new Point( 195, 330 );
1222 fileTypeLabel.Location = new Point( 102, 356 );
1223 fileTypeComboBox.Location = new Point( 195, 356 );
1224 openSaveButton.Location = new Point( 475, 330 );
1225 cancelButton.Location = new Point( 475, 356 );
1228 if ( fileDialog.ShowHelp )
1231 if ( fileDialog.ShowReadOnly )
1235 internal class PopupButtonPanel : Panel
1237 internal class PopupButton : Control
1239 internal enum PopupButtonState
1242 private Image image = null;
1243 private PopupButtonState popupButtonState = PopupButtonState.Normal;
1244 private StringFormat text_format = new StringFormat();
1246 public PopupButton( )
1248 text_format.Alignment = StringAlignment.Center;
1249 text_format.LineAlignment = StringAlignment.Far;
1251 SetStyle( ControlStyles.DoubleBuffer, true );
1252 SetStyle( ControlStyles.AllPaintingInWmPaint, true );
1253 SetStyle( ControlStyles.UserPaint, true );
1268 public PopupButtonState ButtonState
1271 popupButtonState = value;
1276 return popupButtonState;
1280 protected override void OnPaint( PaintEventArgs pe )
1287 private void Draw( PaintEventArgs pe )
1289 Graphics gr = pe.Graphics;
1291 gr.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( BackColor ), ClientRectangle );
1294 if ( image != null )
1296 int i_x = ( ClientSize.Width - image.Width ) / 2;
1298 gr.DrawImage( image, i_x, i_y );
1301 if ( Text != String.Empty )
1303 Rectangle text_rect = Rectangle.Inflate( ClientRectangle, -4, -4 );
1305 gr.DrawString( Text, Font, ThemeEngine.Current.ResPool.GetSolidBrush( ForeColor ), text_rect, text_format );
1308 switch ( popupButtonState )
1310 case PopupButtonState.Up:
1311 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, 0, ClientSize.Width - 1, 0 );
1312 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, 0, 0, ClientSize.Height - 1 );
1313 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1 );
1314 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1 );
1317 case PopupButtonState.Down:
1318 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, 0, ClientSize.Width - 1, 0 );
1319 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, 0, 0, ClientSize.Height - 1 );
1320 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1 );
1321 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1 );
1326 protected override void OnMouseEnter( EventArgs e )
1328 if ( popupButtonState != PopupButtonState.Down )
1329 popupButtonState = PopupButtonState.Up;
1331 base.OnMouseEnter( e );
1334 protected override void OnMouseLeave( EventArgs e )
1336 if ( popupButtonState != PopupButtonState.Down )
1337 popupButtonState = PopupButtonState.Normal;
1339 base.OnMouseLeave( e );
1342 protected override void OnClick( EventArgs e )
1344 popupButtonState = PopupButtonState.Down;
1350 private FileDialogPanel fileDialogPanel;
1352 private PopupButton lastOpenButton;
1353 private PopupButton desktopButton;
1354 private PopupButton homeButton;
1355 private PopupButton workplaceButton;
1356 private PopupButton networkButton;
1358 private PopupButton lastPopupButton = null;
1360 private ImageList imageList = new ImageList();
1362 public PopupButtonPanel( FileDialogPanel fileDialogPanel )
1364 this.fileDialogPanel = fileDialogPanel;
1366 BorderStyle = BorderStyle.Fixed3D;
1367 BackColor = Color.FromArgb( 128, 128, 128 );
1368 Size = new Size( 85, 336 );
1370 // use ImageList to scale the bitmaps
1371 imageList.ColorDepth = ColorDepth.Depth32Bit;
1372 imageList.ImageSize = new Size( 38, 38 );
1373 imageList.Images.Add( (Image)Locale.GetResource( "last_open" ) );
1374 //imageList.Images.Add( (Image)Locale.GetResource( "desktop" ) );
1375 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", imageList.ImageSize ) );
1376 //imageList.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
1377 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", imageList.ImageSize ) );
1378 imageList.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
1379 //imageList.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
1380 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "network/network", imageList.ImageSize ) );
1381 imageList.TransparentColor = Color.Transparent;
1383 lastOpenButton = new PopupButton( );
1384 desktopButton = new PopupButton( );
1385 homeButton = new PopupButton( );
1386 workplaceButton = new PopupButton( );
1387 networkButton = new PopupButton( );
1389 lastOpenButton.Size = new Size( 82, 64 );
1390 lastOpenButton.Image = imageList.Images[ 0 ];
1391 lastOpenButton.BackColor = BackColor;
1392 lastOpenButton.ForeColor = Color.White;
1393 lastOpenButton.Location = new Point( 2, 2 );
1394 lastOpenButton.Text = "Last Open";
1395 lastOpenButton.Click += new EventHandler( OnClickButton );
1397 desktopButton.Image = imageList.Images[ 1 ];
1398 desktopButton.BackColor = BackColor;
1399 desktopButton.ForeColor = Color.White;
1400 desktopButton.Size = new Size( 82, 64 );
1401 desktopButton.Location = new Point( 2, 66 );
1402 desktopButton.Text = "Desktop";
1403 desktopButton.Click += new EventHandler( OnClickButton );
1405 homeButton.Image = imageList.Images[ 2 ];
1406 homeButton.BackColor = BackColor;
1407 homeButton.ForeColor = Color.White;
1408 homeButton.Size = new Size( 82, 64 );
1409 homeButton.Location = new Point( 2, 130 );
1410 homeButton.Text = "Home";
1411 homeButton.Click += new EventHandler( OnClickButton );
1413 workplaceButton.Image = imageList.Images[ 3 ];
1414 workplaceButton.BackColor = BackColor;
1415 workplaceButton.ForeColor = Color.White;
1416 workplaceButton.Size = new Size( 82, 64 );
1417 workplaceButton.Location = new Point( 2, 194 );
1418 workplaceButton.Text = "Workplace";
1419 workplaceButton.Click += new EventHandler( OnClickButton );
1421 networkButton.Image = imageList.Images[ 4 ];
1422 networkButton.BackColor = BackColor;
1423 networkButton.ForeColor = Color.White;
1424 networkButton.Size = new Size( 82, 64 );
1425 networkButton.Location = new Point( 2, 258 );
1426 networkButton.Text = "Network";
1427 networkButton.Click += new EventHandler( OnClickButton );
1429 Controls.Add( lastOpenButton );
1430 Controls.Add( desktopButton );
1431 Controls.Add( homeButton );
1432 Controls.Add( workplaceButton );
1433 Controls.Add( networkButton );
1436 void OnClickButton( object sender, EventArgs e )
1438 if ( lastPopupButton != null && (PopupButton)sender != lastPopupButton )
1439 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1440 lastPopupButton = sender as PopupButton;
1442 if ( sender == lastOpenButton )
1447 if ( sender == desktopButton )
1449 fileDialogPanel.ChangeDirectory( this, Environment.GetFolderPath( Environment.SpecialFolder.Desktop ) );
1452 if ( sender == homeButton )
1454 fileDialogPanel.ChangeDirectory( this, Environment.GetFolderPath( Environment.SpecialFolder.Personal ) );
1457 if ( sender == workplaceButton )
1459 // fileDialogPanel.ChangeDirectory(this, Environment.GetFolderPath( Environment.SpecialFolder.MyComputer ) );
1462 if ( sender == networkButton )
1471 internal struct FilterStruct
1473 public string filterName;
1474 public StringCollection filters;
1476 public FilterStruct( string filterName, string filter )
1478 this.filterName = filterName;
1480 filters = new StringCollection( );
1482 SplitFilters( filter );
1485 private void SplitFilters( string filter )
1487 string[] split = filter.Split( new Char[] {';'} );
1489 filters.AddRange( split );
1493 internal struct FileStruct
1495 public FileStruct( string fullname, FileAttributes attributes )
1497 this.fullname = fullname;
1498 this.attributes = attributes;
1501 public string fullname;
1502 public FileAttributes attributes;
1506 internal class MWFFileView : ListView
1508 // private ImageList fileViewSmallImageList = new ImageList();
1509 // private ImageList fileViewBigImageList = new ImageList();
1511 private ArrayList filterArrayList;
1512 // store the FileStruct of all files in the current directory
1513 private Hashtable fileHashtable = new Hashtable();
1515 private bool showHiddenFiles = false;
1517 private EventHandler on_selected_file_changed;
1518 private EventHandler on_selected_files_changed;
1519 private EventHandler on_directory_changed;
1520 private EventHandler on_force_dialog_end;
1522 private string fileName;
1523 private string fullFileName;
1524 private string selectedFilesString;
1526 private int filterIndex;
1528 public MWFFileView( )
1530 SmallImageList = MimeIconEngine.SmallIcons;
1531 LargeImageList = MimeIconEngine.LargeIcons;
1536 public ArrayList FilterArrayList
1539 filterArrayList = value;
1543 return filterArrayList;
1547 public Hashtable FileHashtable
1550 fileHashtable = value;
1554 return fileHashtable;
1558 public bool ShowHiddenFiles
1561 showHiddenFiles = value;
1565 return showHiddenFiles;
1569 public string FileName
1580 public string FullFileName
1583 fullFileName = value;
1587 return fullFileName;
1591 public int FilterIndex
1594 filterIndex = value;
1602 public string SelectedFilesString
1605 selectedFilesString = value;
1609 return selectedFilesString;
1613 private ArrayList GetFileInfoArrayList( DirectoryInfo directoryInfo )
1615 ArrayList arrayList = new ArrayList( );
1617 if ( filterArrayList != null && filterArrayList.Count != 0 )
1619 FilterStruct fs = (FilterStruct)filterArrayList[ filterIndex - 1 ];
1621 foreach ( string s in fs.filters )
1622 arrayList.AddRange( directoryInfo.GetFiles( s ) );
1625 arrayList.AddRange( directoryInfo.GetFiles( ) );
1630 public void UpdateFileView( DirectoryInfo inputDirectoryInfo )
1632 DirectoryInfo directoryInfo = inputDirectoryInfo;
1634 DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories( );
1636 ArrayList fileInfoArrayList = GetFileInfoArrayList( directoryInfo );
1638 fileHashtable.Clear( );
1643 SelectedItems.Clear( );
1645 foreach ( DirectoryInfo directoryInfoi in directoryInfoArray )
1647 if ( !ShowHiddenFiles )
1648 if ( directoryInfoi.Name.StartsWith( "." ) || directoryInfoi.Attributes == FileAttributes.Hidden )
1651 FileStruct fileStruct = new FileStruct( );
1653 fileStruct.fullname = directoryInfoi.FullName;
1655 ListViewItem listViewItem = new ListViewItem( directoryInfoi.Name );
1657 int index = MimeIconEngine.GetIconIndexForMimeType( "inode/directory" );
1659 listViewItem.ImageIndex = index;
1661 listViewItem.SubItems.Add( "" );
1662 listViewItem.SubItems.Add( "Directory" );
1663 listViewItem.SubItems.Add( directoryInfoi.LastAccessTime.ToShortDateString( ) + " " + directoryInfoi.LastAccessTime.ToShortTimeString( ) );
1665 fileStruct.attributes = FileAttributes.Directory;
1667 fileHashtable.Add( directoryInfoi.Name, fileStruct );
1669 Items.Add( listViewItem );
1672 foreach ( FileInfo fileInfo in fileInfoArrayList )
1674 if ( !ShowHiddenFiles )
1675 if ( fileInfo.Name.StartsWith( "." ) || fileInfo.Attributes == FileAttributes.Hidden )
1678 FileStruct fileStruct = new FileStruct( );
1680 fileStruct.fullname = fileInfo.FullName;
1682 ListViewItem listViewItem = new ListViewItem( fileInfo.Name );
1684 listViewItem.ImageIndex = MimeIconEngine.GetIconIndexForFile( fileStruct.fullname );
1687 if ( fileInfo.Length > 1024 )
1688 fileLen = fileInfo.Length / 1024;
1690 listViewItem.SubItems.Add( fileLen.ToString( ) + " KB" );
1691 listViewItem.SubItems.Add( "File" );
1692 listViewItem.SubItems.Add( fileInfo.LastAccessTime.ToShortDateString( ) + " " + fileInfo.LastAccessTime.ToShortTimeString( ) );
1694 fileStruct.attributes = FileAttributes.Normal;
1696 fileHashtable.Add( fileInfo.Name, fileStruct );
1698 Items.Add( listViewItem );
1704 protected override void OnClick( EventArgs e )
1708 if ( SelectedItems.Count > 0 )
1710 ListViewItem listViewItem = SelectedItems[ 0 ];
1712 FileStruct fileStruct = (FileStruct)fileHashtable[ listViewItem.Text ];
1714 if ( fileStruct.attributes != FileAttributes.Directory )
1716 fileName = listViewItem.Text;
1717 fullFileName = fileStruct.fullname;
1719 if ( on_selected_file_changed != null )
1720 on_selected_file_changed( this, EventArgs.Empty );
1728 protected override void OnDoubleClick( EventArgs e )
1730 if ( SelectedItems.Count > 0 )
1732 ListViewItem listViewItem = SelectedItems[ 0 ];
1734 FileStruct fileStruct = (FileStruct)fileHashtable[ listViewItem.Text ];
1736 if ( fileStruct.attributes == FileAttributes.Directory )
1738 fullFileName = fileStruct.fullname;
1740 if ( on_directory_changed != null )
1741 on_directory_changed( this, EventArgs.Empty );
1745 fileName = listViewItem.Text;
1746 fullFileName = fileStruct.fullname;
1748 if ( on_selected_file_changed != null )
1749 on_selected_file_changed( this, EventArgs.Empty );
1751 if ( on_force_dialog_end != null )
1752 on_force_dialog_end( this, EventArgs.Empty );
1758 base.OnDoubleClick( e );
1761 protected override void OnSelectedIndexChanged( EventArgs e )
1765 if ( SelectedItems.Count > 0 )
1767 selectedFilesString = "";
1769 if ( SelectedItems.Count == 1 )
1771 FileStruct fileStruct = (FileStruct)fileHashtable[ SelectedItems[ 0 ].Text ];
1773 if ( fileStruct.attributes != FileAttributes.Directory )
1774 selectedFilesString = SelectedItems[ 0 ].Text;
1778 foreach ( ListViewItem lvi in SelectedItems )
1780 FileStruct fileStruct = (FileStruct)fileHashtable[ lvi.Text ];
1782 if ( fileStruct.attributes != FileAttributes.Directory )
1783 selectedFilesString += "\"" + lvi.Text + "\" ";
1787 if ( on_selected_files_changed != null )
1788 on_selected_files_changed( this, EventArgs.Empty );
1792 base.OnSelectedIndexChanged( e );
1795 public event EventHandler SelectedFileChanged
1797 add { on_selected_file_changed += value; }
1798 remove { on_selected_file_changed -= value; }
1801 public event EventHandler SelectedFilesChanged
1803 add { on_selected_files_changed += value; }
1804 remove { on_selected_files_changed -= value; }
1807 public event EventHandler DirectoryChanged
1809 add { on_directory_changed += value; }
1810 remove { on_directory_changed -= value; }
1813 public event EventHandler ForceDialogEnd
1815 add { on_force_dialog_end += value; }
1816 remove { on_force_dialog_end -= value; }
1820 internal class FileFilter
1822 private ArrayList filterArrayList = new ArrayList();
1824 private string filter;
1826 public FileFilter( )
1829 public FileFilter( string filter )
1831 this.filter = filter;
1836 public ArrayList FilterArrayList
1839 filterArrayList = value;
1843 return filterArrayList;
1847 public string Filter
1860 private void SplitFilter( )
1862 filterArrayList.Clear( );
1864 if ( filter == null )
1865 throw new NullReferenceException( "Filter" );
1867 if ( filter.Length == 0 )
1870 string[] filters = filter.Split( new Char[] {'|'} );
1872 if ( ( filters.Length % 2 ) != 0 )
1873 throw new ArgumentException( "Filter" );
1875 for ( int i = 0; i < filters.Length; i += 2 )
1877 FilterStruct filterStruct = new FilterStruct( filters[ i ], filters[ i + 1 ] );
1879 filterArrayList.Add( filterStruct );
1884 internal class DirComboBox : ComboBox
1886 internal class DirComboBoxItem
1888 private int imageIndex;
1889 private string name;
1890 private string path;
1893 public DirComboBoxItem( int imageIndex, string name, string path, int xPos )
1895 this.imageIndex = imageIndex;
1901 public int ImageIndex
1946 private ImageList imageList = new ImageList();
1948 private string currentPath;
1950 private bool firstTime = true;
1952 private EventHandler on_directory_changed;
1954 public DirComboBox( )
1956 DrawMode = DrawMode.OwnerDrawFixed;
1958 imageList.ColorDepth = ColorDepth.Depth32Bit;
1959 imageList.ImageSize = new Size( 16, 16 );
1960 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", imageList.ImageSize ) );
1961 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", imageList.ImageSize ) );
1962 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "inode/directory", imageList.ImageSize ) );
1963 imageList.TransparentColor = Color.Transparent;
1965 Items.AddRange( new object[] {
1966 new DirComboBoxItem( 0, "Desktop", Environment.GetFolderPath( Environment.SpecialFolder.Desktop ), 0 ),
1967 new DirComboBoxItem( 1, "Home", Environment.GetFolderPath( Environment.SpecialFolder.Personal ), 0 )
1972 public string CurrentPath
1975 currentPath = value;
1984 private void ShowPath( )
1986 DirectoryInfo di = new DirectoryInfo( currentPath );
1988 Stack dirStack = new Stack( );
1990 dirStack.Push( di );
1992 while ( di.Parent != null )
1995 dirStack.Push( di );
2002 Items.AddRange( new object[] {
2003 new DirComboBoxItem( 0, "Desktop", Environment.GetFolderPath( Environment.SpecialFolder.Desktop ), 0 ),
2004 new DirComboBoxItem( 1, "Home", Environment.GetFolderPath( Environment.SpecialFolder.Personal ), 0 )
2012 while ( dirStack.Count != 0 )
2014 DirectoryInfo dii = (DirectoryInfo)dirStack.Pop( );
2015 sel = Items.Add( new DirComboBoxItem( 2, dii.Name, dii.FullName, xPos + 4 ) );
2020 SelectedIndex = sel;
2025 protected override void OnDrawItem( DrawItemEventArgs e )
2027 if ( e.Index == -1 )
2030 Bitmap bmp = new Bitmap( e.Bounds.Width, e.Bounds.Height, e.Graphics );
2031 Graphics gr = Graphics.FromImage( bmp );
2033 DirComboBoxItem dcbi = Items[ e.Index ] as DirComboBoxItem;
2035 Color backColor = e.BackColor;
2036 Color foreColor = e.ForeColor;
2038 int xPos = dcbi.XPos;
2040 // Bug in ComboBox !!!!!
2041 // we never receive DrawItemState.ComboBoxEdit
2042 if ( ( e.State & DrawItemState.ComboBoxEdit ) != 0 )
2045 if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected )
2047 backColor = ThemeEngine.Current.ColorHighlight;
2048 foreColor = ThemeEngine.Current.ColorHighlightText;
2051 gr.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( backColor ), new Rectangle( 0, 0, bmp.Width, bmp.Height ) );
2053 gr.DrawString( dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush( foreColor ), new Point( 24 + xPos, ( bmp.Height - e.Font.Height ) / 2 ) );
2054 gr.DrawImage( imageList.Images[ dcbi.ImageIndex ], new Rectangle( new Point( xPos + 2, 0 ), new Size( 16, 16 ) ) );
2056 e.Graphics.DrawImage( bmp, e.Bounds.X, e.Bounds.Y );
2061 protected override void OnSelectedIndexChanged( EventArgs e )
2063 // do not call ChangeDirectory when invoked from FileDialogPanel ctor...
2070 if ( Items.Count > 0 )
2072 DirComboBoxItem dcbi = Items[ SelectedIndex ] as DirComboBoxItem;
2074 currentPath = dcbi.Path;
2076 if ( on_directory_changed != null )
2077 on_directory_changed( this, EventArgs.Empty );
2081 public event EventHandler DirectoryChanged
2083 add { on_directory_changed += value; }
2084 remove { on_directory_changed -= value; }