2020-07-21 04:40:44 +00:00
|
|
|
using System.IO;
|
2016-06-20 23:14:32 +00:00
|
|
|
using System.Windows.Media;
|
2016-05-03 20:18:26 +00:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Newtonsoft.Json;
|
2020-04-21 09:12:17 +00:00
|
|
|
using Flow.Launcher.Infrastructure.Image;
|
2020-07-21 22:17:18 +00:00
|
|
|
using Flow.Launcher.Infrastructure;
|
|
|
|
|
using System.Reflection;
|
2015-01-05 14:41:17 +00:00
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
namespace Flow.Launcher.Plugin.WebSearch
|
2014-01-29 14:44:57 +00:00
|
|
|
{
|
2016-06-20 23:14:32 +00:00
|
|
|
public class SearchSource : BaseModel
|
2014-01-29 14:44:57 +00:00
|
|
|
{
|
|
|
|
|
public string Title { get; set; }
|
2015-11-04 22:49:40 +00:00
|
|
|
public string ActionKeyword { get; set; }
|
2016-05-03 20:18:26 +00:00
|
|
|
|
|
|
|
|
[NotNull]
|
2020-07-21 22:17:18 +00:00
|
|
|
public string Icon { get; set; } = "web_search.png";
|
|
|
|
|
|
|
|
|
|
private string iconPath;
|
2016-05-05 15:21:35 +00:00
|
|
|
|
2016-05-03 20:18:26 +00:00
|
|
|
/// <summary>
|
2020-07-21 04:40:44 +00:00
|
|
|
/// Default icons are placed in Images directory in the app location.
|
|
|
|
|
/// Custom icons are placed in the user data directory
|
2016-05-03 20:18:26 +00:00
|
|
|
/// </summary>
|
|
|
|
|
[NotNull]
|
2020-07-21 04:40:44 +00:00
|
|
|
public string IconPath
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(iconPath))
|
2020-07-21 22:17:18 +00:00
|
|
|
{
|
|
|
|
|
var pluginDirectorys = Directory.GetParent(Assembly.GetExecutingAssembly().Location.NonNull()).ToString();
|
|
|
|
|
|
|
|
|
|
var imagesDirectory = Path.Combine(pluginDirectorys, "Images");
|
|
|
|
|
|
|
|
|
|
return Path.Combine(imagesDirectory, Icon);
|
|
|
|
|
}
|
2020-07-21 04:40:44 +00:00
|
|
|
|
|
|
|
|
return iconPath;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
iconPath = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 23:14:32 +00:00
|
|
|
[JsonIgnore]
|
|
|
|
|
public ImageSource Image => ImageLoader.Load(IconPath);
|
2016-05-03 20:18:26 +00:00
|
|
|
|
2020-07-22 10:35:56 +00:00
|
|
|
internal void NotifyImageChange() => OnPropertyChanged(nameof(Image));
|
|
|
|
|
|
2014-01-29 14:44:57 +00:00
|
|
|
public string Url { get; set; }
|
|
|
|
|
public bool Enabled { get; set; }
|
2016-06-20 23:14:32 +00:00
|
|
|
|
|
|
|
|
public SearchSource DeepCopy()
|
|
|
|
|
{
|
|
|
|
|
var webSearch = new SearchSource
|
|
|
|
|
{
|
|
|
|
|
Title = string.Copy(Title),
|
|
|
|
|
ActionKeyword = string.Copy(ActionKeyword),
|
|
|
|
|
Url = string.Copy(Url),
|
|
|
|
|
Icon = string.Copy(Icon),
|
2020-07-21 22:17:18 +00:00
|
|
|
IconPath = string.Copy(IconPath),
|
2016-06-20 23:14:32 +00:00
|
|
|
Enabled = Enabled
|
|
|
|
|
};
|
|
|
|
|
return webSearch;
|
|
|
|
|
}
|
2014-01-29 14:44:57 +00:00
|
|
|
}
|
|
|
|
|
}
|