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

Native MessageBox API #670

Open
zezba9000 opened this issue Aug 6, 2016 · 20 comments
Open

Native MessageBox API #670

zezba9000 opened this issue Aug 6, 2016 · 20 comments
Assignees
Milestone

Comments

@zezba9000
Copy link

zezba9000 commented Aug 6, 2016

It would be great to have a native Message box API. Win32 on Windows and GTK on Linux / OSX (or Cocoa). Because Cocoa would need to probably be used on iOS anyway, it makes sense for OSX.

@ncarrillo
Copy link
Contributor

I think we should take inspiration from UWP and implement MessageDialog and ContentDialog

@danwalmsley
Copy link
Member

+1 for @nc4rrillo

@danwalmsley
Copy link
Member

will require #624 to also be completed.

@grokys grokys added this to the Beta 1 milestone Sep 10, 2016
@kekekeks kekekeks self-assigned this Oct 12, 2017
@jkoritzinsky jkoritzinsky modified the milestones: Beta 1, Beta 2 Dec 10, 2017
@grokys grokys modified the milestones: 0.7.0, 0.8.0 Jul 5, 2018
@grokys grokys modified the milestones: 0.8.0, 0.9 Apr 5, 2019
@TherionIM
Copy link

I know it's a workaround but what about this: https://habr.com/en/post/454386/

@KevinEady
Copy link

Hi @danwalmsley ,

I see that #624 was closed... Is this workable now?

Thanks, Kevin

@danwalmsley
Copy link
Member

Definitely possible now

@grokys
Copy link
Member

grokys commented Jan 26, 2021

Given that this issue is about native message boxes, I've done a bit of research into the various native message box APIs in the platforms we support:

Native Message Boxes

Win32

MessageBox

MessageBox shows a simple message box. It has the following elements:

  • A title
  • A text message
  • A fixed choice of buttons (localized):
    • OK
    • OK, Cancel
    • Yes, No
    • Yes, No, Cancel
    • Abort, Retry, Ignore
    • Cancel, Try Again, Continue
    • An optional Help button an be added to each of the above
  • An icon:
    • Exclamation,
    • Warning
    • Information/Asterisk
    • Question
    • Stop/Error/Hand

This is the API used by WPF's MessageBox.

TaskDialog

TaskDialog shows a "vista"-style messagebox. It has the following elements:

  • A title
  • A message ("main instruction")d
  • Content (additional text that appears below the main instruction, in a smaller font)
  • Any combination of buttons (localized):
    • OK
    • Yes
    • No
    • Cancel
    • Retry
    • Close
  • An icon:
    • Error
    • Information
    • Shield
    • Warning

There is a proposal to add an API for this to WinForms: dotnet/winforms#146

TaskDialogIndirect

TaskDialogIndirect shows an advanced "vista"-style messagebox. It has the elements from TaskDialog plus:

  • A set of buttons that can be:
    • Radio buttons
    • Command links
  • A verification checkbox
  • An expander to show additional information
  • An arbirary footer icon
  • A footer message
  • Hyperlinks in the content/expander/footer
  • A progress bar

OSX

NSAlert shows a message box. It has the following elements:

  • A message
  • Informative text
  • A type
    • Critical
    • Informational/Warning
  • A custom icon
  • An optional help button
  • Arbitrary buttons
  • A supression checkbox
  • An accessory view containing arbitrary content

X11

On X11 message boxes are provided by the toolkit so we would have to implement our own managed message boxes, but for context here's what GTK and QT's message box APIs provide.

GTK

gtk_message_dialog_new is simply a convenince function for creating simple dialogs. It can be modified arbirarily, but the base API has the following elements:

  • A title
  • A message
  • Secondary text
  • An icon
    • Information
    • Warning
    • Question
    • Error
    • Other (No icon)
  • Buttons:
    • OK (discouraged)
    • Close
    • Cancel
    • Yes, No (discouraged)
    • OK, Cancel (discouraged)

QT

QMessageBox shows a message box. It has the following elements:

  • Primary text (plain or rich)
  • Informative text (plain or rich)
  • Optional detailed text
  • An icon
    • Question
    • Information
    • Warning
    • Critical
    • A custom bitmap
  • Buttons:
    • OK
    • Open
    • Save
    • Cancel
    • Close
    • Discard
    • Apply
    • Reset
    • RestoreDefaults
    • Help
    • Save All
    • Yes
    • Yes to All
    • No
    • No to All
    • Abort
    • Retry
    • Ignore

Two APIs for using QMessageBox are provided, the property-based API, and the static functions. Calling one of the static functions is the simpler approach, but it is less flexible than using the property-based API, and the result is less informative. Using the property-based API is recommended.

Android

AlertDialog shows a message box. It has the following elements:

  • Title
  • Content area (can be text, a list or other custom layout)
  • Up to 3 buttons with arbitrary text

iOS

UIAlertController shows a message box. It has the following elements:

  • A title
  • A message
  • A style
    • Action sheet (lays out actions vertically)
    • Alert
  • Arbitrary actions (buttons)

@grokys
Copy link
Member

grokys commented Jan 26, 2021

If we were to implement a native MessageBox API, I can see 3 choices:

  • Implement a common subset. This would appear to be:
    • Title (implemented on all platforms except OSX - could just not display it there)
    • Message in plain text
    • Win32 MessageBox button choices if we use that API, or a arbitrary buttons if we use TaskDialog
      • Does TaskDialog look out of place in Win10? Does that matter?
    • "Content" text could be displayed using the relevant feature on platforms that support it, and appended to the message on platforms that don't?
    • This would essentially be WPF's MessageBox API (perhaps with added "content" text)
  • Have some sort of capabilities query
    • Would somewhat overcomplicate just showing a message box in a cross-platform manner
  • Just provide the bare minimum somewhat like JS:
    • alert displays a message and an OK button
    • confirm displays a mesage and OK, Cancel buttons

Other things to note:

  • MessageBox automatically localizes the button text, which it can do because it has a limited set to choose from
  • Different platforms order the buttons differently (https://www.nngroup.com/articles/ok-cancel-or-cancel-ok/)
  • win32's MessageBox at least blocks the main thread, which might cause problems

@kekekeks
Copy link
Member

Note that we need some kind of localized text database anyway since we have default context menus textboxes.

@grokys
Copy link
Member

grokys commented Jan 26, 2021

Discussion about a new TaskDialog API in WinUI: microsoft/microsoft-ui-xaml#2313 - though this is only really a "native" MessageBox in the sense that MS would be shipping it.

@mysteryx93
Copy link

In terms of UI thread lock, I just worked around this issue in WPF with this simple function.

Can now run sync UI methods in a fully asynchronous way and await!

/// <summary>
/// Runs a synchronous action asynchronously on the UI thread.
/// </summary>
/// <param name="window">Any window to get the dispatcher from.</param>
/// <param name="action">The action to run asynchronously.</param>
/// <typeparam name="T">The return type of the action.</typeparam>
/// <returns>The result of the action.</returns>
public static Task<T> RunUiAsync<T>(this Window window, Func<T> action)
{
    if (window == null) throw new ArgumentNullException(nameof(window));
    TaskCompletionSource<T> completion = new();
    window.Dispatcher.BeginInvoke(new Action(() => completion.SetResult(action())));
    return completion.Task;
}

@mysteryx93
Copy link

mysteryx93 commented Dec 12, 2021

In the Avalonia port of MvvmDialogs, I need to have a common MessageBox API to share between WPF, Avalonia, UWP, WinUI3, Blazor or anything else (because the ViewModel shouldn't need to know which UI it's running on)

What we first need is a basic MessageBox with standard features which should be simple enough to implement.

Later on, you could add an ExtendedMessageBox in Avalonia with extra features, which will take more time and it will be harder to come with a stable cross-platform API for.

ExtendedMessageBox extension could later be added to MvvmDialogs with support for WPF/Ookii, and for Avalonia if that's added. But it's really difficult for these extended feature settings to be platform-agnostic.

My vote is that extended features do not need to be part of the core library but can be added through a separate project, but basic MessageBox features DO need to be part of the core library.

Here are the platform-agnostic settings implemented in MvvmDialogs.

Is there some issue in natively supporting those settings on all platforms? These basic settings cover 90% of use-cases.

@Anequit
Copy link

Anequit commented Feb 2, 2022

NEED this

@DamianSuess
Copy link

NEED this

@Anequit, while we wait for integration of this feature, have you checked out MessageBox.Avalonia?

@Anequit
Copy link

Anequit commented Feb 2, 2022

NEED this

@Anequit, while we wait for integration of this feature, have you checked out MessageBox.Avalonia?

Yes I have, but I'm not a huge fan of it personally. I think for the time being I'll opt for an alert popup instead of a message box

@DmitriyYukhanov
Copy link

have you checked out MessageBox.Avalonia?

I've just gave it a spin, and it's not resizing vertically for a long texts:
AvaloniaCommunity/MessageBox.Avalonia#104

It also has no API docs for MessageBoxStandardParams etc., looks like something unpolished / buggy to me =\

Would be happy to see out-of-the-box platform-agnostic solution in Avalonia.

@mysteryx93
Copy link

Yes it has a lot of unpolished rough edges. It had no option for setting a default button; they added it but the implementation is badly designed and looks more like a hack.

@jsreynolds
Copy link

I'm having a nice laugh finding out a few hours into coding that I basically have to write my own custom message box to give the user feedback. Incredible.

@DamianSuess
Copy link

As an option, with Prism.Avalonia you make use of the DialogService which provides the ability to make it modal and non-modal with ease. It's pretty much 60 seconds of copy/paste as per the end-to-end sample

@mysteryx93
Copy link

or using MvvmDialogs for Avalonia

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

No branches or pull requests