partial void OnDelete(Foundation.NSObject sender) { int row = (int)GuiTableEmails.SelectedRow; if (row < 0) { return; } PrivateEmailInfo email = __Model.PrivateEmails [row]; // Configure alert var alert = new NSAlert() { AlertStyle = NSAlertStyle.Informational, InformativeText = string.Format(LocalizedStrings.Instance.LocalizedString("Label_PrivateEmail_DeleteEmailQuestion_Informative_PARAMETRIZED"), email.Email), MessageText = string.Format(LocalizedStrings.Instance.LocalizedString("Label_PrivateEmail_DeleteEmailQuestion_Header_PARAMETRIZED"), email.Email), }; alert.AddButton(LocalizedStrings.Instance.LocalizedString("Button_Cancel")); alert.AddButton(LocalizedStrings.Instance.LocalizedString("Button_PrivateEmail_Delete")); nint result = alert.RunModal(); if (result == (int)NSAlertButtonReturn.Second) { // Remove the given row from the dataset __Model.DeleteEmail(email); } ; }
private PrivateEmailGeneratedWindowController(PrivateEmailsManagerViewModel model) : base("PrivateEmailGeneratedWindow") { __Model = model; __Model.OnError += __Model_OnError; __Model.OnWillExecute += (sender) => { GuiProgressIndicator.StartAnimation(this); this.Window.ContentView = GuiInProgressView; }; __Model.OnDidExecute += (sender) => { GuiProgressIndicator.StopAnimation(this); this.Window.ContentView = GuiMainView; if (__NeedToCloseWindow) { Close(); } }; __Model.OnNewEmailGenerated += (PrivateEmailInfo emailInfo) => { __GeneratedEmailInfo = emailInfo; GuiGeneratedEmailField.StringValue = emailInfo.Email; GuiForwardToEmailField.StringValue = emailInfo.ForwardToEmail; GuiNotesField.TextStorage.SetString(new NSAttributedString(emailInfo.Notes)); }; }
private int GetEmailIndex(PrivateEmailInfo emailInfo) { int idx = -1; for (int i = 0; i < PrivateEmails.Count; i++) { if (PrivateEmails [i].Email.Equals(emailInfo.Email)) { idx = i; break; } } return(idx); }
private PrivateEmailGenerateWindow(PrivateEmailsManagerViewModel model, PrivateEmailInfo emailToEdit) { Model = model; Email = emailToEdit; __IsEditing = true; InitializeComponent(); MainView.Visibility = Visibility.Visible; ProgressView.Visibility = Visibility.Collapsed; GuiDiscardButtonText.Text = StringUtils.String("Button_Cancel"); DataContext = this; }
partial void OnCopy(Foundation.NSObject sender) { int row = (int)GuiTableEmails.SelectedRow; if (row < 0) { return; } PrivateEmailInfo email = __Model.PrivateEmails [row]; NSPasteboard pb = NSPasteboard.GeneralPasteboard; pb.DeclareTypes(new string [] { NSPasteboard.NSStringType }, null); pb.SetStringForType(email.Email, NSPasteboard.NSStringType); }
public async Task DeleteEmail(PrivateEmailInfo emailInfo, OnErrorDelegate onErrorDelegate = null) { if (emailInfo == null) { return; } OnWillExecute(this); try { await DeleteEmailRequest(emailInfo, onErrorDelegate); } finally { OnDidExecute(this); } }
public async Task <bool> DeleteEmailRequest(PrivateEmailInfo emailInfo, OnErrorDelegate onErrorDelegate = null) { try { CancellationTokenSource src = new CancellationTokenSource(); await ApiServices.Instance.PrivateEmailDeleteAsync(emailInfo.Email, src.Token); int idx = GetEmailIndex(emailInfo); if (idx >= 0) { PrivateEmails.RemoveAt(idx); } // force property updated event PrivateEmails = PrivateEmails; } catch (OperationCanceledException) { return(false); } catch (TimeoutException) { DoNotifyError(onErrorDelegate, __AppServices.LocalizedString("Error_ApiRequestTimeout")); return(false); } catch (WebException ex) { Logging.Info($"REST request exception : {ex}"); DoNotifyError(onErrorDelegate, __AppServices.LocalizedString("Error_RestServer_ConnectionError_Title"), __AppServices.LocalizedString("Error_RestServer_ConnectionError")); return(false); } catch (Exception ex) { Logging.Info($"REST request exception : {ex}"); DoNotifyError(onErrorDelegate, __AppServices.LocalizedString("Error_RestServer_Communication") + Environment.NewLine + Environment.NewLine + $"{ex}"); return(false); } return(true); }
private async Task <PrivateEmailInfo> GenerateNewEmailRequest(OnErrorDelegate onErrorDelegate = null) { try { CancellationTokenSource src = new CancellationTokenSource(); var response = await ApiServices.Instance.PrivateEmailGenerateAsync(src.Token); PrivateEmailInfo email = new PrivateEmailInfo(response.Email, response.ForwardToEmail, response.Notes); ObservableCollection <PrivateEmailInfo> emails = PrivateEmails; emails.Add(email); PrivateEmails = emails; OnNewEmailGenerated(email); return(email); } catch (OperationCanceledException) { return(null); } catch (TimeoutException) { DoNotifyError(onErrorDelegate, __AppServices.LocalizedString("Error_ApiRequestTimeout")); return(null); } catch (WebException ex) { Logging.Info($"REST request exception : {ex}"); DoNotifyError(onErrorDelegate, __AppServices.LocalizedString("Error_RestServer_ConnectionError_Title"), __AppServices.LocalizedString("Error_RestServer_ConnectionError")); return(null); } catch (Exception ex) { Logging.Info($"REST request exception : {ex}"); DoNotifyError(onErrorDelegate, __AppServices.LocalizedString("Error_RestServer_Communication") + Environment.NewLine + Environment.NewLine + $"{IVPNException.GetDetailedMessage(ex)}"); return(null); } }
partial void OnEdit(Foundation.NSObject sender) { int row = (int)GuiTableEmails.SelectedRow; if (row < 0) { return; } PrivateEmailInfo email = __Model.PrivateEmails [row]; string newNotes = IVPNAlert.ShowInputBox(string.Format(LocalizedStrings.Instance.LocalizedString("Label_PrivateEmail_NotesDialog_PARAMETRIZED"), email.Email), "", email.Notes, true); if (newNotes == null || (email.Notes != null && newNotes.Equals(email.Notes))) { return; } __Model.UpdateNotes(email, newNotes); }
private async void PrivateEmailGenerateWindow_OnLoaded(object sender, RoutedEventArgs e) { // hide 'Minimize' button Button minimizeButton = Template.FindName("GuiTemplateButtonMinimizeInTitle", this) as Button; if (minimizeButton != null) { minimizeButton.Visibility = Visibility.Collapsed; } if (!__IsEditing) { try { OnWillExecute(); Email = await Model.GenerateNewEmail(OnError); } finally { OnDidExecute(); } } }
public async Task UpdateNotes(PrivateEmailInfo emailInfo, string notes, OnErrorDelegate onErrorDelegate = null) { if (string.Equals(emailInfo.Notes, notes)) { return; } if (notes == null) { notes = ""; } OnWillExecute(this); try { await UpdateNotesRequest(emailInfo, notes, onErrorDelegate); } finally { OnDidExecute(this); } }
public static void EditEmail(PrivateEmailsManagerViewModel model, PrivateEmailInfo emailToEdit) { __Instance?.Close(); __Instance = new PrivateEmailGenerateWindow(model, emailToEdit); __Instance.Show(); }