@@ -24,17 +24,15 @@ public class StandaloneFileBrowserWindows : IStandaloneFileBrowser {
2424 public string [ ] OpenFilePanel ( string title , string directory , ExtensionFilter [ ] extensions , bool multiselect ) {
2525 var fd = new VistaOpenFileDialog ( ) ;
2626 fd . Title = title ;
27+ fd . InitialDirectory = directory ;
28+ fd . Multiselect = multiselect ;
2729 if ( extensions != null ) {
2830 fd . Filter = GetFilterFromFileExtensionList ( extensions ) ;
2931 fd . FilterIndex = 1 ;
3032 }
3133 else {
3234 fd . Filter = string . Empty ;
3335 }
34- fd . Multiselect = multiselect ;
35- if ( ! string . IsNullOrEmpty ( directory ) ) {
36- fd . FileName = GetDirectoryPath ( directory ) ;
37- }
3836 var res = fd . ShowDialog ( new WindowWrapper ( GetActiveWindow ( ) ) ) ;
3937 var filenames = res == DialogResult . OK ? fd . FileNames : new string [ 0 ] ;
4038 fd . Dispose ( ) ;
@@ -48,11 +46,10 @@ public void OpenFilePanelAsync(string title, string directory, ExtensionFilter[]
4846 public string [ ] OpenFolderPanel ( string title , string directory , bool multiselect ) {
4947 var fd = new VistaFolderBrowserDialog ( ) ;
5048 fd . Description = title ;
51- if ( ! string . IsNullOrEmpty ( directory ) ) {
52- fd . SelectedPath = GetDirectoryPath ( directory ) ;
53- }
49+ fd . RootFolder = Environment . SpecialFolder . MyComputer ;
50+ fd . SelectedPath = directory ;
5451 var res = fd . ShowDialog ( new WindowWrapper ( GetActiveWindow ( ) ) ) ;
55- var filenames = res == DialogResult . OK ? new [ ] { fd . SelectedPath } : new string [ 0 ] ;
52+ var filenames = res == DialogResult . OK ? new [ ] { fd . SelectedPath } : new string [ 0 ] ;
5653 fd . Dispose ( ) ;
5754 return filenames ;
5855 }
@@ -64,18 +61,8 @@ public void OpenFolderPanelAsync(string title, string directory, bool multiselec
6461 public string SaveFilePanel ( string title , string directory , string defaultName , ExtensionFilter [ ] extensions ) {
6562 var fd = new VistaSaveFileDialog ( ) ;
6663 fd . Title = title ;
67-
68- var finalFilename = "" ;
69-
70- if ( ! string . IsNullOrEmpty ( directory ) ) {
71- finalFilename = GetDirectoryPath ( directory ) ;
72- }
73-
74- if ( ! string . IsNullOrEmpty ( defaultName ) ) {
75- finalFilename += defaultName ;
76- }
77-
78- fd . FileName = finalFilename ;
64+ fd . InitialDirectory = directory ;
65+ fd . FileName = defaultName ;
7966 if ( extensions != null ) {
8067 fd . Filter = GetFilterFromFileExtensionList ( extensions ) ;
8168 fd . FilterIndex = 1 ;
@@ -100,6 +87,7 @@ public void SaveFilePanelAsync(string title, string directory, string defaultNam
10087 // .NET Framework FileDialog Filter format
10188 // https://msdn.microsoft.com/en-us/library/microsoft.win32.filedialog.filter
10289 private static string GetFilterFromFileExtensionList ( ExtensionFilter [ ] extensions ) {
90+ if ( extensions == null ) return "" ;
10391 var filterString = "" ;
10492 foreach ( var filter in extensions ) {
10593 filterString += filter . Name + "(" ;
@@ -120,17 +108,6 @@ private static string GetFilterFromFileExtensionList(ExtensionFilter[] extension
120108 filterString = filterString . Remove ( filterString . Length - 1 ) ;
121109 return filterString ;
122110 }
123-
124- private static string GetDirectoryPath ( string directory ) {
125- var directoryPath = Path . GetFullPath ( directory ) ;
126- if ( ! directoryPath . EndsWith ( "\\ " ) ) {
127- directoryPath += "\\ " ;
128- }
129- if ( Path . GetPathRoot ( directoryPath ) == directoryPath ) {
130- return directory ;
131- }
132- return Path . GetDirectoryName ( directoryPath ) + Path . DirectorySeparatorChar ;
133- }
134111 }
135112}
136113
0 commit comments