AndrewBelt / osdialog

A cross platform wrapper for OS dialogs like file save, open, message boxes, inputs, color picking, etc.
Creative Commons Zero v1.0 Universal
122 stars 19 forks source link

On Windows, re-open directory dialog with last directory used. #7

Closed cschol closed 3 years ago

cschol commented 5 years ago

On Windows, the directory selection dialog does not remember show the directory passed in. This PR fixes the issue.

The general approach to the solution is described here.

Microsoft documentation for SHBrowseForFolderW states: "If you implement a callback function, specified in the lpfn member of the BROWSEINFO structure, you receive a handle to the dialog box. One use of this window handle is to modify the layout or contents of the dialog box. Because it is not resizable, modifying the older style dialog box is relatively straightforward. Modifying the newer style dialog box is much more difficult, and not recommended. Not only does it have a different size and layout than the old style, but its dimensions and the positions of its controls change every time it is resized by the user."

Why is this important? The current implementation uses the new style dialog box. The issue with the callback solution is that the current directory is not "focused" in the directory box when using the new style box. The user still has to scroll to get to the currently selected directory to change it. The old style dialog box focuses correctly and the user can very quickly select a new directory at the same level. Therefore, the dialog box style was changed to old style box for this solution.

AndrewBelt commented 5 years ago

osdialog should not hold a state or tell Windows to hold a state for the last used directory. It should be the responsibility of the caller of osdialog_file to give the last selected directory as an argument to that function.

cschol commented 5 years ago

I am not sure I understand. path is passed in by the caller. The callback sends a message to update the window to the passed in path. That's the way that dialog box works, at least on Windows.

EDIT: My initial description of the issue is misleading. The Dialog should not remember the last location, but it should show the location passed in, which it currently does not. Updated.

Nowhk commented 4 years ago

+1 for this! Hope in a merge sono, thanks.

AndrewBelt commented 3 years ago

Fixed with https://github.com/AndrewBelt/osdialog/commit/0ed6318c6ed8f8726f7c626cd535520dd4d126c5