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

SelectDirectoryDialog always starts at Desktop level in Windows #139

Open
IvanScheers opened this issue Jun 5, 2021 · 2 comments
Open
Labels

Comments

@IvanScheers
Copy link

I would like the user to start at a certain directory, so to only traverse down the directory tree. However setting dialog.startDirectory has no effect. It always starts at Desktop in Windows. For OpenFileDialog setting dialog.directory works as expected, going straight to the preset directory. I started the test with an edited version of the example code.

Am I doing something wrong (I'm fairly new to Nim), or is this an issue ?

`

This example shows how to use the Open File and Save File As dialogs.

import nigui

app.init()

var window = newWindow()
var mainContainer = newLayoutContainer(Layout_Vertical)
window.add(mainContainer)

var buttons = newLayoutContainer(Layout_Horizontal)
mainContainer.add(buttons)

var textArea = newTextArea()
mainContainer.add(textArea)

var button1 = newButton("Open ...")
buttons.add(button1)
button1.onClick = proc(event: ClickEvent) =
var dialog = newOpenFileDialog()
dialog.title = "Test Open"
dialog.multiple = true

dialog.directory = "D:\Software"
dialog.run()
textArea.addLine($dialog.files.len & " files selected")
if dialog.files.len > 0:
for file in dialog.files:
textArea.addLine(file)

var button2 = newButton("Select Directory ...")
buttons.add(button2)
button2.onClick = proc(event: ClickEvent) =

var dialog = SelectDirectoryDialog()

newSelectDirectory ?? -> doesn't work either

dialog.title = "Test Select Directory"
dialog.startdirectory = "C:\Users\Ivan"

check whether startdirectory is set properly

echo "startdirectory: ", dialog.startdirectory

dialog.run()
if dialog.selectedDirectory == "":
textArea.addLine("No directory selected")
else:
textArea.addLine(dialog.selectedDirectory)

window.show()
app.run()`

@IvanScheers
Copy link
Author

I think I'm onto the reason it doesn't work. But I'm too new at Nim to try and correct it. I've had a look at the source code and saw this in windows/platform_impl.nim :

in the run method for OpenFile the dialog.directory has what I think is a pointer (line 535)
ofn.lpstrInitialDir = dialog.directory.pUtf8ToUtf16()

in SelectDialog (line 556)
dialog.selectedDirectory = ""

Shouldn't that be something like
ofn.lpstrInitialDir = dialog.startdirectory.pUtf8ToUtf16()

I dare not change this myself in fear of breaking things... too new at this

@IvanScheers
Copy link
Author

Did some more digging myself. Did the change to windows/platform_impl.nim anyway to

bi.lpstrInitialDir = dialog.startdirectory.pUtf8ToUtf16()

However, that threw a compile error, since the BrowseInfo object doesn't have the startdirectory item. It does have
pidlRoot*: pointer

which in turn is (C++ code)
typedef struct _browseinfoA { HWND hwndOwner; PCIDLIST_ABSOLUTE pidlRoot; LPSTR pszDisplayName; LPCSTR lpszTitle; UINT ulFlags; BFFCALLBACK lpfn; LPARAM lParam; int iImage; } BROWSEINFOA, *PBROWSEINFOA, *LPBROWSEINFOA;

so PCIDLIST_ABSOLUTE should point to an absolute path (starting at Desktop)

This may be of interest for solving the issue, but solving it is beyond my knowledge of windows and C++

https://docs.microsoft.com/en-us/windows/win32/api/shtypes/ns-shtypes-itemidlist
https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shcreateshellitem
https://devblogs.microsoft.com/oldnewthing/20130503-00/?p=4463

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants