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 public abstract class FileDialog : CommonDialog
44 internal enum FileDialogType
50 internal FileDialogPanel fileDialogPanel;
52 private bool addExtension = true;
53 internal bool checkFileExists = false;
54 private bool checkPathExists = true;
55 private string defaultExt = "";
56 private bool dereferenceLinks = true;
57 private string fileName = "";
58 private string[] fileNames;
59 private string filter;
60 private int filterIndex = 1;
61 private string initialDirectory = "";
62 private bool restoreDirectory = false;
63 private bool showHelp = false;
64 private string title = "";
65 private bool validateNames = true;
67 //protected bool readOnlyChecked = false;
69 internal string openSaveButtonText;
70 internal string searchSaveLabelText;
71 internal bool showReadOnly = false;
72 internal bool readOnlyChecked = false;
73 internal bool multiSelect = false;
74 internal bool createPrompt = false;
75 internal bool overwritePrompt = true;
77 private bool showHiddenFiles = false;
79 internal FileDialogType fileDialogType;
81 public bool AddExtension
94 public virtual bool CheckFileExists
98 return checkFileExists;
103 checkFileExists = value;
107 public bool CheckPathExists
111 return checkPathExists;
116 checkPathExists = value;
120 public string DefaultExt
131 // if there is a dot remove it and everything before it
132 if ( defaultExt.LastIndexOf( '.' ) != - 1 )
134 string[] split = defaultExt.Split( new char[] { '.' } );
135 defaultExt = split[ split.Length - 1 ];
140 // in MS.NET it doesn't make a difference if
141 // DerefenceLinks is true or false
142 // if the selected file is a link FileDialog
143 // always returns the link
144 public bool DereferenceLinks
148 return dereferenceLinks;
153 dereferenceLinks = value;
157 public string FileName
170 public string[] FileNames
191 throw new NullReferenceException( "Filter" );
195 fileFilter = new FileFilter( filter );
197 fileDialogPanel.UpdateFilters( );
201 public int FilterIndex
214 public string InitialDirectory
218 return initialDirectory;
223 initialDirectory = value;
227 public bool RestoreDirectory
231 return restoreDirectory;
236 restoreDirectory = value;
250 fileDialogPanel.ResizeAndRelocateForHelpOrReadOnly( );
269 // this one is a hard one ;)
271 // - up to MAX_PATH characters (windef.h) = 260
272 // - no trailing dots or spaces
275 // NTFS/Posix filename:
276 // - up to 32,768 Unicode characters
277 // - trailing periods or spaces
280 public bool ValidateNames
284 return validateNames;
289 validateNames = value;
293 internal string OpenSaveButtonText
297 openSaveButtonText = value;
302 return openSaveButtonText;
306 internal string SearchSaveLabelText
310 searchSaveLabelText = value;
315 return searchSaveLabelText;
319 internal virtual bool ShowReadOnly
323 showReadOnly = value;
324 fileDialogPanel.ResizeAndRelocateForHelpOrReadOnly( );
333 internal virtual bool ReadOnlyChecked
337 readOnlyChecked = value;
338 fileDialogPanel.CheckBox.Checked = value;
343 return readOnlyChecked;
347 internal virtual bool Multiselect
352 fileDialogPanel.MultiSelect = value;
361 // extension to MS.NET framework...
362 public bool ShowHiddenFiles
366 showHiddenFiles = value;
371 return showHiddenFiles;
375 internal virtual bool CreatePrompt
379 createPrompt = value;
388 internal virtual bool OverwritePrompt
392 overwritePrompt = value;
397 return overwritePrompt;
401 internal FileFilter FileFilter
414 public override void Reset( )
417 checkFileExists = false;
418 checkPathExists = true;
420 dereferenceLinks = true;
425 initialDirectory = "";
426 restoreDirectory = false;
429 validateNames = true;
431 fileDialogPanel.UpdateFilters( );
434 public override string ToString( )
436 return base.ToString( );
439 public event CancelEventHandler FileOk;
441 protected override IntPtr HookProc( IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam )
443 throw new NotImplementedException( );
446 protected void OnFileOk( CancelEventArgs e )
448 if ( FileOk != null ) FileOk( this, e );
452 protected override bool RunDialog( IntPtr hWndOwner )
454 form.Controls.Add( fileDialogPanel );
459 internal void SendHelpRequest( EventArgs e )
464 internal void SetFilenames( string[] filenames )
466 fileNames = filenames;
469 internal FileFilter fileFilter;
471 internal class FileDialogPanel : Panel
473 private Button cancelButton;
474 private ToolBarButton upToolBarButton;
475 private PopupButtonPanel popupButtonPanel;
476 private Button openSaveButton;
477 private Button helpButton;
478 private Label fileTypeLabel;
479 private ToolBarButton menueToolBarButton;
480 private ContextMenu menueToolBarButtonContextMenu;
481 private ToolBarButton desktopToolBarButton;
482 private ToolBar smallButtonToolBar;
483 private DirComboBox dirComboBox;
484 private ToolBarButton lastUsedToolBarButton;
485 private ComboBox fileNameComboBox;
486 private ToolBarButton networkToolBarButton;
487 private Label fileNameLabel;
488 private MWFFileView mwfFileView;
489 private Label searchSaveLabel;
490 private ToolBarButton newdirToolBarButton;
491 private ToolBarButton backToolBarButton;
492 private ToolBarButton homeToolBarButton;
493 private ToolBarButton workplaceToolBarButton;
494 private ComboBox fileTypeComboBox;
495 private ImageList imageListTopToolbar;
496 private ContextMenu contextMenu;
497 private CheckBox checkBox;
499 internal FileDialog fileDialog;
501 private string currentDirectoryName;
503 internal string currentFileName = "";
505 // store current directoryInfo
506 private DirectoryInfo directoryInfo;
508 // store DirectoryInfo for backButton
509 internal Stack directoryStack = new Stack();
511 private MenuItem previousCheckedMenuItem;
513 private bool multiSelect = false;
515 private string restoreDirectory = "";
517 public FileDialogPanel( FileDialog fileDialog )
519 this.fileDialog = fileDialog;
521 fileTypeComboBox = new ComboBox( );
522 workplaceToolBarButton = new ToolBarButton( );
523 homeToolBarButton = new ToolBarButton( );
524 backToolBarButton = new ToolBarButton( );
525 newdirToolBarButton = new ToolBarButton( );
526 searchSaveLabel = new Label( );
527 mwfFileView = new MWFFileView( );
528 fileNameLabel = new Label( );
529 networkToolBarButton = new ToolBarButton( );
530 fileNameComboBox = new ComboBox( );
531 lastUsedToolBarButton = new ToolBarButton( );
532 dirComboBox = new DirComboBox( );
533 smallButtonToolBar = new ToolBar( );
534 desktopToolBarButton = new ToolBarButton( );
535 menueToolBarButton = new ToolBarButton( );
536 fileTypeLabel = new Label( );
537 openSaveButton = new Button( );
538 fileDialog.form.AcceptButton = openSaveButton;
539 helpButton = new Button( );
540 popupButtonPanel = new PopupButtonPanel( this );
541 upToolBarButton = new ToolBarButton( );
542 cancelButton = new Button( );
543 fileDialog.form.CancelButton = cancelButton;
544 imageListTopToolbar = new ImageList( );
545 menueToolBarButtonContextMenu = new ContextMenu( );
546 contextMenu = new ContextMenu( );
547 checkBox = new CheckBox( );
551 //imageListTopToolbar
552 imageListTopToolbar.ColorDepth = ColorDepth.Depth32Bit;
553 imageListTopToolbar.ImageSize = new Size( 16, 16 ); // 16, 16
554 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "back_arrow" ) );
555 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_arrow_up" ) );
556 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_star" ) );
557 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "window" ) );
558 imageListTopToolbar.TransparentColor = Color.Transparent;
561 searchSaveLabel.FlatStyle = FlatStyle.System;
562 searchSaveLabel.Location = new Point( 7, 8 );
563 searchSaveLabel.Size = new Size( 72, 21 );
564 searchSaveLabel.TabIndex = 0;
565 searchSaveLabel.Text = fileDialog.SearchSaveLabelText;
566 searchSaveLabel.TextAlign = ContentAlignment.MiddleRight;
569 dirComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Top | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
570 dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
571 dirComboBox.Location = new Point( 99, 8 );
572 dirComboBox.Size = new Size( 260, 21 );
573 dirComboBox.TabIndex = 1;
575 // smallButtonToolBar
576 smallButtonToolBar.Anchor = ( (AnchorStyles)( ( AnchorStyles.Top | AnchorStyles.Right ) ) );
577 smallButtonToolBar.Appearance = ToolBarAppearance.Flat;
578 smallButtonToolBar.AutoSize = false;
579 smallButtonToolBar.Buttons.AddRange( new ToolBarButton[] {
583 menueToolBarButton} );
584 smallButtonToolBar.ButtonSize = new Size( 21, 16 ); // 21, 16
585 smallButtonToolBar.Divider = false;
586 smallButtonToolBar.Dock = DockStyle.None;
587 smallButtonToolBar.DropDownArrows = true;
588 smallButtonToolBar.ImageList = imageListTopToolbar;
589 smallButtonToolBar.Location = new Point( 372, 8 );
590 smallButtonToolBar.ShowToolTips = true;
591 smallButtonToolBar.Size = new Size( 110, 20 );
592 smallButtonToolBar.TabIndex = 2;
593 smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
596 popupButtonPanel.Dock = DockStyle.None;
597 popupButtonPanel.Location = new Point( 7, 37 );
598 popupButtonPanel.TabIndex = 3;
601 mwfFileView.Anchor = ( (AnchorStyles)( ( ( ( AnchorStyles.Top | AnchorStyles.Bottom ) | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
602 mwfFileView.Location = new Point( 99, 37 );
603 mwfFileView.Size = new Size( 449, 282 );
604 mwfFileView.Columns.Add( " Name", 170, HorizontalAlignment.Left );
605 mwfFileView.Columns.Add( "Size ", 80, HorizontalAlignment.Right );
606 mwfFileView.Columns.Add( " Type", 100, HorizontalAlignment.Left );
607 mwfFileView.Columns.Add( " Last Access", 150, HorizontalAlignment.Left );
608 mwfFileView.AllowColumnReorder = true;
609 mwfFileView.MultiSelect = false;
610 mwfFileView.TabIndex = 4;
611 mwfFileView.FilterIndex = fileDialog.FilterIndex;
614 fileNameLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
615 fileNameLabel.FlatStyle = FlatStyle.System;
616 fileNameLabel.Location = new Point( 102, 330 );
617 fileNameLabel.Size = new Size( 70, 21 );
618 fileNameLabel.TabIndex = 5;
619 fileNameLabel.Text = "Filename:";
620 fileNameLabel.TextAlign = ContentAlignment.MiddleLeft;
623 fileNameComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
624 fileNameComboBox.Location = new Point( 195, 330 );
625 fileNameComboBox.Size = new Size( 245, 21 );
626 fileNameComboBox.TabIndex = 6;
629 fileTypeLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
630 fileTypeLabel.FlatStyle = FlatStyle.System;
631 fileTypeLabel.Location = new Point( 102, 356 );
632 fileTypeLabel.Size = new Size( 70, 21 );
633 fileTypeLabel.TabIndex = 7;
634 fileTypeLabel.Text = "Filetype:";
635 fileTypeLabel.TextAlign = ContentAlignment.MiddleLeft;
638 fileTypeComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
639 fileTypeComboBox.Location = new Point( 195, 356 );
640 fileTypeComboBox.Size = new Size( 245, 21 );
641 fileTypeComboBox.TabIndex = 8;
644 backToolBarButton.ImageIndex = 0;
645 backToolBarButton.Enabled = false;
646 backToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
649 upToolBarButton.ImageIndex = 1;
650 upToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
652 // newdirToolBarButton
653 newdirToolBarButton.ImageIndex = 2;
654 newdirToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
656 // menueToolBarButton
657 menueToolBarButton.ImageIndex = 3;
658 menueToolBarButton.DropDownMenu = menueToolBarButtonContextMenu;
659 menueToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
661 // menueToolBarButtonContextMenu
662 MenuItem mi = new MenuItem( "Small Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
663 menueToolBarButtonContextMenu.MenuItems.Add( mi );
664 mi = new MenuItem( "Tiles", new EventHandler( OnClickMenuToolBarContextMenu ) );
665 menueToolBarButtonContextMenu.MenuItems.Add( mi );
666 mi = new MenuItem( "Large Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
667 menueToolBarButtonContextMenu.MenuItems.Add( mi );
668 mi = new MenuItem( "List", new EventHandler( OnClickMenuToolBarContextMenu ) );
670 previousCheckedMenuItem = mi;
671 menueToolBarButtonContextMenu.MenuItems.Add( mi );
672 mi = new MenuItem( "Details", new EventHandler( OnClickMenuToolBarContextMenu ) );
673 menueToolBarButtonContextMenu.MenuItems.Add( mi );
676 mi = new MenuItem( "Show hidden files", new EventHandler( OnClickContextMenu ) );
677 mi.Checked = fileDialog.ShowHiddenFiles;
678 mwfFileView.ShowHiddenFiles = fileDialog.ShowHiddenFiles;
679 contextMenu.MenuItems.Add( mi );
682 openSaveButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
683 openSaveButton.FlatStyle = FlatStyle.System;
684 openSaveButton.Location = new Point( 475, 330 );
685 openSaveButton.Size = new Size( 72, 21 );
686 openSaveButton.TabIndex = 9;
687 openSaveButton.Text = fileDialog.OpenSaveButtonText;
688 openSaveButton.FlatStyle = FlatStyle.System;
691 cancelButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
692 cancelButton.FlatStyle = FlatStyle.System;
693 cancelButton.Location = new Point( 475, 356 );
694 cancelButton.Size = new Size( 72, 21 );
695 cancelButton.TabIndex = 10;
696 cancelButton.Text = "Cancel";
697 cancelButton.FlatStyle = FlatStyle.System;
700 helpButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
701 helpButton.FlatStyle = FlatStyle.System;
702 helpButton.Location = new Point( 475, 350 );
703 helpButton.Size = new Size( 72, 21 );
704 helpButton.TabIndex = 11;
705 helpButton.Text = "Help";
706 helpButton.FlatStyle = FlatStyle.System;
710 checkBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
711 checkBox.Text = "Open Readonly";
712 checkBox.Location = new Point( 195, 350 );
713 checkBox.Size = new Size( 245, 21 );
714 checkBox.FlatStyle = FlatStyle.System;
715 checkBox.TabIndex = 12;
718 ClientSize = new Size( 554, 405 ); // 384
720 ContextMenu = contextMenu;
722 Controls.Add( smallButtonToolBar );
723 Controls.Add( cancelButton );
724 Controls.Add( openSaveButton );
725 Controls.Add( helpButton );
726 Controls.Add( mwfFileView );
727 Controls.Add( fileTypeLabel );
728 Controls.Add( fileNameLabel );
729 Controls.Add( fileTypeComboBox );
730 Controls.Add( fileNameComboBox );
731 Controls.Add( dirComboBox );
732 Controls.Add( searchSaveLabel );
733 Controls.Add( popupButtonPanel );
734 Controls.Add( checkBox );
736 ResumeLayout( false );
738 if ( fileDialog.InitialDirectory == String.Empty )
739 currentDirectoryName = Environment.CurrentDirectory;
741 currentDirectoryName = fileDialog.InitialDirectory;
743 directoryInfo = new DirectoryInfo( currentDirectoryName );
745 dirComboBox.CurrentPath = currentDirectoryName;
747 if ( fileDialog.RestoreDirectory )
748 restoreDirectory = currentDirectoryName;
750 mwfFileView.UpdateFileView( directoryInfo );
752 openSaveButton.Click += new EventHandler( OnClickOpenSaveButton );
753 cancelButton.Click += new EventHandler( OnClickCancelButton );
754 helpButton.Click += new EventHandler( OnClickHelpButton );
756 smallButtonToolBar.ButtonClick += new ToolBarButtonClickEventHandler( OnClickSmallButtonToolBar );
758 // Key events DONT'T work
759 fileNameComboBox.KeyUp += new KeyEventHandler( OnKeyUpFileNameComboBox );
761 fileTypeComboBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFileTypeComboBox );
763 mwfFileView.SelectedFileChanged += new EventHandler( OnSelectedFileChangedFileView );
764 mwfFileView.DirectoryChanged += new EventHandler( OnDirectoryChangedFileView );
765 mwfFileView.ForceDialogEnd += new EventHandler( OnForceDialogEndFileView );
766 mwfFileView.SelectedFilesChanged += new EventHandler( OnSelectedFilesChangedFileView );
768 dirComboBox.DirectoryChanged += new EventHandler( OnDirectoryChangedDirComboBox );
770 checkBox.CheckedChanged += new EventHandler( OnCheckCheckChanged );
773 public ComboBox FileNameComboBox
777 fileNameComboBox = value;
782 return fileNameComboBox;
786 public string CurrentFileName
790 currentFileName = value;
795 return currentFileName;
799 public DirectoryInfo DirectoryInfo
803 directoryInfo = value;
808 return directoryInfo;
812 public bool MultiSelect
817 mwfFileView.MultiSelect = value;
826 public CheckBox CheckBox
839 void OnClickContextMenu( object sender, EventArgs e )
841 MenuItem senderMenuItem = sender as MenuItem;
843 if ( senderMenuItem.Index == 0 )
845 senderMenuItem.Checked = !senderMenuItem.Checked;
846 fileDialog.ShowHiddenFiles = senderMenuItem.Checked;
847 mwfFileView.ShowHiddenFiles = fileDialog.ShowHiddenFiles;
848 mwfFileView.UpdateFileView( directoryInfo );
852 void OnClickOpenSaveButton( object sender, EventArgs e )
856 string fileFromComboBox = fileNameComboBox.Text.Trim( );
858 if ( fileFromComboBox.Length > 0 )
859 fileFromComboBox = Path.Combine( currentDirectoryName, fileFromComboBox );
861 if ( currentFileName != fileFromComboBox )
862 currentFileName = fileFromComboBox;
864 if ( currentFileName.Length == 0 )
868 if ( fileDialog.fileDialogType == FileDialogType.OpenFileDialog )
870 if ( fileDialog.CheckFileExists )
872 if ( !File.Exists( currentFileName ) )
874 string message = currentFileName + " doesn't exist. Please verify that you have entered the correct file name.";
875 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
877 currentFileName = "";
883 else // FileDialogType == SaveFileDialog
885 if ( fileDialog.OverwritePrompt )
887 if ( File.Exists( currentFileName ) )
889 string message = currentFileName + " exists. Overwrite ?";
890 DialogResult dr = MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
892 if ( dr == DialogResult.Cancel )
894 currentFileName = "";
901 if ( fileDialog.CreatePrompt )
903 if ( !File.Exists( currentFileName ) )
905 string message = currentFileName + " doesn't exist. Create ?";
906 DialogResult dr = MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
908 if ( dr == DialogResult.Cancel )
910 currentFileName = "";
918 if ( fileDialog.fileDialogType == FileDialogType.SaveFileDialog )
920 if ( fileDialog.AddExtension && fileDialog.DefaultExt.Length > 0 )
922 if ( !currentFileName.EndsWith( fileDialog.DefaultExt ) )
924 currentFileName += "." + fileDialog.DefaultExt;
929 fileDialog.FileName = currentFileName;
931 else // multiSelect = true
932 if ( fileDialog.fileDialogType != FileDialogType.SaveFileDialog )
934 if ( mwfFileView.SelectedItems.Count > 0 )
936 // first remove all selected directories
937 ArrayList al = new ArrayList( );
939 foreach ( ListViewItem lvi in mwfFileView.SelectedItems )
941 FileStruct fileStruct = (FileStruct)mwfFileView.FileHashtable[ lvi.Text ];
943 if ( fileStruct.attributes != FileAttributes.Directory )
945 al.Add( fileStruct );
949 fileDialog.FileName = ( (FileStruct)al[ 0 ] ).fullname;
951 string[] filenames = new string[ al.Count ];
953 for ( int i = 0; i < al.Count; i++ )
955 filenames[ i ] = ( (FileStruct)al[ i ] ).fullname;
958 fileDialog.SetFilenames( filenames );
962 if ( fileDialog.CheckPathExists )
964 if ( !Directory.Exists( currentDirectoryName ) )
966 string message = currentDirectoryName + " doesn't exist. Please verify that you have entered the correct directory name.";
967 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
969 if ( fileDialog.InitialDirectory == String.Empty )
970 currentDirectoryName = Environment.CurrentDirectory;
972 currentDirectoryName = fileDialog.InitialDirectory;
978 if ( fileDialog.RestoreDirectory )
979 currentDirectoryName = restoreDirectory;
981 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
983 cancelEventArgs.Cancel = false;
985 fileDialog.OnFileOk( cancelEventArgs );
987 fileDialog.form.Controls.Remove( this );
988 fileDialog.form.DialogResult = DialogResult.OK;
991 void OnClickCancelButton( object sender, EventArgs e )
993 if ( fileDialog.RestoreDirectory )
994 currentDirectoryName = restoreDirectory;
996 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
998 cancelEventArgs.Cancel = true;
1000 fileDialog.OnFileOk( cancelEventArgs );
1002 fileDialog.form.Controls.Remove( this );
1003 fileDialog.form.DialogResult = DialogResult.Cancel;
1006 void OnClickHelpButton( object sender, EventArgs e )
1008 fileDialog.SendHelpRequest( e );
1011 void OnClickSmallButtonToolBar( object sender, ToolBarButtonClickEventArgs e )
1013 if ( e.Button == upToolBarButton )
1015 if ( directoryInfo.Parent != null )
1017 PushDirectory( directoryInfo );
1019 directoryInfo = directoryInfo.Parent;
1021 currentDirectoryName = directoryInfo.FullName;
1023 dirComboBox.CurrentPath = currentDirectoryName;
1025 mwfFileView.UpdateFileView( directoryInfo );
1029 if ( e.Button == backToolBarButton )
1031 if ( directoryStack.Count != 0 )
1035 dirComboBox.CurrentPath = currentDirectoryName;
1037 mwfFileView.UpdateFileView( directoryInfo );
1041 if ( e.Button == newdirToolBarButton )
1047 void OnClickMenuToolBarContextMenu( object sender, EventArgs e )
1049 MenuItem senderMenuItem = (MenuItem)sender;
1051 previousCheckedMenuItem.Checked = false;
1052 senderMenuItem.Checked = true;
1053 previousCheckedMenuItem = senderMenuItem;
1057 switch ( senderMenuItem.Index )
1060 mwfFileView.View = View.SmallIcon;
1063 mwfFileView.View = View.LargeIcon;
1066 mwfFileView.View = View.LargeIcon;
1069 mwfFileView.View = View.List;
1072 mwfFileView.View = View.Details;
1080 void OnKeyUpFileNameComboBox( object sender, KeyEventArgs e )
1082 if ( e.KeyCode == Keys.Enter )
1084 currentFileName = currentDirectoryName + fileNameComboBox.Text;
1089 void OnSelectedIndexChangedFileTypeComboBox( object sender, EventArgs e )
1091 fileDialog.FilterIndex = fileTypeComboBox.SelectedIndex + 1;
1093 mwfFileView.FilterIndex = fileDialog.FilterIndex;
1095 mwfFileView.UpdateFileView( directoryInfo );
1098 void OnSelectedFileChangedFileView( object sender, EventArgs e )
1100 fileNameComboBox.Text = mwfFileView.FileName;
1101 currentFileName = mwfFileView.FullFileName;
1104 void OnDirectoryChangedFileView( object sender, EventArgs e )
1106 ChangeDirectory( sender, mwfFileView.FullFileName );
1109 void OnForceDialogEndFileView( object sender, EventArgs e )
1114 void OnSelectedFilesChangedFileView( object sender, EventArgs e )
1116 fileNameComboBox.Text = mwfFileView.SelectedFilesString;
1119 void OnDirectoryChangedDirComboBox( object sender, EventArgs e )
1121 ChangeDirectory( sender, dirComboBox.CurrentPath );
1124 void OnCheckCheckChanged( object sender, EventArgs e )
1126 fileDialog.ReadOnlyChecked = checkBox.Checked;
1129 public void UpdateFilters( )
1131 ArrayList filters = fileDialog.FileFilter.FilterArrayList;
1133 fileTypeComboBox.Items.Clear( );
1135 fileTypeComboBox.BeginUpdate( );
1137 foreach ( FilterStruct fs in filters )
1139 fileTypeComboBox.Items.Add( fs.filterName );
1142 fileTypeComboBox.SelectedIndex = fileDialog.FilterIndex - 1;
1144 fileTypeComboBox.EndUpdate( );
1146 mwfFileView.FilterArrayList = filters;
1148 mwfFileView.FilterIndex = fileDialog.FilterIndex;
1150 mwfFileView.UpdateFileView( directoryInfo );
1153 public void ChangeDirectory( object sender, string path )
1155 currentDirectoryName = path;
1157 PushDirectory( directoryInfo );
1159 directoryInfo = new DirectoryInfo( path );
1161 if ( sender != dirComboBox )
1162 dirComboBox.CurrentPath = path;
1164 mwfFileView.UpdateFileView( directoryInfo );
1167 public void ForceDialogEnd( )
1169 OnClickOpenSaveButton( this, EventArgs.Empty );
1172 private void PushDirectory( DirectoryInfo di )
1174 directoryStack.Push( directoryInfo );
1175 backToolBarButton.Enabled = true;
1178 private void PopDirectory( )
1180 directoryInfo = (DirectoryInfo)directoryStack.Pop( );
1182 currentDirectoryName = directoryInfo.FullName;
1184 if ( directoryStack.Count == 0 )
1185 backToolBarButton.Enabled = false;
1188 public void ResizeAndRelocateForHelpOrReadOnly( )
1190 if ( fileDialog.ShowHelp || fileDialog.ShowReadOnly )
1192 mwfFileView.Size = new Size( 449, 250 );
1193 fileNameLabel.Location = new Point( 102, 298 );
1194 fileNameComboBox.Location = new Point( 195, 298 );
1195 fileTypeLabel.Location = new Point( 102, 324 );
1196 fileTypeComboBox.Location = new Point( 195, 324 );
1197 openSaveButton.Location = new Point( 475, 298 );
1198 cancelButton.Location = new Point( 475, 324 );
1202 mwfFileView.Size = new Size( 449, 282 );
1203 fileNameLabel.Location = new Point( 102, 330 );
1204 fileNameComboBox.Location = new Point( 195, 330 );
1205 fileTypeLabel.Location = new Point( 102, 356 );
1206 fileTypeComboBox.Location = new Point( 195, 356 );
1207 openSaveButton.Location = new Point( 475, 330 );
1208 cancelButton.Location = new Point( 475, 356 );
1211 if ( fileDialog.ShowHelp )
1214 if ( fileDialog.ShowReadOnly )
1218 internal class PopupButtonPanel : Panel
1220 internal class PopupButton : Control
1222 internal enum PopupButtonState
1225 private Image image = null;
1226 private PopupButtonState popupButtonState = PopupButtonState.Normal;
1227 private StringFormat text_format = new StringFormat();
1229 public PopupButton( )
1231 text_format.Alignment = StringAlignment.Center;
1232 text_format.LineAlignment = StringAlignment.Far;
1234 SetStyle( ControlStyles.DoubleBuffer, true );
1235 SetStyle( ControlStyles.AllPaintingInWmPaint, true );
1236 SetStyle( ControlStyles.UserPaint, true );
1253 public PopupButtonState ButtonState
1257 popupButtonState = value;
1263 return popupButtonState;
1267 protected override void OnPaint( PaintEventArgs pe )
1274 private void Draw( PaintEventArgs pe )
1276 Graphics gr = pe.Graphics;
1278 gr.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush ( BackColor ), ClientRectangle );
1281 if ( image != null )
1283 int i_x = ( ClientSize.Width - image.Width ) / 2;
1285 gr.DrawImage( image, i_x, i_y );
1288 if ( Text != String.Empty )
1290 Rectangle text_rect = Rectangle.Inflate( ClientRectangle, -4, -4 );
1292 gr.DrawString( Text, Font, ThemeEngine.Current.ResPool.GetSolidBrush (ForeColor ), text_rect, text_format );
1295 switch ( popupButtonState )
1297 case PopupButtonState.Up:
1298 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, 0, ClientSize.Width - 1, 0 );
1299 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, 0, 0, ClientSize.Height - 1 );
1300 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1 );
1301 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1 );
1304 case PopupButtonState.Down:
1305 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, 0, ClientSize.Width - 1, 0 );
1306 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, 0, 0, ClientSize.Height - 1 );
1307 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1 );
1308 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1 );
1313 protected override void OnMouseEnter( EventArgs e )
1315 if ( popupButtonState != PopupButtonState.Down )
1316 popupButtonState = PopupButtonState.Up;
1318 base.OnMouseEnter( e );
1321 protected override void OnMouseLeave( EventArgs e )
1323 if ( popupButtonState != PopupButtonState.Down )
1324 popupButtonState = PopupButtonState.Normal;
1326 base.OnMouseLeave( e );
1329 protected override void OnClick( EventArgs e )
1331 popupButtonState = PopupButtonState.Down;
1337 private FileDialogPanel fileDialogPanel;
1339 private PopupButton lastOpenButton;
1340 private PopupButton desktopButton;
1341 private PopupButton homeButton;
1342 private PopupButton workplaceButton;
1343 private PopupButton networkButton;
1345 private PopupButton lastPopupButton = null;
1347 private ImageList imageList = new ImageList();
1349 public PopupButtonPanel( FileDialogPanel fileDialogPanel )
1351 this.fileDialogPanel = fileDialogPanel;
1353 BorderStyle = BorderStyle.Fixed3D;
1354 BackColor = Color.FromArgb( 128, 128, 128 );
1355 Size = new Size( 85, 336 );
1357 // use ImageList to scale the bitmaps
1358 imageList.ColorDepth = ColorDepth.Depth32Bit;
1359 imageList.ImageSize = new Size( 38, 38 );
1360 imageList.Images.Add( (Image)Locale.GetResource( "last_open" ) );
1361 imageList.Images.Add( (Image)Locale.GetResource( "desktop" ) );
1362 imageList.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
1363 imageList.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
1364 imageList.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
1365 imageList.TransparentColor = Color.Transparent;
1367 lastOpenButton = new PopupButton( );
1368 desktopButton = new PopupButton( );
1369 homeButton = new PopupButton( );
1370 workplaceButton = new PopupButton( );
1371 networkButton = new PopupButton( );
1373 lastOpenButton.Size = new Size( 82, 64 );
1374 lastOpenButton.Image = imageList.Images[ 0 ];
1375 lastOpenButton.BackColor = BackColor;
1376 lastOpenButton.ForeColor = Color.White;
1377 lastOpenButton.Location = new Point( 2, 2 );
1378 lastOpenButton.Text = "Last Open";
1379 lastOpenButton.Click += new EventHandler( OnClickButton );
1381 desktopButton.Image = imageList.Images[ 1 ];
1382 desktopButton.BackColor = BackColor;
1383 desktopButton.ForeColor = Color.White;
1384 desktopButton.Size = new Size( 82, 64 );
1385 desktopButton.Location = new Point( 2, 66 );
1386 desktopButton.Text = "Desktop";
1387 desktopButton.Click += new EventHandler( OnClickButton );
1389 homeButton.Image = imageList.Images[ 2 ];
1390 homeButton.BackColor = BackColor;
1391 homeButton.ForeColor = Color.White;
1392 homeButton.Size = new Size( 82, 64 );
1393 homeButton.Location = new Point( 2, 130 );
1394 homeButton.Text = "Home";
1395 homeButton.Click += new EventHandler( OnClickButton );
1397 workplaceButton.Image = imageList.Images[ 3 ];
1398 workplaceButton.BackColor = BackColor;
1399 workplaceButton.ForeColor = Color.White;
1400 workplaceButton.Size = new Size( 82, 64 );
1401 workplaceButton.Location = new Point( 2, 194 );
1402 workplaceButton.Text = "Workplace";
1403 workplaceButton.Click += new EventHandler( OnClickButton );
1405 networkButton.Image = imageList.Images[ 4 ];
1406 networkButton.BackColor = BackColor;
1407 networkButton.ForeColor = Color.White;
1408 networkButton.Size = new Size( 82, 64 );
1409 networkButton.Location = new Point( 2, 258 );
1410 networkButton.Text = "Network";
1411 networkButton.Click += new EventHandler( OnClickButton );
1413 Controls.Add( lastOpenButton );
1414 Controls.Add( desktopButton );
1415 Controls.Add( homeButton );
1416 Controls.Add( workplaceButton );
1417 Controls.Add( networkButton );
1420 void OnClickButton( object sender, EventArgs e )
1422 if ( lastPopupButton != null && (PopupButton)sender != lastPopupButton )
1423 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1424 lastPopupButton = sender as PopupButton;
1426 if ( sender == lastOpenButton )
1431 if ( sender == desktopButton )
1433 fileDialogPanel.ChangeDirectory( this, Environment.GetFolderPath( Environment.SpecialFolder.Desktop ) );
1436 if ( sender == homeButton )
1438 fileDialogPanel.ChangeDirectory( this, Environment.GetFolderPath( Environment.SpecialFolder.Personal ) );
1441 if ( sender == workplaceButton )
1443 // fileDialogPanel.ChangeDirectory(this, Environment.GetFolderPath( Environment.SpecialFolder.MyComputer ) );
1446 if ( sender == networkButton )
1455 internal struct FilterStruct
1457 public string filterName;
1458 public StringCollection filters;
1460 public FilterStruct( string filterName, string filter )
1462 this.filterName = filterName;
1464 filters = new StringCollection( );
1466 SplitFilters( filter );
1469 private void SplitFilters( string filter )
1471 string[] split = filter.Split( new Char[] {';'} );
1473 filters.AddRange( split );
1477 internal struct FileStruct
1479 public FileStruct( string fullname, FileAttributes attributes )
1481 this.fullname = fullname;
1482 this.attributes = attributes;
1485 public string fullname;
1486 public FileAttributes attributes;
1490 internal class MWFFileView : ListView
1492 private ImageList fileViewSmallImageList = new ImageList();
1493 private ImageList fileViewBigImageList = new ImageList();
1495 private ArrayList filterArrayList;
1496 // store the FileStruct of all files in the current directory
1497 private Hashtable fileHashtable = new Hashtable();
1499 private bool showHiddenFiles = false;
1501 private EventHandler on_selected_file_changed;
1502 private EventHandler on_selected_files_changed;
1503 private EventHandler on_directory_changed;
1504 private EventHandler on_force_dialog_end;
1506 private string fileName;
1507 private string fullFileName;
1508 private string selectedFilesString;
1510 private int filterIndex;
1512 public MWFFileView( )
1514 fileViewSmallImageList.ColorDepth = ColorDepth.Depth32Bit;
1515 fileViewSmallImageList.ImageSize = new Size( 16, 16 );
1516 fileViewSmallImageList.Images.Add( (Image)Locale.GetResource( "paper" ) );
1517 fileViewSmallImageList.Images.Add( (Image)Locale.GetResource( "folder" ) );
1518 fileViewSmallImageList.TransparentColor = Color.Transparent;
1520 fileViewBigImageList.ColorDepth = ColorDepth.Depth32Bit;
1521 fileViewBigImageList.ImageSize = new Size( 48, 48 );
1522 fileViewBigImageList.Images.Add( (Image)Locale.GetResource( "paper" ) );
1523 fileViewBigImageList.Images.Add( (Image)Locale.GetResource( "folder" ) );
1524 fileViewBigImageList.TransparentColor = Color.Transparent;
1526 SmallImageList = fileViewSmallImageList;
1527 LargeImageList = fileViewBigImageList;
1532 public ArrayList FilterArrayList
1536 filterArrayList = value;
1541 return filterArrayList;
1545 public Hashtable FileHashtable
1549 fileHashtable = value;
1554 return fileHashtable;
1558 public bool ShowHiddenFiles
1562 showHiddenFiles = value;
1567 return showHiddenFiles;
1571 public string FileName
1584 public string FullFileName
1588 fullFileName = value;
1593 return fullFileName;
1597 public int FilterIndex
1601 filterIndex = value;
1610 public string SelectedFilesString
1614 selectedFilesString = value;
1619 return selectedFilesString;
1623 private ArrayList GetFileInfoArrayList( DirectoryInfo directoryInfo )
1625 ArrayList arrayList = new ArrayList( );
1627 if ( filterArrayList != null && filterArrayList.Count != 0 )
1629 FilterStruct fs = (FilterStruct)filterArrayList[ filterIndex - 1 ];
1631 foreach ( string s in fs.filters )
1632 arrayList.AddRange( directoryInfo.GetFiles( s ) );
1635 arrayList.AddRange( directoryInfo.GetFiles( ) );
1640 public void UpdateFileView( DirectoryInfo inputDirectoryInfo )
1642 DirectoryInfo directoryInfo = inputDirectoryInfo;
1644 DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories( );
1646 ArrayList fileInfoArrayList = GetFileInfoArrayList( directoryInfo );
1648 fileHashtable.Clear( );
1653 SelectedItems.Clear( );
1655 foreach ( DirectoryInfo directoryInfoi in directoryInfoArray )
1657 if ( !ShowHiddenFiles )
1658 if ( directoryInfoi.Name.StartsWith( "." ) || directoryInfoi.Attributes == FileAttributes.Hidden )
1661 FileStruct fileStruct = new FileStruct( );
1663 fileStruct.fullname = directoryInfoi.FullName;
1665 ListViewItem listViewItem = new ListViewItem( directoryInfoi.Name );
1667 listViewItem.ImageIndex = 1;
1669 listViewItem.SubItems.Add( "" );
1670 listViewItem.SubItems.Add( "Directory" );
1671 listViewItem.SubItems.Add( directoryInfoi.LastAccessTime.ToShortDateString( ) + " " + directoryInfoi.LastAccessTime.ToShortTimeString( ) );
1673 fileStruct.attributes = FileAttributes.Directory;
1675 fileHashtable.Add( directoryInfoi.Name, fileStruct );
1677 Items.Add( listViewItem );
1680 foreach ( FileInfo fileInfo in fileInfoArrayList )
1682 if ( !ShowHiddenFiles )
1683 if ( fileInfo.Name.StartsWith( "." ) || fileInfo.Attributes == FileAttributes.Hidden )
1686 FileStruct fileStruct = new FileStruct( );
1688 fileStruct.fullname = fileInfo.FullName;
1690 ListViewItem listViewItem = new ListViewItem( fileInfo.Name );
1692 listViewItem.ImageIndex = 0;
1695 if ( fileInfo.Length > 1024 )
1696 fileLen = fileInfo.Length / 1024;
1698 listViewItem.SubItems.Add( fileLen.ToString( ) + " KB" );
1699 listViewItem.SubItems.Add( "File" );
1700 listViewItem.SubItems.Add( fileInfo.LastAccessTime.ToShortDateString( ) + " " + fileInfo.LastAccessTime.ToShortTimeString( ) );
1702 fileStruct.attributes = FileAttributes.Normal;
1704 fileHashtable.Add( fileInfo.Name, fileStruct );
1706 Items.Add( listViewItem );
1712 protected override void OnClick( EventArgs e )
1716 if ( SelectedItems.Count > 0 )
1718 ListViewItem listViewItem = SelectedItems[ 0 ];
1720 FileStruct fileStruct = (FileStruct)fileHashtable[ listViewItem.Text ];
1722 if ( fileStruct.attributes != FileAttributes.Directory )
1724 fileName = listViewItem.Text;
1725 fullFileName = fileStruct.fullname;
1727 if ( on_selected_file_changed != null )
1728 on_selected_file_changed( this, EventArgs.Empty );
1736 protected override void OnDoubleClick( EventArgs e )
1738 if ( SelectedItems.Count > 0 )
1740 ListViewItem listViewItem = SelectedItems[ 0 ];
1742 FileStruct fileStruct = (FileStruct)fileHashtable[ listViewItem.Text ];
1744 if ( fileStruct.attributes == FileAttributes.Directory )
1746 fullFileName = fileStruct.fullname;
1748 if ( on_directory_changed != null )
1749 on_directory_changed( this, EventArgs.Empty );
1753 fileName = listViewItem.Text;
1754 fullFileName = fileStruct.fullname;
1756 if ( on_selected_file_changed != null )
1757 on_selected_file_changed( this, EventArgs.Empty );
1759 if ( on_force_dialog_end != null )
1760 on_force_dialog_end( this, EventArgs.Empty );
1766 base.OnDoubleClick( e );
1769 protected override void OnSelectedIndexChanged( EventArgs e )
1773 if ( SelectedItems.Count > 0 )
1775 selectedFilesString = "";
1777 if ( SelectedItems.Count == 1 )
1779 FileStruct fileStruct = (FileStruct)fileHashtable[ SelectedItems[ 0 ].Text ];
1781 if ( fileStruct.attributes != FileAttributes.Directory )
1782 selectedFilesString = SelectedItems[ 0 ].Text;
1786 foreach ( ListViewItem lvi in SelectedItems )
1788 FileStruct fileStruct = (FileStruct)fileHashtable[ lvi.Text ];
1790 if ( fileStruct.attributes != FileAttributes.Directory )
1791 selectedFilesString += "\"" + lvi.Text + "\" ";
1795 if ( on_selected_files_changed != null )
1796 on_selected_files_changed( this, EventArgs.Empty );
1800 base.OnSelectedIndexChanged( e );
1803 public event EventHandler SelectedFileChanged
1806 { on_selected_file_changed += value; }
1808 { on_selected_file_changed -= value; }
1811 public event EventHandler SelectedFilesChanged
1814 { on_selected_files_changed += value; }
1816 { on_selected_files_changed -= value; }
1819 public event EventHandler DirectoryChanged
1822 { on_directory_changed += value; }
1824 { on_directory_changed -= value; }
1827 public event EventHandler ForceDialogEnd
1830 { on_force_dialog_end += value; }
1832 { on_force_dialog_end -= value; }
1836 internal class FileFilter
1838 private ArrayList filterArrayList = new ArrayList();
1840 private string filter;
1842 public FileFilter( )
1845 public FileFilter( string filter )
1847 this.filter = filter;
1852 public ArrayList FilterArrayList
1856 filterArrayList = value;
1861 return filterArrayList;
1865 public string Filter
1880 private void SplitFilter( )
1882 filterArrayList.Clear( );
1884 if ( filter == null )
1885 throw new NullReferenceException( "Filter" );
1887 if ( filter.Length == 0 )
1890 string[] filters = filter.Split( new Char[] {'|'} );
1892 if ( ( filters.Length % 2 ) != 0 )
1893 throw new ArgumentException( "Filter" );
1895 for ( int i = 0; i < filters.Length; i += 2 )
1897 FilterStruct filterStruct = new FilterStruct( filters[ i ], filters[ i + 1 ] );
1899 filterArrayList.Add( filterStruct );
1904 internal class DirComboBox : ComboBox
1906 internal class DirComboBoxItem
1908 private int imageIndex;
1909 private string name;
1910 private string path;
1913 public DirComboBoxItem( int imageIndex, string name, string path, int xPos )
1915 this.imageIndex = imageIndex;
1921 public int ImageIndex
1974 private ImageList imageList = new ImageList();
1976 private string currentPath;
1978 private bool firstTime = true;
1980 private EventHandler on_directory_changed;
1982 public DirComboBox( )
1984 DrawMode = DrawMode.OwnerDrawFixed;
1986 imageList.ColorDepth = ColorDepth.Depth32Bit;
1987 imageList.ImageSize = new Size( 16, 16 );
1988 imageList.Images.Add( (Image)Locale.GetResource( "last_open" ) );
1989 imageList.Images.Add( (Image)Locale.GetResource( "desktop" ) );
1990 imageList.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
1991 imageList.Images.Add( (Image)Locale.GetResource( "folder" ) );
1992 imageList.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
1993 imageList.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
1994 imageList.TransparentColor = Color.Transparent;
1996 Items.AddRange( new object[] {
1997 new DirComboBoxItem( 1, "Desktop", Environment.GetFolderPath( Environment.SpecialFolder.Desktop ), 0 ),
1998 new DirComboBoxItem( 2, "Home", Environment.GetFolderPath( Environment.SpecialFolder.Personal ), 0 )
2003 public string CurrentPath
2007 currentPath = value;
2017 private void ShowPath( )
2019 DirectoryInfo di = new DirectoryInfo( currentPath );
2021 Stack dirStack = new Stack( );
2023 dirStack.Push( di );
2025 while ( di.Parent != null )
2028 dirStack.Push( di );
2035 Items.AddRange( new object[] {
2036 new DirComboBoxItem( 1, "Desktop", Environment.GetFolderPath( Environment.SpecialFolder.Desktop ), 0 ),
2037 new DirComboBoxItem( 2, "Home", Environment.GetFolderPath( Environment.SpecialFolder.Personal ), 0 )
2045 while ( dirStack.Count != 0 )
2047 DirectoryInfo dii = (DirectoryInfo)dirStack.Pop( );
2048 sel = Items.Add( new DirComboBoxItem( 3, dii.Name, dii.FullName, xPos + 4 ) );
2053 SelectedIndex = sel;
2058 protected override void OnDrawItem( DrawItemEventArgs e )
2060 if ( e.Index == -1 )
2063 Bitmap bmp = new Bitmap( e.Bounds.Width, e.Bounds.Height, e.Graphics );
2064 Graphics gr = Graphics.FromImage( bmp );
2066 DirComboBoxItem dcbi = Items[ e.Index ] as DirComboBoxItem;
2068 Color backColor = e.BackColor;
2069 Color foreColor = e.ForeColor;
2071 int xPos = dcbi.XPos;
2073 // Bug in ComboBox !!!!!
2074 // we never receive DrawItemState.ComboBoxEdit
2075 if ( ( e.State & DrawItemState.ComboBoxEdit ) != 0 )
2078 if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected )
2080 backColor = Color.Blue;
2081 foreColor = Color.White;
2084 gr.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush (backColor ), new Rectangle( 0, 0, bmp.Width, bmp.Height ) );
2086 gr.DrawString( dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush (foreColor ), new Point( 24 + xPos, ( bmp.Height - e.Font.Height ) / 2 ) );
2087 gr.DrawImage( imageList.Images[ dcbi.ImageIndex ], new Rectangle( new Point( xPos + 2, 0 ), new Size( 16, 16 ) ) );
2089 e.Graphics.DrawImage( bmp, e.Bounds.X, e.Bounds.Y );
2092 protected override void OnSelectedIndexChanged( EventArgs e )
2094 // do not call ChangeDirectory when invoked from FileDialogPanel ctor...
2101 if ( Items.Count > 0 )
2103 DirComboBoxItem dcbi = Items[ SelectedIndex ] as DirComboBoxItem;
2105 currentPath = dcbi.Path;
2107 if ( on_directory_changed != null )
2108 on_directory_changed( this, EventArgs.Empty );
2112 public event EventHandler DirectoryChanged
2115 { on_directory_changed += value; }
2117 { on_directory_changed -= value; }