question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Select Folder type of Dialog

See original GitHub issue

Feature Request

Currently, when using the Dialog method, we can use the DialogTypeEnum to determine if we want a dialog for:

  • Message - a simple message
  • Error - an error message
  • Open - open a file
  • Save - save a file

Well, it turns out that sometimes we want the user to also select a folder instead of a file. So I would like to propose a new DialogType:

  • Folder - select a folder

User Story

As a user, I want to be able to select a folder, In order to select the destiny of a generated file, for example.

As a developer, I want to be able to popup a Dialog to request a folder destiny to the user, In order to get the path I should use as destiny of a generated file, for example.

(I’m no good at writing user stories, but well, I tried)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
andlabscommented, Mar 14, 2018

I didn’t reject the PR. I decided to hold off on merging it, because the current APIs for dialogs isn’t ideal. It all has to do with event handling and synchronicity. I’ll use pseudocode in JavaScript to explain what I mean (this will probably be easier than explaining it in C in the main repo, to be honest…).

On Windows, the system dialog API only gives me one option:

var selectedItem = runDialog(parentWindow);

You’ll notice this function does not return until the dialog is dismissed. You’ll notice that a parent window must be specified. Clicking on that window while the dialog is open will cause that window to flash.

Other windows can still be interacted with, but they will NOT respond to things like tab navigation. This is because tab navigation on Windows is intrinsically tied to dialog boxes! Specifically, the IsDialogMessage() function requires you to pass a handle to the top-level window (I’m not sure if it’s the dialog box or the parent window), and only handles tab navigation for the window you passed in. libui works around this for the outermost main loop by passing the currently active window into this function, but in the runDialog() function above I have no such control. Likewise, I have no such control over what happens inside the main loop body, so no custom main loops (uiMainSteps()/uiMainStep()).

I could also disable all the windows during the dialog’s lifetime, but then clicking on those other windows won’t flash the dialog window (and I don’t think I have a way to do this myself at all…).

Now I could theoretically use a dialog message hook to try to work around this, but I’m not sure if this solution might be flaky (I would have to write it). I have tried to deduce what the correct programming model on Windows is based on all this information, even going so far as to ask outright, but I can’t get an answer out.

Failure to provide a parent window will cause Windows to not flash the dialog window when clicking other windows.

GTK+ is the nicest of the bunch, as I have two options:

var selectedItem = runDialog(parentWindow);

openDialog(parentWindow).then((selectedItem) => {
    // ...
});

The former will prevent interaction with any window during the dialog’s lifetime, but in a weird some-of-the-events-still-go-through way. I also can’t do any custom main loops with this option.

The latter will let you interact with everything else in the program while the dialog is running. I don’t remember if there were caveats, but notice you still need to provide a window to disable while the dialog is running.

In both cases, failure to provide a parent window will do nothing but cause GTK+ to spit the dreaded GtkDialog mapped without a transient parent on stderr.

macOS is only slightly less nice:

var selectedItem = runDialog();

openDialog(parentWindow).then((selectedItem) => {
    // ...
});

In the former case, the dialog is global to the application, and all window interaction is blocked until the dialog is dismissed. I also can’t do any custom main loop stuff.

In the latter case, the dialog is modal to to a specific window, and appears as a “sheet” that pulls down from the titlebar. You can still interact just fine with other windows, under certain circumstances. While custom main loops are still possible, this approach probably tells NSApplication to run in a different main loop run mode which might affect things. I need to read more on how NSApplication and sheets work together before I can make a verdict here. Also, you must provide a parent window in this case.

So hopefully that explains the dilemma.

1reaction
mischniccommented, Mar 11, 2018

There was already a pull request for openFolder (closed): https://github.com/andlabs/libui/pull/190

Read more comments on GitHub >

github_iconTop Results From Across the Web

Automate Tasks with a Select Folder Dialog feature
Allows a user to choose a directory on local HDD in the middle of automated Task execution. The selected folder is passed to...
Read more >
FolderBrowserDialog Class (System.Windows.Forms)
FolderBrowserDialog is a modal dialog box; therefore, when shown, it blocks the rest of the application until the user has chosen a folder....
Read more >
Show Select Folder Dialog (script step reference) - troi.com
This will present a folder selection dialog. The dialog initially shows the folder: “C:\Data\”. The user can then select a folder and click...
Read more >
Using the Show Browse for Folder Dialog Function
Using the Show Browse for Folder Dialog Function · Click Select Title, and type a title for the dialog box. · Click Select...
Read more >
SelectFolderDialog - Xojo documentation
Used to create and present customized Select Folder dialog boxes. The non-customized version of this function is provided by the FolderItem function.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found