private async void DeleteFlyoutItem_OnClick(object sender, RoutedEventArgs e) { if (sender is MenuFlyoutItem flyout) { var resource = new ResourcesService(); var database = DatabaseService.Instance; var item = (GroupItem)flyout.DataContext; var deleteFileDialog = new ContentDialog { Title = $"{resource.GetResourceValue("EntityDeleteActionButton")} {item.Text} ?", Content = database.IsRecycleBinEnabled ? resource.GetResourceValue("GroupRecyclingConfirmation") : resource.GetResourceValue("GroupDeletingConfirmation"), PrimaryButtonText = resource.GetResourceValue("EntityDeleteActionButton"), CloseButtonText = resource.GetResourceValue("EntityDeleteCancelButton") }; var result = await deleteFileDialog.ShowAsync(); // Delete the file if the user clicked the primary button. // Otherwise, do nothing. if (result == ContentDialogResult.Primary) { item.Parent.Children.Remove(item); // TODO: refresh treeview if (database.IsRecycleBinEnabled) { database.RecyleBinGroup.AddGroup(item.Group, true); } } } }
private async void OnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs) { // Save the argument exception because it's cleared on first access var exception = unhandledExceptionEventArgs.Exception; var realException = exception is TargetInvocationException && exception.InnerException != null ? exception.InnerException : exception; var database = DatabaseService.Instance; var resource = new ResourcesService(); if (realException is SaveException) { unhandledExceptionEventArgs.Handled = true; await MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("MessageDialogSaveErrorTitle"), realException.InnerException.Message, resource.GetResourceValue("MessageDialogSaveErrorButtonSaveAs"), resource.GetResourceValue("MessageDialogSaveErrorButtonDiscard"), async command => { var savePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary, SuggestedFileName = $"{database.Name} - copy" }; savePicker.FileTypeChoices.Add(resource.GetResourceValue("MessageDialogSaveErrorFileTypeDesc"), new List <string> { ".kdbx" }); var file = await savePicker.PickSaveFileAsync(); if (file != null) { database.Save(file); } }, null); } }
private void ImportFormatComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { var resources = new ResourcesService(); var comboBox = sender as ComboBox; switch (comboBox?.SelectedIndex) { case 0: Model.ImportFormat = new CsvImportFormat(); Model.ImportFileExtensionFilter = ".csv"; Model.ImportFormatHelp = resources.GetResourceValue("NewImportFormatHelpCSV"); break; default: Model.ImportFormat = new NullImportFormat(); break; } }