Skip to content

Commit

Permalink
Add option to show only installed themes
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed Apr 23, 2024
1 parent 9ba3280 commit 7e011b2
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/JsonConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
20 changes: 18 additions & 2 deletions src/ThemeDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions src/ThemeDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -372,14 +379,17 @@ 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");
}
else
{
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)
Expand Down Expand Up @@ -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 &&
Expand Down
31 changes: 31 additions & 0 deletions src/ThemeDialogUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ internal static void LoadThemes(List<ThemeConfig> 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))
Expand Down Expand Up @@ -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());
}
}
}
}

0 comments on commit 7e011b2

Please sign in to comment.