Databinding for plugin tab + faster image load

This commit is contained in:
bao-qian
2016-05-22 05:30:38 +01:00
parent 708dba6cb1
commit 7056be0870
22 changed files with 286 additions and 274 deletions

View File

@@ -20,7 +20,10 @@ namespace Wox.Infrastructure.Image
{
TopUsedImages[path] = 1;
}
}
public void Cleanup()
{
if (TopUsedImages.Count > MaxCached)
{
var images = TopUsedImages.OrderByDescending(o => o.Value)

View File

@@ -43,6 +43,7 @@ namespace Wox.Infrastructure.Image
public static void Save()
{
_cache.Cleanup();
_storage.Save();
}
@@ -115,11 +116,6 @@ namespace Wox.Infrastructure.Image
var img = Load(i.Key);
if (img != null)
{
// todo happlebao magic
// the image created on other threads can be accessed from main ui thread,
// this line made it possible
// should be changed the Dispatcher.InvokeAsync in the future
img.Freeze();
ImageSources[i.Key] = img;
}
});
@@ -185,9 +181,9 @@ namespace Wox.Infrastructure.Image
path = ErrorIcon;
}
}
ImageSources[path] = image;
_cache.Add(path);
image.Freeze();
}
return image;
}

View File

@@ -1,25 +0,0 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace Wox.Infrastructure.Image
{
public class ImagePathConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || value == DependencyProperty.UnsetValue)
{
return null;
}
var image = ImageLoader.Load(value.ToString());
return image;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}