Beispiel #1
0
        unsafe static Task <string[]> ShowDialog(string title, GtkWindow parent, GtkFileChooserAction action,
                                                 bool multiselect, string initialFileName)
        {
            GtkFileChooser dlg;

            parent = parent ?? GtkWindow.Null;
            using (var name = new Utf8Buffer(title))
                dlg = Native.GtkFileChooserDialogNew(name, parent, action, IntPtr.Zero);
            if (multiselect)
            {
                Native.GtkFileChooserSetSelectMultiple(dlg, true);
            }

            Native.GtkWindowSetModal(dlg, true);
            var tcs = new TaskCompletionSource <string[]>();
            List <IDisposable> disposables = null;
            Action             dispose     = () =>
            {
                // ReSharper disable once PossibleNullReferenceException
                foreach (var d in disposables)
                {
                    d.Dispose();
                }
                disposables.Clear();
            };

            disposables = new List <IDisposable>
            {
                Signal.Connect <Native.D.signal_generic>(dlg, "close", delegate
                {
                    tcs.TrySetResult(null);
                    dispose();
                    return(false);
                }),
                Signal.Connect <Native.D.signal_dialog_response>(dlg, "response", (_, resp, __) =>
                {
                    string[] result = null;
                    if (resp == GtkResponseType.Accept)
                    {
                        var rlst = new List <string>();
                        var gs   = Native.GtkFileChooserGetFilenames(dlg);
                        var cgs  = gs;
                        while (cgs != null)
                        {
                            if (cgs->Data != IntPtr.Zero)
                            {
                                rlst.Add(Utf8Buffer.StringFromPtr(cgs->Data));
                            }
                            cgs = cgs->Next;
                        }
                        Native.GSlistFree(gs);
                        result = rlst.ToArray();
                    }
                    Native.GtkWidgetHide(dlg);
                    dispose();
                    tcs.TrySetResult(result);
                    return(false);
                }),
                dlg
            };
            using (var open = new Utf8Buffer("Open"))
                Native.GtkDialogAddButton(dlg, open, GtkResponseType.Accept);
            using (var open = new Utf8Buffer("Cancel"))
                Native.GtkDialogAddButton(dlg, open, GtkResponseType.Cancel);
            if (initialFileName != null)
            {
                using (var fn = new Utf8Buffer(initialFileName))
                    Native.GtkFileChooserSetFilename(dlg, fn);
            }
            Native.GtkWindowPresent(dlg);
            return(tcs.Task);
        }
 void Connect <T>(string name, T handler) => Disposables.Add(Signal.Connect(GtkWidget, name, handler));
Beispiel #3
0
 public void Connect <T>(string name, T handler, IntPtr userData) => signals.Add(Signal.Connect(GtkWidget, name, handler, userData));
 void ConnectEvent(string name, Native.D.signal_onevent handler)
 => Disposables.Add(Signal.Connect <Native.D.signal_onevent>(GtkWidget, name, handler));
Beispiel #5
0
 public void ConnectEvent(string name, Native.D.signal_onevent handler) => signals.Add(Signal.Connect <Native.D.signal_onevent>(GtkWidget, name, handler));