From 0c53c97a481554e541ad59026920c9bc091d881b Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 2 Aug 2022 20:43:58 +0200 Subject: [PATCH] Implemented the culture delete function --- I18N Commander/Processor/AppSettings.cs | 23 ++++++++++++++ .../Components/Settings.Designer.cs | 26 ++++++++++++++++ .../UI WinForms/Components/Settings.cs | 29 ++++++++++++++++++ .../UI WinForms/Components/Settings.resx | 3 ++ .../UI WinForms/Resources/Icons.Designer.cs | 10 ++++++ .../UI WinForms/Resources/Icons.resx | 3 ++ .../Resources/icons8-trash-can-512.png | Bin 0 -> 2285 bytes 7 files changed, 94 insertions(+) create mode 100644 I18N Commander/UI WinForms/Resources/icons8-trash-can-512.png diff --git a/I18N Commander/Processor/AppSettings.cs b/I18N Commander/Processor/AppSettings.cs index edd48cb..dcae4d9 100644 --- a/I18N Commander/Processor/AppSettings.cs +++ b/I18N Commander/Processor/AppSettings.cs @@ -385,6 +385,29 @@ public static class AppSettings #endregion + #region Delete a culture + + public static async Task DeleteCulture(int index) + { + // Get the database: + await using var db = ProcessorMeta.ServiceProvider.GetRequiredService(); + + // Check, if the setting is already set: + if (await db.Settings.FirstOrDefaultAsync(n => n.Code.StartsWith(SettingNames.CULTURE) && n.IntegerValue == index) is {} existingSetting) + { + db.Settings.Remove(existingSetting); + await db.SaveChangesAsync(); + } + + // Update the list of cultures indices: + CACHE_CULTURES_INDICES.Remove(index); + + // Update the cache: + CACHE_CULTURES.Remove(index); + } + + #endregion + #region Get a list of cultures public readonly record struct CultureInfo(string Code, int Index); diff --git a/I18N Commander/UI WinForms/Components/Settings.Designer.cs b/I18N Commander/UI WinForms/Components/Settings.Designer.cs index e38eb64..6701b53 100644 --- a/I18N Commander/UI WinForms/Components/Settings.Designer.cs +++ b/I18N Commander/UI WinForms/Components/Settings.Designer.cs @@ -35,6 +35,8 @@ this.panelSettings = new System.Windows.Forms.Panel(); this.flowLayoutToolbar = new System.Windows.Forms.FlowLayoutPanel(); this.buttonAddCulture = new System.Windows.Forms.Button(); + this.buttonDeleteCulture = new System.Windows.Forms.Button(); + this.contextMenuDelete = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolTip = new System.Windows.Forms.ToolTip(this.components); this.tableLayout.SuspendLayout(); this.flowLayoutToolbar.SuspendLayout(); @@ -97,6 +99,7 @@ // this.tableLayout.SetColumnSpan(this.flowLayoutToolbar, 2); this.flowLayoutToolbar.Controls.Add(this.buttonAddCulture); + this.flowLayoutToolbar.Controls.Add(this.buttonDeleteCulture); this.flowLayoutToolbar.Dock = System.Windows.Forms.DockStyle.Fill; this.flowLayoutToolbar.Location = new System.Drawing.Point(0, 315); this.flowLayoutToolbar.Margin = new System.Windows.Forms.Padding(0); @@ -117,6 +120,27 @@ this.buttonAddCulture.UseVisualStyleBackColor = true; this.buttonAddCulture.Click += new System.EventHandler(this.buttonAddCulture_Click); // + // buttonDeleteCulture + // + this.buttonDeleteCulture.ContextMenuStrip = this.contextMenuDelete; + this.buttonDeleteCulture.FlatAppearance.BorderSize = 0; + this.buttonDeleteCulture.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.buttonDeleteCulture.Image = global::UI_WinForms.Resources.Icons.icons8_trash_can_512; + this.buttonDeleteCulture.Location = new System.Drawing.Point(69, 3); + this.buttonDeleteCulture.Name = "buttonDeleteCulture"; + this.buttonDeleteCulture.Size = new System.Drawing.Size(60, 60); + this.buttonDeleteCulture.TabIndex = 0; + this.toolTip.SetToolTip(this.buttonDeleteCulture, "Delete a culture"); + this.buttonDeleteCulture.UseVisualStyleBackColor = true; + this.buttonDeleteCulture.Click += new System.EventHandler(this.buttonDeleteCulture_Click); + // + // contextMenuDelete + // + this.contextMenuDelete.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); + this.contextMenuDelete.ImageScalingSize = new System.Drawing.Size(20, 20); + this.contextMenuDelete.Name = "contextMenuDelete"; + this.contextMenuDelete.Size = new System.Drawing.Size(211, 32); + // // toolTip // this.toolTip.AutoPopDelay = 30000; @@ -149,5 +173,7 @@ private FlowLayoutPanel flowLayoutToolbar; private ToolTip toolTip; private Button buttonAddCulture; + private Button buttonDeleteCulture; + private ContextMenuStrip contextMenuDelete; } } diff --git a/I18N Commander/UI WinForms/Components/Settings.cs b/I18N Commander/UI WinForms/Components/Settings.cs index ba36e48..ef8efd4 100644 --- a/I18N Commander/UI WinForms/Components/Settings.cs +++ b/I18N Commander/UI WinForms/Components/Settings.cs @@ -28,4 +28,33 @@ public partial class Settings : UserControl // Reload all settings: await this.LoadAllSettings(); } + + private async void buttonDeleteCulture_Click(object sender, EventArgs e) + { + // Read all cultures: + var cultures = await AppSettings.GetCultureInfos(); + + // Populate the delete button's menu strip with all cultures: + this.contextMenuDelete.Items.Clear(); + foreach (var culture in cultures) + { + var item = new ToolStripMenuItem($"{culture.Index}. Culture: {culture.Code}"); + item.Tag = culture.Index; + item.Click += async (senderObj, args) => + { + if (senderObj is not ToolStripMenuItem toolStripMenuItem) + return; + + // Delete the culture: + await AppSettings.DeleteCulture((int)toolStripMenuItem.Tag); + + // Reload all settings: + await this.LoadAllSettings(); + }; + + this.contextMenuDelete.Items.Add(item); + } + + this.contextMenuDelete.Show((Button)sender, new Point(0, (this.contextMenuDelete.Height + this.buttonDeleteCulture.Height / 2) * -1)); + } } diff --git a/I18N Commander/UI WinForms/Components/Settings.resx b/I18N Commander/UI WinForms/Components/Settings.resx index 99de901..3688329 100644 --- a/I18N Commander/UI WinForms/Components/Settings.resx +++ b/I18N Commander/UI WinForms/Components/Settings.resx @@ -60,4 +60,7 @@ 17, 17 + + 122, 17 + \ No newline at end of file diff --git a/I18N Commander/UI WinForms/Resources/Icons.Designer.cs b/I18N Commander/UI WinForms/Resources/Icons.Designer.cs index 7f3e9af..ab02ede 100644 --- a/I18N Commander/UI WinForms/Resources/Icons.Designer.cs +++ b/I18N Commander/UI WinForms/Resources/Icons.Designer.cs @@ -259,5 +259,15 @@ namespace UI_WinForms.Resources { return ((System.Drawing.Bitmap)(obj)); } } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap icons8_trash_can_512 { + get { + object obj = ResourceManager.GetObject("icons8_trash_can_512", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/I18N Commander/UI WinForms/Resources/Icons.resx b/I18N Commander/UI WinForms/Resources/Icons.resx index 6b0ceae..f4a76ae 100644 --- a/I18N Commander/UI WinForms/Resources/Icons.resx +++ b/I18N Commander/UI WinForms/Resources/Icons.resx @@ -178,4 +178,7 @@ icons8-settings.svg.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + icons8-trash-can-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/I18N Commander/UI WinForms/Resources/icons8-trash-can-512.png b/I18N Commander/UI WinForms/Resources/icons8-trash-can-512.png new file mode 100644 index 0000000000000000000000000000000000000000..ac54a12e5d6e7b3b3fa5f02f4188bbfe178e1ac3 GIT binary patch literal 2285 zcmai0ZCDdm7M@5cC8)Ip1Qgpi(o$QKNdiGKn@CAQNrY$$LBW1VNG4<;$%M>=1nmQq zm8TJ0ZIGh1;0KBbSkS6f5C|4%cTtPWBK3=}Qbp@p+h+x_NZCn3p;q1fF-h)y-}9bx z&pG!@Hp^B;&!H}$0st^aA{NDw-*m_G+_U5-yx{v?0PxHaRGvsAN@HOqrei2nSPH_h z=nNzd0K5o`L7_}X2wDn~it72`-P3lEhN}4BT8@+{H3$(6D&Am3;y0|4D>tMoxhgPX z1(j!kNdX-~C}Z#l*(vA%!tr93=V?{uAtI*MwJ?l z6TLNMOs@E#h9C?u1ewidhB<_R8B-w^m&=8iY>3UKlMFhZr6&{?x*lKRkZ@^;5L{_Q z4FrnmX%0#6uJX>jBe0i1cqxc z!}I|jaWM@)W=N**$tD(s;Ynnv^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