Skip to content

Commit

Permalink
FIX: Initial directory fix applied for SaveFileDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
gkngkc committed Feb 7, 2017
1 parent 6f29d00 commit f15b57a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ public string[] OpenFilePanel(string title, string directory, ExtensionFilter[]
}
fd.Multiselect = multiselect;
if (!string.IsNullOrEmpty(directory)) {
var directoryPath = Path.GetFullPath(directory);
if (!directoryPath.EndsWith("\\")) {
directoryPath += "\\";
}
fd.FileName = Path.GetDirectoryName(directoryPath) + Path.DirectorySeparatorChar;
fd.FileName = GetDirectoryPath(directory);
}
var res = fd.ShowDialog();
var filenames = res == DialogResult.OK ? fd.FileNames : new string[0];
Expand All @@ -34,11 +30,7 @@ public string[] OpenFolderPanel(string title, string directory, bool multiselect
var fd = new VistaFolderBrowserDialog();
fd.Description = title;
if (!string.IsNullOrEmpty(directory)) {
var directoryPath = Path.GetFullPath(directory);
if (!directoryPath.EndsWith("\\")) {
directoryPath += "\\";
}
fd.SelectedPath = Path.GetDirectoryName(directoryPath) + Path.DirectorySeparatorChar;
fd.SelectedPath = GetDirectoryPath(directory);
}
var res = fd.ShowDialog();
var filenames = res == DialogResult.OK ? new []{ fd.SelectedPath } : new string[0];
Expand All @@ -49,8 +41,18 @@ public string[] OpenFolderPanel(string title, string directory, bool multiselect
public string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) {
var fd = new VistaSaveFileDialog();
fd.Title = title;
fd.InitialDirectory = string.IsNullOrEmpty(directory) ? "" : Path.GetFullPath(directory);
fd.FileName = defaultName;

var finalFilename = "";

if (!string.IsNullOrEmpty(directory)) {
finalFilename = GetDirectoryPath(directory);
}

if (!string.IsNullOrEmpty(defaultName)) {
finalFilename += defaultName;
}

fd.FileName = finalFilename;
if (extensions != null) {
fd.Filter = GetFilterFromFileExtensionList(extensions);
fd.FilterIndex = 1;
Expand Down Expand Up @@ -91,6 +93,14 @@ private static string GetFilterFromFileExtensionList(ExtensionFilter[] extension
filterString = filterString.Remove(filterString.Length - 1);
return filterString;
}

private static string GetDirectoryPath(string directory) {
var directoryPath = Path.GetFullPath(directory);
if (!directoryPath.EndsWith("\\")) {
directoryPath += "\\";
}
return Path.GetDirectoryName(directoryPath) + Path.DirectorySeparatorChar;
}
}
}

Expand Down
Binary file modified Package/StandaloneFileBrowser.unitypackage
Binary file not shown.

0 comments on commit f15b57a

Please sign in to comment.