80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows.Media.Imaging;
|
|
using JD.Asset.Types.Map;
|
|
using Plume.Icons;
|
|
using Plume.Interfaces.WPF.Documents;
|
|
using Quik.API;
|
|
using Quik.Details;
|
|
using JD.Quik.Helpers;
|
|
|
|
namespace JD.Quik.Providers
|
|
{
|
|
public class MapQuikItem : QuikItem
|
|
{
|
|
private readonly Map _map;
|
|
private readonly IDocumentManager _documentManager;
|
|
|
|
public MapQuikItem(Map map, IDocumentManager documentManager)
|
|
{
|
|
_map = map;
|
|
_documentManager = documentManager;
|
|
}
|
|
|
|
public override string Name => _map.Name;
|
|
|
|
public override string Hint => "Map";
|
|
|
|
public override QuikImage Image
|
|
{
|
|
get
|
|
{
|
|
var imageUrl = _map.CoverImages.Select(x => x.FilePath).FirstOrDefault(x => x.Contains("Cover_Phone")) ?? _map.CoverImages.Select(x => x.FilePath).FirstOrDefault();
|
|
if (imageUrl != null && File.Exists(imageUrl))
|
|
{
|
|
var image = new BitmapImage(new Uri(imageUrl, UriKind.Absolute))
|
|
{
|
|
DecodePixelHeight = 24,
|
|
DecodePixelWidth = 24,
|
|
};
|
|
return new BitmapToQuikImage(image);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public override IEnumerable<IQuikItem> Children
|
|
{
|
|
get
|
|
{
|
|
yield return new QuikItem
|
|
{
|
|
Name = "Open containing folder",
|
|
ActivateAction = options => Process.Start(_map.Folder),
|
|
Image = new BitmapToQuikImage(new Icon(StandardIcon.OpenFolder).ToImageSource(16, 16) as BitmapImage)
|
|
};
|
|
foreach (var documentBinding in _documentManager.DocumentBindings)
|
|
{
|
|
foreach (var extension in documentBinding.FileFilter.Extensions)
|
|
{
|
|
var files = Directory.EnumerateFiles(_map.Folder, extension, SearchOption.AllDirectories);
|
|
foreach (var file in files)
|
|
{
|
|
yield return new QuikItem
|
|
{
|
|
Name = Path.GetFileName(file),
|
|
Hint = file,
|
|
Image = new BitmapToQuikImage(ImageHelpers.GetImageForFilePath(file)),
|
|
ActivateAction = options => _documentManager.CreateFromFile(file)
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|