Skip to content

Commit 7e011b2

Browse files
committed
Add option to show only installed themes
1 parent 9ba3280 commit 7e011b2

File tree

4 files changed

+70
-7
lines changed

4 files changed

+70
-7
lines changed

src/JsonConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class AppConfig : INotifyPropertyChanged
4444
public string lastShuffleTime { get; set; }
4545
public string[] shuffleHistory { get; set; }
4646
public string[] favoriteThemes { get; set; }
47+
public bool showInstalledOnly { get; set; }
4748

4849
// General settings
4950
public string language { get; set; }

src/ThemeDialog.Designer.cs

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ThemeDialog.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,17 +350,24 @@ private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
350350
{
351351
var hitTestInfo = listView1.HitTest(listView1.PointToClient(Cursor.Position));
352352
int itemIndex = hitTestInfo.Item?.Index ?? -1;
353+
string themeId = null;
354+
ThemeConfig theme = null;
353355

354-
if (itemIndex <= 0)
356+
if (itemIndex < 0)
355357
{
356358
e.Cancel = true;
357359
return;
358360
}
361+
else if (itemIndex > 0)
362+
{
363+
themeId = (string)listView1.Items[itemIndex].Tag;
364+
theme = ThemeManager.themeSettings.Find(t => t.themeId == themeId);
365+
}
359366

360-
string themeId = (string)listView1.Items[itemIndex].Tag;
361-
ThemeConfig theme = ThemeManager.themeSettings.Find(t => t.themeId == themeId);
362367
bool isWindowsTheme = themeId == DefaultThemes.GetWindowsTheme()?.themeId;
363-
contextMenuStrip1.Items[1].Enabled = ThemeManager.IsThemeDownloaded(theme) && !isWindowsTheme;
368+
contextMenuStrip1.Items[0].Enabled = itemIndex > 0;
369+
contextMenuStrip1.Items[1].Enabled = theme != null && ThemeManager.IsThemeDownloaded(theme) &&
370+
!isWindowsTheme;
364371

365372
if (JsonConfig.settings.favoriteThemes == null ||
366373
!JsonConfig.settings.favoriteThemes.Contains(themeId))
@@ -372,14 +379,17 @@ private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
372379
contextMenuStrip1.Items[0].Text = _("Remove from favorites");
373380
}
374381

375-
if (ThemeManager.defaultThemes.Contains(themeId) || isWindowsTheme)
382+
if (themeId == null || ThemeManager.defaultThemes.Contains(themeId) || isWindowsTheme)
376383
{
377384
contextMenuStrip1.Items[1].Text = _("Delete");
378385
}
379386
else
380387
{
381388
contextMenuStrip1.Items[1].Text = _("Delete permanently");
382389
}
390+
391+
contextMenuStrip1.Items[3].Text = _("Show only installed themes");
392+
(contextMenuStrip1.Items[3] as ToolStripMenuItem).Checked = JsonConfig.settings.showInstalledOnly;
383393
}
384394

385395
private void favoriteThemeMenuItem_Click(object sender, EventArgs e)
@@ -424,6 +434,11 @@ private void deleteThemeMenuItem_Click(object sender, EventArgs e)
424434
}
425435
}
426436

437+
private void showInstalledMenuItem_Click(object sender, EventArgs e)
438+
{
439+
ThemeDialogUtils.ToggleShowInstalledOnly(listView1, !JsonConfig.settings.showInstalledOnly);
440+
}
441+
427442
private void OnDownloadDialogClosed(object sender, FormClosedEventArgs e)
428443
{
429444
if (e.CloseReason == CloseReason.UserClosing &&

src/ThemeDialogUtils.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ internal static void LoadThemes(List<ThemeConfig> themes, ListView listView, The
7272

7373
foreach (ThemeConfig theme in themes.ToList())
7474
{
75+
if (JsonConfig.settings.showInstalledOnly && !ThemeManager.IsThemeDownloaded(theme))
76+
{
77+
continue;
78+
}
79+
7580
try
7681
{
7782
using (Image thumbnailImage = ThemeThumbLoader.GetThumbnailImage(theme, thumbnailSize, true))
@@ -221,5 +226,31 @@ internal static bool DeleteTheme(ThemeConfig theme, ListView listView, int itemI
221226

222227
return result == DialogResult.Yes;
223228
}
229+
230+
internal static void ToggleShowInstalledOnly(ListView listView, bool newValue)
231+
{
232+
JsonConfig.settings.showInstalledOnly = newValue;
233+
if (newValue)
234+
{
235+
foreach (ListViewItem item in listView.Items)
236+
{
237+
if (item.Index > 0)
238+
{
239+
string themeId = (string)item.Tag;
240+
ThemeConfig theme = ThemeManager.themeSettings.Find(t => t.themeId == themeId);
241+
if (!ThemeManager.IsThemeDownloaded(theme))
242+
{
243+
listView.Items.Remove(item);
244+
listView.LargeImageList.Images[item.ImageIndex].Dispose();
245+
}
246+
}
247+
}
248+
}
249+
else
250+
{
251+
LoadThemes(ThemeManager.themeSettings.Where(theme => !ThemeManager.IsThemeDownloaded(theme)).ToList(),
252+
listView, new ThemeLoadOpts());
253+
}
254+
}
224255
}
225256
}

0 commit comments

Comments
 (0)