2019-08-06 18:36:28 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-10-06 09:55:57 +08:00
|
|
|
|
using Wox.Plugin.BrowserBookmark.Commands;
|
2019-08-06 20:23:41 +08:00
|
|
|
|
using Wox.Plugin.SharedCommands;
|
2019-08-06 18:36:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Wox.Plugin.BrowserBookmark
|
|
|
|
|
{
|
2019-10-07 23:08:06 +08:00
|
|
|
|
public class Main : IPlugin, IReloadable, IPluginI18n
|
2019-08-06 18:36:28 +08:00
|
|
|
|
{
|
|
|
|
|
private PluginInitContext context;
|
2019-10-06 09:55:57 +08:00
|
|
|
|
|
2019-08-06 18:36:28 +08:00
|
|
|
|
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
|
|
|
|
|
|
|
|
|
|
public void Init(PluginInitContext context)
|
|
|
|
|
{
|
|
|
|
|
this.context = context;
|
|
|
|
|
|
2019-10-06 09:55:57 +08:00
|
|
|
|
cachedBookmarks = Bookmarks.LoadAllBookmarks();
|
2019-08-06 18:36:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Result> Query(Query query)
|
|
|
|
|
{
|
|
|
|
|
string param = query.GetAllRemainingParameter().TrimStart();
|
|
|
|
|
|
|
|
|
|
// Should top results be returned? (true if no search parameters have been passed)
|
|
|
|
|
var topResults = string.IsNullOrEmpty(param);
|
|
|
|
|
|
|
|
|
|
var returnList = cachedBookmarks;
|
|
|
|
|
|
|
|
|
|
if (!topResults)
|
|
|
|
|
{
|
2019-09-29 12:30:33 +08:00
|
|
|
|
// Since we mixed chrome and firefox bookmarks, we should order them again
|
2019-10-06 09:55:57 +08:00
|
|
|
|
returnList = cachedBookmarks.Where(o => Bookmarks.MatchProgram(o, param)).ToList();
|
2019-08-06 18:36:28 +08:00
|
|
|
|
returnList = returnList.OrderByDescending(o => o.Score).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return returnList.Select(c => new Result()
|
|
|
|
|
{
|
|
|
|
|
Title = c.Name,
|
2019-10-06 12:39:12 +08:00
|
|
|
|
SubTitle = c.Url,
|
2019-08-06 18:36:28 +08:00
|
|
|
|
IcoPath = @"Images\bookmark.png",
|
|
|
|
|
Score = 5,
|
|
|
|
|
Action = (e) =>
|
|
|
|
|
{
|
|
|
|
|
context.API.HideApp();
|
2019-08-06 20:23:41 +08:00
|
|
|
|
c.Url.NewBrowserWindow("");
|
2019-08-06 18:36:28 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
2019-10-06 09:58:36 +08:00
|
|
|
|
|
|
|
|
|
public void ReloadData()
|
|
|
|
|
{
|
|
|
|
|
cachedBookmarks.Clear();
|
|
|
|
|
|
|
|
|
|
cachedBookmarks = Bookmarks.LoadAllBookmarks();
|
|
|
|
|
}
|
2019-10-07 23:08:06 +08:00
|
|
|
|
|
|
|
|
|
public string GetTranslatedPluginTitle()
|
|
|
|
|
{
|
|
|
|
|
return context.API.GetTranslation("wox_plugin_browserbookmark_plugin_name");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetTranslatedPluginDescription()
|
|
|
|
|
{
|
|
|
|
|
return context.API.GetTranslation("wox_plugin_browserbookmark_plugin_description");
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-06 18:36:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|