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;
248 fileDialogPanel.ChangeDirectory( null, initialDirectory );
252 [DefaultValue(false)]
253 public bool RestoreDirectory
256 return restoreDirectory;
260 restoreDirectory = value;
264 [DefaultValue(false)]
273 fileDialogPanel.ResizeAndRelocateForHelpOrReadOnly( );
292 // this one is a hard one ;)
294 // - up to MAX_PATH characters (windef.h) = 260
295 // - no trailing dots or spaces
298 // NTFS/Posix filename:
299 // - up to 32,768 Unicode characters
300 // - trailing periods or spaces
304 public bool ValidateNames
307 return validateNames;
311 validateNames = value;
315 internal string OpenSaveButtonText
318 openSaveButtonText = value;
322 return openSaveButtonText;
326 internal string SearchSaveLabelText
329 searchSaveLabelText = value;
333 return searchSaveLabelText;
337 internal virtual bool ShowReadOnly
340 showReadOnly = value;
341 fileDialogPanel.ResizeAndRelocateForHelpOrReadOnly( );
349 internal virtual bool ReadOnlyChecked
352 readOnlyChecked = value;
353 fileDialogPanel.CheckBox.Checked = value;
357 return readOnlyChecked;
361 internal virtual bool Multiselect
365 fileDialogPanel.MultiSelect = value;
373 // extension to MS.NET framework...
374 // Must keep this internal, otherwise our signature doesn't match MS
375 internal bool ShowHiddenFiles
378 showHiddenFiles = value;
382 return showHiddenFiles;
386 internal virtual bool CreatePrompt
389 createPrompt = value;
397 internal virtual bool OverwritePrompt
400 overwritePrompt = value;
404 return overwritePrompt;
408 internal FileFilter FileFilter
419 public override void Reset( )
422 checkFileExists = false;
423 checkPathExists = true;
425 dereferenceLinks = true;
430 initialDirectory = "";
431 restoreDirectory = false;
434 validateNames = true;
436 fileDialogPanel.UpdateFilters( );
439 public override string ToString( )
441 return base.ToString( );
444 public event CancelEventHandler FileOk;
446 protected override IntPtr HookProc( IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam )
448 throw new NotImplementedException( );
451 protected void OnFileOk( CancelEventArgs e )
453 if ( FileOk != null ) FileOk( this, e );
457 protected override bool RunDialog( IntPtr hWndOwner )
459 form.Controls.Add( fileDialogPanel );
464 internal void SendHelpRequest( EventArgs e )
469 internal void SetFilenames( string[] filenames )
471 fileNames = filenames;
474 internal FileFilter fileFilter;
476 internal class FileDialogPanel : Panel
478 private Button cancelButton;
479 private ToolBarButton upToolBarButton;
480 private PopupButtonPanel popupButtonPanel;
481 private Button openSaveButton;
482 private Button helpButton;
483 private Label fileTypeLabel;
484 private ToolBarButton menueToolBarButton;
485 private ContextMenu menueToolBarButtonContextMenu;
486 private ToolBarButton desktopToolBarButton;
487 private ToolBar smallButtonToolBar;
488 private DirComboBox dirComboBox;
489 private ToolBarButton lastUsedToolBarButton;
490 private ComboBox fileNameComboBox;
491 private ToolBarButton networkToolBarButton;
492 private Label fileNameLabel;
493 private MWFFileView mwfFileView;
494 private Label searchSaveLabel;
495 private ToolBarButton newdirToolBarButton;
496 private ToolBarButton backToolBarButton;
497 private ToolBarButton homeToolBarButton;
498 private ToolBarButton workplaceToolBarButton;
499 private ComboBox fileTypeComboBox;
500 private ImageList imageListTopToolbar;
501 private ContextMenu contextMenu;
502 private CheckBox checkBox;
504 internal FileDialog fileDialog;
506 private string currentDirectoryName;
508 internal string currentFileName = "";
510 // store current directoryInfo
511 private DirectoryInfo directoryInfo;
513 // store DirectoryInfo for backButton
514 internal Stack directoryStack = new Stack();
516 private MenuItem previousCheckedMenuItem;
518 private bool multiSelect = false;
520 private string restoreDirectory = "";
522 public FileDialogPanel( FileDialog fileDialog )
524 this.fileDialog = fileDialog;
526 fileTypeComboBox = new ComboBox( );
527 workplaceToolBarButton = new ToolBarButton( );
528 homeToolBarButton = new ToolBarButton( );
529 backToolBarButton = new ToolBarButton( );
530 newdirToolBarButton = new ToolBarButton( );
531 searchSaveLabel = new Label( );
532 mwfFileView = new MWFFileView( );
533 fileNameLabel = new Label( );
534 networkToolBarButton = new ToolBarButton( );
535 fileNameComboBox = new ComboBox( );
536 lastUsedToolBarButton = new ToolBarButton( );
537 dirComboBox = new DirComboBox( );
538 smallButtonToolBar = new ToolBar( );
539 desktopToolBarButton = new ToolBarButton( );
540 menueToolBarButton = new ToolBarButton( );
541 fileTypeLabel = new Label( );
542 openSaveButton = new Button( );
543 fileDialog.form.AcceptButton = openSaveButton;
544 helpButton = new Button( );
545 popupButtonPanel = new PopupButtonPanel( this );
546 upToolBarButton = new ToolBarButton( );
547 cancelButton = new Button( );
548 fileDialog.form.CancelButton = cancelButton;
549 imageListTopToolbar = new ImageList( );
550 menueToolBarButtonContextMenu = new ContextMenu( );
551 contextMenu = new ContextMenu( );
552 checkBox = new CheckBox( );
556 //imageListTopToolbar
557 imageListTopToolbar.ColorDepth = ColorDepth.Depth32Bit;
558 imageListTopToolbar.ImageSize = new Size( 16, 16 ); // 16, 16
559 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "back_arrow" ) );
560 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_arrow_up" ) );
561 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_star" ) );
562 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "window" ) );
563 imageListTopToolbar.TransparentColor = Color.Transparent;
566 searchSaveLabel.FlatStyle = FlatStyle.System;
567 searchSaveLabel.Location = new Point( 7, 8 );
568 searchSaveLabel.Size = new Size( 72, 21 );
569 searchSaveLabel.TabIndex = 0;
570 searchSaveLabel.Text = fileDialog.SearchSaveLabelText;
571 searchSaveLabel.TextAlign = ContentAlignment.MiddleRight;
574 dirComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Top | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
575 dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
576 dirComboBox.Location = new Point( 99, 8 );
577 dirComboBox.Size = new Size( 260, 21 );
578 dirComboBox.TabIndex = 1;
580 // smallButtonToolBar
581 smallButtonToolBar.Anchor = ( (AnchorStyles)( ( AnchorStyles.Top | AnchorStyles.Right ) ) );
582 smallButtonToolBar.Appearance = ToolBarAppearance.Flat;
583 smallButtonToolBar.AutoSize = false;
584 smallButtonToolBar.Buttons.AddRange( new ToolBarButton[] {
588 menueToolBarButton} );
589 smallButtonToolBar.ButtonSize = new Size( 21, 16 ); // 21, 16
590 smallButtonToolBar.Divider = false;
591 smallButtonToolBar.Dock = DockStyle.None;
592 smallButtonToolBar.DropDownArrows = true;
593 smallButtonToolBar.ImageList = imageListTopToolbar;
594 smallButtonToolBar.Location = new Point( 372, 8 );
595 smallButtonToolBar.ShowToolTips = true;
596 smallButtonToolBar.Size = new Size( 110, 20 );
597 smallButtonToolBar.TabIndex = 2;
598 smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
601 popupButtonPanel.Dock = DockStyle.None;
602 popupButtonPanel.Location = new Point( 7, 37 );
603 popupButtonPanel.TabIndex = 3;
606 mwfFileView.Anchor = ( (AnchorStyles)( ( ( ( AnchorStyles.Top | AnchorStyles.Bottom ) | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
607 mwfFileView.Location = new Point( 99, 37 );
608 mwfFileView.Size = new Size( 449, 282 );
609 mwfFileView.Columns.Add( " Name", 170, HorizontalAlignment.Left );
610 mwfFileView.Columns.Add( "Size ", 80, HorizontalAlignment.Right );
611 mwfFileView.Columns.Add( " Type", 100, HorizontalAlignment.Left );
612 mwfFileView.Columns.Add( " Last Access", 150, HorizontalAlignment.Left );
613 mwfFileView.AllowColumnReorder = true;
614 mwfFileView.MultiSelect = false;
615 mwfFileView.TabIndex = 4;
616 mwfFileView.FilterIndex = fileDialog.FilterIndex;
619 fileNameLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
620 fileNameLabel.FlatStyle = FlatStyle.System;
621 fileNameLabel.Location = new Point( 102, 330 );
622 fileNameLabel.Size = new Size( 70, 21 );
623 fileNameLabel.TabIndex = 5;
624 fileNameLabel.Text = "Filename:";
625 fileNameLabel.TextAlign = ContentAlignment.MiddleLeft;
628 fileNameComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
629 fileNameComboBox.Location = new Point( 195, 330 );
630 fileNameComboBox.Size = new Size( 245, 21 );
631 fileNameComboBox.TabIndex = 6;
634 fileTypeLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
635 fileTypeLabel.FlatStyle = FlatStyle.System;
636 fileTypeLabel.Location = new Point( 102, 356 );
637 fileTypeLabel.Size = new Size( 70, 21 );
638 fileTypeLabel.TabIndex = 7;
639 fileTypeLabel.Text = "Filetype:";
640 fileTypeLabel.TextAlign = ContentAlignment.MiddleLeft;
643 fileTypeComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
644 fileTypeComboBox.Location = new Point( 195, 356 );
645 fileTypeComboBox.Size = new Size( 245, 21 );
646 fileTypeComboBox.TabIndex = 8;
649 backToolBarButton.ImageIndex = 0;
650 backToolBarButton.Enabled = false;
651 backToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
654 upToolBarButton.ImageIndex = 1;
655 upToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
657 // newdirToolBarButton
658 newdirToolBarButton.ImageIndex = 2;
659 newdirToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
661 // menueToolBarButton
662 menueToolBarButton.ImageIndex = 3;
663 menueToolBarButton.DropDownMenu = menueToolBarButtonContextMenu;
664 menueToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
666 // menueToolBarButtonContextMenu
667 MenuItem mi = new MenuItem( "Small Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
668 menueToolBarButtonContextMenu.MenuItems.Add( mi );
669 mi = new MenuItem( "Tiles", new EventHandler( OnClickMenuToolBarContextMenu ) );
670 menueToolBarButtonContextMenu.MenuItems.Add( mi );
671 mi = new MenuItem( "Large Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
672 menueToolBarButtonContextMenu.MenuItems.Add( mi );
673 mi = new MenuItem( "List", new EventHandler( OnClickMenuToolBarContextMenu ) );
675 previousCheckedMenuItem = mi;
676 menueToolBarButtonContextMenu.MenuItems.Add( mi );
677 mi = new MenuItem( "Details", new EventHandler( OnClickMenuToolBarContextMenu ) );
678 menueToolBarButtonContextMenu.MenuItems.Add( mi );
681 mi = new MenuItem( "Show hidden files", new EventHandler( OnClickContextMenu ) );
682 mi.Checked = fileDialog.ShowHiddenFiles;
683 mwfFileView.ShowHiddenFiles = fileDialog.ShowHiddenFiles;
684 contextMenu.MenuItems.Add( mi );
687 openSaveButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
688 openSaveButton.FlatStyle = FlatStyle.System;
689 openSaveButton.Location = new Point( 475, 330 );
690 openSaveButton.Size = new Size( 72, 21 );
691 openSaveButton.TabIndex = 9;
692 openSaveButton.Text = fileDialog.OpenSaveButtonText;
693 openSaveButton.FlatStyle = FlatStyle.System;
696 cancelButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
697 cancelButton.FlatStyle = FlatStyle.System;
698 cancelButton.Location = new Point( 475, 356 );
699 cancelButton.Size = new Size( 72, 21 );
700 cancelButton.TabIndex = 10;
701 cancelButton.Text = "Cancel";
702 cancelButton.FlatStyle = FlatStyle.System;
705 helpButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
706 helpButton.FlatStyle = FlatStyle.System;
707 helpButton.Location = new Point( 475, 350 );
708 helpButton.Size = new Size( 72, 21 );
709 helpButton.TabIndex = 11;
710 helpButton.Text = "Help";
711 helpButton.FlatStyle = FlatStyle.System;
715 checkBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
716 checkBox.Text = "Open Readonly";
717 checkBox.Location = new Point( 195, 350 );
718 checkBox.Size = new Size( 245, 21 );
719 checkBox.FlatStyle = FlatStyle.System;
720 checkBox.TabIndex = 12;
723 ClientSize = new Size( 554, 405 ); // 384
725 ContextMenu = contextMenu;
727 Dock = DockStyle.Fill;
729 Controls.Add( smallButtonToolBar );
730 Controls.Add( cancelButton );
731 Controls.Add( openSaveButton );
732 Controls.Add( helpButton );
733 Controls.Add( mwfFileView );
734 Controls.Add( fileTypeLabel );
735 Controls.Add( fileNameLabel );
736 Controls.Add( fileTypeComboBox );
737 Controls.Add( fileNameComboBox );
738 Controls.Add( dirComboBox );
739 Controls.Add( searchSaveLabel );
740 Controls.Add( popupButtonPanel );
741 Controls.Add( checkBox );
743 ResumeLayout( false );
745 currentDirectoryName = Environment.CurrentDirectory;
747 directoryInfo = new DirectoryInfo( currentDirectoryName );
749 dirComboBox.CurrentPath = currentDirectoryName;
751 if ( fileDialog.RestoreDirectory )
752 restoreDirectory = currentDirectoryName;
754 mwfFileView.UpdateFileView( directoryInfo );
756 openSaveButton.Click += new EventHandler( OnClickOpenSaveButton );
757 cancelButton.Click += new EventHandler( OnClickCancelButton );
758 helpButton.Click += new EventHandler( OnClickHelpButton );
760 smallButtonToolBar.ButtonClick += new ToolBarButtonClickEventHandler( OnClickSmallButtonToolBar );
762 // Key events DONT'T work
763 fileNameComboBox.KeyUp += new KeyEventHandler( OnKeyUpFileNameComboBox );
765 fileTypeComboBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFileTypeComboBox );
767 mwfFileView.SelectedFileChanged += new EventHandler( OnSelectedFileChangedFileView );
768 mwfFileView.DirectoryChanged += new EventHandler( OnDirectoryChangedFileView );
769 mwfFileView.ForceDialogEnd += new EventHandler( OnForceDialogEndFileView );
770 mwfFileView.SelectedFilesChanged += new EventHandler( OnSelectedFilesChangedFileView );
772 dirComboBox.DirectoryChanged += new EventHandler( OnDirectoryChangedDirComboBox );
774 checkBox.CheckedChanged += new EventHandler( OnCheckCheckChanged );
777 public ComboBox FileNameComboBox
780 fileNameComboBox = value;
784 return fileNameComboBox;
788 public string CurrentFileName
791 currentFileName = value;
795 return currentFileName;
799 public DirectoryInfo DirectoryInfo
802 directoryInfo = value;
806 return directoryInfo;
810 public bool MultiSelect
814 mwfFileView.MultiSelect = value;
822 public CheckBox CheckBox
833 void OnClickContextMenu( object sender, EventArgs e )
835 MenuItem senderMenuItem = sender as MenuItem;
837 if ( senderMenuItem.Index == 0 )
839 senderMenuItem.Checked = !senderMenuItem.Checked;
840 fileDialog.ShowHiddenFiles = senderMenuItem.Checked;
841 mwfFileView.ShowHiddenFiles = fileDialog.ShowHiddenFiles;
842 mwfFileView.UpdateFileView( directoryInfo );
846 void OnClickOpenSaveButton( object sender, EventArgs e )
850 string fileFromComboBox = fileNameComboBox.Text.Trim( );
852 if ( fileFromComboBox.Length > 0 ) {
853 if (!Path.IsPathRooted (fileFromComboBox))
854 fileFromComboBox = Path.Combine( currentDirectoryName, fileFromComboBox );
856 FileInfo fileInfo = new FileInfo (fileFromComboBox);
858 currentFileName = fileFromComboBox;
860 DirectoryInfo dirInfo = new DirectoryInfo (fileFromComboBox);
861 if (dirInfo.Exists) {
863 PushDirectory( dirInfo );
864 directoryInfo = dirInfo.Parent;
865 currentDirectoryName = dirInfo.FullName;
866 dirComboBox.CurrentPath = currentDirectoryName;
867 mwfFileView.UpdateFileView( dirInfo );
869 currentFileName = "";
875 if ( currentFileName != fileFromComboBox )
876 currentFileName = fileFromComboBox;
878 if ( currentFileName.Length == 0 )
882 if ( fileDialog.fileDialogType == FileDialogType.OpenFileDialog )
884 if ( fileDialog.CheckFileExists )
886 if ( !File.Exists( currentFileName ) )
888 string message = currentFileName + " doesn't exist. Please verify that you have entered the correct file name.";
889 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
891 currentFileName = "";
897 else // FileDialogType == SaveFileDialog
899 if ( fileDialog.OverwritePrompt )
901 if ( File.Exists( currentFileName ) )
903 string message = currentFileName + " exists. Overwrite ?";
904 DialogResult dr = MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
906 if ( dr == DialogResult.Cancel )
908 currentFileName = "";
915 if ( fileDialog.CreatePrompt )
917 if ( !File.Exists( currentFileName ) )
919 string message = currentFileName + " doesn't exist. Create ?";
920 DialogResult dr = MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
922 if ( dr == DialogResult.Cancel )
924 currentFileName = "";
932 if ( fileDialog.fileDialogType == FileDialogType.SaveFileDialog )
934 if ( fileDialog.AddExtension && fileDialog.DefaultExt.Length > 0 )
936 if ( !currentFileName.EndsWith( fileDialog.DefaultExt ) )
938 currentFileName += "." + fileDialog.DefaultExt;
943 fileDialog.FileName = currentFileName;
945 else // multiSelect = true
946 if ( fileDialog.fileDialogType != FileDialogType.SaveFileDialog )
948 if ( mwfFileView.SelectedItems.Count > 0 )
950 // first remove all selected directories
951 ArrayList al = new ArrayList( );
953 foreach ( ListViewItem lvi in mwfFileView.SelectedItems )
955 FileStruct fileStruct = (FileStruct)mwfFileView.FileHashtable[ lvi.Text ];
957 if ( fileStruct.attributes != FileAttributes.Directory )
959 al.Add( fileStruct );
963 fileDialog.FileName = ( (FileStruct)al[ 0 ] ).fullname;
965 string[] filenames = new string[ al.Count ];
967 for ( int i = 0; i < al.Count; i++ )
969 filenames[ i ] = ( (FileStruct)al[ i ] ).fullname;
972 fileDialog.SetFilenames( filenames );
976 if ( fileDialog.CheckPathExists )
978 if ( !Directory.Exists( currentDirectoryName ) )
980 string message = currentDirectoryName + " doesn't exist. Please verify that you have entered the correct directory name.";
981 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
983 if ( fileDialog.InitialDirectory == String.Empty )
984 currentDirectoryName = Environment.CurrentDirectory;
986 currentDirectoryName = fileDialog.InitialDirectory;
992 if ( fileDialog.RestoreDirectory )
993 currentDirectoryName = restoreDirectory;
995 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
997 cancelEventArgs.Cancel = false;
999 fileDialog.OnFileOk( cancelEventArgs );
1001 fileDialog.form.Controls.Remove( this );
1002 fileDialog.form.DialogResult = DialogResult.OK;
1005 void OnClickCancelButton( object sender, EventArgs e )
1007 if ( fileDialog.RestoreDirectory )
1008 currentDirectoryName = restoreDirectory;
1010 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
1012 cancelEventArgs.Cancel = true;
1014 fileDialog.OnFileOk( cancelEventArgs );
1016 fileDialog.form.Controls.Remove( this );
1017 fileDialog.form.DialogResult = DialogResult.Cancel;
1020 void OnClickHelpButton( object sender, EventArgs e )
1022 fileDialog.SendHelpRequest( e );
1025 void OnClickSmallButtonToolBar( object sender, ToolBarButtonClickEventArgs e )
1027 if ( e.Button == upToolBarButton )
1029 if ( directoryInfo.Parent != null )
1031 PushDirectory( directoryInfo );
1033 directoryInfo = directoryInfo.Parent;
1035 currentDirectoryName = directoryInfo.FullName;
1037 dirComboBox.CurrentPath = currentDirectoryName;
1039 mwfFileView.UpdateFileView( directoryInfo );
1043 if ( e.Button == backToolBarButton )
1045 if ( directoryStack.Count != 0 )
1049 dirComboBox.CurrentPath = currentDirectoryName;
1051 mwfFileView.UpdateFileView( directoryInfo );
1055 if ( e.Button == newdirToolBarButton )
1061 void OnClickMenuToolBarContextMenu( object sender, EventArgs e )
1063 MenuItem senderMenuItem = (MenuItem)sender;
1065 previousCheckedMenuItem.Checked = false;
1066 senderMenuItem.Checked = true;
1067 previousCheckedMenuItem = senderMenuItem;
1071 switch ( senderMenuItem.Index )
1074 mwfFileView.View = View.SmallIcon;
1077 mwfFileView.View = View.LargeIcon;
1080 mwfFileView.View = View.LargeIcon;
1083 mwfFileView.View = View.List;
1086 mwfFileView.View = View.Details;
1093 mwfFileView.UpdateFileView( directoryInfo );
1096 void OnKeyUpFileNameComboBox( object sender, KeyEventArgs e )
1098 if ( e.KeyCode == Keys.Enter )
1100 currentFileName = currentDirectoryName + fileNameComboBox.Text;
1105 void OnSelectedIndexChangedFileTypeComboBox( object sender, EventArgs e )
1107 fileDialog.FilterIndex = fileTypeComboBox.SelectedIndex + 1;
1109 mwfFileView.FilterIndex = fileDialog.FilterIndex;
1111 mwfFileView.UpdateFileView( directoryInfo );
1114 void OnSelectedFileChangedFileView( object sender, EventArgs e )
1116 fileNameComboBox.Text = mwfFileView.FileName;
1117 currentFileName = mwfFileView.FullFileName;
1120 void OnDirectoryChangedFileView( object sender, EventArgs e )
1122 ChangeDirectory( sender, mwfFileView.FullFileName );
1125 void OnForceDialogEndFileView( object sender, EventArgs e )
1130 void OnSelectedFilesChangedFileView( object sender, EventArgs e )
1132 fileNameComboBox.Text = mwfFileView.SelectedFilesString;
1135 void OnDirectoryChangedDirComboBox( object sender, EventArgs e )
1137 ChangeDirectory( sender, dirComboBox.CurrentPath );
1140 void OnCheckCheckChanged( object sender, EventArgs e )
1142 fileDialog.ReadOnlyChecked = checkBox.Checked;
1145 public void UpdateFilters( )
1147 ArrayList filters = fileDialog.FileFilter.FilterArrayList;
1149 fileTypeComboBox.Items.Clear( );
1151 fileTypeComboBox.BeginUpdate( );
1153 foreach ( FilterStruct fs in filters )
1155 fileTypeComboBox.Items.Add( fs.filterName );
1158 fileTypeComboBox.SelectedIndex = fileDialog.FilterIndex - 1;
1160 fileTypeComboBox.EndUpdate( );
1162 mwfFileView.FilterArrayList = filters;
1164 mwfFileView.FilterIndex = fileDialog.FilterIndex;
1166 mwfFileView.UpdateFileView( directoryInfo );
1169 public void ChangeDirectory( object sender, string path )
1171 currentDirectoryName = path;
1173 PushDirectory( directoryInfo );
1175 directoryInfo = new DirectoryInfo( path );
1177 if ( sender != dirComboBox )
1178 dirComboBox.CurrentPath = path;
1180 mwfFileView.UpdateFileView( directoryInfo );
1183 public void ForceDialogEnd( )
1185 OnClickOpenSaveButton( this, EventArgs.Empty );
1188 private void PushDirectory( DirectoryInfo di )
1190 directoryStack.Push( directoryInfo );
1191 backToolBarButton.Enabled = true;
1194 private void PopDirectory( )
1196 directoryInfo = (DirectoryInfo)directoryStack.Pop( );
1198 currentDirectoryName = directoryInfo.FullName;
1200 if ( directoryStack.Count == 0 )
1201 backToolBarButton.Enabled = false;
1204 public void ResizeAndRelocateForHelpOrReadOnly( )
1206 if ( fileDialog.ShowHelp || fileDialog.ShowReadOnly )
1208 mwfFileView.Size = new Size( 449, 250 );
1209 fileNameLabel.Location = new Point( 102, 298 );
1210 fileNameComboBox.Location = new Point( 195, 298 );
1211 fileTypeLabel.Location = new Point( 102, 324 );
1212 fileTypeComboBox.Location = new Point( 195, 324 );
1213 openSaveButton.Location = new Point( 475, 298 );
1214 cancelButton.Location = new Point( 475, 324 );
1218 mwfFileView.Size = new Size( 449, 282 );
1219 fileNameLabel.Location = new Point( 102, 330 );
1220 fileNameComboBox.Location = new Point( 195, 330 );
1221 fileTypeLabel.Location = new Point( 102, 356 );
1222 fileTypeComboBox.Location = new Point( 195, 356 );
1223 openSaveButton.Location = new Point( 475, 330 );
1224 cancelButton.Location = new Point( 475, 356 );
1227 if ( fileDialog.ShowHelp )
1230 if ( fileDialog.ShowReadOnly )
1234 internal class PopupButtonPanel : Panel
1236 internal class PopupButton : Control
1238 internal enum PopupButtonState
1241 private Image image = null;
1242 private PopupButtonState popupButtonState = PopupButtonState.Normal;
1243 private StringFormat text_format = new StringFormat();
1245 public PopupButton( )
1247 text_format.Alignment = StringAlignment.Center;
1248 text_format.LineAlignment = StringAlignment.Far;
1250 SetStyle( ControlStyles.DoubleBuffer, true );
1251 SetStyle( ControlStyles.AllPaintingInWmPaint, true );
1252 SetStyle( ControlStyles.UserPaint, true );
1267 public PopupButtonState ButtonState
1270 popupButtonState = value;
1275 return popupButtonState;
1279 protected override void OnPaint( PaintEventArgs pe )
1286 private void Draw( PaintEventArgs pe )
1288 Graphics gr = pe.Graphics;
1290 gr.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( BackColor ), ClientRectangle );
1293 if ( image != null )
1295 int i_x = ( ClientSize.Width - image.Width ) / 2;
1297 gr.DrawImage( image, i_x, i_y );
1300 if ( Text != String.Empty )
1302 Rectangle text_rect = Rectangle.Inflate( ClientRectangle, -4, -4 );
1304 gr.DrawString( Text, Font, ThemeEngine.Current.ResPool.GetSolidBrush( ForeColor ), text_rect, text_format );
1307 switch ( popupButtonState )
1309 case PopupButtonState.Up:
1310 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, 0, ClientSize.Width - 1, 0 );
1311 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, 0, 0, ClientSize.Height - 1 );
1312 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1 );
1313 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1 );
1316 case PopupButtonState.Down:
1317 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, 0, ClientSize.Width - 1, 0 );
1318 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, 0, 0, ClientSize.Height - 1 );
1319 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1 );
1320 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1 );
1325 protected override void OnMouseEnter( EventArgs e )
1327 if ( popupButtonState != PopupButtonState.Down )
1328 popupButtonState = PopupButtonState.Up;
1330 base.OnMouseEnter( e );
1333 protected override void OnMouseLeave( EventArgs e )
1335 if ( popupButtonState != PopupButtonState.Down )
1336 popupButtonState = PopupButtonState.Normal;
1338 base.OnMouseLeave( e );
1341 protected override void OnClick( EventArgs e )
1343 popupButtonState = PopupButtonState.Down;
1349 private FileDialogPanel fileDialogPanel;
1351 private PopupButton lastOpenButton;
1352 private PopupButton desktopButton;
1353 private PopupButton homeButton;
1354 private PopupButton workplaceButton;
1355 private PopupButton networkButton;
1357 private PopupButton lastPopupButton = null;
1359 private ImageList imageList = new ImageList();
1361 public PopupButtonPanel( FileDialogPanel fileDialogPanel )
1363 this.fileDialogPanel = fileDialogPanel;
1365 BorderStyle = BorderStyle.Fixed3D;
1366 BackColor = Color.FromArgb( 128, 128, 128 );
1367 Size = new Size( 85, 336 );
1369 // use ImageList to scale the bitmaps
1370 imageList.ColorDepth = ColorDepth.Depth32Bit;
1371 imageList.ImageSize = new Size( 38, 38 );
1372 imageList.Images.Add( (Image)Locale.GetResource( "last_open" ) );
1373 //imageList.Images.Add( (Image)Locale.GetResource( "desktop" ) );
1374 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", imageList.ImageSize ) );
1375 //imageList.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
1376 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", imageList.ImageSize ) );
1377 imageList.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
1378 //imageList.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
1379 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "network/network", imageList.ImageSize ) );
1380 imageList.TransparentColor = Color.Transparent;
1382 lastOpenButton = new PopupButton( );
1383 desktopButton = new PopupButton( );
1384 homeButton = new PopupButton( );
1385 workplaceButton = new PopupButton( );
1386 networkButton = new PopupButton( );
1388 lastOpenButton.Size = new Size( 82, 64 );
1389 lastOpenButton.Image = imageList.Images[ 0 ];
1390 lastOpenButton.BackColor = BackColor;
1391 lastOpenButton.ForeColor = Color.White;
1392 lastOpenButton.Location = new Point( 2, 2 );
1393 lastOpenButton.Text = "Last Open";
1394 lastOpenButton.Click += new EventHandler( OnClickButton );
1396 desktopButton.Image = imageList.Images[ 1 ];
1397 desktopButton.BackColor = BackColor;
1398 desktopButton.ForeColor = Color.White;
1399 desktopButton.Size = new Size( 82, 64 );
1400 desktopButton.Location = new Point( 2, 66 );
1401 desktopButton.Text = "Desktop";
1402 desktopButton.Click += new EventHandler( OnClickButton );
1404 homeButton.Image = imageList.Images[ 2 ];
1405 homeButton.BackColor = BackColor;
1406 homeButton.ForeColor = Color.White;
1407 homeButton.Size = new Size( 82, 64 );
1408 homeButton.Location = new Point( 2, 130 );
1409 homeButton.Text = "Home";
1410 homeButton.Click += new EventHandler( OnClickButton );
1412 workplaceButton.Image = imageList.Images[ 3 ];
1413 workplaceButton.BackColor = BackColor;
1414 workplaceButton.ForeColor = Color.White;
1415 workplaceButton.Size = new Size( 82, 64 );
1416 workplaceButton.Location = new Point( 2, 194 );
1417 workplaceButton.Text = "Workplace";
1418 workplaceButton.Click += new EventHandler( OnClickButton );
1420 networkButton.Image = imageList.Images[ 4 ];
1421 networkButton.BackColor = BackColor;
1422 networkButton.ForeColor = Color.White;
1423 networkButton.Size = new Size( 82, 64 );
1424 networkButton.Location = new Point( 2, 258 );
1425 networkButton.Text = "Network";
1426 networkButton.Click += new EventHandler( OnClickButton );
1428 Controls.Add( lastOpenButton );
1429 Controls.Add( desktopButton );
1430 Controls.Add( homeButton );
1431 Controls.Add( workplaceButton );
1432 Controls.Add( networkButton );
1435 void OnClickButton( object sender, EventArgs e )
1437 if ( lastPopupButton != null && (PopupButton)sender != lastPopupButton )
1438 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1439 lastPopupButton = sender as PopupButton;
1441 if ( sender == lastOpenButton )
1446 if ( sender == desktopButton )
1448 fileDialogPanel.ChangeDirectory( this, Environment.GetFolderPath( Environment.SpecialFolder.Desktop ) );
1451 if ( sender == homeButton )
1453 fileDialogPanel.ChangeDirectory( this, Environment.GetFolderPath( Environment.SpecialFolder.Personal ) );
1456 if ( sender == workplaceButton )
1458 // fileDialogPanel.ChangeDirectory(this, Environment.GetFolderPath( Environment.SpecialFolder.MyComputer ) );
1461 if ( sender == networkButton )
1470 internal struct FilterStruct
1472 public string filterName;
1473 public StringCollection filters;
1475 public FilterStruct( string filterName, string filter )
1477 this.filterName = filterName;
1479 filters = new StringCollection( );
1481 SplitFilters( filter );
1484 private void SplitFilters( string filter )
1486 string[] split = filter.Split( new Char[] {';'} );
1488 filters.AddRange( split );
1492 internal struct FileStruct
1494 public FileStruct( string fullname, FileAttributes attributes )
1496 this.fullname = fullname;
1497 this.attributes = attributes;
1500 public string fullname;
1501 public FileAttributes attributes;
1505 internal class MWFFileView : ListView
1507 // private ImageList fileViewSmallImageList = new ImageList();
1508 // private ImageList fileViewBigImageList = new ImageList();
1510 private ArrayList filterArrayList;
1511 // store the FileStruct of all files in the current directory
1512 private Hashtable fileHashtable = new Hashtable();
1514 private bool showHiddenFiles = false;
1516 private EventHandler on_selected_file_changed;
1517 private EventHandler on_selected_files_changed;
1518 private EventHandler on_directory_changed;
1519 private EventHandler on_force_dialog_end;
1521 private string fileName;
1522 private string fullFileName;
1523 private string selectedFilesString;
1525 private int filterIndex;
1527 public MWFFileView( )
1529 SmallImageList = MimeIconEngine.SmallIcons;
1530 LargeImageList = MimeIconEngine.LargeIcons;
1535 public ArrayList FilterArrayList
1538 filterArrayList = value;
1542 return filterArrayList;
1546 public Hashtable FileHashtable
1549 fileHashtable = value;
1553 return fileHashtable;
1557 public bool ShowHiddenFiles
1560 showHiddenFiles = value;
1564 return showHiddenFiles;
1568 public string FileName
1579 public string FullFileName
1582 fullFileName = value;
1586 return fullFileName;
1590 public int FilterIndex
1593 filterIndex = value;
1601 public string SelectedFilesString
1604 selectedFilesString = value;
1608 return selectedFilesString;
1612 private ArrayList GetFileInfoArrayList( DirectoryInfo directoryInfo )
1614 ArrayList arrayList = new ArrayList( );
1616 if ( filterArrayList != null && filterArrayList.Count != 0 )
1618 FilterStruct fs = (FilterStruct)filterArrayList[ filterIndex - 1 ];
1620 foreach ( string s in fs.filters )
1621 arrayList.AddRange( directoryInfo.GetFiles( s ) );
1624 arrayList.AddRange( directoryInfo.GetFiles( ) );
1629 public void UpdateFileView( DirectoryInfo inputDirectoryInfo )
1631 DirectoryInfo directoryInfo = inputDirectoryInfo;
1633 DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories( );
1635 ArrayList fileInfoArrayList = GetFileInfoArrayList( directoryInfo );
1637 fileHashtable.Clear( );
1642 SelectedItems.Clear( );
1644 foreach ( DirectoryInfo directoryInfoi in directoryInfoArray )
1646 if ( !ShowHiddenFiles )
1647 if ( directoryInfoi.Name.StartsWith( "." ) || directoryInfoi.Attributes == FileAttributes.Hidden )
1650 FileStruct fileStruct = new FileStruct( );
1652 fileStruct.fullname = directoryInfoi.FullName;
1654 ListViewItem listViewItem = new ListViewItem( directoryInfoi.Name );
1656 int index = MimeIconEngine.GetIconIndexForMimeType( "inode/directory" );
1658 listViewItem.ImageIndex = index;
1660 listViewItem.SubItems.Add( "" );
1661 listViewItem.SubItems.Add( "Directory" );
1662 listViewItem.SubItems.Add( directoryInfoi.LastAccessTime.ToShortDateString( ) + " " + directoryInfoi.LastAccessTime.ToShortTimeString( ) );
1664 fileStruct.attributes = FileAttributes.Directory;
1666 fileHashtable.Add( directoryInfoi.Name, fileStruct );
1668 Items.Add( listViewItem );
1671 foreach ( FileInfo fileInfo in fileInfoArrayList )
1673 if ( !ShowHiddenFiles )
1674 if ( fileInfo.Name.StartsWith( "." ) || fileInfo.Attributes == FileAttributes.Hidden )
1677 FileStruct fileStruct = new FileStruct( );
1679 fileStruct.fullname = fileInfo.FullName;
1681 ListViewItem listViewItem = new ListViewItem( fileInfo.Name );
1683 listViewItem.ImageIndex = MimeIconEngine.GetIconIndexForFile( fileStruct.fullname );
1686 if ( fileInfo.Length > 1024 )
1687 fileLen = fileInfo.Length / 1024;
1689 listViewItem.SubItems.Add( fileLen.ToString( ) + " KB" );
1690 listViewItem.SubItems.Add( "File" );
1691 listViewItem.SubItems.Add( fileInfo.LastAccessTime.ToShortDateString( ) + " " + fileInfo.LastAccessTime.ToShortTimeString( ) );
1693 fileStruct.attributes = FileAttributes.Normal;
1695 fileHashtable.Add( fileInfo.Name, fileStruct );
1697 Items.Add( listViewItem );
1703 protected override void OnClick( EventArgs e )
1707 if ( SelectedItems.Count > 0 )
1709 ListViewItem listViewItem = SelectedItems[ 0 ];
1711 FileStruct fileStruct = (FileStruct)fileHashtable[ listViewItem.Text ];
1713 if ( fileStruct.attributes != FileAttributes.Directory )
1715 fileName = listViewItem.Text;
1716 fullFileName = fileStruct.fullname;
1718 if ( on_selected_file_changed != null )
1719 on_selected_file_changed( this, EventArgs.Empty );
1727 protected override void OnDoubleClick( EventArgs e )
1729 if ( SelectedItems.Count > 0 )
1731 ListViewItem listViewItem = SelectedItems[ 0 ];
1733 FileStruct fileStruct = (FileStruct)fileHashtable[ listViewItem.Text ];
1735 if ( fileStruct.attributes == FileAttributes.Directory )
1737 fullFileName = fileStruct.fullname;
1739 if ( on_directory_changed != null )
1740 on_directory_changed( this, EventArgs.Empty );
1744 fileName = listViewItem.Text;
1745 fullFileName = fileStruct.fullname;
1747 if ( on_selected_file_changed != null )
1748 on_selected_file_changed( this, EventArgs.Empty );
1750 if ( on_force_dialog_end != null )
1751 on_force_dialog_end( this, EventArgs.Empty );
1757 base.OnDoubleClick( e );
1760 protected override void OnSelectedIndexChanged( EventArgs e )
1764 if ( SelectedItems.Count > 0 )
1766 selectedFilesString = "";
1768 if ( SelectedItems.Count == 1 )
1770 FileStruct fileStruct = (FileStruct)fileHashtable[ SelectedItems[ 0 ].Text ];
1772 if ( fileStruct.attributes != FileAttributes.Directory )
1773 selectedFilesString = SelectedItems[ 0 ].Text;
1777 foreach ( ListViewItem lvi in SelectedItems )
1779 FileStruct fileStruct = (FileStruct)fileHashtable[ lvi.Text ];
1781 if ( fileStruct.attributes != FileAttributes.Directory )
1782 selectedFilesString += "\"" + lvi.Text + "\" ";
1786 if ( on_selected_files_changed != null )
1787 on_selected_files_changed( this, EventArgs.Empty );
1791 base.OnSelectedIndexChanged( e );
1794 public event EventHandler SelectedFileChanged
1796 add { on_selected_file_changed += value; }
1797 remove { on_selected_file_changed -= value; }
1800 public event EventHandler SelectedFilesChanged
1802 add { on_selected_files_changed += value; }
1803 remove { on_selected_files_changed -= value; }
1806 public event EventHandler DirectoryChanged
1808 add { on_directory_changed += value; }
1809 remove { on_directory_changed -= value; }
1812 public event EventHandler ForceDialogEnd
1814 add { on_force_dialog_end += value; }
1815 remove { on_force_dialog_end -= value; }
1819 internal class FileFilter
1821 private ArrayList filterArrayList = new ArrayList();
1823 private string filter;
1825 public FileFilter( )
1828 public FileFilter( string filter )
1830 this.filter = filter;
1835 public ArrayList FilterArrayList
1838 filterArrayList = value;
1842 return filterArrayList;
1846 public string Filter
1859 private void SplitFilter( )
1861 filterArrayList.Clear( );
1863 if ( filter == null )
1864 throw new NullReferenceException( "Filter" );
1866 if ( filter.Length == 0 )
1869 string[] filters = filter.Split( new Char[] {'|'} );
1871 if ( ( filters.Length % 2 ) != 0 )
1872 throw new ArgumentException( "Filter" );
1874 for ( int i = 0; i < filters.Length; i += 2 )
1876 FilterStruct filterStruct = new FilterStruct( filters[ i ], filters[ i + 1 ] );
1878 filterArrayList.Add( filterStruct );
1883 internal class DirComboBox : ComboBox
1885 internal class DirComboBoxItem
1887 private int imageIndex;
1888 private string name;
1889 private string path;
1892 public DirComboBoxItem( int imageIndex, string name, string path, int xPos )
1894 this.imageIndex = imageIndex;
1900 public int ImageIndex
1945 private ImageList imageList = new ImageList();
1947 private string currentPath;
1949 private bool firstTime = true;
1951 private EventHandler on_directory_changed;
1953 public DirComboBox( )
1955 DrawMode = DrawMode.OwnerDrawFixed;
1957 imageList.ColorDepth = ColorDepth.Depth32Bit;
1958 imageList.ImageSize = new Size( 16, 16 );
1959 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", imageList.ImageSize ) );
1960 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", imageList.ImageSize ) );
1961 imageList.Images.Add( MimeIconEngine.GetIconForMimeTypeAndSize( "inode/directory", imageList.ImageSize ) );
1962 imageList.TransparentColor = Color.Transparent;
1964 Items.AddRange( new object[] {
1965 new DirComboBoxItem( 0, "Desktop", Environment.GetFolderPath( Environment.SpecialFolder.Desktop ), 0 ),
1966 new DirComboBoxItem( 1, "Home", Environment.GetFolderPath( Environment.SpecialFolder.Personal ), 0 )
1971 public string CurrentPath
1974 currentPath = value;
1983 private void ShowPath( )
1985 DirectoryInfo di = new DirectoryInfo( currentPath );
1987 Stack dirStack = new Stack( );
1989 dirStack.Push( di );
1991 while ( di.Parent != null )
1994 dirStack.Push( di );
2001 Items.AddRange( new object[] {
2002 new DirComboBoxItem( 0, "Desktop", Environment.GetFolderPath( Environment.SpecialFolder.Desktop ), 0 ),
2003 new DirComboBoxItem( 1, "Home", Environment.GetFolderPath( Environment.SpecialFolder.Personal ), 0 )
2011 while ( dirStack.Count != 0 )
2013 DirectoryInfo dii = (DirectoryInfo)dirStack.Pop( );
2014 sel = Items.Add( new DirComboBoxItem( 2, dii.Name, dii.FullName, xPos + 4 ) );
2019 SelectedIndex = sel;
2024 protected override void OnDrawItem( DrawItemEventArgs e )
2026 if ( e.Index == -1 )
2029 Bitmap bmp = new Bitmap( e.Bounds.Width, e.Bounds.Height, e.Graphics );
2030 Graphics gr = Graphics.FromImage( bmp );
2032 DirComboBoxItem dcbi = Items[ e.Index ] as DirComboBoxItem;
2034 Color backColor = e.BackColor;
2035 Color foreColor = e.ForeColor;
2037 int xPos = dcbi.XPos;
2039 // Bug in ComboBox !!!!!
2040 // we never receive DrawItemState.ComboBoxEdit
2041 if ( ( e.State & DrawItemState.ComboBoxEdit ) != 0 )
2044 if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected )
2046 backColor = ThemeEngine.Current.ColorHighlight;
2047 foreColor = ThemeEngine.Current.ColorHighlightText;
2050 gr.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( backColor ), new Rectangle( 0, 0, bmp.Width, bmp.Height ) );
2052 gr.DrawString( dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush( foreColor ), new Point( 24 + xPos, ( bmp.Height - e.Font.Height ) / 2 ) );
2053 gr.DrawImage( imageList.Images[ dcbi.ImageIndex ], new Rectangle( new Point( xPos + 2, 0 ), new Size( 16, 16 ) ) );
2055 e.Graphics.DrawImage( bmp, e.Bounds.X, e.Bounds.Y );
2060 protected override void OnSelectedIndexChanged( EventArgs e )
2062 // do not call ChangeDirectory when invoked from FileDialogPanel ctor...
2069 if ( Items.Count > 0 )
2071 DirComboBoxItem dcbi = Items[ SelectedIndex ] as DirComboBoxItem;
2073 currentPath = dcbi.Path;
2075 if ( on_directory_changed != null )
2076 on_directory_changed( this, EventArgs.Empty );
2080 public event EventHandler DirectoryChanged
2082 add { on_directory_changed += value; }
2083 remove { on_directory_changed -= value; }