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
31 using System.ComponentModel;
32 using System.Resources;
34 using System.Collections;
35 using System.Collections.Specialized;
37 namespace System.Windows.Forms
39 public abstract class FileDialog : CommonDialog
41 internal FileDialogPanel fileDialogPanel;
43 private bool addExtension = true;
44 private bool checkFileExists = false;
45 private bool checkPathExists = true;
46 private string defaultExt = "";
47 private bool dereferenceLinks = true;
48 private string fileName = "";
49 private string[] fileNames;
50 private string filter;
51 private int filterIndex = 1;
52 private string initialDirectory = "";
53 private bool restoreDirectory = false;
54 private bool showHelp = false;
55 private string title = "";
56 private bool validateNames = true;
58 internal string openSaveButtonText;
59 internal string searchSaveLabelText;
60 internal bool fileDialogShowReadOnly;
62 public bool AddExtension
75 public virtual bool CheckFileExists
79 return checkFileExists;
84 checkFileExists = value;
88 public bool CheckPathExists
92 return checkPathExists;
97 checkPathExists = value;
101 public string DefaultExt
114 public bool DereferenceLinks
118 return dereferenceLinks;
123 dereferenceLinks = value;
127 public string FileName
140 public string[] FileNames
158 throw new NullReferenceException( "Filter" );
164 fileDialogPanel.UpdateFilters( filterArrayList );
168 public int FilterIndex
181 public string InitialDirectory
185 return initialDirectory;
190 initialDirectory = value;
194 public bool RestoreDirectory
198 return restoreDirectory;
203 restoreDirectory = value;
217 fileDialogPanel.ResizeAndRelocateForHelpOrReadOnly( );
236 public bool ValidateNames
240 return validateNames;
245 validateNames = value;
249 internal string OpenSaveButtonText
253 openSaveButtonText = value;
258 return openSaveButtonText;
262 public string SearchSaveLabelText
266 searchSaveLabelText = value;
271 return searchSaveLabelText;
275 public bool FileDialogShowReadOnly
279 fileDialogShowReadOnly = value;
284 return fileDialogShowReadOnly;
288 public override void Reset( )
291 checkFileExists = false;
292 checkPathExists = true;
294 dereferenceLinks = true;
299 initialDirectory = "";
300 restoreDirectory = false;
303 validateNames = true;
306 public override string ToString( )
308 return base.ToString( );
311 public event CancelEventHandler FileOk;
313 protected override IntPtr HookProc( IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam )
315 throw new NotImplementedException( );
318 protected void OnFileOk( CancelEventArgs e )
320 if ( FileOk != null ) FileOk( this, e );
324 protected override bool RunDialog( IntPtr hWndOwner )
326 form.Controls.Add( fileDialogPanel );
331 private void SplitFilter( )
333 filterArrayList.Clear( );
335 if ( filter == null )
336 throw new NullReferenceException( "Filter" );
338 // FIXME: default, MS default is nothing, nada...
339 if ( filter.Length == 0 )
340 filter = "All Files (*.*)|*.*";
342 string[] filters = filter.Split( new Char[] {'|'} );
344 if ( ( filters.Length % 2 ) != 0 )
345 throw new ArgumentException( "Filter" );
347 for ( int i = 0; i < filters.Length; i += 2 )
349 FilterStruct filterStruct = new FilterStruct( filters[ i ], filters[ i + 1 ] );
351 filterArrayList.Add( filterStruct );
354 // if ( filterAL.Count > 1 )
358 internal void SendHelpRequest( EventArgs e )
363 internal struct FilterStruct
365 public string filterName;
366 public StringCollection filters;
368 public FilterStruct( string filterName, string filter )
370 this.filterName = filterName;
372 filters = new StringCollection( );
374 SplitFilters( filter );
377 private void SplitFilters( string filter )
379 string[] split = filter.Split( new Char[] {';'} );
381 filters.AddRange( split );
385 internal ArrayList filterArrayList = new ArrayList();
387 internal class FileDialogPanel : Panel
389 internal struct FileStruct
391 public FileStruct( string fullname, FileAttributes attributes )
393 this.fullname = fullname;
394 this.attributes = attributes;
397 public string fullname;
398 public FileAttributes attributes;
401 private Button cancelButton;
402 private ToolBarButton upToolBarButton;
403 // private ToolBar bigButtonToolBar;
404 private ButtonPanel buttonPanel;
405 private Button openSaveButton;
406 private Button helpButton;
407 private Label fileTypeLabel;
408 private ToolBarButton menueToolBarButton;
409 private ContextMenu menueToolBarButtonContextMenu;
410 private ToolBarButton desktopToolBarButton;
411 private ToolBar smallButtonToolBar;
412 private ComboBox dirComboBox;
413 private ToolBarButton lastUsedToolBarButton;
414 private ComboBox fileNameComboBox;
415 private ToolBarButton networkToolBarButton;
416 private Label fileNameLabel;
417 private FileListView fileListView;
418 private Label searchSaveLabel;
419 private ToolBarButton newdirToolBarButton;
420 private ToolBarButton backToolBarButton;
421 private ToolBarButton homeToolBarButton;
422 private ToolBarButton workplaceToolBarButton;
423 private ComboBox fileTypeComboBox;
424 // private ImageList imageListLeftToolbar;
425 private ImageList imageListTopToolbar;
427 private FileDialog fileDialog;
429 private string currentDirectoryName;
431 // store current directoryInfo
432 private DirectoryInfo directoryInfo;
434 // store the FileStruct of all files in the current directory
435 internal Hashtable fileHashtable = new Hashtable();
437 // store DirectoryInfo for backButton
438 internal Stack directoryStack = new Stack();
440 internal string currentFileName = "";
442 private MenuItem previousCheckedMenuItem;
444 public FileDialogPanel( FileDialog fileDialog )
446 this.fileDialog = fileDialog;
448 fileTypeComboBox = new ComboBox( );
449 workplaceToolBarButton = new ToolBarButton( );
450 homeToolBarButton = new ToolBarButton( );
451 backToolBarButton = new ToolBarButton( );
452 newdirToolBarButton = new ToolBarButton( );
453 searchSaveLabel = new Label( );
454 fileListView = new FileListView( this );
455 fileNameLabel = new Label( );
456 networkToolBarButton = new ToolBarButton( );
457 fileNameComboBox = new ComboBox( );
458 lastUsedToolBarButton = new ToolBarButton( );
459 dirComboBox = new ComboBox( );
460 smallButtonToolBar = new ToolBar( );
461 desktopToolBarButton = new ToolBarButton( );
462 menueToolBarButton = new ToolBarButton( );
463 fileTypeLabel = new Label( );
464 openSaveButton = new Button( );
465 fileDialog.form.AcceptButton = openSaveButton;
466 helpButton = new Button( );
467 // bigButtonToolBar = new ToolBar( );
468 buttonPanel = new ButtonPanel( this );
469 upToolBarButton = new ToolBarButton( );
470 cancelButton = new Button( );
471 fileDialog.form.CancelButton = cancelButton;
472 imageListTopToolbar = new ImageList( );
473 // imageListLeftToolbar = new ImageList( );
474 menueToolBarButtonContextMenu = new ContextMenu( );
478 // imageListLeftToolbar
479 // imageListLeftToolbar.ColorDepth = ColorDepth.Depth32Bit;
480 // imageListLeftToolbar.ImageSize = new Size( 48, 48 );
481 // imageListLeftToolbar.Images.Add( (Image)Locale.GetResource( "last_open" ) );
482 // imageListLeftToolbar.Images.Add( (Image)Locale.GetResource( "desktop" ) );
483 // imageListLeftToolbar.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
484 // imageListLeftToolbar.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
485 // imageListLeftToolbar.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
486 // imageListLeftToolbar.TransparentColor = Color.Transparent;
488 //imageListTopToolbar
489 imageListTopToolbar.ColorDepth = ColorDepth.Depth32Bit;
490 imageListTopToolbar.ImageSize = new Size( 16, 16 ); // 16, 16
491 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "back_arrow" ) );
492 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_arrow_up" ) );
493 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_star" ) );
494 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "window" ) );
495 imageListTopToolbar.TransparentColor = Color.Transparent;
498 searchSaveLabel.FlatStyle = FlatStyle.System;
499 searchSaveLabel.Location = new Point( 7, 8 );
500 searchSaveLabel.Size = new Size( 72, 21 );
501 searchSaveLabel.TabIndex = 0;
502 searchSaveLabel.Text = fileDialog.SearchSaveLabelText;
503 searchSaveLabel.TextAlign = ContentAlignment.MiddleRight;
506 dirComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Top | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
507 dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
508 dirComboBox.Location = new Point( 99, 8 );
509 dirComboBox.Size = new Size( 260, 21 );
510 dirComboBox.TabIndex = 1;
513 fileListView.Anchor = ( (AnchorStyles)( ( ( ( AnchorStyles.Top | AnchorStyles.Bottom ) | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
514 fileListView.Location = new Point( 99, 37 );
515 fileListView.Size = new Size( 449, 282 );
516 fileListView.Columns.Add( " Name", 170, HorizontalAlignment.Left );
517 fileListView.Columns.Add( "Size ", 80, HorizontalAlignment.Right );
518 fileListView.Columns.Add( " Type", 100, HorizontalAlignment.Left );
519 fileListView.Columns.Add( " Last Access", 150, HorizontalAlignment.Left );
520 fileListView.AllowColumnReorder = true;
521 fileListView.TabIndex = 2;
524 fileNameLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
525 fileNameLabel.FlatStyle = FlatStyle.System;
526 fileNameLabel.Location = new Point( 102, 330 );
527 fileNameLabel.Size = new Size( 70, 21 );
528 fileNameLabel.TabIndex = 6;
529 fileNameLabel.Text = "Filename:";
530 fileNameLabel.TextAlign = ContentAlignment.MiddleLeft;
533 fileNameComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
534 fileNameComboBox.Location = new Point( 195, 330 );
535 fileNameComboBox.Size = new Size( 245, 21 );
536 fileNameComboBox.TabIndex = 4;
539 fileTypeLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
540 fileTypeLabel.FlatStyle = FlatStyle.System;
541 fileTypeLabel.Location = new Point( 102, 356 );
542 fileTypeLabel.Size = new Size( 70, 21 );
543 fileTypeLabel.TabIndex = 5;
544 fileTypeLabel.Text = "Filetype:";
545 fileTypeLabel.TextAlign = ContentAlignment.MiddleLeft;
548 fileTypeComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
549 fileTypeComboBox.Location = new Point( 195, 356 );
550 fileTypeComboBox.Size = new Size( 245, 21 );
551 fileTypeComboBox.TabIndex = 6;
553 // smallButtonToolBar
554 smallButtonToolBar.Anchor = ( (AnchorStyles)( ( AnchorStyles.Top | AnchorStyles.Right ) ) );
555 smallButtonToolBar.Appearance = ToolBarAppearance.Flat;
556 smallButtonToolBar.AutoSize = false;
557 smallButtonToolBar.Buttons.AddRange( new ToolBarButton[] {
561 menueToolBarButton} );
562 smallButtonToolBar.ButtonSize = new Size( 21, 16 ); // 21, 16
563 smallButtonToolBar.Divider = false;
564 smallButtonToolBar.Dock = DockStyle.None;
565 smallButtonToolBar.DropDownArrows = true;
566 smallButtonToolBar.ImageList = imageListTopToolbar;
567 smallButtonToolBar.Location = new Point( 372, 8 );
568 smallButtonToolBar.ShowToolTips = true;
569 smallButtonToolBar.Size = new Size( 110, 20 );
570 smallButtonToolBar.TabIndex = 10;
571 smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
574 backToolBarButton.ImageIndex = 0;
575 backToolBarButton.Enabled = false;
576 backToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
579 upToolBarButton.ImageIndex = 1;
580 upToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
582 // newdirToolBarButton
583 newdirToolBarButton.ImageIndex = 2;
584 newdirToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
586 // menueToolBarButton
587 menueToolBarButton.ImageIndex = 3;
588 menueToolBarButton.DropDownMenu = menueToolBarButtonContextMenu;
589 menueToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
591 // // bigButtonToolBar
592 // bigButtonToolBar.Appearance = ToolBarAppearance.Flat;
593 // bigButtonToolBar.AutoSize = false;
594 // bigButtonToolBar.Buttons.AddRange( new ToolBarButton[] {
595 // lastUsedToolBarButton,
596 // desktopToolBarButton,
597 // homeToolBarButton,
598 // workplaceToolBarButton,
599 // networkToolBarButton} );
600 // bigButtonToolBar.ButtonSize = new Size( 82, 68 );
601 // bigButtonToolBar.Dock = DockStyle.None;
602 // bigButtonToolBar.Location = new Point( 7, 37 );
603 // bigButtonToolBar.ShowToolTips = true;
604 // bigButtonToolBar.Size = new Size( 85, 412 ); // 85, 412
605 // bigButtonToolBar.ImageList = imageListLeftToolbar;
606 // bigButtonToolBar.BackColor = Color.FromArgb( 128, 128, 128 );
607 // bigButtonToolBar.TabIndex = 3;
609 buttonPanel.Dock = DockStyle.None;
610 buttonPanel.Location = new Point( 7, 37 );
611 buttonPanel.TabIndex = 3;
613 // lastUsedToolBarButton
614 // lastUsedToolBarButton.ImageIndex = 0;
615 // lastUsedToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
616 // lastUsedToolBarButton.Text = "Last files";
618 // desktopToolBarButton
619 // desktopToolBarButton.ImageIndex = 1;
620 // desktopToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
621 // desktopToolBarButton.Text = "Desktop";
624 // homeToolBarButton.ImageIndex = 2;
625 // homeToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
626 // homeToolBarButton.Text = "Home";
628 // workplaceToolBarButton
629 // workplaceToolBarButton.ImageIndex = 3;
630 // workplaceToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
631 // workplaceToolBarButton.Text = "Workplace";
633 // networkToolBarButton
634 // networkToolBarButton.ImageIndex = 4;
635 // networkToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
636 // networkToolBarButton.Text = "Network";
638 // menueToolBarButtonContextMenu
639 MenuItem mi = new MenuItem( "Small Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
640 menueToolBarButtonContextMenu.MenuItems.Add( mi );
641 mi = new MenuItem( "Tiles", new EventHandler( OnClickMenuToolBarContextMenu ) );
642 menueToolBarButtonContextMenu.MenuItems.Add( mi );
643 mi = new MenuItem( "Large Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
644 menueToolBarButtonContextMenu.MenuItems.Add( mi );
645 mi = new MenuItem( "List", new EventHandler( OnClickMenuToolBarContextMenu ) );
647 previousCheckedMenuItem = mi;
648 menueToolBarButtonContextMenu.MenuItems.Add( mi );
649 mi = new MenuItem( "Details", new EventHandler( OnClickMenuToolBarContextMenu ) );
650 menueToolBarButtonContextMenu.MenuItems.Add( mi );
653 openSaveButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
654 openSaveButton.FlatStyle = FlatStyle.System;
655 openSaveButton.Location = new Point( 475, 330 );
656 openSaveButton.Size = new Size( 72, 21 );
657 openSaveButton.TabIndex = 8;
658 openSaveButton.Text = fileDialog.OpenSaveButtonText;
661 cancelButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
662 cancelButton.FlatStyle = FlatStyle.System;
663 cancelButton.Location = new Point( 475, 356 );
664 cancelButton.Size = new Size( 72, 21 );
665 cancelButton.TabIndex = 9;
666 cancelButton.Text = "Cancel";
669 helpButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
670 helpButton.FlatStyle = FlatStyle.System;
671 helpButton.Location = new Point( 475, 350 );
672 helpButton.Size = new Size( 72, 21 );
673 helpButton.TabIndex = 10;
674 helpButton.Text = "Help";
677 ClientSize = new Size( 554, 405 ); // 384
679 Controls.Add( smallButtonToolBar );
680 Controls.Add( cancelButton );
681 Controls.Add( openSaveButton );
682 Controls.Add( helpButton );
683 Controls.Add( fileTypeLabel );
684 Controls.Add( fileNameLabel );
685 Controls.Add( fileTypeComboBox );
686 Controls.Add( fileNameComboBox );
687 Controls.Add( dirComboBox );
688 Controls.Add( searchSaveLabel );
689 Controls.Add( fileListView );
690 // Controls.Add( bigButtonToolBar );
691 Controls.Add( buttonPanel );
693 ResumeLayout( false );
695 if ( fileDialog.InitialDirectory == String.Empty )
696 currentDirectoryName = Environment.CurrentDirectory;
698 directoryInfo = new DirectoryInfo( currentDirectoryName );
700 fileListView.UpdateFileListView( );
702 openSaveButton.Click += new EventHandler( OnClickOpenButton );
703 cancelButton.Click += new EventHandler( OnClickCancelButton );
704 helpButton.Click += new EventHandler( OnClickHelpButton );
706 smallButtonToolBar.ButtonClick += new ToolBarButtonClickEventHandler( OnClickSmallButtonToolBar );
708 // Key events DONT'T work
709 fileNameComboBox.KeyUp += new KeyEventHandler( OnKeyUpFileNameComboBox );
711 // FIXME: Default for Filter is "", aka nothing, nada...
712 // which means, show all files
713 FilterStruct fs = new FilterStruct( "All Files (*.*)", "*.*" ); // set default filter;
715 fileDialog.filterArrayList.Add( fs );
717 UpdateFilters( fileDialog.filterArrayList );
720 public ComboBox FileNameComboBox
724 fileNameComboBox = value;
729 return fileNameComboBox;
733 public string CurrentFileName
737 currentFileName = value;
742 return currentFileName;
746 public DirectoryInfo DirectoryInfo
750 directoryInfo = value;
755 return directoryInfo;
759 void OnClickOpenButton( object sender, EventArgs e )
761 currentFileName = Path.Combine(currentDirectoryName, fileNameComboBox.Text.Trim());
762 Console.WriteLine( "OnClickOpenButton currentFileName: " + currentFileName );
764 if ( currentFileName.Length == 0 )
767 if ( fileDialog.CheckFileExists )
769 if ( !File.Exists( currentFileName ) )
771 string message = currentFileName + " doesn't exist. Please verify that you have entered the correct file name.";
772 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
774 currentFileName = "";
780 if ( fileDialog.CheckPathExists )
782 if ( !Directory.Exists( currentDirectoryName ) )
784 string message = currentDirectoryName + " doesn't exist. Please verify that you have entered the correct directory name.";
785 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
787 currentDirectoryName = Environment.CurrentDirectory;
793 fileDialog.FileName = currentFileName;
795 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
797 cancelEventArgs.Cancel = false;
799 fileDialog.OnFileOk( cancelEventArgs );
801 fileDialog.form.Controls.Remove( this );
802 fileDialog.form.DialogResult = DialogResult.OK;
805 void OnClickCancelButton( object sender, EventArgs e )
807 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
809 cancelEventArgs.Cancel = true;
811 fileDialog.OnFileOk( cancelEventArgs );
813 fileDialog.form.Controls.Remove( this );
814 fileDialog.form.DialogResult = DialogResult.Cancel;
817 void OnClickHelpButton( object sender, EventArgs e )
819 fileDialog.SendHelpRequest( e );
822 void OnClickSmallButtonToolBar( object sender, ToolBarButtonClickEventArgs e )
824 if ( e.Button == upToolBarButton )
826 if ( directoryInfo.Parent != null )
828 PushDirectory( directoryInfo );
830 directoryInfo = directoryInfo.Parent;
832 currentDirectoryName = directoryInfo.FullName;
834 fileListView.UpdateFileListView( );
838 if ( e.Button == backToolBarButton )
840 if ( directoryStack.Count != 0 )
844 fileListView.UpdateFileListView( );
849 void OnClickMenuToolBarContextMenu( object sender, EventArgs e )
851 MenuItem senderMenuItem = (MenuItem)sender;
853 previousCheckedMenuItem.Checked = false;
854 senderMenuItem.Checked = true;
855 previousCheckedMenuItem = senderMenuItem;
859 switch ( senderMenuItem.Index )
862 fileListView.View = View.SmallIcon;
865 fileListView.View = View.LargeIcon;
868 fileListView.View = View.LargeIcon;
871 fileListView.View = View.List;
874 fileListView.View = View.Details;
882 void OnKeyUpFileNameComboBox( object sender, KeyEventArgs e )
884 Console.WriteLine( "OnKeyUpFileNameComboBox" );
886 if ( e.KeyCode == Keys.Enter )
888 Console.WriteLine( "OnKeyUpFileNameComboBox e.KeyCode =..." );
889 currentFileName = currentDirectoryName + fileNameComboBox.Text;
894 public void UpdateFilters( ArrayList filters )
896 fileTypeComboBox.Items.Clear( );
898 fileTypeComboBox.BeginUpdate( );
900 foreach ( FilterStruct fs in filters )
902 fileTypeComboBox.Items.Add( fs.filterName );
905 fileTypeComboBox.SelectedIndex = fileDialog.FilterIndex - 1;
907 fileTypeComboBox.EndUpdate( );
909 // TODO: Update the fileListView also...
912 public void ChangeDirectory( string path )
914 currentDirectoryName = path;
916 PushDirectory( directoryInfo );
918 directoryInfo = new DirectoryInfo( path );
920 fileListView.UpdateFileListView( );
923 public void ForceDialogEnd( )
925 OnClickOpenButton( this, EventArgs.Empty );
928 private void PushDirectory( DirectoryInfo di )
930 directoryStack.Push( directoryInfo );
931 backToolBarButton.Enabled = true;
934 private void PopDirectory( )
936 directoryInfo = (DirectoryInfo)directoryStack.Pop( );
938 currentDirectoryName = directoryInfo.FullName;
940 if ( directoryStack.Count == 0 )
941 backToolBarButton.Enabled = false;
944 public void ResizeAndRelocateForHelpOrReadOnly( )
946 if ( fileDialog.ShowHelp || fileDialog.FileDialogShowReadOnly )
948 fileListView.Size = new Size( 449, 250 );
949 fileNameLabel.Location = new Point( 102, 298 );
950 fileNameComboBox.Location = new Point( 195, 298 );
951 fileTypeLabel.Location = new Point( 102, 324 );
952 fileTypeComboBox.Location = new Point( 195, 324 );
953 openSaveButton.Location = new Point( 475, 298 );
954 cancelButton.Location = new Point( 475, 324 );
958 fileListView.Size = new Size( 449, 282 );
959 fileNameLabel.Location = new Point( 102, 330 );
960 fileNameComboBox.Location = new Point( 195, 330 );
961 fileTypeLabel.Location = new Point( 102, 356 );
962 fileTypeComboBox.Location = new Point( 195, 356 );
963 openSaveButton.Location = new Point( 475, 330 );
964 cancelButton.Location = new Point( 475, 356 );
967 if ( fileDialog.ShowHelp )
972 internal class FileListView : ListView
974 private ImageList fileListViewSmallImageList = new ImageList();
975 private ImageList fileListViewBigImageList = new ImageList();
977 private FileDialogPanel fileDialogPanel;
979 public FileListView( FileDialogPanel fileDialogPanel )
981 this.fileDialogPanel = fileDialogPanel;
983 fileListViewSmallImageList.ColorDepth = ColorDepth.Depth32Bit;
984 fileListViewSmallImageList.ImageSize = new Size( 16, 16 );
985 fileListViewSmallImageList.Images.Add( (Image)Locale.GetResource( "paper" ) );
986 fileListViewSmallImageList.Images.Add( (Image)Locale.GetResource( "folder" ) );
987 fileListViewSmallImageList.TransparentColor = Color.Transparent;
989 fileListViewBigImageList.ColorDepth = ColorDepth.Depth32Bit;
990 fileListViewBigImageList.ImageSize = new Size( 48, 48 );
991 fileListViewBigImageList.Images.Add( (Image)Locale.GetResource( "paper" ) );
992 fileListViewBigImageList.Images.Add( (Image)Locale.GetResource( "folder" ) );
993 fileListViewBigImageList.TransparentColor = Color.Transparent;
995 SmallImageList = fileListViewSmallImageList;
996 LargeImageList = fileListViewBigImageList;
1001 public void UpdateFileListView( )
1003 DirectoryInfo directoryInfo = fileDialogPanel.DirectoryInfo;
1005 DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories( );
1006 FileInfo[] fileInfoArray = directoryInfo.GetFiles( );
1008 fileDialogPanel.fileHashtable.Clear( );
1014 foreach ( DirectoryInfo directoryInfoi in directoryInfoArray )
1016 FileStruct fileStruct = new FileStruct( );
1018 fileStruct.fullname = directoryInfoi.FullName;
1020 ListViewItem listViewItem = new ListViewItem( directoryInfoi.Name );
1022 listViewItem.ImageIndex = 1;
1024 listViewItem.SubItems.Add( "" );
1025 listViewItem.SubItems.Add( "Directory" );
1026 listViewItem.SubItems.Add( directoryInfoi.LastAccessTime.ToShortDateString( ) + " " + directoryInfoi.LastAccessTime.ToShortTimeString( ) );
1028 fileStruct.attributes = FileAttributes.Directory;
1030 fileDialogPanel.fileHashtable.Add( directoryInfoi.Name, fileStruct );
1032 Items.Add( listViewItem );
1035 foreach ( FileInfo fileInfo in fileInfoArray )
1037 FileStruct fileStruct = new FileStruct( );
1039 fileStruct.fullname = fileInfo.FullName;
1041 ListViewItem listViewItem = new ListViewItem( fileInfo.Name );
1043 listViewItem.ImageIndex = 0;
1046 if ( fileInfo.Length > 1024 )
1047 fileLen = fileInfo.Length / 1024;
1049 listViewItem.SubItems.Add( fileLen.ToString( ) + " KB" );
1050 listViewItem.SubItems.Add( "File" );
1051 listViewItem.SubItems.Add( fileInfo.LastAccessTime.ToShortDateString( ) + " " + fileInfo.LastAccessTime.ToShortTimeString( ) );
1053 fileStruct.attributes = FileAttributes.Normal;
1055 fileDialogPanel.fileHashtable.Add( fileInfo.Name, fileStruct );
1057 Items.Add( listViewItem );
1060 Console.WriteLine( "Items.Count: " + Items.Count );
1065 protected override void OnClick( EventArgs e )
1067 ListViewItem listViewItem;
1069 if (SelectedItems.Count > 0) {
1070 listViewItem = SelectedItems[ 0 ];
1072 FileStruct fileStruct = (FileStruct)fileDialogPanel.fileHashtable[ listViewItem.Text ];
1074 if ( fileStruct.attributes != FileAttributes.Directory )
1076 fileDialogPanel.FileNameComboBox.Text = listViewItem.Text;
1077 fileDialogPanel.CurrentFileName = fileStruct.fullname;
1084 protected override void OnDoubleClick( EventArgs e )
1086 ListViewItem listViewItem = SelectedItems[ 0 ];
1088 FileStruct fileStruct = (FileStruct)fileDialogPanel.fileHashtable[ listViewItem.Text ];
1090 if ( fileStruct.attributes == FileAttributes.Directory )
1092 fileDialogPanel.ChangeDirectory( fileStruct.fullname );
1096 fileDialogPanel.FileNameComboBox.Text = listViewItem.Text;
1097 fileDialogPanel.CurrentFileName = fileStruct.fullname;
1098 fileDialogPanel.ForceDialogEnd( );
1102 base.OnDoubleClick( e );
1106 // helper class until ToolBar is working correctly
1107 internal class ButtonPanel : Panel
1109 private FileDialogPanel fileDialogPanel;
1111 private Button lastOpenButton;
1112 private Button desktopButton;
1113 private Button homeButton;
1114 private Button workplaceButton;
1115 private Button networkButton;
1117 private ImageList imageList = new ImageList();
1119 public ButtonPanel( FileDialogPanel fileDialogPanel )
1121 this.fileDialogPanel = fileDialogPanel;
1123 BorderStyle = BorderStyle.Fixed3D;
1124 BackColor = Color.FromArgb( 128, 128, 128 );
1125 Size = new Size( 85, 336 );
1127 // use ImageList to scale the bitmaps
1128 imageList.ColorDepth = ColorDepth.Depth32Bit;
1129 imageList.ImageSize = new Size( 38, 38 );
1130 imageList.Images.Add( (Image)Locale.GetResource( "last_open" ) );
1131 imageList.Images.Add( (Image)Locale.GetResource( "desktop" ) );
1132 imageList.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
1133 imageList.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
1134 imageList.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
1135 imageList.TransparentColor = Color.Transparent;
1137 lastOpenButton = new Button( );
1138 desktopButton = new Button( );
1139 homeButton = new Button( );
1140 workplaceButton = new Button( );
1141 networkButton = new Button( );
1143 lastOpenButton.Image = imageList.Images[ 0 ];
1144 lastOpenButton.ImageAlign = ContentAlignment.TopCenter;
1145 lastOpenButton.TextAlign = ContentAlignment.BottomCenter;
1146 lastOpenButton.ForeColor = Color.White;
1147 lastOpenButton.FlatStyle = FlatStyle.Popup;
1148 lastOpenButton.Size = new Size( 82, 64 );
1149 lastOpenButton.Location = new Point( 0, 2 );
1150 lastOpenButton.Text = "Last Open";
1151 lastOpenButton.Click += new EventHandler( OnClickButton );
1153 desktopButton.Image = imageList.Images[ 1 ];
1154 desktopButton.ImageAlign = ContentAlignment.TopCenter;
1155 desktopButton.TextAlign = ContentAlignment.BottomCenter;
1156 desktopButton.ForeColor = Color.White;
1157 desktopButton.FlatStyle = FlatStyle.Popup;
1158 desktopButton.Size = new Size( 82, 64 );
1159 desktopButton.Location = new Point( 0, 66 );
1160 desktopButton.Text = "Desktop";
1161 desktopButton.Click += new EventHandler( OnClickButton );
1163 homeButton.Image = imageList.Images[ 2 ];
1164 homeButton.ImageAlign = ContentAlignment.TopCenter;
1165 homeButton.TextAlign = ContentAlignment.BottomCenter;
1166 homeButton.ForeColor = Color.White;
1167 homeButton.FlatStyle = FlatStyle.Popup;
1168 homeButton.Size = new Size( 82, 64 );
1169 homeButton.Location = new Point( 0, 130 );
1170 homeButton.Text = "Home";
1171 homeButton.Click += new EventHandler( OnClickButton );
1173 workplaceButton.Image = imageList.Images[ 3 ];
1174 workplaceButton.ImageAlign = ContentAlignment.TopCenter;
1175 workplaceButton.TextAlign = ContentAlignment.BottomCenter;
1176 workplaceButton.ForeColor = Color.White;
1177 workplaceButton.FlatStyle = FlatStyle.Popup;
1178 workplaceButton.Size = new Size( 82, 64 );
1179 workplaceButton.Location = new Point( 0, 194 );
1180 workplaceButton.Text = "Workplace";
1181 workplaceButton.Click += new EventHandler( OnClickButton );
1183 networkButton.Image = imageList.Images[ 4 ];
1184 networkButton.ImageAlign = ContentAlignment.TopCenter;
1185 networkButton.TextAlign = ContentAlignment.BottomCenter;
1186 networkButton.ForeColor = Color.White;
1187 networkButton.FlatStyle = FlatStyle.Popup;
1188 networkButton.Size = new Size( 82, 64 );
1189 networkButton.Location = new Point( 0, 258 );
1190 networkButton.Text = "Network";
1191 networkButton.Click += new EventHandler( OnClickButton );
1193 Controls.Add( lastOpenButton );
1194 Controls.Add( desktopButton );
1195 Controls.Add( homeButton );
1196 Controls.Add( workplaceButton );
1197 Controls.Add( networkButton );
1200 void OnClickButton( object sender, EventArgs e )
1202 if ( sender == lastOpenButton )
1207 if ( sender == desktopButton )
1209 fileDialogPanel.ChangeDirectory( Environment.GetFolderPath( Environment.SpecialFolder.Desktop ) );
1212 if ( sender == homeButton )
1214 fileDialogPanel.ChangeDirectory( Environment.GetFolderPath( Environment.SpecialFolder.Personal ) );
1217 if ( sender == workplaceButton )
1219 // fileDialogPanel.ChangeDirectory( Environment.GetFolderPath( Environment.SpecialFolder.MyComputer ) );
1222 if ( sender == networkButton )