diff --git a/src/JsonConfig.cs b/src/JsonConfig.cs index 121f5ae..70cc763 100644 --- a/src/JsonConfig.cs +++ b/src/JsonConfig.cs @@ -44,6 +44,7 @@ public class AppConfig : INotifyPropertyChanged public string lastShuffleTime { get; set; } public string[] shuffleHistory { get; set; } public string[] favoriteThemes { get; set; } + public bool showInstalledOnly { get; set; } // General settings public string language { get; set; } diff --git a/src/ThemeDialog.Designer.cs b/src/ThemeDialog.Designer.cs index 66cbb49..c22f442 100644 --- a/src/ThemeDialog.Designer.cs +++ b/src/ThemeDialog.Designer.cs @@ -43,6 +43,8 @@ private void InitializeComponent() toolStrip1 = new System.Windows.Forms.ToolStrip(); displayComboBox = new System.Windows.Forms.ToolStripComboBox(); meatballButton = new System.Windows.Forms.ToolStripDropDownButton(); + toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + showInstalledMenuItem = new System.Windows.Forms.ToolStripMenuItem(); contextMenuStrip1.SuspendLayout(); toolStrip1.SuspendLayout(); SuspendLayout(); @@ -106,10 +108,10 @@ private void InitializeComponent() // contextMenuStrip1 // contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); - contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { favoriteThemeMenuItem, deleteThemeMenuItem }); + contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { favoriteThemeMenuItem, deleteThemeMenuItem, toolStripSeparator1, showInstalledMenuItem }); contextMenuStrip1.Name = "contextMenuStrip1"; contextMenuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System; - contextMenuStrip1.Size = new System.Drawing.Size(181, 48); + contextMenuStrip1.Size = new System.Drawing.Size(181, 98); contextMenuStrip1.Opening += contextMenuStrip1_Opening; // // favoriteThemeMenuItem @@ -192,6 +194,18 @@ private void InitializeComponent() meatballButton.Text = "…"; meatballButton.ToolTipText = "See More"; // + // toolStripSeparator1 + // + toolStripSeparator1.Name = "toolStripSeparator1"; + toolStripSeparator1.Size = new System.Drawing.Size(177, 6); + // + // showInstalledMenuItem + // + showInstalledMenuItem.Name = "showInstalledMenuItem"; + showInstalledMenuItem.Size = new System.Drawing.Size(180, 22); + showInstalledMenuItem.Text = "toolStripMenuItem3"; + showInstalledMenuItem.Click += showInstalledMenuItem_Click; + // // ThemeDialog // AcceptButton = applyButton; @@ -236,5 +250,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolStrip toolStrip1; private System.Windows.Forms.ToolStripComboBox displayComboBox; private System.Windows.Forms.ToolStripDropDownButton meatballButton; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.ToolStripMenuItem showInstalledMenuItem; } } \ No newline at end of file diff --git a/src/ThemeDialog.cs b/src/ThemeDialog.cs index 9e82228..3af5651 100644 --- a/src/ThemeDialog.cs +++ b/src/ThemeDialog.cs @@ -350,17 +350,24 @@ private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) { var hitTestInfo = listView1.HitTest(listView1.PointToClient(Cursor.Position)); int itemIndex = hitTestInfo.Item?.Index ?? -1; + string themeId = null; + ThemeConfig theme = null; - if (itemIndex <= 0) + if (itemIndex < 0) { e.Cancel = true; return; } + else if (itemIndex > 0) + { + themeId = (string)listView1.Items[itemIndex].Tag; + theme = ThemeManager.themeSettings.Find(t => t.themeId == themeId); + } - string themeId = (string)listView1.Items[itemIndex].Tag; - ThemeConfig theme = ThemeManager.themeSettings.Find(t => t.themeId == themeId); bool isWindowsTheme = themeId == DefaultThemes.GetWindowsTheme()?.themeId; - contextMenuStrip1.Items[1].Enabled = ThemeManager.IsThemeDownloaded(theme) && !isWindowsTheme; + contextMenuStrip1.Items[0].Enabled = itemIndex > 0; + contextMenuStrip1.Items[1].Enabled = theme != null && ThemeManager.IsThemeDownloaded(theme) && + !isWindowsTheme; if (JsonConfig.settings.favoriteThemes == null || !JsonConfig.settings.favoriteThemes.Contains(themeId)) @@ -372,7 +379,7 @@ private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) contextMenuStrip1.Items[0].Text = _("Remove from favorites"); } - if (ThemeManager.defaultThemes.Contains(themeId) || isWindowsTheme) + if (themeId == null || ThemeManager.defaultThemes.Contains(themeId) || isWindowsTheme) { contextMenuStrip1.Items[1].Text = _("Delete"); } @@ -380,6 +387,9 @@ private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) { contextMenuStrip1.Items[1].Text = _("Delete permanently"); } + + contextMenuStrip1.Items[3].Text = _("Show only installed themes"); + (contextMenuStrip1.Items[3] as ToolStripMenuItem).Checked = JsonConfig.settings.showInstalledOnly; } private void favoriteThemeMenuItem_Click(object sender, EventArgs e) @@ -424,6 +434,11 @@ private void deleteThemeMenuItem_Click(object sender, EventArgs e) } } + private void showInstalledMenuItem_Click(object sender, EventArgs e) + { + ThemeDialogUtils.ToggleShowInstalledOnly(listView1, !JsonConfig.settings.showInstalledOnly); + } + private void OnDownloadDialogClosed(object sender, FormClosedEventArgs e) { if (e.CloseReason == CloseReason.UserClosing && diff --git a/src/ThemeDialogUtils.cs b/src/ThemeDialogUtils.cs index f8769d2..831f101 100644 --- a/src/ThemeDialogUtils.cs +++ b/src/ThemeDialogUtils.cs @@ -72,6 +72,11 @@ internal static void LoadThemes(List themes, ListView listView, The foreach (ThemeConfig theme in themes.ToList()) { + if (JsonConfig.settings.showInstalledOnly && !ThemeManager.IsThemeDownloaded(theme)) + { + continue; + } + try { using (Image thumbnailImage = ThemeThumbLoader.GetThumbnailImage(theme, thumbnailSize, true)) @@ -221,5 +226,31 @@ internal static bool DeleteTheme(ThemeConfig theme, ListView listView, int itemI return result == DialogResult.Yes; } + + internal static void ToggleShowInstalledOnly(ListView listView, bool newValue) + { + JsonConfig.settings.showInstalledOnly = newValue; + if (newValue) + { + foreach (ListViewItem item in listView.Items) + { + if (item.Index > 0) + { + string themeId = (string)item.Tag; + ThemeConfig theme = ThemeManager.themeSettings.Find(t => t.themeId == themeId); + if (!ThemeManager.IsThemeDownloaded(theme)) + { + listView.Items.Remove(item); + listView.LargeImageList.Images[item.ImageIndex].Dispose(); + } + } + } + } + else + { + LoadThemes(ThemeManager.themeSettings.Where(theme => !ThemeManager.IsThemeDownloaded(theme)).ToList(), + listView, new ThemeLoadOpts()); + } + } } }