public IAsyncOperation <IUICommand> ShowAsync() { Func <CancellationToken, Task <IUICommand> > func = async(ct) => { return(await Task.Run(() => { var waitHandle = new ManualResetEventSlim(); int result = -1; Gtk.Application.Invoke((s, a) => { var dialog = new Gtk.Dialog(Title, GtkHost.Window, Gtk.DialogFlags.Modal); dialog.SkipTaskbarHint = true; Gtk.Label label = new Gtk.Label(Content); label.Halign = Gtk.Align.Fill; dialog.ContentArea.Add(label); label.Show(); if (Commands.Count == 0) { Commands.Add(new UICommand("Close")); } for (int i = 0; i < Commands.Count; ++i) { dialog.AddButton(Commands[i].Label, i); } dialog.DefaultResponse = (Gtk.ResponseType)DefaultCommandIndex; result = dialog.Run(); dialog.Hide(); // dialog.Destroy(); dialog.Dispose(); waitHandle.Set(); }); waitHandle.Wait(); if (result < 0) { result = unchecked ((int)CancelCommandIndex); } // CancelCommandIndex still not set. if (result < 0) { result = (int)DefaultCommandIndex; } return Commands[result]; }, ct)); }; return(FromTaskFunction.Invoke(null, new object[] { func }) as IAsyncOperation <IUICommand>); }
public static void ShowHintWindow(Gtk.Widget parent, String caption, String text) { Gtk.Dialog dialog = new Gtk.Dialog(); dialog.ParentWindow = parent.GdkWindow; dialog.Parent = parent; dialog.Title = caption; dialog.VBox.PackStart(new Gtk.Label(text), true, true, 12); Gtk.Button closeButton = (Gtk.Button)dialog.AddButton(Gtk.Stock.Ok, Gtk.ResponseType.Close); closeButton.Clicked += delegate(object sender, EventArgs ea) { dialog.Hide(); dialog.Dispose(); }; EventHandler showDelegate = delegate(object s, EventArgs ea) { dialog.ShowAll(); dialog.Present(); }; Gtk.Application.Invoke(showDelegate); }