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 fileFromComboBox = Path.Combine( currentDirectoryName, fileFromComboBox );
856 if ( currentFileName != fileFromComboBox )
857 currentFileName = fileFromComboBox;
859 if ( currentFileName.Length == 0 )
863 if ( fileDialog.fileDialogType == FileDialogType.OpenFileDialog )
865 if ( fileDialog.CheckFileExists )
867 if ( !File.Exists( currentFileName ) )
869 string message = currentFileName + " doesn't exist. Please verify that you have entered the correct file name.";
870 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
872 currentFileName = "";
878 else // FileDialogType == SaveFileDialog
880 if ( fileDialog.OverwritePrompt )
882 if ( File.Exists( currentFileName ) )
884 string message = currentFileName + " exists. Overwrite ?";
885 DialogResult dr = MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
887 if ( dr == DialogResult.Cancel )
889 currentFileName = "";
896 if ( fileDialog.CreatePrompt )
898 if ( !File.Exists( currentFileName ) )
900 string message = currentFileName + " doesn't exist. Create ?";
901 DialogResult dr = MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
903 if ( dr == DialogResult.Cancel )
905 currentFileName = "";
913 if ( fileDialog.fileDialogType == FileDialogType.SaveFileDialog )
915 if ( fileDialog.AddExtension && fileDialog.DefaultExt.Length > 0 )
917 if ( !currentFileName.EndsWith( fileDialog.DefaultExt ) )
919 currentFileName += "." + fileDialog.DefaultExt;
924 fileDialog.FileName = currentFileName;
926 else // multiSelect = true
927 if ( fileDialog.fileDialogType != FileDialogType.SaveFileDialog )
929 if ( mwfFileView.SelectedItems.Count > 0 )
931 // first remove all selected directories
932 ArrayList al = new ArrayList( );
934 foreach ( ListViewItem lvi in mwfFileView.SelectedItems )
936 FileStruct fileStruct = (FileStruct)mwfFileView.FileHashtable[ lvi.Text ];
938 if ( fileStruct.attributes != FileAttributes.Directory )
940 al.Add( fileStruct );
944 fileDialog.FileName = ( (FileStruct)al[ 0 ] ).fullname;
946 string[] filenames = new string[ al.Count ];
948 for ( int i = 0; i < al.Count; i++ )
950 filenames[ i ] = ( (FileStruct)al[ i ] ).fullname;
953 fileDialog.SetFilenames( filenames );
957 if ( fileDialog.CheckPathExists )
959 if ( !Directory.Exists( currentDirectoryName ) )
961 string message = currentDirectoryName + " doesn't exist. Please verify that you have entered the correct directory name.";
962 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
964 if ( fileDialog.InitialDirectory == String.Empty )
965 currentDirectoryName = Environment.CurrentDirectory;
967 currentDirectoryName = fileDialog.InitialDirectory;
973 if ( fileDialog.RestoreDirectory )
974 currentDirectoryName = restoreDirectory;
976 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
978 cancelEventArgs.Cancel = false;
980 fileDialog.OnFileOk( cancelEventArgs );
982 fileDialog.form.Controls.Remove( this );
983 fileDialog.form.DialogResult = DialogResult.OK;
986 void OnClickCancelButton( object sender, EventArgs e )
988 if ( fileDialog.RestoreDirectory )
989 currentDirectoryName = restoreDirectory;
991 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
993 cancelEventArgs.Cancel = true;
995 fileDialog.OnFileOk( cancelEventArgs );
997 fileDialog.form.Controls.Remove( this );
998 fileDialog.form.DialogResult = DialogResult.Cancel;
1001 void OnClickHelpButton( object sender, EventArgs e )
1003 fileDialog.SendHelpRequest( e );
1006 void OnClickSmallButtonToolBar( object sender, ToolBarButtonClickEventArgs e )
1008 if ( e.Button == upToolBarButton )
1010 if ( directoryInfo.Parent != null )
1012 PushDirectory( directoryInfo );
1014 directoryInfo = directoryInfo.Parent;
1016 currentDirectoryName = directoryInfo.FullName;
1018 dirComboBox.CurrentPath = currentDirectoryName;
1020 mwfFileView.UpdateFileView( directoryInfo );
1024 if ( e.Button == backToolBarButton )
1026 if ( directoryStack.Count != 0 )
1030 dirComboBox.CurrentPath = currentDirectoryName;
1032 mwfFileView.UpdateFileView( directoryInfo );
1036 if ( e.Button == newdirToolBarButton )
1042 void OnClickMenuToolBarContextMenu( object sender, EventArgs e )
1044 MenuItem senderMenuItem = (MenuItem)sender;
1046 previousCheckedMenuItem.Checked = false;
1047 senderMenuItem.Checked = true;
1048 previousCheckedMenuItem = senderMenuItem;
1052 switch ( senderMenuItem.Index )
1055 mwfFileView.View = View.SmallIcon;
1058 mwfFileView.View = View.LargeIcon;
1061 mwfFileView.View = View.LargeIcon;
1064 mwfFileView.View = View.List;
1067 mwfFileView.View = View.Details;
1074 mwfFileView.UpdateFileView( directoryInfo );
1077 void OnKeyUpFileNameComboBox( object sender, KeyEventArgs e )
1079 if ( e.KeyCode == Keys.Enter )
1081 currentFileName = currentDirectoryName + fileNameComboBox.Text;
1086 void OnSelectedIndexChangedFileTypeComboBox( object sender, EventArgs e )
1088 fileDialog.FilterIndex = fileTypeComboBox.SelectedIndex + 1;
1090 mwfFileView.FilterIndex = fileDialog.FilterIndex;
1092 mwfFileView.UpdateFileView( directoryInfo );
1095 void OnSelectedFileChangedFileView( object sender, EventArgs e )
1097 fileNameComboBox.Text = mwfFileView.FileName;
1098 currentFileName = mwfFileView.FullFileName;
1101 void OnDirectoryChangedFileView( object sender, EventArgs e )
1103 ChangeDirectory( sender, mwfFileView.FullFileName );
1106 void OnForceDialogEndFileView( object sender, EventArgs e )
1111 void OnSelectedFilesChangedFileView( object sender, EventArgs e )
1113 fileNameComboBox.Text = mwfFileView.SelectedFilesString;
1116 void OnDirectoryChangedDirComboBox( object sender, EventArgs e )
1118 ChangeDirectory( sender, dirComboBox.CurrentPath );
1121 void OnCheckCheckChanged( object sender, EventArgs e )
1123 fileDialog.ReadOnlyChecked = checkBox.Checked;
1126 public void UpdateFilters( )
1128 ArrayList filters = fileDialog.FileFilter.FilterArrayList;
1130 fileTypeComboBox.Items.Clear( );
1132 fileTypeComboBox.BeginUpdate( );
1134 foreach ( FilterStruct fs in filters )
1136 fileTypeComboBox.Items.Add( fs.filterName );
1139 fileTypeComboBox.SelectedIndex = fileDialog.FilterIndex - 1;
1141 fileTypeComboBox.EndUpdate( );
1143 mwfFileView.FilterArrayList = filters;
1145 mwfFileView.FilterIndex = fileDialog.FilterIndex;
1147 mwfFileView.UpdateFileView( directoryInfo );
1150 public void ChangeDirectory( object sender, string path )
1152 currentDirectoryName = path;
1154 PushDirectory( directoryInfo );
1156 directoryInfo = new DirectoryInfo( path );
1158 if ( sender != dirComboBox )
1159 dirComboBox.CurrentPath = path;
1161 mwfFileView.UpdateFileView( directoryInfo );
1164 public void ForceDialogEnd( )
1166 OnClickOpenSaveButton( this, EventArgs.Empty );
1169 private void PushDirectory( DirectoryInfo di )
1171 directoryStack.Push( directoryInfo );
1172 backToolBarButton.Enabled = true;
1175 private void PopDirectory( )
1177 directoryInfo = (DirectoryInfo)directoryStack.Pop( );
1179 currentDirectoryName = directoryInfo.FullName;
1181 if ( directoryStack.Count == 0 )
1182 backToolBarButton.Enabled = false;
1185 public void ResizeAndRelocateForHelpOrReadOnly( )
1187 if ( fileDialog.ShowHelp || fileDialog.ShowReadOnly )
1189 mwfFileView.Size = new Size( 449, 250 );
1190 fileNameLabel.Location = new Point( 102, 298 );
1191 fileNameComboBox.Location = new Point( 195, 298 );
1192 fileTypeLabel.Location = new Point( 102, 324 );
1193 fileTypeComboBox.Location = new Point( 195, 324 );
1194 openSaveButton.Location = new Point( 475, 298 );
1195 cancelButton.Location = new Point( 475, 324 );
1199 mwfFileView.Size = new Size( 449, 282 );
1200 fileNameLabel.Location = new Point( 102, 330 );
1201 fileNameComboBox.Location = new Point( 195, 330 );
1202 fileTypeLabel.Location = new Point( 102, 356 );
1203 fileTypeComboBox.Location = new Point( 195, 356 );
1204 openSaveButton.Location = new Point( 475, 330 );
1205 cancelButton.Location = new Point( 475, 356 );
1208 if ( fileDialog.ShowHelp )
1211 if ( fileDialog.ShowReadOnly )
1215 internal class PopupButtonPanel : Panel
1217 internal class PopupButton : Control
1219 internal enum PopupButtonState
1222 private Image image = null;
1223 private PopupButtonState popupButtonState = PopupButtonState.Normal;
1224 private StringFormat text_format = new StringFormat();
1226 public PopupButton( )
1228 text_format.Alignment = StringAlignment.Center;
1229 text_format.LineAlignment = StringAlignment.Far;
1231 SetStyle( ControlStyles.DoubleBuffer, true );
1232 SetStyle( ControlStyles.AllPaintingInWmPaint, true );
1233 SetStyle( ControlStyles.UserPaint, true );
1248 public PopupButtonState ButtonState
1251 popupButtonState = value;
1256 return popupButtonState;
1260 protected override void OnPaint( PaintEventArgs pe )
1267 private void Draw( PaintEventArgs pe )
1269 Graphics gr = pe.Graphics;
1271 gr.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( BackColor ), ClientRectangle );
1274 if ( image != null )
1276 int i_x = ( ClientSize.Width - image.Width ) / 2;
1278 gr.DrawImage( image, i_x, i_y );
1281 if ( Text != String.Empty )
1283 Rectangle text_rect = Rectangle.Inflate( ClientRectangle, -4, -4 );
1285 gr.DrawString( Text, Font, ThemeEngine.Current.ResPool.GetSolidBrush( ForeColor ), text_rect, text_format );
1288 switch ( popupButtonState )
1290 case PopupButtonState.Up:
1291 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, 0, ClientSize.Width - 1, 0 );
1292 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, 0, 0, ClientSize.Height - 1 );
1293 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1 );
1294 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1 );
1297 case PopupButtonState.Down:
1298 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, 0, ClientSize.Width - 1, 0 );
1299 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, 0, 0, ClientSize.Height - 1 );
1300 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1 );
1301 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1 );
1306 protected override void OnMouseEnter( EventArgs e )
1308 if ( popupButtonState != PopupButtonState.Down )
1309 popupButtonState = PopupButtonState.Up;
1311 base.OnMouseEnter( e );
1314 protected override void OnMouseLeave( EventArgs e )
1316 if ( popupButtonState != PopupButtonState.Down )
1317 popupButtonState = PopupButtonState.Normal;
1319 base.OnMouseLeave( e );
1322 protected override void OnClick( EventArgs e )
1324 popupButtonState = PopupButtonState.Down;
1330 private FileDialogPanel fileDialogPanel;
1332 private PopupButton lastOpenButton;
1333 private PopupButton desktopButton;
1334 private PopupButton homeButton;
1335 private PopupButton workplaceButton;
1336 private PopupButton networkButton;
1338 private PopupButton lastPopupButton = null;
1340 private ImageList imageList = new ImageList();
1342 public PopupButtonPanel( FileDialogPanel fileDialogPanel )
1344 this.fileDialogPanel = fileDialogPanel;
1346 BorderStyle = BorderStyle.Fixed3D;
1347 BackColor = Color.FromArgb( 128, 128, 128 );
1348 Size = new Size( 85, 336 );
1350 // use ImageList to scale the bitmaps
1351 imageList.ColorDepth = ColorDepth.Depth32Bit;
1352 imageList.ImageSize = new Size( 38, 38 );
1353 imageList.Images.Add( (Image)Locale.GetResource( "last_open" ) );
1354 //imageList.Images.Add( (Image)Locale.GetResource( "desktop" ) );
1355 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", imageList.ImageSize ) );
1356 //imageList.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
1357 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", imageList.ImageSize ) );
1358 imageList.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
1359 //imageList.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
1360 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "network/network", imageList.ImageSize ) );
1361 imageList.TransparentColor = Color.Transparent;
1363 lastOpenButton = new PopupButton( );
1364 desktopButton = new PopupButton( );
1365 homeButton = new PopupButton( );
1366 workplaceButton = new PopupButton( );
1367 networkButton = new PopupButton( );
1369 lastOpenButton.Size = new Size( 82, 64 );
1370 lastOpenButton.Image = imageList.Images[ 0 ];
1371 lastOpenButton.BackColor = BackColor;
1372 lastOpenButton.ForeColor = Color.White;
1373 lastOpenButton.Location = new Point( 2, 2 );
1374 lastOpenButton.Text = "Last Open";
1375 lastOpenButton.Click += new EventHandler( OnClickButton );
1377 desktopButton.Image = imageList.Images[ 1 ];
1378 desktopButton.BackColor = BackColor;
1379 desktopButton.ForeColor = Color.White;
1380 desktopButton.Size = new Size( 82, 64 );
1381 desktopButton.Location = new Point( 2, 66 );
1382 desktopButton.Text = "Desktop";
1383 desktopButton.Click += new EventHandler( OnClickButton );
1385 homeButton.Image = imageList.Images[ 2 ];
1386 homeButton.BackColor = BackColor;
1387 homeButton.ForeColor = Color.White;
1388 homeButton.Size = new Size( 82, 64 );
1389 homeButton.Location = new Point( 2, 130 );
1390 homeButton.Text = "Home";
1391 homeButton.Click += new EventHandler( OnClickButton );
1393 workplaceButton.Image = imageList.Images[ 3 ];
1394 workplaceButton.BackColor = BackColor;
1395 workplaceButton.ForeColor = Color.White;
1396 workplaceButton.Size = new Size( 82, 64 );
1397 workplaceButton.Location = new Point( 2, 194 );
1398 workplaceButton.Text = "Workplace";
1399 workplaceButton.Click += new EventHandler( OnClickButton );
1401 networkButton.Image = imageList.Images[ 4 ];
1402 networkButton.BackColor = BackColor;
1403 networkButton.ForeColor = Color.White;
1404 networkButton.Size = new Size( 82, 64 );
1405 networkButton.Location = new Point( 2, 258 );
1406 networkButton.Text = "Network";
1407 networkButton.Click += new EventHandler( OnClickButton );
1409 Controls.Add( lastOpenButton );
1410 Controls.Add( desktopButton );
1411 Controls.Add( homeButton );
1412 Controls.Add( workplaceButton );
1413 Controls.Add( networkButton );
1416 void OnClickButton( object sender, EventArgs e )
1418 if ( lastPopupButton != null && (PopupButton)sender != lastPopupButton )
1419 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1420 lastPopupButton = sender as PopupButton;
1422 if ( sender == lastOpenButton )
1427 if ( sender == desktopButton )
1429 fileDialogPanel.ChangeDirectory( this, Environment.GetFolderPath( Environment.SpecialFolder.Desktop ) );
1432 if ( sender == homeButton )
1434 fileDialogPanel.ChangeDirectory( this, Environment.GetFolderPath( Environment.SpecialFolder.Personal ) );
1437 if ( sender == workplaceButton )
1439 // fileDialogPanel.ChangeDirectory(this, Environment.GetFolderPath( Environment.SpecialFolder.MyComputer ) );
1442 if ( sender == networkButton )
1451 internal struct FilterStruct
1453 public string filterName;
1454 public StringCollection filters;
1456 public FilterStruct( string filterName, string filter )
1458 this.filterName = filterName;
1460 filters = new StringCollection( );
1462 SplitFilters( filter );
1465 private void SplitFilters( string filter )
1467 string[] split = filter.Split( new Char[] {';'} );
1469 filters.AddRange( split );
1473 internal struct FileStruct
1475 public FileStruct( string fullname, FileAttributes attributes )
1477 this.fullname = fullname;
1478 this.attributes = attributes;
1481 public string fullname;
1482 public FileAttributes attributes;
1486 internal class MWFFileView : ListView
1488 // private ImageList fileViewSmallImageList = new ImageList();
1489 // private ImageList fileViewBigImageList = new ImageList();
1491 private ArrayList filterArrayList;
1492 // store the FileStruct of all files in the current directory
1493 private Hashtable fileHashtable = new Hashtable();
1495 private bool showHiddenFiles = false;
1497 private EventHandler on_selected_file_changed;
1498 private EventHandler on_selected_files_changed;
1499 private EventHandler on_directory_changed;
1500 private EventHandler on_force_dialog_end;
1502 private string fileName;
1503 private string fullFileName;
1504 private string selectedFilesString;
1506 private int filterIndex;
1508 public MWFFileView( )
1510 SmallImageList = MimeIconEngine.SmallIcons;
1511 LargeImageList = MimeIconEngine.LargeIcons;
1516 public ArrayList FilterArrayList
1519 filterArrayList = value;
1523 return filterArrayList;
1527 public Hashtable FileHashtable
1530 fileHashtable = value;
1534 return fileHashtable;
1538 public bool ShowHiddenFiles
1541 showHiddenFiles = value;
1545 return showHiddenFiles;
1549 public string FileName
1560 public string FullFileName
1563 fullFileName = value;
1567 return fullFileName;
1571 public int FilterIndex
1574 filterIndex = value;
1582 public string SelectedFilesString
1585 selectedFilesString = value;
1589 return selectedFilesString;
1593 private ArrayList GetFileInfoArrayList( DirectoryInfo directoryInfo )
1595 ArrayList arrayList = new ArrayList( );
1597 if ( filterArrayList != null && filterArrayList.Count != 0 )
1599 FilterStruct fs = (FilterStruct)filterArrayList[ filterIndex - 1 ];
1601 foreach ( string s in fs.filters )
1602 arrayList.AddRange( directoryInfo.GetFiles( s ) );
1605 arrayList.AddRange( directoryInfo.GetFiles( ) );
1610 public void UpdateFileView( DirectoryInfo inputDirectoryInfo )
1612 DirectoryInfo directoryInfo = inputDirectoryInfo;
1614 DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories( );
1616 ArrayList fileInfoArrayList = GetFileInfoArrayList( directoryInfo );
1618 fileHashtable.Clear( );
1623 SelectedItems.Clear( );
1625 foreach ( DirectoryInfo directoryInfoi in directoryInfoArray )
1627 if ( !ShowHiddenFiles )
1628 if ( directoryInfoi.Name.StartsWith( "." ) || directoryInfoi.Attributes == FileAttributes.Hidden )
1631 FileStruct fileStruct = new FileStruct( );
1633 fileStruct.fullname = directoryInfoi.FullName;
1635 ListViewItem listViewItem = new ListViewItem( directoryInfoi.Name );
1637 int index = MimeIconEngine.GetIconIndexForMimeType( "inode/directory" );
1639 listViewItem.ImageIndex = index;
1641 listViewItem.SubItems.Add( "" );
1642 listViewItem.SubItems.Add( "Directory" );
1643 listViewItem.SubItems.Add( directoryInfoi.LastAccessTime.ToShortDateString( ) + " " + directoryInfoi.LastAccessTime.ToShortTimeString( ) );
1645 fileStruct.attributes = FileAttributes.Directory;
1647 fileHashtable.Add( directoryInfoi.Name, fileStruct );
1649 Items.Add( listViewItem );
1652 foreach ( FileInfo fileInfo in fileInfoArrayList )
1654 if ( !ShowHiddenFiles )
1655 if ( fileInfo.Name.StartsWith( "." ) || fileInfo.Attributes == FileAttributes.Hidden )
1658 FileStruct fileStruct = new FileStruct( );
1660 fileStruct.fullname = fileInfo.FullName;
1662 ListViewItem listViewItem = new ListViewItem( fileInfo.Name );
1664 listViewItem.ImageIndex = MimeIconEngine.GetIconIndexForFile( fileStruct.fullname );
1667 if ( fileInfo.Length > 1024 )
1668 fileLen = fileInfo.Length / 1024;
1670 listViewItem.SubItems.Add( fileLen.ToString( ) + " KB" );
1671 listViewItem.SubItems.Add( "File" );
1672 listViewItem.SubItems.Add( fileInfo.LastAccessTime.ToShortDateString( ) + " " + fileInfo.LastAccessTime.ToShortTimeString( ) );
1674 fileStruct.attributes = FileAttributes.Normal;
1676 fileHashtable.Add( fileInfo.Name, fileStruct );
1678 Items.Add( listViewItem );
1684 protected override void OnClick( EventArgs e )
1688 if ( SelectedItems.Count > 0 )
1690 ListViewItem listViewItem = SelectedItems[ 0 ];
1692 FileStruct fileStruct = (FileStruct)fileHashtable[ listViewItem.Text ];
1694 if ( fileStruct.attributes != FileAttributes.Directory )
1696 fileName = listViewItem.Text;
1697 fullFileName = fileStruct.fullname;
1699 if ( on_selected_file_changed != null )
1700 on_selected_file_changed( this, EventArgs.Empty );
1708 protected override void OnDoubleClick( EventArgs e )
1710 if ( SelectedItems.Count > 0 )
1712 ListViewItem listViewItem = SelectedItems[ 0 ];
1714 FileStruct fileStruct = (FileStruct)fileHashtable[ listViewItem.Text ];
1716 if ( fileStruct.attributes == FileAttributes.Directory )
1718 fullFileName = fileStruct.fullname;
1720 if ( on_directory_changed != null )
1721 on_directory_changed( this, EventArgs.Empty );
1725 fileName = listViewItem.Text;
1726 fullFileName = fileStruct.fullname;
1728 if ( on_selected_file_changed != null )
1729 on_selected_file_changed( this, EventArgs.Empty );
1731 if ( on_force_dialog_end != null )
1732 on_force_dialog_end( this, EventArgs.Empty );
1738 base.OnDoubleClick( e );
1741 protected override void OnSelectedIndexChanged( EventArgs e )
1745 if ( SelectedItems.Count > 0 )
1747 selectedFilesString = "";
1749 if ( SelectedItems.Count == 1 )
1751 FileStruct fileStruct = (FileStruct)fileHashtable[ SelectedItems[ 0 ].Text ];
1753 if ( fileStruct.attributes != FileAttributes.Directory )
1754 selectedFilesString = SelectedItems[ 0 ].Text;
1758 foreach ( ListViewItem lvi in SelectedItems )
1760 FileStruct fileStruct = (FileStruct)fileHashtable[ lvi.Text ];
1762 if ( fileStruct.attributes != FileAttributes.Directory )
1763 selectedFilesString += "\"" + lvi.Text + "\" ";
1767 if ( on_selected_files_changed != null )
1768 on_selected_files_changed( this, EventArgs.Empty );
1772 base.OnSelectedIndexChanged( e );
1775 public event EventHandler SelectedFileChanged
1777 add { on_selected_file_changed += value; }
1778 remove { on_selected_file_changed -= value; }
1781 public event EventHandler SelectedFilesChanged
1783 add { on_selected_files_changed += value; }
1784 remove { on_selected_files_changed -= value; }
1787 public event EventHandler DirectoryChanged
1789 add { on_directory_changed += value; }
1790 remove { on_directory_changed -= value; }
1793 public event EventHandler ForceDialogEnd
1795 add { on_force_dialog_end += value; }
1796 remove { on_force_dialog_end -= value; }
1800 internal class FileFilter
1802 private ArrayList filterArrayList = new ArrayList();
1804 private string filter;
1806 public FileFilter( )
1809 public FileFilter( string filter )
1811 this.filter = filter;
1816 public ArrayList FilterArrayList
1819 filterArrayList = value;
1823 return filterArrayList;
1827 public string Filter
1840 private void SplitFilter( )
1842 filterArrayList.Clear( );
1844 if ( filter == null )
1845 throw new NullReferenceException( "Filter" );
1847 if ( filter.Length == 0 )
1850 string[] filters = filter.Split( new Char[] {'|'} );
1852 if ( ( filters.Length % 2 ) != 0 )
1853 throw new ArgumentException( "Filter" );
1855 for ( int i = 0; i < filters.Length; i += 2 )
1857 FilterStruct filterStruct = new FilterStruct( filters[ i ], filters[ i + 1 ] );
1859 filterArrayList.Add( filterStruct );
1864 internal class DirComboBox : ComboBox
1866 internal class DirComboBoxItem
1868 private int imageIndex;
1869 private string name;
1870 private string path;
1873 public DirComboBoxItem( int imageIndex, string name, string path, int xPos )
1875 this.imageIndex = imageIndex;
1881 public int ImageIndex
1926 private ImageList imageList = new ImageList();
1928 private string currentPath;
1930 private bool firstTime = true;
1932 private EventHandler on_directory_changed;
1934 public DirComboBox( )
1936 DrawMode = DrawMode.OwnerDrawFixed;
1938 imageList.ColorDepth = ColorDepth.Depth32Bit;
1939 imageList.ImageSize = new Size( 16, 16 );
1940 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", imageList.ImageSize ) );
1941 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", imageList.ImageSize ) );
1942 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "inode/directory", imageList.ImageSize ) );
1943 imageList.TransparentColor = Color.Transparent;
1945 Items.AddRange( new object[] {
1946 new DirComboBoxItem( 0, "Desktop", Environment.GetFolderPath( Environment.SpecialFolder.Desktop ), 0 ),
1947 new DirComboBoxItem( 1, "Home", Environment.GetFolderPath( Environment.SpecialFolder.Personal ), 0 )
1952 public string CurrentPath
1955 currentPath = value;
1964 private void ShowPath( )
1966 DirectoryInfo di = new DirectoryInfo( currentPath );
1968 Stack dirStack = new Stack( );
1970 dirStack.Push( di );
1972 while ( di.Parent != null )
1975 dirStack.Push( di );
1982 Items.AddRange( new object[] {
1983 new DirComboBoxItem( 0, "Desktop", Environment.GetFolderPath( Environment.SpecialFolder.Desktop ), 0 ),
1984 new DirComboBoxItem( 1, "Home", Environment.GetFolderPath( Environment.SpecialFolder.Personal ), 0 )
1992 while ( dirStack.Count != 0 )
1994 DirectoryInfo dii = (DirectoryInfo)dirStack.Pop( );
1995 sel = Items.Add( new DirComboBoxItem( 2, dii.Name, dii.FullName, xPos + 4 ) );
2000 SelectedIndex = sel;
2005 protected override void OnDrawItem( DrawItemEventArgs e )
2007 if ( e.Index == -1 )
2010 Bitmap bmp = new Bitmap( e.Bounds.Width, e.Bounds.Height, e.Graphics );
2011 Graphics gr = Graphics.FromImage( bmp );
2013 DirComboBoxItem dcbi = Items[ e.Index ] as DirComboBoxItem;
2015 Color backColor = e.BackColor;
2016 Color foreColor = e.ForeColor;
2018 int xPos = dcbi.XPos;
2020 // Bug in ComboBox !!!!!
2021 // we never receive DrawItemState.ComboBoxEdit
2022 if ( ( e.State & DrawItemState.ComboBoxEdit ) != 0 )
2025 if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected )
2027 backColor = Color.Blue;
2028 foreColor = Color.White;
2031 gr.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( backColor ), new Rectangle( 0, 0, bmp.Width, bmp.Height ) );
2033 gr.DrawString( dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush( foreColor ), new Point( 24 + xPos, ( bmp.Height - e.Font.Height ) / 2 ) );
2034 gr.DrawImage( imageList.Images[ dcbi.ImageIndex ], new Rectangle( new Point( xPos + 2, 0 ), new Size( 16, 16 ) ) );
2036 e.Graphics.DrawImage( bmp, e.Bounds.X, e.Bounds.Y );
2039 protected override void OnSelectedIndexChanged( EventArgs e )
2041 // do not call ChangeDirectory when invoked from FileDialogPanel ctor...
2048 if ( Items.Count > 0 )
2050 DirComboBoxItem dcbi = Items[ SelectedIndex ] as DirComboBoxItem;
2052 currentPath = dcbi.Path;
2054 if ( on_directory_changed != null )
2055 on_directory_changed( this, EventArgs.Empty );
2059 public event EventHandler DirectoryChanged
2061 add { on_directory_changed += value; }
2062 remove { on_directory_changed -= value; }