From 99cc6a642543036f4fd8b090bd29e1ae8bc5255d Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Thu, 27 Aug 2020 11:36:38 -0400 Subject: [PATCH] Accounts are editable from ScanAccountsDialog via new edit button --- LibationLauncher/LibationLauncher.csproj | 2 +- .../UNTESTED/Dialogs/AccountsDialog.cs | 7 ++++++- .../UNTESTED/Dialogs/EditQuickFilters.cs | 1 + .../Dialogs/ScanAccountsDialog.Designer.cs | 18 +++++++++++++++-- .../UNTESTED/Dialogs/ScanAccountsDialog.cs | 20 ++++++++++++++++++- LibationWinForms/UNTESTED/Form1.cs | 18 +++++++---------- WinFormsDesigner/Dialogs/AccountsDialog.cs | 2 +- .../Dialogs/ScanAccountsDialog.Designer.cs | 17 ++++++++++++++-- .../Dialogs/ScanAccountsDialog.cs | 2 +- 9 files changed, 67 insertions(+), 20 deletions(-) diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 9068f689..da7cfb6c 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 3.1.12.299 + 3.1.12.300 diff --git a/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs b/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs index 8f0c1717..8032e03f 100644 --- a/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs +++ b/LibationWinForms/UNTESTED/Dialogs/AccountsDialog.cs @@ -15,8 +15,12 @@ namespace LibationWinForms.Dialogs const string COL_AccountName = nameof(AccountName); const string COL_Locale = nameof(Locale); - public AccountsDialog() + Form1 _parent { get; } + + public AccountsDialog(Form1 parent) { + _parent = parent; + InitializeComponent(); dataGridView1.Columns[COL_AccountName].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; @@ -111,6 +115,7 @@ namespace LibationWinForms.Dialogs persister.CommitTransation(); + _parent.RefreshImportMenu(); this.DialogResult = DialogResult.OK; this.Close(); } diff --git a/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.cs b/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.cs index f495db02..5413f9e4 100644 --- a/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.cs +++ b/LibationWinForms/UNTESTED/Dialogs/EditQuickFilters.cs @@ -55,6 +55,7 @@ namespace LibationWinForms.Dialogs QuickFilters.ReplaceAll(list); _parent.UpdateFilterDropDown(); + this.DialogResult = DialogResult.OK; this.Close(); } diff --git a/LibationWinForms/UNTESTED/Dialogs/ScanAccountsDialog.Designer.cs b/LibationWinForms/UNTESTED/Dialogs/ScanAccountsDialog.Designer.cs index bfdc8e15..76be9b49 100644 --- a/LibationWinForms/UNTESTED/Dialogs/ScanAccountsDialog.Designer.cs +++ b/LibationWinForms/UNTESTED/Dialogs/ScanAccountsDialog.Designer.cs @@ -32,6 +32,7 @@ this.accountsClb = new System.Windows.Forms.CheckedListBox(); this.importBtn = new System.Windows.Forms.Button(); this.cancelBtn = new System.Windows.Forms.Button(); + this.editBtn = new System.Windows.Forms.Button(); this.SuspendLayout(); // // accountsLbl @@ -61,7 +62,7 @@ this.importBtn.Location = new System.Drawing.Point(396, 125); this.importBtn.Name = "importBtn"; this.importBtn.Size = new System.Drawing.Size(75, 23); - this.importBtn.TabIndex = 2; + this.importBtn.TabIndex = 3; this.importBtn.Text = "Import"; this.importBtn.UseVisualStyleBackColor = true; this.importBtn.Click += new System.EventHandler(this.importBtn_Click); @@ -73,11 +74,22 @@ this.cancelBtn.Location = new System.Drawing.Point(497, 125); this.cancelBtn.Name = "cancelBtn"; this.cancelBtn.Size = new System.Drawing.Size(75, 23); - this.cancelBtn.TabIndex = 3; + this.cancelBtn.TabIndex = 4; this.cancelBtn.Text = "Cancel"; this.cancelBtn.UseVisualStyleBackColor = true; this.cancelBtn.Click += new System.EventHandler(this.cancelBtn_Click); // + // editBtn + // + this.editBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.editBtn.Location = new System.Drawing.Point(12, 125); + this.editBtn.Name = "editBtn"; + this.editBtn.Size = new System.Drawing.Size(90, 23); + this.editBtn.TabIndex = 2; + this.editBtn.Text = "Edit accounts"; + this.editBtn.UseVisualStyleBackColor = true; + this.editBtn.Click += new System.EventHandler(this.editBtn_Click); + // // ScanAccountsDialog // this.AcceptButton = this.importBtn; @@ -85,6 +97,7 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.cancelBtn; this.ClientSize = new System.Drawing.Size(584, 160); + this.Controls.Add(this.editBtn); this.Controls.Add(this.cancelBtn); this.Controls.Add(this.importBtn); this.Controls.Add(this.accountsClb); @@ -103,5 +116,6 @@ private System.Windows.Forms.CheckedListBox accountsClb; private System.Windows.Forms.Button importBtn; private System.Windows.Forms.Button cancelBtn; + private System.Windows.Forms.Button editBtn; } } \ No newline at end of file diff --git a/LibationWinForms/UNTESTED/Dialogs/ScanAccountsDialog.cs b/LibationWinForms/UNTESTED/Dialogs/ScanAccountsDialog.cs index 61dea148..b4470035 100644 --- a/LibationWinForms/UNTESTED/Dialogs/ScanAccountsDialog.cs +++ b/LibationWinForms/UNTESTED/Dialogs/ScanAccountsDialog.cs @@ -12,8 +12,12 @@ namespace LibationWinForms.Dialogs { public List CheckedAccounts { get; } = new List(); - public ScanAccountsDialog() + Form1 _parent { get; } + + public ScanAccountsDialog(Form1 parent) { + _parent = parent; + InitializeComponent(); } @@ -25,6 +29,8 @@ namespace LibationWinForms.Dialogs } private void ScanAccountsDialog_Load(object sender, EventArgs e) { + // DO NOT dispose of this connection. + // Here we (clumsily) connect to the persistent file. Accounts returned from here are used throughout library scan INCLUDING updates. eg: identity tokens var accounts = AudibleApiStorage.GetPersistentAccountsSettings().Accounts; foreach (var account in accounts) @@ -34,6 +40,18 @@ namespace LibationWinForms.Dialogs } } + private void editBtn_Click(object sender, EventArgs e) + { + if (new AccountsDialog(_parent).ShowDialog()== DialogResult.OK) + { + // clear grid + this.accountsClb.Items.Clear(); + + // reload grid and default checkboxes + ScanAccountsDialog_Load(sender, e); + } + } + private void importBtn_Click(object sender, EventArgs e) { foreach (listItem item in accountsClb.CheckedItems) diff --git a/LibationWinForms/UNTESTED/Form1.cs b/LibationWinForms/UNTESTED/Form1.cs index d1907ebc..f7907fe7 100644 --- a/LibationWinForms/UNTESTED/Form1.cs +++ b/LibationWinForms/UNTESTED/Form1.cs @@ -43,7 +43,7 @@ namespace LibationWinForms PictureStorage.SetDefaultImage(PictureSize._300x300, Properties.Resources.default_cover_300x300.ToBytes(format)); PictureStorage.SetDefaultImage(PictureSize._500x500, Properties.Resources.default_cover_500x500.ToBytes(format)); - setImportMenu(); + RefreshImportMenu(); setVisibleCount(null, 0); @@ -182,7 +182,7 @@ namespace LibationWinForms #endregion #region filter - private void filterHelpBtn_Click(object sender, EventArgs e) => new Dialogs.SearchSyntaxDialog().ShowDialog(); + private void filterHelpBtn_Click(object sender, EventArgs e) => new SearchSyntaxDialog().ShowDialog(); private void AddFilterBtn_Click(object sender, EventArgs e) { @@ -229,7 +229,7 @@ namespace LibationWinForms #endregion #region Import menu - private void setImportMenu() + public void RefreshImportMenu() { var count = AudibleApiStorage.GetPersistentAccountsSettings().Accounts.Count; @@ -242,7 +242,7 @@ namespace LibationWinForms private void noAccountsYetAddAccountToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("To load your Audible library, come back here to the Import menu after adding your account"); - accountsToolStripMenuItem_Click(sender, e); + new AccountsDialog(this).ShowDialog(); } private void scanLibraryToolStripMenuItem_Click(object sender, EventArgs e) @@ -259,7 +259,7 @@ namespace LibationWinForms private void scanLibraryOfSomeAccountsToolStripMenuItem_Click(object sender, EventArgs e) { - using var scanAccountsDialog = new ScanAccountsDialog(); + using var scanAccountsDialog = new ScanAccountsDialog(this); if (scanAccountsDialog.ShowDialog() != DialogResult.OK) return; @@ -341,15 +341,11 @@ namespace LibationWinForms } } - private void EditQuickFiltersToolStripMenuItem_Click(object sender, EventArgs e) => new Dialogs.EditQuickFilters(this).ShowDialog(); + private void EditQuickFiltersToolStripMenuItem_Click(object sender, EventArgs e) => new EditQuickFilters(this).ShowDialog(); #endregion #region settings menu - private void accountsToolStripMenuItem_Click(object sender, EventArgs e) - { - new AccountsDialog().ShowDialog(); - setImportMenu(); - } + private void accountsToolStripMenuItem_Click(object sender, EventArgs e) => new AccountsDialog(this).ShowDialog(); private void basicSettingsToolStripMenuItem_Click(object sender, EventArgs e) => new SettingsDialog().ShowDialog(); diff --git a/WinFormsDesigner/Dialogs/AccountsDialog.cs b/WinFormsDesigner/Dialogs/AccountsDialog.cs index db1e2e3d..bfd13ac6 100644 --- a/WinFormsDesigner/Dialogs/AccountsDialog.cs +++ b/WinFormsDesigner/Dialogs/AccountsDialog.cs @@ -5,7 +5,7 @@ namespace WinFormsDesigner.Dialogs { public partial class AccountsDialog : Form { - public AccountsDialog() + public AccountsDialog(Form1 parent) { InitializeComponent(); } diff --git a/WinFormsDesigner/Dialogs/ScanAccountsDialog.Designer.cs b/WinFormsDesigner/Dialogs/ScanAccountsDialog.Designer.cs index e2d8182e..e9f321ad 100644 --- a/WinFormsDesigner/Dialogs/ScanAccountsDialog.Designer.cs +++ b/WinFormsDesigner/Dialogs/ScanAccountsDialog.Designer.cs @@ -32,6 +32,7 @@ this.accountsClb = new System.Windows.Forms.CheckedListBox(); this.importBtn = new System.Windows.Forms.Button(); this.cancelBtn = new System.Windows.Forms.Button(); + this.editBtn = new System.Windows.Forms.Button(); this.SuspendLayout(); // // accountsLbl @@ -61,7 +62,7 @@ this.importBtn.Location = new System.Drawing.Point(396, 125); this.importBtn.Name = "importBtn"; this.importBtn.Size = new System.Drawing.Size(75, 23); - this.importBtn.TabIndex = 2; + this.importBtn.TabIndex = 3; this.importBtn.Text = "Import"; this.importBtn.UseVisualStyleBackColor = true; // @@ -72,10 +73,20 @@ this.cancelBtn.Location = new System.Drawing.Point(497, 125); this.cancelBtn.Name = "cancelBtn"; this.cancelBtn.Size = new System.Drawing.Size(75, 23); - this.cancelBtn.TabIndex = 3; + this.cancelBtn.TabIndex = 4; this.cancelBtn.Text = "Cancel"; this.cancelBtn.UseVisualStyleBackColor = true; // + // editBtn + // + this.editBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.editBtn.Location = new System.Drawing.Point(12, 125); + this.editBtn.Name = "editBtn"; + this.editBtn.Size = new System.Drawing.Size(90, 23); + this.editBtn.TabIndex = 2; + this.editBtn.Text = "Edit accounts"; + this.editBtn.UseVisualStyleBackColor = true; + // // ScanAccountsDialog // this.AcceptButton = this.importBtn; @@ -83,6 +94,7 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.cancelBtn; this.ClientSize = new System.Drawing.Size(584, 160); + this.Controls.Add(this.editBtn); this.Controls.Add(this.cancelBtn); this.Controls.Add(this.importBtn); this.Controls.Add(this.accountsClb); @@ -100,5 +112,6 @@ private System.Windows.Forms.CheckedListBox accountsClb; private System.Windows.Forms.Button importBtn; private System.Windows.Forms.Button cancelBtn; + private System.Windows.Forms.Button editBtn; } } \ No newline at end of file diff --git a/WinFormsDesigner/Dialogs/ScanAccountsDialog.cs b/WinFormsDesigner/Dialogs/ScanAccountsDialog.cs index 63237b77..bcc027fa 100644 --- a/WinFormsDesigner/Dialogs/ScanAccountsDialog.cs +++ b/WinFormsDesigner/Dialogs/ScanAccountsDialog.cs @@ -12,7 +12,7 @@ namespace WinFormsDesigner.Dialogs { public partial class ScanAccountsDialog : Form { - public ScanAccountsDialog() + public ScanAccountsDialog(Form1 parent) { InitializeComponent(); }