private void ButtonPassword_Click(object sender, RoutedEventArgs e)
 {
     if (InputBoxWindow.ShowDialog("New password, enter empty string to remove password.", "", "", out string password) == true)
     {
         Database.Shrink(string.IsNullOrEmpty(password) ? null : password);
     }
 }
        public static bool?ShowDialog(string message, string caption, string predefined, out string input)
        {
            var window = new InputBoxWindow();

            window.TextMessage.Text = message;
            window.Title            = caption;
            window.TextText.Text    = predefined;

            var result = window.ShowDialog();

            input = window.Text;
            return(result);
        }
        public static bool?ShowDialog(string message, string caption, string predefined, Window owner, out string input)
        {
            var window = new InputBoxWindow
            {
                Owner       = owner,
                TextMessage = { Text = message }, Title = caption, TextText = { Text = predefined }
            };

            var result = window.ShowDialog();

            input = window.Text;
            return(result);
        }
        private void NewFieldMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (InputBoxWindow.ShowDialog("Enter name of new field.", "New field name:", "", out string fieldName) != true)
            {
                return;
            }

            if (currentDocument.Keys.Contains(fieldName))
            {
                MessageBox.Show(string.Format("Field \"{0}\" already exists!", fieldName), "", 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 "Int32":
                newValue = new BsonValue((int)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);
        }