Skip to content

Commit

Permalink
Wait to cache thumbnails after theme dialog finishes loading
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed May 6, 2020
1 parent fb71d7d commit beafa44
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/ImportDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ private void ImportNext()
else
{
ThemeManager.importMode = false;
this.Invoke(new Action(() => this.Close()));
this.Invoke(new Action(() =>
{
label1.Text = _("Generating thumbnails, please wait...");
this.Close();
}));
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/ThemeDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ private void LoadImportedThemes(List<ThemeConfig> themes, ImportDialog importDia
}));
}

ThemeThumbLoader.CacheThumbnails(imageListView1.Items);
importDialog.thumbnailsLoaded = true;
this.Invoke(new Action(() => importDialog.Close()));
});
Expand Down Expand Up @@ -324,6 +325,8 @@ private void ThemeDialog_Load(object sender, EventArgs e)
imageListView1.EnsureVisible(focusItem.Index);
}));
}

ThemeThumbLoader.CacheThumbnails(imageListView1.Items);
}));
}

Expand Down
23 changes: 20 additions & 3 deletions src/ThemeThumbLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace WinDynamicDesktop
{
class ThemeThumbLoader
{
private static List<string> outdatedThemeIds = new List<string>();

public static Size GetThumbnailSize(System.Windows.Forms.Control control)
{
int scaledWidth;
Expand Down Expand Up @@ -71,7 +73,6 @@ public static Image GetThumbnailImage(ThemeConfig theme, Size size, bool useCach
else
{
cachedImage.Dispose();
File.Delete(thumbnailPath);
}
}
else if (ThemeManager.defaultThemes.Contains(theme.themeId))
Expand All @@ -96,10 +97,26 @@ public static Image GetThumbnailImage(ThemeConfig theme, Size size, bool useCach
g.DrawImage(bmp1, 0, 0, new Rectangle(0, 0, bmp1.Width / 2, bmp1.Height), GraphicsUnit.Pixel);
}

bmp2.Save(thumbnailPath, ImageFormat.Png);

outdatedThemeIds.Add(theme.themeId);
return bmp2;
}
}

public static void CacheThumbnails(Manina.Windows.Forms.ImageListView.ImageListViewItemCollection items)
{
foreach (Manina.Windows.Forms.ImageListViewItem item in items.Skip(1))
{
string themeId = (string)item.Tag;

if (outdatedThemeIds.Contains(themeId))
{
ThemeConfig theme = ThemeManager.themeSettings.Find(t => t.themeId == themeId);
string thumbnailPath = Path.Combine("themes", themeId, "thumbnail.png");

item.ThumbnailImage.Save(thumbnailPath, ImageFormat.Png);
outdatedThemeIds.Remove(themeId);
}
}
}
}
}

0 comments on commit beafa44

Please sign in to comment.