public static async Task <Maybe <string> > Show(string dialogIdentifier, string message, string caption, string predefined = "")
        {
            var dialogView = new InputDialogView(message, caption, predefined);
            var result     = await DialogHost.Show(dialogView, dialogIdentifier);

            if ((bool)result)
            {
                return(Maybe <string> .From(dialogView.ValueTextBox.Text));
            }

            return(Maybe <string> .None);
        }
Example #2
0
        public static async Task <Maybe <string> > Show(string dialogIdentifier, string message, string caption, string predefined = "", Func <string, Result> validationFunc = null)
        {
            var dialogView = new InputDialogView(message, caption, predefined, validationFunc);
            var result     = await DialogHost.Show(dialogView, dialogIdentifier,
                                                   delegate(object sender, DialogClosingEventArgs args)
            {
                if ((bool)args.Parameter && !dialogView.Validate())
                {
                    args.Cancel();
                    args.Handled = true;
                }
            });

            if ((bool)result)
            {
                return(Maybe <string> .From(dialogView.Text));
            }

            return(Maybe <string> .None);
        }
Example #3
0
        private async void NewFieldMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var maybeFieldName = await InputDialogView.Show("DocumentViewerDialogHost", "Enter name of new field.", "New field name");

            if (maybeFieldName.HasNoValue)
            {
                return;
            }

            var fieldName = maybeFieldName.Value;

            if (_currentDocument.Keys.Contains(fieldName))
            {
                MessageBox.Show($"Field \"{fieldName}\" already exists!", "", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            var       menuItem = sender as MenuItem;
            BsonValue newValue;

            switch (menuItem.Header as string)
            {
            case "String":
                newValue = new BsonValue(string.Empty);
                break;

            case "Boolean":
                newValue = new BsonValue(false);
                break;

            case "Double":
                newValue = new BsonValue((double)0);
                break;

            case "Decimal":
                newValue = new BsonValue((decimal)0.0m);
                break;

            case "Int32":
                newValue = new BsonValue(0);
                break;

            case "Int64":
                newValue = new BsonValue((long)0);
                break;

            case "DateTime":
                newValue = new BsonValue(DateTime.MinValue);
                break;

            case "Array":
                newValue = new BsonArray();
                break;

            case "Document":
                newValue = new BsonDocument();
                break;

            default:
                throw new Exception("Uknown value type.");
            }

            _currentDocument.Add(fieldName, newValue);
            var newField = NewField(fieldName, false);

            _customControls.Add(newField);
            newField.EditControl.Focus();
            ItemsField_SizeChanged(ListItems, null);
            ListItems.ScrollIntoView(newField);
        }