mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
Move code from Main class to Bookmarks class for cleanliness
This commit is contained in:
35
Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs
Normal file
35
Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Wox.Infrastructure;
|
||||||
|
|
||||||
|
namespace Wox.Plugin.BrowserBookmark.Commands
|
||||||
|
{
|
||||||
|
internal static class Bookmarks
|
||||||
|
{
|
||||||
|
internal static bool MatchProgram(Bookmark bookmark, string queryString)
|
||||||
|
{
|
||||||
|
if (StringMatcher.FuzzySearch(queryString, bookmark.Name, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
||||||
|
if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
||||||
|
if (StringMatcher.FuzzySearch(queryString, bookmark.Url, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static List<Bookmark> LoadAllBookmarks()
|
||||||
|
{
|
||||||
|
var allbookmarks = new List<Bookmark>();
|
||||||
|
|
||||||
|
var chromeBookmarks = new ChromeBookmarks();
|
||||||
|
var mozBookmarks = new FirefoxBookmarks();
|
||||||
|
|
||||||
|
//TODO: Let the user select which browser's bookmarks are displayed
|
||||||
|
// Add Firefox bookmarks
|
||||||
|
mozBookmarks.GetBookmarks().ForEach(x => allbookmarks.Add(x));
|
||||||
|
|
||||||
|
// Add Chrome bookmarks
|
||||||
|
chromeBookmarks.GetBookmarks().ForEach(x => allbookmarks.Add(x));
|
||||||
|
|
||||||
|
return allbookmarks.Distinct().ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Wox.Infrastructure;
|
using Wox.Plugin.BrowserBookmark.Commands;
|
||||||
using Wox.Plugin.SharedCommands;
|
using Wox.Plugin.SharedCommands;
|
||||||
|
|
||||||
namespace Wox.Plugin.BrowserBookmark
|
namespace Wox.Plugin.BrowserBookmark
|
||||||
@@ -9,24 +9,13 @@ namespace Wox.Plugin.BrowserBookmark
|
|||||||
{
|
{
|
||||||
private PluginInitContext context;
|
private PluginInitContext context;
|
||||||
|
|
||||||
// TODO: periodically refresh the Cache?
|
|
||||||
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
|
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
// Cache all bookmarks
|
cachedBookmarks = Bookmarks.LoadAllBookmarks();
|
||||||
var chromeBookmarks = new ChromeBookmarks();
|
|
||||||
var mozBookmarks = new FirefoxBookmarks();
|
|
||||||
|
|
||||||
//TODO: Let the user select which browser's bookmarks are displayed
|
|
||||||
// Add Firefox bookmarks
|
|
||||||
cachedBookmarks.AddRange(mozBookmarks.GetBookmarks());
|
|
||||||
// Add Chrome bookmarks
|
|
||||||
cachedBookmarks.AddRange(chromeBookmarks.GetBookmarks());
|
|
||||||
|
|
||||||
cachedBookmarks = cachedBookmarks.Distinct().ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
@@ -41,7 +30,7 @@ namespace Wox.Plugin.BrowserBookmark
|
|||||||
if (!topResults)
|
if (!topResults)
|
||||||
{
|
{
|
||||||
// Since we mixed chrome and firefox bookmarks, we should order them again
|
// Since we mixed chrome and firefox bookmarks, we should order them again
|
||||||
returnList = cachedBookmarks.Where(o => MatchProgram(o, param)).ToList();
|
returnList = cachedBookmarks.Where(o => Bookmarks.MatchProgram(o, param)).ToList();
|
||||||
returnList = returnList.OrderByDescending(o => o.Score).ToList();
|
returnList = returnList.OrderByDescending(o => o.Score).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,14 +48,5 @@ namespace Wox.Plugin.BrowserBookmark
|
|||||||
}
|
}
|
||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool MatchProgram(Bookmark bookmark, string queryString)
|
|
||||||
{
|
|
||||||
if (StringMatcher.FuzzySearch(queryString, bookmark.Name, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
|
||||||
if ( StringMatcher.FuzzySearch(queryString, bookmark.PinyinName, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
|
||||||
if (StringMatcher.FuzzySearch(queryString, bookmark.Url, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user