コード例 #1
0
        public override string Ask(string title, string message, string defaultValue)
        {
            const int OK       = 1;
            string    response = null;

            using (var alert = NSAlert.WithMessage(title,
                                                   "OK",
                                                   "Cancel",
                                                   null,
                                                   message))
            {
                using (var input = new NSTextField(new CGRect(0, 0, 200, 24)))
                {
                    alert.AccessoryView = input;
                    nint result;

                    do
                    {
                        input.StringValue = defaultValue;

                        result = alert.RunSheetModal(_mainWindow);

                        input.ValidateEditing();
                    }while ((result == OK) && string.IsNullOrWhiteSpace(input.StringValue));

                    if (result == OK)
                    {
                        response = input.StringValue;
                    }
                }
            }

            return(response);
        }