Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VistaFolderBrowserDialog: Set InitialDirectory (not SelectedPath) #35

Open
nzain opened this issue Jan 29, 2021 · 5 comments
Open

VistaFolderBrowserDialog: Set InitialDirectory (not SelectedPath) #35

nzain opened this issue Jan 29, 2021 · 5 comments
Labels
enhancement New feature or request hacktoberfest https://hacktoberfest.digitalocean.com help wanted Extra attention is needed up-for-grabs
Milestone

Comments

@nzain
Copy link

nzain commented Jan 29, 2021

The VistaFolderBrowserDialog does not have an InitialDirectory property (like the open/save file variants do). The SelectedPath property sounds similar, but actually navigates to the parent directory and sets the given directory name as input for the textbox at the bottom.

Unless (hidden feature) you append a trailing backslash or slash. In that case, the dialog opens in the given path and nothing is selected.
I guess this only works because Path.GetDirectoryName(..) is tricked into a different result here: https://github.com/augustoproiete/ookii-dialogs-wpf/blob/d157189c795d4fdb500662bde8ad328d7d3eb602/src/Ookii.Dialogs.Wpf/VistaFolderBrowserDialog.cs#L280-L290

Whatever the implementation details, it would be good to have an explicit API that allows to set the initial directory.

Additional remarks:

  • Path.DirectorySeparatorChar (backslash) works
  • Path.AltDirectorySeparatorChar (slash) works, too but I'm on windows 10. Not sure if that makes any difference.
    My code looks like this for now:
string initialDirectory = string.IsNullOrEmpty(dir) 
        || dir[dir.Length - 1] == Path.DirectorySeparatorChar
        || dir[dir.Length - 1] == Path.AltDirectorySeparatorChar
    ? dir
    : dir + Path.DirectorySeparatorChar;
@nzain
Copy link
Author

nzain commented Apr 19, 2021

I've created a PR and tried to match your coding style. Feel free to change the style.

@augustoproiete augustoproiete modified the milestones: 3.2.0, Future Apr 25, 2021
@nzain
Copy link
Author

nzain commented May 12, 2021

@augustoproiete did you have the time to look at my PR? The change is small and does not change / break existing code.

@augustoproiete
Copy link
Member

Hey @nzain thanks for the nudge. I looked at the code and in principle looks great. I'll set aside some time this week to run a few tests and get this merged in.

@nzain
Copy link
Author

nzain commented Jun 4, 2021

Did you run into problems? I'm willing to help!

@augustoproiete augustoproiete added help wanted Extra attention is needed up-for-grabs labels Sep 9, 2021
@augustoproiete augustoproiete added the hacktoberfest https://hacktoberfest.digitalocean.com label Oct 2, 2021
@antikmozib
Copy link

I believe this is same behaviour utilised by the WinForms FolderBrowserDialog. So I reckon this is default behaviour for these type of selectors, and hence, would leave it as it is to avoid confusions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest https://hacktoberfest.digitalocean.com help wanted Extra attention is needed up-for-grabs
Development

Successfully merging a pull request may close this issue.

3 participants