Merge branch 'dev' into add_dedicated_programplugin_logger

This commit is contained in:
Jeremy Wu 2019-10-27 12:23:16 +11:00
commit 140e2a026e
14 changed files with 60 additions and 33 deletions

View file

@ -8,5 +8,6 @@
"Language":"csharp",
"Website":"https://github.com/Wox-launcher/Wox",
"ExecuteFileName":"HelloWorldCSharp.dll",
"IcoPath":"app.png"
"IcoPath":"app.png",
"Disabled": true
}

View file

@ -8,9 +8,9 @@ namespace Wox.Plugin.BrowserBookmark.Commands
{
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;
if (StringMatcher.FuzzySearch(queryString, bookmark.Name).IsSearchPrecisionScoreMet()) return true;
if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName).IsSearchPrecisionScoreMet()) return true;
if (StringMatcher.FuzzySearch(queryString, bookmark.Url).IsSearchPrecisionScoreMet()) return true;
return false;
}

View file

@ -8,5 +8,6 @@
"Language":"csharp",
"Website":"http://www.wox.one",
"IcoPath":"Images\\find.png",
"ExecuteFileName":"Wox.Plugin.Everything.dll"
"ExecuteFileName":"Wox.Plugin.Everything.dll",
"Disabled": true
}

View file

@ -30,6 +30,8 @@ namespace Wox.Plugin.Program
_settings.ProgramSuffixes = tbSuffixes.Text.Split(Settings.SuffixSeperator);
string msg = context.API.GetTranslation("wox_plugin_program_update_file_suffixes");
MessageBox.Show(msg);
DialogResult = true;
}
}
}

View file

@ -102,8 +102,11 @@ namespace Wox.Plugin.Program.Views
private void BtnProgramSuffixes_OnClick(object sender, RoutedEventArgs e)
{
ProgramSuffixes p = new ProgramSuffixes(context, _settings);
p.ShowDialog();
var p = new ProgramSuffixes(context, _settings);
if (p.ShowDialog() ?? false)
{
ReIndexing();
}
}
private void programSourceView_DragEnter(object sender, DragEventArgs e)

View file

@ -135,7 +135,7 @@ namespace Wox.Core.Plugin
var rawQuery = string.Join(Query.TermSeperater, terms);
var actionKeyword = string.Empty;
var search = rawQuery;
List<string> actionParameters = terms.ToList();
var actionParameters = terms.ToList();
if (terms.Length == 0) return null;
if (NonGlobalPlugins.ContainsKey(terms[0]) &&
!Settings.Plugins[NonGlobalPlugins[terms[0]].Metadata.ID].Disabled)

View file

@ -16,7 +16,7 @@ namespace Wox.Infrastructure
public static FuzzyMatcher Create(string query)
{
return new FuzzyMatcher(query, new MatchOption());
return new FuzzyMatcher(query, StringMatcher.DefaultMatchOption);
}
public static FuzzyMatcher Create(string query, MatchOption opt)

View file

@ -8,6 +8,8 @@ namespace Wox.Infrastructure
{
public static class StringMatcher
{
public static MatchOption DefaultMatchOption = new MatchOption();
public static string UserSettingSearchPrecision { get; set; }
[Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")]
@ -15,7 +17,7 @@ namespace Wox.Infrastructure
{
if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(target))
{
return FuzzySearch(target, source, new MatchOption()).Score;
return FuzzySearch(target, source, DefaultMatchOption).Score;
}
else
{
@ -26,12 +28,12 @@ namespace Wox.Infrastructure
[Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")]
public static bool IsMatch(string source, string target)
{
return FuzzySearch(target, source, new MatchOption()).Score > 0;
return FuzzySearch(target, source, DefaultMatchOption).Score > 0;
}
public static MatchResult FuzzySearch(string query, string stringToCompare)
{
return FuzzySearch(query, stringToCompare, new MatchOption());
return FuzzySearch(query, stringToCompare, DefaultMatchOption);
}
/// <summary>
@ -41,7 +43,7 @@ namespace Wox.Infrastructure
{
if (string.IsNullOrEmpty(stringToCompare) || string.IsNullOrEmpty(query)) return new MatchResult { Success = false };
query.Trim();
query = query.Trim();
var len = stringToCompare.Length;
var compareString = opt.IgnoreCase ? stringToCompare.ToLower() : stringToCompare;
@ -98,9 +100,9 @@ namespace Wox.Infrastructure
var score = 100 * (query.Length + 1) / ((1 + firstIndex) + (matchLen + 1));
//a match with less characters assigning more weights
if (stringToCompare.Length - query.Length < 5)
score = score + 20;
score += 20;
else if (stringToCompare.Length - query.Length < 10)
score = score + 10;
score += 10;
return score;
}
@ -139,10 +141,10 @@ namespace Wox.Infrastructure
{
var combination = Alphabet.PinyinComination(source);
var pinyinScore = combination
.Select(pinyin => FuzzySearch(target, string.Join("", pinyin), new MatchOption()).Score)
.Select(pinyin => FuzzySearch(target, string.Join("", pinyin)).Score)
.Max();
var acronymScore = combination.Select(Alphabet.Acronym)
.Select(pinyin => FuzzySearch(target, pinyin, new MatchOption()).Score)
.Select(pinyin => FuzzySearch(target, pinyin).Score)
.Max();
var score = Math.Max(pinyinScore, acronymScore);
return score;
@ -163,8 +165,9 @@ namespace Wox.Infrastructure
{
public bool Success { get; set; }
public int Score { get; set; }
/// <summary>
/// hightlight string
/// highlight string
/// </summary>
public string Value { get; set; }
}

View file

@ -29,7 +29,7 @@ namespace Wox.Infrastructure.UserSettings
ID = metadata.ID,
Name = metadata.Name,
ActionKeywords = metadata.ActionKeywords,
Disabled = false
Disabled = metadata.Disabled
};
}
}

View file

@ -66,7 +66,7 @@ namespace Wox.Infrastructure.UserSettings
}
}
public bool LeaveCmdOpen { get; set; }
public bool HideWhenDeactive { get; set; }
public bool HideWhenDeactive { get; set; } = true;
public bool RememberLastLaunchLocation { get; set; }
public bool IgnoreHotkeysOnFullscreen { get; set; }

View file

@ -6,6 +6,19 @@ namespace Wox.Plugin
{
public class Query
{
internal Query() { }
/// <summary>
/// to allow unit tests for plug ins
/// </summary>
public Query(string rawQuery, string search, string[] terms, string actionKeyword = "")
{
Search = search;
RawQuery = rawQuery;
Terms = terms;
ActionKeyword = actionKeyword;
}
/// <summary>
/// Raw query, this includes action keyword if it has
/// We didn't recommend use this property directly. You should always use Search property.

View file

@ -110,6 +110,6 @@ namespace Wox.Plugin
/// <summary>
/// Plugin ID that generate this result
/// </summary>
public string PluginID { get; set; }
public string PluginID { get; internal set; }
}
}

View file

@ -55,7 +55,7 @@ namespace Wox.Test
results.Add(new Result
{
Title = str,
Score = StringMatcher.FuzzySearch("inst", str, new MatchOption()).Score
Score = StringMatcher.FuzzySearch("inst", str).Score
});
}
@ -72,7 +72,7 @@ namespace Wox.Test
{
var compareString = "Can have rum only in my glass";
var scoreResult = StringMatcher.FuzzySearch(searchString, compareString, new MatchOption()).Score;
var scoreResult = StringMatcher.FuzzySearch(searchString, compareString).Score;
Assert.True(scoreResult == 0);
}
@ -92,7 +92,7 @@ namespace Wox.Test
results.Add(new Result
{
Title = str,
Score = StringMatcher.FuzzySearch(searchTerm, str, new MatchOption()).Score
Score = StringMatcher.FuzzySearch(searchTerm, str).Score
});
}
@ -135,7 +135,7 @@ namespace Wox.Test
results.Add(new Result
{
Title = str,
Score = StringMatcher.FuzzySearch(searchTerm, str, new MatchOption()).Score
Score = StringMatcher.FuzzySearch(searchTerm, str).Score
});
}
@ -173,7 +173,7 @@ namespace Wox.Test
{
var expectedPrecisionString = (StringMatcher.SearchPrecisionScore)expectedPrecisionScore;
StringMatcher.UserSettingSearchPrecision = expectedPrecisionString.ToString();
var matchResult = StringMatcher.FuzzySearch(queryString, compareString, new MatchOption());
var matchResult = StringMatcher.FuzzySearch(queryString, compareString);
Debug.WriteLine("");
Debug.WriteLine("###############################################");

View file

@ -96,7 +96,7 @@ namespace Wox.ViewModel
{
EscCommand = new RelayCommand(_ =>
{
if (!ResultsSelected())
if (!SelectedIsFromQueryResults())
{
SelectedResults = Results;
}
@ -153,17 +153,21 @@ namespace Wox.ViewModel
MainWindowVisibility = Visibility.Collapsed;
}
if (ResultsSelected())
if (SelectedIsFromQueryResults())
{
_userSelectedRecord.Add(result);
_history.Add(result.OriginQuery.RawQuery);
}
else
{
SelectedResults = Results;
}
}
});
LoadContextMenuCommand = new RelayCommand(_ =>
{
if (ResultsSelected())
if (SelectedIsFromQueryResults())
{
SelectedResults = ContextMenu;
}
@ -175,7 +179,7 @@ namespace Wox.ViewModel
LoadHistoryCommand = new RelayCommand(_ =>
{
if (ResultsSelected())
if (SelectedIsFromQueryResults())
{
SelectedResults = History;
History.SelectedIndex = _history.Items.Count - 1;
@ -226,7 +230,7 @@ namespace Wox.ViewModel
set
{
_selectedResults = value;
if (ResultsSelected())
if (SelectedIsFromQueryResults())
{
ContextMenu.Visbility = Visibility.Collapsed;
History.Visbility = Visibility.Collapsed;
@ -273,7 +277,7 @@ namespace Wox.ViewModel
public void Query()
{
if (ResultsSelected())
if (SelectedIsFromQueryResults())
{
QueryResults();
}
@ -487,7 +491,7 @@ namespace Wox.ViewModel
return menu;
}
private bool ResultsSelected()
private bool SelectedIsFromQueryResults()
{
var selected = SelectedResults == Results;
return selected;