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.

Dialog cancel consistency

See original GitHub issue

Describe the bug The file dialogs (OpenFileDialog, SaveFileDialog, and OpenFileDialog) do not have consistent return values when pressing cancel. On windows, I get OpenFileDialog returning empty array, SaveFileDialog returning null, and OpenFolderDialog returning an empty string. On linux, all of these return null when pressing cancel.

To Reproduce Open different dialogs on different platforms, press cancel on them, and look at the return values.

private async void Test()
{
    OpenFileDialog ofd = new OpenFileDialog();
    string[] ofdRes = await ofd.ShowAsync(this);

    SaveFileDialog sfd = new SaveFileDialog();
    string sfdRes = await sfd.ShowAsync(this);

    OpenFolderDialog old = new OpenFolderDialog();
    string oldRes = await old.ShowAsync(this);

    response = $"openfile: {SetName(ofdRes)}, savefile: {SetName(sfdRes)}, openfolder: {SetName(oldRes)}";
}

private string SetName(string text)
{
    if (text == null)
        return "[null]";
    else if (text == "")
        return "[empty]";
    else
        return $"\"{text}\"";
}

private string SetName(string[] textArr)
{
    if (textArr == null)
        return "[null]";
    else if (textArr.Length == 0)
        return "[empty array]";
    else
        return $"\"{string.Join(", ", textArr)}\"";
}

Expected behavior Should be consistent across all platforms. I’m not entirely sure what the cancel values for these dialogs are supposed to be. Maybe all null like on linux?

Screenshots

Windows windows Linux linux

Desktop (please complete the following information):

  • OS: Windows, Linux (PopOS w/ XFCE)
  • Version 0.10.6

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
YgorSouzacommented, Jun 25, 2021

One argument for returning empty over null is that you wouldn’t need to change anything later if you decided to enable nullable reference types, whereas if you return null you have to change the return type to string? and string[]? and that would be a breaking change.

0reactions
workgroupengineeringcommented, Jul 1, 2021

Personally I would expect null string as default and empty array as default. Having nullable array is not good practice usually.

On PR #6160 i used Linux behavior .

@grokys @kekekeks What behavior do you recommend?

Read more comments on GitHub >

github_iconTop Results From Across the Web

UX writing: an effective 'Cancel' dialog confirmation on Web
Aiming to provide more clarity and guidance on how to design effective 'Cancel' confirmation dialogs on Web apps through specific examples.
Read more >
OK-Cancel or Cancel-OK? The Trouble With Buttons
One classic is the order of buttons in dialog boxes: OK / Cancel; Cancel / OK. Both are reasonable choices, and people can...
Read more >
Cancel dialog text. Is this good?
I have a dialog that comes up when someone cancels creating a new piece of data. They click cancel and the dialog says:...
Read more >
Consistent accept/cancel options in menus/dialog boxes
Consistent accept/cancel options in menus/dialog boxes ... What's missing is a cancel option for popup dialog boxes like yes/no response boxes.
Read more >
Why 'Ok' Buttons in Dialog Boxes Work Best on the Right
The 'Cancel' button is the secondary action that takes users back to their ... “Consistency” is a popular word used among designers.
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